Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

SSO discovery revisited #1080

Merged
merged 1 commit into from
May 21, 2018
Merged

SSO discovery revisited #1080

merged 1 commit into from
May 21, 2018

Conversation

jcdyer
Copy link

@jcdyer jcdyer commented May 14, 2018

Make SSO provider discovery use the same endpoint as the existing request. Gate unprivileged rquests with a setting. Revises work done in #1047.

JIRA tickets: Fixes OC-4285

Discussions: See OC-4285

Dependencies: None

Screenshots:

Sandbox URL: TBD - sandbox is being provisioned.

Merge deadline: ?

Testing instructions:

  1. Set up a user (username1) with TPA providers.
  2. Enable the ALLOW_UNPRIVILEGED_SSO_PROVIDER_QUERY setting in lms.env.json.
  3. Log in as some other user (username2)
  4. Request /api/third_party_auth/v0/users/username1
  5. See that the providers were returned, but that remote_id was excluded from the response.

Author notes and concerns:

  1. This removes the ability to query by email, since that wasn't part of the old endpoint. It could be added back.
  2. It also changes the response format, to match the existing endpoint.

Reviewers

FYI: @bradenmacdonald

Settings

ALLOW_UNPRIVILEGED_SSO_PROVIDER_QUERY: true

"""
Only throttle unauthenticated requests.
"""
if view.is_unprivileged_query(request, view.kwargs[u'username']):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the throttle should be in place to privileged queries as well? The issue I see right now is that a someone can just create a regular user account and get past the throttle. So this should either check for staff users or throttle all queries

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to mess to much with existing queries. The current definition of an "unprivileged" query is one where a non-staff user is requesting information about someone else, or an unauthenticated user is requesting any information. The primary purpose of the throttle is to keep people from using this endpoint to scrape information about a broad number of users. The scenario you present would allow the user to request information about themselves all day long, but they would still be throttled trying to get everyone else's information. I think a general-purpose throttle on api usage is not what we need here, and would be better implemented as part of a general site policy.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough! I think I misunderstood something here. Your approach seems entirely reasonable.

lms/envs/aws.py Outdated
@@ -668,7 +668,7 @@
ORA2_FILE_PREFIX = ENV_TOKENS.get("ORA2_FILE_PREFIX", ORA2_FILE_PREFIX)

##### ACCOUNT LOCKOUT DEFAULT PARAMETERS #####
MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = ENV_TOKENS.get("MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED", 5)
MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = ENV_TOKENS.https://www.google.com/l?q=logging+service&oq=logging+service&aqs=chrome..69i57j0l5.7484j1j4&sourceid=chrome&ie=UTF-8get("MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED", 5)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems accidental

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. My middle mouse button does double duty as paster and trackpoint scroll, so sometimes it pastes things when I'm trying to scroll. Glad it was just a google search. :D

"""
Return True if a non-superuser requests information about another user.
"""
if request.user.username != username:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also need adjustment to check if the request user email matches the requested email.

@jcdyer jcdyer force-pushed the cliff/sso-discovery-revisited branch from f1bc614 to 58a65fc Compare May 16, 2018 21:10
@jcdyer
Copy link
Author

jcdyer commented May 17, 2018

@xitij2000 This is ready for another review.

Copy link

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Once the issues are addressed.

with patch.object(ThirdPartyAuthProviderApiPermission, 'has_permission', return_value=token_permission):
response = self.client.get(url)
self.assertEqual(response.status_code, expect)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you removed these tests on purpose? Is that needed?

@@ -142,7 +142,9 @@ def is_unprivileged_query(self, request, username):
"""
Return True if a non-superuser requests information about another user.
"""
if request.user.username != username:
# AnonymousUser does not have an email attribute, so fall back to something
# that will never comapre equal to username.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comapre -> compare

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.



PROVIDER_PATTERN = r'(?P<provider_id>[\w.+-]+)(?:\:(?P<idp_slug>[\w.+-]+))?'

urlpatterns = patterns(
'',
url(r'^v0/users/(?P<identifier>[^/]+)/providers/$', ProviderView.as_view(), name='third_party_auth_providers_api'),
url(
r'^v0/users/{username_pattern}$'.format(username_pattern=settings.USERNAME_PATTERN),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to support email pattern here as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is covered by the existing pattern. Note that @, ., and + are all included:

From lms/envs/common.py

USERNAME_REGEX_PARTIAL = r'[\w .@_+-]+'
USERNAME_PATTERN = r'(?P<username>{regex})'.format(regex=USERNAME_REGEX_PARTIAL)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I thought it was configurable, but it doesn't seem to be, so I guess it's OK.

@jcdyer
Copy link
Author

jcdyer commented May 20, 2018

Issues addressed. Tests are running again.

@jcdyer jcdyer force-pushed the cliff/sso-discovery-revisited branch from abd7b54 to 1e7e7f0 Compare May 20, 2018 17:48
@jcdyer jcdyer force-pushed the cliff/sso-discovery-revisited branch from a43daf8 to 1e7e7f0 Compare May 20, 2018 17:57
@xitij2000
Copy link

@jcdyer I think there is just one very minor PEP8 fix left.

@jcdyer jcdyer force-pushed the cliff/sso-discovery-revisited branch from 1e7e7f0 to 90f0394 Compare May 21, 2018 00:46
@jcdyer
Copy link
Author

jcdyer commented May 21, 2018

Fixed and squashed. Will merge after CI finishes.

@jcdyer jcdyer merged commit 5dc4c93 into integration May 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants