-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add OAuth2 ClientCredentials flow support #1013
Conversation
108a493
to
4462ff8
Compare
class OpenAPISecurityScheme: | ||
def __init__(self, security_scheme: SecurityScheme): | ||
self.security_scheme = security_scheme | ||
|
||
self.parse() | ||
|
||
def parse(self) -> None: | ||
self.type = self.security_scheme["type"] | ||
self.description = self.security_scheme.get("description", "") | ||
|
||
if self.type == "oauth2": | ||
self.flows: OAuth2Flows = self.security_scheme.get("flows") | ||
client_credentials: ClientCredentials = self.flows["clientCredentials"] | ||
if client_credentials: | ||
self.flow_type: t.Optional[str] = "clientCredentials" | ||
self.token_url: str = client_credentials["tokenUrl"] | ||
self.scopes: OAuth2FlowsScopes = list(client_credentials.get("scopes").keys()) | ||
|
||
if self.type == "http": | ||
self.scheme = self.security_scheme["scheme"] |
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 all kind of hazy.
Can you explain why the logic didn't fit in the authproviderbase call method?
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.
Does the AuthProviderBase need to understand how to properly parse an OpenAPI SecurityScheme for each of those authentication methods? I was thinking on abstracting this to AuthProviderBase and exposes the minimum needed to choose which method to call.
I accidentally used wrong credentials and got the following traceback:
|
Thanks @dkliban. We worked on that case and CLI is handling it fine now. Thanks. |
Many of the changes made, and we're going to accept the result and refactor "soon"
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.
Review suggests we really want to refactor how AuthBase deals with handling/prioritizing multiple-arbitrary-schemes. However, that will have to wait. The PR in its current state answers a pressing existing need, and is "correct enough" to be useful. Approving, while recognizing this is truly "tech preview" and we are likely going to make significant changes in this code flow.
This work adds OAuth2 ClientCredentials grant flow support to the Pulp-CLI.
Closes #926
We're going with the short-term pragmatic approach, and reserving the right to completely refactor this whole area soon
As test strategy, we have two options here:
1- Use the
responses
lib (link here), a library that mocks therequests
lib. With that we can intercept calls to a IdP mock to obtain a token, and then intercept the call to a Pulp instance and assert that there's theaccess_token
being used with theAuthorization
header.2- Mock an IdP using nginx rewrite module to return a 200 Ok message with an appropriate response to the token request. Together we need to configure the pulp server to provide the proper URL to allow pulp-cli to request a token and test an authorized operation on it.