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

feat: implements aws oidc backendSecurityPolicy API #306

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

aabchoo
Copy link
Contributor

@aabchoo aabchoo commented Feb 6, 2025

Commit Message

The PR implements the backendSecurityPolicy API for AWS's OIDC credentials.

Related Issues/PRs (if applicable)

Special notes for reviewers (if applicable)

I've tested the implementation with our SSO (oauth2), and was able to query bedrock.

Checklist (you don't need to keep in your PR description):

  • The PR title follows the same format as the merged PRs.
  • I have read the CONTRIBUTING.md (for first-time contributors).
  • I have made sure that make precommit test passes locally.
  • I have written tests for any new line of code unless there's existing tests that cover the changes.
  • I have updated the documentation accordingly.
  • I am sure the coding style is consistent with the rest of the codebase.

@aabchoo aabchoo added feature go Pull requests that update Go code labels Feb 6, 2025
Signed-off-by: Aaron Choo <[email protected]>
@mathetake
Copy link
Member

I think you are missing two things (not serious):

otherwise, looking good

@aabchoo
Copy link
Contributor Author

aabchoo commented Feb 6, 2025

One scenario I realize that needs to be address is:

  1. OIDC credentials or AWS specific fields are updated
  2. Either or both values are cached/not expired.

We may need to cache the oidc credentials and aws specific fields to compare. Else users will have to wait til expiration time (ie 1 hour for AWS or however long for OIDC)

Comment on lines 48 to 56
for _, backendSecurityPolicy := range backendSecPolicyList.Items {
if isBackendSecurityPolicyAuthOIDC(backendSecurityPolicy.Spec) {
backendSecurityPolicy.Annotations["refresh"] = refreshTime
}
err = b.client.Update(ctx, &backendSecurityPolicy)
if err != nil {
b.logger.Error(err, "failed to trigger refresh for existing backendSecPolicy resource", "name", backendSecurityPolicy.Name)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Signed-off-by: Aaron Choo <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
var backendSecPolicyList aigv1a1.BackendSecurityPolicyList
err = b.client.List(ctx, &backendSecPolicyList)
if err != nil {
b.logger.Error(err, "failed to trigger refresh for existing backendSecPolicy resources")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
b.logger.Error(err, "failed to trigger refresh for existing backendSecPolicy resources")
b.logger.Error(err, "failed to list existing backendSecPolicy resources")

if err != nil {
b.logger.Error(err, "failed to trigger refresh for existing backendSecPolicy resources")
} else {
for _, backendSecurityPolicy := range backendSecPolicyList.Items {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit odd to trigger the reconciliation for all security policies on a single resource reconciliation function. Controller runtime might have a way to resync all the resources periodically.

Copy link
Member

Choose a reason for hiding this comment

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

Controller runtime might have a way to resync all the resources periodically.

ha! if there's a way, then that should be much better

Copy link
Member

Choose a reason for hiding this comment

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

@aabchoo sorry it seems like i was misunderstanding the default behavior

operator-framework/operator-sdk#6035 (comment)

you can delete this all patching stuff!

Copy link
Member

Choose a reason for hiding this comment

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

wait, this is operator-sdk... not sure about controller-runtime (operator-sdk using it under the hood?)

Copy link
Member

Choose a reason for hiding this comment

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

yeah i think this applies to controller-runtime as well, let's delete this startup patching stuff

Comment on lines +92 to +106
func isBackendSecurityPolicyAuthOIDC(spec aigv1a1.BackendSecurityPolicySpec) bool {
if spec.AWSCredentials != nil {
return spec.AWSCredentials.OIDCExchangeToken != nil
}
return false
}

func getBackendSecurityPolicyAuthOIDC(spec aigv1a1.BackendSecurityPolicySpec) *egv1a1.OIDC {
if isBackendSecurityPolicyAuthOIDC(spec) {
if spec.AWSCredentials.OIDCExchangeToken != nil {
return &spec.AWSCredentials.OIDCExchangeToken.OIDC
}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

think carefully.... you won't need these two functions ...

)

// ClientCredentialsProvider implements the standard OAuth2 client credentials flow
type ClientCredentialsProvider struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Client credential is a grant type for oauth not provider

return nil, fmt.Errorf("failed to create request: %w", err)
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the oauth client library instead of the raw curl request?

}

// OIDCMetadata represents the OpenID Connect provider metadata
type OIDCMetadata struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

"sigs.k8s.io/controller-runtime/pkg/client"
)

// BaseProvider implements common OAuth functionality
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear to me for the relationship between BaseProvider and OidcProvider. If it is common OAuth functions it is better to be defined as util functions.

internal/controller/oauth/types.go Outdated Show resolved Hide resolved
internal/controller/oauth/oidc_provider.go Outdated Show resolved Hide resolved
internal/controller/oauth/oidc_provider.go Outdated Show resolved Hide resolved
internal/controller/sink.go Outdated Show resolved Hide resolved
}

// Provider defines the interface for OAuth token providers
type Provider interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

@missBerg I think the Provider interface is confusing, from the code we are not actually implementing different oauth2/oidc providers like GitHub, google etc if that was what this is meant. It is implementing the OIDC protocol itself.

Signed-off-by: Dan Sun <[email protected]>
Signed-off-by: Dan Sun <[email protected]>
Signed-off-by: Dan Sun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants