Skip to content

Commit 1ebd027

Browse files
committed
Merge branch 'release/0.3.1'
2 parents 471b294 + 1c021b6 commit 1ebd027

24 files changed

Lines changed: 284 additions & 187 deletions

File tree

applications/accounts/Docker-compose.yaml

Lines changed: 0 additions & 40 deletions
This file was deleted.

applications/jupyterhub/deploy/templates/hub/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ spec:
3939
- name: config
4040
configMap:
4141
name: hub-config
42+
- name: cloudharness-allvalues
43+
configMap:
44+
name: cloudharness-allvalues
4245
- name: secret
4346
secret:
4447
{{- if .Values.apps.jupyterhub.hub.existingSecret }}
@@ -114,6 +117,9 @@ spec:
114117
name: config
115118
- mountPath: /etc/jupyterhub/secret/
116119
name: secret
120+
- name: cloudharness-allvalues
121+
mountPath: /opt/cloudharness/resources/allvalues.yaml
122+
subPath: allvalues.yaml
117123
{{- if .Values.apps.jupyterhub.hub.extraVolumeMounts }}
118124
{{- .Values.apps.jupyterhub.hub.extraVolumeMounts | toYaml | trimSuffix "\n" | nindent 12 }}
119125
{{- end }}

applications/jupyterhub/src/chauthenticator/chauthenticator/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tornado import gen
66
from traitlets import Bool
77
from jupyterhub.utils import url_path_join
8-
from .utils import get_keycloak_data
8+
from cloudharness.auth import AuthClient
99

1010
class CloudHarnessAuthenticateHandler(BaseHandler):
1111
"""
@@ -34,8 +34,8 @@ def get(self):
3434
self.redirect('/hub/logout')
3535

3636
accessToken = accessToken.value
37-
keycloak_id, keycloak_data = get_keycloak_data(accessToken)
38-
username = keycloak_id
37+
user_data = AuthClient.decode_token(accessToken)
38+
username = user_data['sub']
3939
raw_user = self.user_from_username(username)
4040
self.set_login_cookie(raw_user)
4141
user = yield gen.maybe_future(self.process_user(raw_user, self))

applications/jupyterhub/src/chauthenticator/chauthenticator/utils.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

applications/sentry/deploy/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
harness:
2-
subdomain: errormonitor
2+
subdomain: sentry
33
secured: false
44
service:
55
auto: true

libraries/cloudharness-common/cloudharness/auth/keycloak/__init__.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
from cloudharness.utils.config import CloudharnessConfig as conf, ALLVALUES_PATH
1313
from cloudharness.applications import get_configuration
1414
accounts_app = get_configuration('accounts')
15-
AUTH_REALM = env.get_auth_realm()
15+
AUTH_REALM = conf.get_namespace()
1616
SERVER_URL = accounts_app.get_service_address() + '/auth/'
1717
if not os.environ.get('KUBERNETES_SERVICE_HOST', None):
1818
# running outside kubernetes
1919
SERVER_URL = accounts_app.get_public_address() + '/auth/'
2020
USER = accounts_app.admin['user']
2121
PASSWD = accounts_app.admin['pass']
2222
except:
23-
log.error("Error on cloudharness configuration. Check that the values file %s your deployment.", ALLVALUES_PATH, exc_info=True)
23+
log.error("Error on cloudharness configuration. Check that the values file %s your deployment.",
24+
ALLVALUES_PATH, exc_info=True)
2425

2526

2627
def with_refreshtoken(func):
@@ -32,6 +33,7 @@ def wrapper(self, *args, **kwargs):
3233
return func(self, *args, **kwargs)
3334
return wrapper
3435

36+
3537
def decode_token(token):
3638
"""
3739
Check and retrieve authentication information from custom bearer token.
@@ -51,17 +53,18 @@ def decode_token(token):
5153

5254

5355
class AuthClient():
54-
__public_key=None
56+
__public_key = None
5557

5658
@staticmethod
5759
def _get_keycloak_user_id():
5860
bearer = request.headers.get('Authorization', None)
5961
current_app.logger.debug(f'Bearer: {bearer}')
6062
if not bearer or bearer == 'Bearer undefined':
6163
if current_app.config['ENV'] == 'development':
62-
# when development and not using KeyCloak (no current user),
64+
# when development and not using KeyCloak (no current user),
6365
# get id from X-Current-User-Id header
64-
keycloak_user_id = request.headers.get("X-Current-User-Id", "-1")
66+
keycloak_user_id = request.headers.get(
67+
"X-Current-User-Id", "-1")
6568
else:
6669
keycloak_user_id = "-1" # No authorization --> no user
6770
else:
@@ -98,7 +101,7 @@ def get_admin_client(self):
98101

99102
def refresh_token(self):
100103
try:
101-
self._admin_client.refresh_token()
104+
self._admin_client.refresh_token()
102105
except Exception as e:
103106
# reset the internal admin client to create a new one
104107
self._admin_client = None
@@ -107,10 +110,13 @@ def refresh_token(self):
107110
@classmethod
108111
def get_public_key(cls):
109112
if not cls.__public_key:
110-
AUTH_PUBLIC_KEY_URL = os.path.join(SERVER_URL, "realms", AUTH_REALM)
113+
AUTH_PUBLIC_KEY_URL = os.path.join(
114+
SERVER_URL, "realms", AUTH_REALM)
111115

112-
KEY = json.loads(requests.get(AUTH_PUBLIC_KEY_URL, verify=False).text)['public_key']
113-
cls.__public_key = b"-----BEGIN PUBLIC KEY-----\n" + str.encode(KEY) + b"\n-----END PUBLIC KEY-----"
116+
KEY = json.loads(requests.get(AUTH_PUBLIC_KEY_URL,
117+
verify=False).text)['public_key']
118+
cls.__public_key = b"-----BEGIN PUBLIC KEY-----\n" + \
119+
str.encode(KEY) + b"\n-----END PUBLIC KEY-----"
114120
return cls.__public_key
115121

