Skip to content

Commit 8dd7c9c

Browse files
Merge pull request #111 from tapis-project/rsp-tacc
Rsp tacc
2 parents 9659d73 + 0e65779 commit 8dd7c9c

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

service/auth.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def authentication():
6060
raise common_errors.ResourceError("The endpoint and HTTP method combination "
6161
"are not available from this service.")
6262

63+
6364
# the metadata endpoint is publicly available
6465
if '/v3/oauth2/.well-known/' in request.url_rule.rule:
6566
logger.debug(".well-known endpoint; request is allowed to be made unauthenticated.")
@@ -82,7 +83,7 @@ def authentication():
8283
# first, make sure this request is for a tenant served by this authenticator
8384
if g.request_tenant_id not in conf.tenants:
8485
raise common_errors.PermissionsError(f"The request is for a tenant ({g.request_tenant_id}) that is not "
85-
f"served by this authenticator.")
86+
f"served by this authenticator.")
8687
# we only want to honor tokens from THIS authenticator; i.e., not some other authenticator. therefore, we need
8788
# to check that the tenant_id associated with the token (g.tenant_id) is the same as THIS authenticator's tenant
8889
# id;
@@ -91,28 +92,28 @@ def authentication():
9192
f"and tenant was {conf.service_tenant_id}")
9293
return True
9394
logger.debug(f"request token does not represent THIS authenticator: token username: {g.username};"
94-
f" request tenant: {g.tenant_id}. Now checking for tenant admin...")
95+
f" request tenant: {g.tenant_id}. Now checking for tenant admin...")
9596
# all other service accounts are not allowed to update authenticator
9697
if g.account_type == 'service':
9798
raise common_errors.PermissionsError("Not authorized -- service accounts are not allowed to access the"
98-
"authenticator admin endpoints.")
99+
"authenticator admin endpoints.")
99100
# sanity check -- the request tenant id should be the same as the token tenant id in the remaining cases because
100101
# they are all user tokens
101102
if not g.request_tenant_id == g.tenant_id:
102103
logger.error(f"program error -- g.request_tenant_id: {g.request_tenant_id} not equal to "
103-
f"g.tenant_id: {g.tenant_id} even though account type was user!")
104+
f"g.tenant_id: {g.tenant_id} even though account type was user!")
104105
raise common_errors.ServiceConfigError(f"Unexpected program error checking permissions. The tenant id of"
105-
f"the request ({g.request_tenant_id}) did not match the tenant id "
106-
f"of the access token ({g.tenant_id}). Please contact server "
107-
f"administrators.")
106+
f"the request ({g.request_tenant_id}) did not match the tenant id "
107+
f"of the access token ({g.tenant_id}). Please contact server "
108+
f"administrators.")
108109
# check SK for tenant admin --
109110
try:
110111
rsp = t.sk.isAdmin(tenant=g.tenant_id, user=g.username)
111112
except Exception as e:
112113
logger.error(f"Got exception trying to check tenant admin role for tenant: {g.tenant_id} "
113-
f"and user: {g.username}; exception: {e}")
114+
f"and user: {g.username}; exception: {e}")
114115
raise common_errors.PermissionsError("Could not check tenant admin role with SK; this role is required for "
115-
"accessing the authenticator admin endpoints.")
116+
"accessing the authenticator admin endpoints.")
116117
try:
117118
if rsp.isAuthorized:
118119
logger.info(f"user {g.username} had tenant admin role for tenant {g.tenant_id}; allowing request.")
@@ -121,14 +122,14 @@ def authentication():
121122
logger.info(f"user {g.username} DID NOT have tenant admin role for tenant {g.tenant_id}; "
122123
f"NOT allowing request.")
123124
raise common_errors.PermissionsError("Permission denied -- Tenant admin role required for accessing "
124-
"the authenticator admin endpoints.")
125+
"the authenticator admin endpoints.")
125126
except Exception as e:
126127
logger.error(f"got exception trying to check isAuthorized property from isAdmin() call to SK."
127-
f"username: {g.username}; tenant: {g.tenant_id}; rsp: {rsp}; e: {e}")
128+
f"username: {g.username}; tenant: {g.tenant_id}; rsp: {rsp}; e: {e}")
128129
logger.info(f"user {g.username} DID NOT have tenant admin role for tenant {g.tenant_id}; "
129130
f"NOT allowing request.")
130131
raise common_errors.PermissionsError("Permission denied -- Tenant admin role required for accessing the "
131-
"authenticator admin endpoints.")
132+
"authenticator admin endpoints.")
132133

