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

Rework security flow #686

Merged
merged 5 commits into from
Sep 28, 2018
Merged

Rework security flow #686

merged 5 commits into from
Sep 28, 2018

Conversation

cziebuhr
Copy link
Contributor

The PR addresses some issues I had when trying to use connexion for a production-ready product.

  • Use token_info['sub'] instead of token_info['uid'] to better align with RFC7662 (oauth token introspection)
  • x-tokenInfoUrl is only kept for compability reasons. IMHO it's only useful for a small amount of people, because it hardcodes bearer authentication (to the authorization server) and the response format is not standardized. I suggest providing an example instead, how RFC7662 can be used with a custom x-tokenInfoFunc.
  • validate_token_info was not customizable and simply compared two sets of strings.
    In our setup, we want to add more logic, e.g. scope 'ressource' is superior to 'ressource:read'. One can now set a custom scope validator.
  • If security definitons don't match the connexion implementation (only one definition supported), connexion silently ignors ALL definitions and allows full access to the api.
  • Basic authentication / apiKey authentication had to be done manully as function decorator instead of using the security definitions from the swagger definition. Now one can define callbacks similar to x-tokenInfoFunc.
  • Bonus: If both, oauth and basic auth / apiKey is specified for an operation, the new x-basicInfoFunc / x-apikeyInfoFunc also receives the required oauth scopes. This allows using oauth scopes for authorization while using basic auth / apiKey for authentication.

It's not yet fully tested and documentation/examples are not updated yet, but I would like to get some general feedback on that approach.

@cziebuhr cziebuhr mentioned this pull request Sep 18, 2018
@dtkav dtkav requested a review from jmcs September 19, 2018 01:01
@dtkav dtkav force-pushed the dev-2.0 branch 2 times, most recently from b4a794c to 6258264 Compare September 20, 2018 03:36
if not scope_validate_func(required_scopes, token_scopes):
raise OAuthScopeProblem(
description='Provided token doesn\'t have the required scope',
required_scopes=oauth_args[2],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think oauth_args is in scope here.
I think you want required_scopes

@cziebuhr cziebuhr force-pushed the security branch 2 times, most recently from 0b49ed2 to f76dcc3 Compare September 20, 2018 16:04
@spec-first spec-first deleted a comment Sep 20, 2018
@spec-first spec-first deleted a comment Sep 20, 2018
@spec-first spec-first deleted a comment Sep 20, 2018
@spec-first spec-first deleted a comment Sep 20, 2018
@spec-first spec-first deleted a comment Sep 20, 2018
Backward incompatible change!

Instead of connexion.request.user / flask.request.user, use connexion.context['user']
Copy link
Contributor

@jmcs jmcs left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Can you also include some examples of possible customizations in the documentation?

connexion/operations/secure.py Show resolved Hide resolved
@cziebuhr
Copy link
Contributor Author

Do you have any objectives on breaking changes?
Especially the change in FlaskRequestContextProxy. It's not really needed, but aligns better to flasks recommended approach on storing data.
What do you think about keeping/abandoning x-tokenInfoUrl?

I'm currently thinking about creating the verify_* callbacks on api level (instead of creating them for each operation). They only depend on the security_scheme, scope is passed later at call-time.

That would also fix auth_all_paths for openapi 3, which currently uses AbstractAPI.security_definitions, which is only set for swagger 2.

@jmcs
Copy link
Contributor

jmcs commented Sep 27, 2018

Do you have any objectives on breaking changes?

We don't have a hard policy about breaking changes, but 2.0 already includes big backward incompatible changes, and any new breaking change will make it harder for people to migrate.

What do you think about keeping/abandoning x-tokenInfoUrl?

I would keep it with a DeprecationWarning to minimize disruption, and then we can remove it at a later time (what do you thing @hjacobs).

@cziebuhr
Copy link
Contributor Author

Updated documentation and examples.

@cziebuhr cziebuhr force-pushed the security branch 2 times, most recently from 14ff115 to 3257f56 Compare September 27, 2018 15:52
@cziebuhr cziebuhr mentioned this pull request Sep 27, 2018
@spec-first spec-first deleted a comment Sep 27, 2018
@jmcs
Copy link
Contributor

jmcs commented Sep 28, 2018

👍

@spec-first spec-first deleted a comment Sep 28, 2018
@spec-first spec-first deleted a comment Sep 28, 2018
@spec-first spec-first deleted a comment Sep 28, 2018
@cziebuhr
Copy link
Contributor Author

Do you want me to squash again and also add a note about the change in flask.request?

@jmcs
Copy link
Contributor

jmcs commented Sep 28, 2018

@cziebuhr That would be perfect.

@cziebuhr
Copy link
Contributor Author

Done and updated readme.

@jmcs
Copy link
Contributor

jmcs commented Sep 28, 2018

👍

@jmcs jmcs merged commit ed6535e into spec-first:dev-2.0 Sep 28, 2018
@cziebuhr cziebuhr mentioned this pull request Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants