-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(passport-exp): handle expiration edge cases [PXP-9235] #988
Conversation
…ad' into feat/passport-exp
The style in this PR agrees with This formatting comment was generated automatically by a script in uc-cdis/wool. |
Pull Request Test Coverage Report for Build 12229
💛 - Coveralls |
…to fix up unit tests
…ser.username, improve error handling
…ser.username, improve error handling
@@ -46,10 +45,10 @@ | |||
get_google_app_creds, | |||
give_service_account_billing_access_if_necessary, | |||
) | |||
from fence.resources.ga4gh.passports import get_gen3_users_from_ga4gh_passports | |||
from fence.resources.ga4gh.passports import sync_gen3_users_authz_from_ga4gh_passports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more descriptive to show that it's changing database and not just "get"-ing information
@@ -62,15 +61,21 @@ | |||
|
|||
SUPPORTED_PROTOCOLS = ["s3", "http", "ftp", "https", "gs", "az"] | |||
SUPPORTED_ACTIONS = ["upload", "download"] | |||
ANONYMOUS_USER_ID = "anonymous" | |||
ANONYMOUS_USER_ID = "-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fact that the user_id was not an integer was causing downstream validation problems since User.id is int in the database
fence/blueprints/data/indexd.py
Outdated
@@ -517,12 +526,28 @@ def set_acls(self): | |||
else: | |||
raise Unauthorized("This file is not accessible") | |||
|
|||
def check_authz(self, action, user_ids_from_passports=None): | |||
def get_authorized_and_user_id(self, action, user_ids_from_passports=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more descriptive / consistent return for this functionality
@@ -37,76 +39,52 @@ def __init__(self): | |||
) | |||
|
|||
def post_login(self, user=None, token_result=None, id_from_idp=None): | |||
# TODO: I'm not convinced this code should be in post_login. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this file, the goal was to reduce duplication and replace this additional custom logic with the already built sync_gen3_users_authz_from_ga4gh_passports
functionality as much as possible
fence/resources/openid/ras_oauth2.py
Outdated
@@ -270,91 +285,31 @@ def map_iss_sub_pair_to_user(self, issuer, subject_id, username, email): | |||
return iss_sub_pair_to_user.user.username | |||
|
|||
@backoff.on_exception(backoff.expo, Exception, **DEFAULT_BACKOFF_SETTINGS) | |||
def update_user_visas(self, user, pkey_cache, db_session=current_session): | |||
def update_user_authorization(self, user, pkey_cache, db_session=current_session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this file, the goal was to reduce duplication and replace this additional custom logic with the already built sync_gen3_users_authz_from_ga4gh_passports
functionality as much as possible
@@ -210,7 +239,6 @@ def init_syncer( | |||
sync_from_local_yaml_file=None, | |||
arborist=None, | |||
folder=None, | |||
sync_from_visas=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usersync no longer provides the option to sync from visas. This is handled entirely by the access token polling job
fence/sync/passport_sync/ras_sync.py
Outdated
info["tags"] = {"dbgap_role": permission.get("role", "")} | ||
else: | ||
# Remove visas if its invalid or expired | ||
user.ga4gh_visas_v1 = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't mess with db here, handle upstream
@@ -1954,196 +1952,24 @@ def parse_user_visas(self, db_session): | |||
|
|||
return (user_projects, user_info) | |||
|
|||
def _sync_visas(self, sess): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is handled entirely by access token polling and sync_gen3_users_authz_from_ga4gh_passports
now
@@ -221,8 +221,8 @@ def add_visa_manually(db_session, user, rsa_private_key, kid): | |||
"ga4gh_visa_v1": { | |||
"type": "https://ras.nih.gov/visas/v1", | |||
"asserted": int(time.time()), | |||
"value": "https://nig/passport/dbgap", | |||
"source": "https://ncbi/gap", | |||
"value": "https://stsstg.nih.gov/passport/dbgap/v1.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of tests had to change so that the fake visas were actually "valid", since sync_gen3_users_authz_from_ga4gh_passports
validates all the Visas
…in usersync), ensure single visa sync is only updating storage backend and arborist
…mprove handling of IdPs throughout
return self.public_authz | ||
else: | ||
return self.public_acl | ||
|
||
@cached_property | ||
def public_acl(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this for some backwards compatibility
("upload", 5, None, False, "fake conn str", "some user", False, False), | ||
("upload", 5, True, None, "fake conn str", ANONYMOUS_USER_ID, True, False), | ||
("upload", 5, True, None, "fake conn str", ANONYMOUS_USER_ID, False, False), | ||
("download", 5, None, "fake conn str", "some user", False, False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove public_data
as an option, remove duplicate tests, and adjust expected behavior to meet new expectations. See "Breaking Changes" in the PR description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the swagger doc could be updated too?
fence/blueprints/login/ras.py
Outdated
users_from_passports = fence.resources.ga4gh.passports.sync_gen3_users_authz_from_ga4gh_passports( | ||
[passport], | ||
authz_policy_prefix="POST.LOGIN", | ||
pkey_cache=pkey_cache, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried logging in and am getting: NameError: name 'pkey_cache' is not defined
for this line.
PXP-9235
In order to better handle updating/expiration of authorization from Passports, this PR has number of pieces.
Adjusts overall architecture such that:
This PR also adds a variety of refactoring and updating around the above 3 to consolidate code, clarify logic, and fix unit tests.
Relies on uc-cdis/cloud-automation#1806
New Features
Breaking Changes
no_force_sign
query param is provided: Previously Fence would make a decision based off if the data was public andno_force_sign
provided. Fence will now NEVER sign ifno_force_sign
is provided (since the concept of "public" data has been abstracted out of Fence. Data access - public or not - is the sole responsibility of the policy engine). In other words, ifno_force_sign
is provided at the API level, Fence will respect that regardless of whether the resulting URL will actually work. The default Fence behavior should remain the same.Bug Fixes
Improvements
Dependency updates
Deployment changes