133134
# no credentials required on the authorize, login and oa2 extension pages
134135
if '/v3/oauth2/authorize' in request.url_rule.rule or '/v3/oauth2/login' in request.url_rule.rule \
@@ -144,7 +145,7 @@ def authentication():
144145
# make sure this request is for a tenant served by this authenticator
145146
if g.request_tenant_id not in conf.tenants:
146147
raise common_errors.PermissionsError(f"The request is for a tenant ({g.request_tenant_id}) that is not "
147-
f"served by this authenticator.")
148+
f"served by this authenticator.")
148149
return True
149150

150151
# the profiles endpoints always use standard Tapis Token auth -
@@ -156,7 +157,7 @@ def authentication():
156157
# make sure this request is for a tenant served by this authenticator
157158
if g.request_tenant_id not in conf.tenants:
158159
raise common_errors.PermissionsError(f"The request is for a tenant ({g.request_tenant_id}) that is not "
159-
f"served by this authenticator.")
160+
f"served by this authenticator.")
160161
return True
161162

162163
# the clients endpoints need to accept both standard Tapis Token auth and basic auth,
@@ -244,7 +245,7 @@ def authentication():
244245
# make sure this request is for a tenant served by this authenticator
245246
if g.request_tenant_id not in conf.tenants:
246247
raise common_errors.PermissionsError(f"The request is for a tenant ({g.request_tenant_id}) that is not "
247-
f"served by this authenticator.")
248+
f"served by this authenticator.")
248249
return True
249250

250251
# Special v3->v2 token generation endpoint.

service/controllers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,17 @@ def get(self):
397397
pem_key = tenant.public_key
398398
key = jwk.JWK.from_pem(pem_key.encode('utf-8'))
399399
jwk_json = key.export(as_dict=True)
400+
# check for required values:
401+
if 'alg' not in jwk_json.keys():
402+
jwk_json['alg'] = 'RS256'
403+
if 'typ' not in jwk_json.keys():
404+
jwk_json['typ'] = 'JWT'
405+
# NOTE 2025.3.28 kprice -- these values can be hard coded since they are also hard coded in tokens. If these values ever change in tokens we'll need to update this block.
400406

401407
json_response = {
402408
'keys': [jwk_json]
403409
}
404-
return json_response #utils.ok(result=metadata, msg='OAuth OIDC metadata retrieved successfully.')
410+
return jsonify(json_response) #utils.ok(result=metadata, msg='OAuth OIDC metadata retrieved successfully.')
405411

406412

407413
# ---------------------------------
@@ -459,7 +465,6 @@ def check_client(use_session=False):
459465
logout()
460466
raise errors.ResourceError("Required query parameter client_id missing.")
461467
# make sure the client exists and the redirect_uri matches
462-
logger.debug(f"checking for client with id: {client_id} in tenant {tenant_id}")
463468
client = Client.query.filter_by(tenant_id=tenant_id, client_id=client_id).first()
464469
if not client:
465470
logout()
@@ -1405,6 +1410,7 @@ def _handle_tokens_request(request, oidc=False):
14051410
client = Client.query.filter_by(tenant_id=tenant_id, client_id=client_id, client_key=client_key).first()
14061411
if not client:
14071412
# todo -- remove session
1413+
logger.debug(f'Client with id {client_id} and key {client_key} not found on tenant {tenant_id}.')
14081414
raise errors.ResourceError(msg=f'Invalid client credentials: {client_id}, {client_key}. '
14091415
f'session: {session}')
14101416

service/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ def __init__(self, form):
870870
self.redirect_uri = form.get('redirect_uri')
871871
self.code = form.get('code')
872872
self.refresh_token = form.get('refresh_token')
873+
self.client_id = form.get('client_id')
874+
self.client_key = form.get('client_key') or form.get('client_secret')
873875

874876

875877
class Token(object):
@@ -913,7 +915,7 @@ def get_derived_values(cls, data):
913915
result['code'] = getattr(data, 'code', None)
914916
# device code grant:
915917
result['client_id'] = getattr(data, 'client_id', None)
916-
result['client_key'] = getattr(data, 'client_key', None)
918+
result['client_key'] = getattr(data, 'client_key', None) or getattr(data, 'client_secret', None)
917919
result['device_code'] = getattr(data, 'device_code', None)
918920
# refresh token:
919921
result['refresh_token'] = getattr(data, 'refresh_token', None)

0 commit comments

Comments
 (0)