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

Actually check for auth flows in provider enrollment #2601

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Mar 12, 2024

Summary

This modifies the provider enrollment to actually verify that the provider supports the given auth flows before attempting them.

This is enforced both in the CLI and the server.

Closes: #2518

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@JAORMX JAORMX requested a review from a team as a code owner March 12, 2024 12:23
@JAORMX JAORMX marked this pull request as draft March 12, 2024 12:25
@JAORMX JAORMX force-pushed the provider-use-authflows branch from 2f9e950 to 656a54c Compare March 12, 2024 12:32
@JAORMX JAORMX marked this pull request as ready for review March 12, 2024 12:35
@JAORMX JAORMX force-pushed the provider-use-authflows branch from 656a54c to 013aa38 Compare March 12, 2024 12:40
@coveralls
Copy link

Coverage Status

coverage: 38.666% (-0.04%) from 38.701%
when pulling 013aa38 on provider-use-authflows
into af48a2c on main.

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

it would be nice to reuse the utility function but that's a non-blocking comment

@@ -288,6 +295,11 @@ func (s *Server) StoreProviderToken(ctx context.Context,
return nil, providerError(err)
}

if !slices.Contains(provider.AuthFlows, db.AuthorizationFlowUserInput) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not call p.SupportsAuthFlow() here? is it because one is using a protobuf constant and the other a db constant? Since we're using the constant verbatim and not from a variable, could we use the protobuf constant here as well?

Copy link
Member

Choose a reason for hiding this comment

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

I think getProviderFromRequestOrDefault actually returns a db.Provider, not a proto object mentioned in SupportsAuthFlow.

With that said, I'd prefer to have it return something (maybe a ProviderBuilder?) that encapsulates this check more than slices.Contains on a returned database row.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we have a separate PR with that refactor?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with a separate PR if it comes soon and we don't propagate code patters like this over time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on it.

@@ -288,6 +295,11 @@ func (s *Server) StoreProviderToken(ctx context.Context,
return nil, providerError(err)
}

if !slices.Contains(provider.AuthFlows, db.AuthorizationFlowUserInput) {
Copy link
Member

Choose a reason for hiding this comment

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

I think getProviderFromRequestOrDefault actually returns a db.Provider, not a proto object mentioned in SupportsAuthFlow.

With that said, I'd prefer to have it return something (maybe a ProviderBuilder?) that encapsulates this check more than slices.Contains on a returned database row.

@@ -56,6 +58,11 @@ func (s *Server) GetAuthorizationURL(ctx context.Context,
return nil, providerError(err)
}

if !slices.Contains(provider.AuthFlows, db.AuthorizationFlowOauth2AuthorizationCodeFlow) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use provider.SupportsAuthFlow(...) here? I think this is the same comment jakub had down below.

Ideally, provider returned from getProviderFromRequestOrDefault would be either an actual Provider instance, or at least a ProviderBuilder instance. But that's a larger refactor.

Comment on lines +28 to +32

// SupportsAuthFlow returns true if the provider supports the given auth flow
func (p *Provider) SupportsAuthFlow(flow AuthorizationFlow) bool {
return slices.Contains(p.GetAuthFlows(), flow)
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see where this is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in the CLI

@JAORMX JAORMX merged commit e174e74 into main Mar 13, 2024
20 checks passed
@JAORMX JAORMX deleted the provider-use-authflows branch March 13, 2024 07:52
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.

Use suitable enrollment flow based on the provider
4 participants