116122
@classmethod
@@ -126,8 +132,8 @@ def decode_token(cls, token):
126132
:rtype: dict | None
127133
"""
128134

129-
130-
decoded = jwt.decode(token, cls.get_public_key(), algorithms='RS256', audience='account')
135+
decoded = jwt.decode(token, cls.get_public_key(),
136+
algorithms='RS256', audience='account')
131137
return decoded
132138

133139
@with_refreshtoken
@@ -147,15 +153,15 @@ def get_client(self, client_name):
147153
return client
148154

149155
@with_refreshtoken
150-
def create_client(self,
151-
client_name,
156+
def create_client(self,
157+
client_name,
152158
protocol="openid-connect",
153159
enabled=True,
154160
public=True,
155161
standard_flow_enabled=True,
156162
direct_access_grants_enable=True,
157163
redirect_uris=["*"],
158-
web_origins=["*","+"]):
164+
web_origins=["*", "+"]):
159165
"""
160166
Creates a new KC client
161167
@@ -170,7 +176,7 @@ def create_client(self,
170176
:return: True on success or exception
171177
"""
172178
admin_client = self.get_admin_client()
173-
x= admin_client.create_client({
179+
x = admin_client.create_client({
174180
'id': client_name,
175181
'name': client_name,
176182
'protocol': protocol,
@@ -218,8 +224,10 @@ def get_group(self, group_id, with_members=False):
218224
if with_members:
219225
members = admin_client.get_group_members(group_id)
220226
for user in members:
221-
user.update({'userGroups': admin_client.get_user_groups(user['id'])})
222-
user.update({'realmRoles': admin_client.get_realm_roles_of_user(user['id'])})
227+
user.update(
228+
{'userGroups': admin_client.get_user_groups(user['id'])})
229+
user.update(
230+
{'realmRoles': admin_client.get_realm_roles_of_user(user['id'])})
223231
group.update({'members': members})
224232
return group
225233

@@ -257,8 +265,10 @@ def get_users(self, query=None):
257265
admin_client = self.get_admin_client()
258266
users = []
259267
for user in admin_client.get_users(query=query):
260-
user.update({'userGroups': admin_client.get_user_groups(user['id'])})
261-
user.update({'realmRoles': admin_client.get_realm_roles_of_user(user['id'])})
268+
user.update(
269+
{'userGroups': admin_client.get_user_groups(user['id'])})
270+
user.update(
271+
{'realmRoles': admin_client.get_realm_roles_of_user(user['id'])})
262272
users.append(user)
263273
return users
264274

@@ -280,7 +290,8 @@ def get_user(self, user_id):
280290
admin_client = self.get_admin_client()
281291
user = admin_client.get_user(user_id)
282292
user.update({'userGroups': admin_client.get_user_groups(user_id)})
283-
user.update({'realmRoles': admin_client.get_realm_roles_of_user(user_id)})
293+
user.update(
294+
{'realmRoles': admin_client.get_realm_roles_of_user(user_id)})
284295
return user
285296

286297
@with_refreshtoken
@@ -357,7 +368,8 @@ def user_has_client_role(self, user_id, client_name, role):
357368
:param role: Name of the role
358369
:return: (array RoleRepresentation)
359370
"""
360-
roles = [user_client_role for user_client_role in self.get_user_client_roles(user_id, client_name) if user_client_role['name'] == role]
371+
roles = [user_client_role for user_client_role in self.get_user_client_roles(
372+
user_id, client_name) if user_client_role['name'] == role]
361373
return roles != []
362374

363375
def user_has_realm_role(self, user_id, role):
@@ -368,7 +380,8 @@ def user_has_realm_role(self, user_id, role):
368380
:param role: Name of the role
369381
:return: (array RoleRepresentation)
370382
"""
371-
roles = [user_realm_role for user_realm_role in self.get_user_realm_roles(user_id) if user_realm_role['name'] == role]
383+
roles = [user_realm_role for user_realm_role in self.get_user_realm_roles(
384+
user_id) if user_realm_role['name'] == role]
372385
return roles != []
373386

374387
def current_user_has_client_role(self, client_name, role):

libraries/cloudharness-common/cloudharness/infrastructure/k8s.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
namespace = conf.get_namespace()
2222

2323

24-
25-
26-
27-
2824
# --- Api functions --- `
2925

3026
def get_api_client():
@@ -53,15 +49,13 @@ def create_namespace():
5349
api_instance = kubernetes.client.CoreV1Api(kubernetes.client.ApiClient(get_configuration()))
5450
body = kubernetes.client.V1Namespace(metadata=kubernetes.client.V1ObjectMeta(name=namespace)) # V1Namespace |
5551

56-
5752
try:
5853
api_response = api_instance.create_namespace(body)
5954
except Exception as e:
6055
raise Exception(f"Error creating namespace: {namespace}") from e
6156

6257

63-
64-
def get_objects(group = 'argoproj.io', plural='workflows', status=None, limit=10, continue_token=None, timeout_seconds=3):
58+
def get_objects(group='argoproj.io', plural='workflows', status=None, limit=10, continue_token=None, timeout_seconds=3):
6559
"""https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CustomObjectsApi.md#list_namespaced_custom_object"""
6660
# Notice: field selector doesn't work though advertised, except fot metadata.name and metadata.namespace https://github.com/kubernetes/kubernetes/issues/51046
6761
# The filtering by phase can be obtained through labels: https://github.com/argoproj/argo/issues/496
@@ -77,38 +71,41 @@ def get_object(object_name):
7771
api_instance = kubernetes.client.CustomObjectsApi(kubernetes.client.ApiClient(configuration))
7872
return api_instance.get_namespaced_custom_object(group, version, namespace, plural, object_name)
7973

80-
def get_pod_logs(pod_name, namespace=namespace):
8174

75+
def get_pod_logs(pod_name, namespace=namespace):
8276
try:
8377
return api_instance.read_namespaced_pod_log(name=pod_name, namespace=namespace, container="main")
8478
except kubernetes.client.rest.ApiException as e:
8579
if e.status == 400:
8680
return f"Pod {pod_name} has not emitted logs yet..."
8781
raise Exception(e.status) from e
8882

89-
def get_pod(pod_name, namespace=namespace):
9083

84+
def get_pod(pod_name, namespace=namespace):
9185
try:
9286
return api_instance.read_namespaced_pod(name=pod_name, namespace=namespace)
9387
except kubernetes.client.rest.ApiException as e:
9488
if 404 == e.status:
9589
raise Exception(f"Pod {pod_name} not found")
9690
raise Exception(e.status) from e
9791

92+
9893
def get_pods(namespace=namespace):
9994
try:
100-
return api_instance.list_namespaced_pod( namespace=namespace)
95+
return api_instance.list_namespaced_pod(namespace=namespace)
10196
except kubernetes.client.rest.ApiException as e:
10297
raise Exception("Error retrieving pods") from e
10398

99+
104100
def get_deployments(namespace=namespace):
105101
api_instance = kubernetes.client.AppsV1Api(kubernetes.client.ApiClient(get_configuration()))
106102
try:
107-
return api_instance.list_namespaced_deployment( namespace=namespace)
103+
return api_instance.list_namespaced_deployment(namespace=namespace)
108104
except kubernetes.client.rest.ApiException as e:
109105
raise Exception("Error retrieving deployments") from e
110106

107+
111108
if __name__ == '__main__':
112109
from pprint import pprint
113110

114-
pprint(get_objects())
111+
pprint(get_objects())

0 commit comments

Comments
 (0)