-
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
Actually check for auth flows in provider enrollment #2601
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"fmt" | ||
"net/http" | ||
"net/url" | ||
"slices" | ||
|
||
"github.com/google/uuid" | ||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
|
@@ -39,6 +40,7 @@ import ( | |
"github.com/stacklok/minder/internal/db" | ||
"github.com/stacklok/minder/internal/engine" | ||
"github.com/stacklok/minder/internal/logger" | ||
"github.com/stacklok/minder/internal/util" | ||
pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" | ||
) | ||
|
||
|
@@ -56,6 +58,11 @@ func (s *Server) GetAuthorizationURL(ctx context.Context, | |
return nil, providerError(err) | ||
} | ||
|
||
if !slices.Contains(provider.AuthFlows, db.AuthorizationFlowOauth2AuthorizationCodeFlow) { | ||
return nil, util.UserVisibleError(codes.InvalidArgument, | ||
"provider does not support authorization code flow") | ||
} | ||
|
||
// Configure tracing | ||
// trace call to AuthCodeURL | ||
span := trace.SpanFromContext(ctx) | ||
|
@@ -288,6 +295,11 @@ func (s *Server) StoreProviderToken(ctx context.Context, | |
return nil, providerError(err) | ||
} | ||
|
||
if !slices.Contains(provider.AuthFlows, db.AuthorizationFlowUserInput) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think With that said, I'd prefer to have it return something (maybe a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a separate PR with that refactor? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on it. |
||
return nil, util.UserVisibleError(codes.InvalidArgument, | ||
"provider does not support token enrollment") | ||
} | ||
|
||
// validate token | ||
err = auth.ValidateProviderToken(ctx, provider.Name, in.AccessToken) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
package v1 | ||
|
||
import "slices" | ||
|
||
// ToString returns the string representation of the ProviderType | ||
func (provt ProviderType) ToString() string { | ||
return enumToStringViaDescriptor(provt.Descriptor(), provt.Number()) | ||
|
@@ -23,3 +25,8 @@ func (provt ProviderType) ToString() string { | |
func (a AuthorizationFlow) ToString() string { | ||
return enumToStringViaDescriptor(a.Descriptor(), a.Number()) | ||
} | ||
|
||
// SupportsAuthFlow returns true if the provider supports the given auth flow | ||
func (p *Provider) SupportsAuthFlow(flow AuthorizationFlow) bool { | ||
return slices.Contains(p.GetAuthFlows(), flow) | ||
} | ||
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where this is used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is in the CLI |
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.
Can we use
provider.SupportsAuthFlow(...)
here? I think this is the same comment jakub had down below.Ideally,
provider
returned fromgetProviderFromRequestOrDefault
would be either an actual Provider instance, or at least a ProviderBuilder instance. But that's a larger refactor.