Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PXP-6406 Feat/ga4gh scope #799

Merged
merged 6 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions TECHDEBT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Tech debt

### Using 'aud' claim for scopes
- Observed: July 2020
- Impact: (If this tech debt affected your work somehow, add a +1 here with a date and note)
- +1 Zoe 2020 July 15 This is an example of a +1
##### Problem:
Fence puts OAuth2 scopes into the 'aud' claim of access tokens.
##### Why it was done this way:
We don't know.
##### Why this way is problematic:
Per RFC7519 the aud claim [is not meant for scopes](https://tools.ietf.org/html/rfc7519#section-4.1.3).
##### What the solution might be:
GA4GH AAI [already requires](https://github.com/ga4gh/data-security/blob/master/AAI/AAIConnectProfile.md#access_token-issued-by-broker) that a 'scope' claim be included in access tokens issued by Passport Brokers. So as of July 2020 we will put scopes in the 'scope' claim. However, this is in addition to keeping them in the 'aud' claim. Ideally we would only have the scopes in the 'scope' claim.
##### Why we aren't already doing the above:
Fence presently guards several endpoints (e.g. /data, signed urls, SA registration) by checking the scopes in the 'aud' claim of the JWT. This code would need to be changed.
##### Next steps:
Address above.
##### Other notes:
n/a
2 changes: 2 additions & 0 deletions fence/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ USER_ALLOWED_SCOPES:
- "google_credentials"
- "google_service_account"
- "google_link"
- "ga4gh_passport_v1"

# these are the scopes that a browser session can create for a user (very
# similar to USER_ALLOWED_SCOPES, as the session will actually create access_tokens
Expand All @@ -223,6 +224,7 @@ SESSION_ALLOWED_SCOPES:
- "google_credentials"
- "google_service_account"
- "google_link"
- "ga4gh_passport_v1"

# //////////////////////////////////////////////////////////////////////////////////////
# LOGIN
Expand Down
1 change: 1 addition & 0 deletions fence/jwt/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def generate_signed_access_token(
"iat": iat,
"exp": exp,
"jti": jti,
"scope": scopes,
"context": {
"user": {
"name": user.username,
Expand Down
12 changes: 9 additions & 3 deletions fence/resources/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ def get_user_info(current_session, username):
info.update(optional_info)

# Include ga4gh passport visas
# TODO: Respect access token claims (only include if ga4gh_passport_v1 scope present)
encoded_visas = [row.ga4gh_visa for row in user.ga4gh_visas_v1]
info["ga4gh_passport_v1"] = encoded_visas
if not flask.g.access_token:
logger.warning(
"Session token present but no access token found. Unable to check scopes in userinfo; returning."
)
else:
at_scopes = jwt.decode(flask.g.access_token, verify=False).get("scope", "")
if "ga4gh_passport_v1" in at_scopes:
encoded_visas = [row.ga4gh_visa for row in user.ga4gh_visas_v1]
info["ga4gh_passport_v1"] = encoded_visas

return info

Expand Down
1 change: 1 addition & 0 deletions tests/oidc/core/token/test_token_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_access_token_correct_fields(token_response):
"exp",
"iat",
"jti",
"scope",
"context",
"azp",
}
Expand Down