-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add GCP Authentication Support #752
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
Merged
yuzisun
merged 12 commits into
envoyproxy:main
from
sukumargaonkar:gcp-auth-implementaion
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
58a0187
api: implement GCP OIDC token rotator for Workload Identity Federation
sukumargaonkar a89edc2
update gcp-url generation and add tests
sukumargaonkar ac7a21d
test: add unit test for NewAzureTokenRotator implementation
sukumargaonkar 289a82f
test: improve test coverage
sukumargaonkar 12f0ac2
Fix lint
sukumargaonkar 7a1f61e
test: add error handling tests for GCP OIDC token rotator
sukumargaonkar 920fb33
test: add error handling tests for GatewayController methods
sukumargaonkar a7dcb4d
rename GCPGemini to GCPVertexAI and address PR comments
sukumargaonkar 330cf44
Merge remote-tracking branch 'upstream/main' into gcp-auth-implementaion
sukumargaonkar 4722692
add proxy support for gcp auth
sukumargaonkar 65e2230
Merge remote-tracking branch 'upstream/main' into gcp-auth-implementaion
sukumargaonkar 4473a55
docs: enhance comments for GenerateContentRequest fields in gcp.go
sukumargaonkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright Envoy AI Gateway Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // The full text of the Apache license is available in the LICENSE file at | ||
| // the root of the repo. | ||
|
|
||
| package gcp | ||
|
|
||
| import "google.golang.org/genai" | ||
|
|
||
| type GenerateContentRequest struct { | ||
| // Contains the multipart content of a message. | ||
| // | ||
| // https://github.com/googleapis/go-genai/blob/6a8184fcaf8bf15f0c566616a7b356560309be9b/types.go#L858 | ||
| Contents []genai.Content `json:"contents"` | ||
| // Tool details of a tool that the model may use to generate a response. | ||
| // | ||
| // https://github.com/googleapis/go-genai/blob/6a8184fcaf8bf15f0c566616a7b356560309be9b/types.go#L1406 | ||
| Tools []genai.Tool `json:"tools"` | ||
| // Optional. Tool config. | ||
| // This config is shared for all tools provided in the request. | ||
| // | ||
| // https://github.com/googleapis/go-genai/blob/6a8184fcaf8bf15f0c566616a7b356560309be9b/types.go#L1466 | ||
| ToolConfig *genai.ToolConfig `json:"tool_config,omitempty"` | ||
| // Optional. Generation config. | ||
| // You can find API default values and more details at https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#generationconfig | ||
| // and https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/content-generation-parameters. | ||
| GenerationConfig *genai.GenerationConfig `json:"generation_config,omitempty"` | ||
| // Optional. Instructions for the model to steer it toward better performance. | ||
| // For example, "Answer as concisely as possible" or "Don't use technical | ||
| // terms in your response". | ||
| // | ||
| // https://github.com/googleapis/go-genai/blob/6a8184fcaf8bf15f0c566616a7b356560309be9b/types.go#L858 | ||
| SystemInstruction *genai.Content `json:"system_instruction,omitempty"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,26 @@ func (c *BackendSecurityPolicyController) rotateCredential(ctx context.Context, | |
| if err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
| case aigv1a1.BackendSecurityPolicyTypeGCPCredentials: | ||
| if err = validateGCPCredentialsParams(bsp.Spec.GCPCredentials); err != nil { | ||
| return ctrl.Result{}, fmt.Errorf("invalid GCP credentials configuration: %w", err) | ||
| } | ||
|
|
||
| // For GCP, OIDC is currently the only supported authentication method. | ||
| // If additional methods are added, validate that OIDC is used before calling getBackendSecurityPolicyAuthOIDC. | ||
| oidc := getBackendSecurityPolicyAuthOIDC(bsp.Spec) | ||
yuzisun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Create the OIDC token provider that will be used to get tokens from the OIDC provider. | ||
| var oidcProvider tokenprovider.TokenProvider | ||
| oidcProvider, err = tokenprovider.NewOidcTokenProvider(ctx, c.client, oidc) | ||
| if err != nil { | ||
| return ctrl.Result{}, fmt.Errorf("failed to initialize OIDC provider: %w", err) | ||
| } | ||
| rotator, err = rotators.NewGCPOIDCTokenRotator(c.client, c.logger, *bsp, preRotationWindow, oidcProvider) | ||
| if err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
|
|
||
| default: | ||
| err = fmt.Errorf("backend security type %s does not support OIDC token exchange", bsp.Spec.Type) | ||
| c.logger.Error(err, "unsupported backend security type", "namespace", bsp.Namespace, "name", bsp.Name) | ||
|
|
@@ -207,6 +227,10 @@ func getBackendSecurityPolicyAuthOIDC(spec aigv1a1.BackendSecurityPolicySpec) *e | |
| return &spec.AzureCredentials.OIDCExchangeToken.OIDC | ||
| } | ||
| return nil | ||
| case aigv1a1.BackendSecurityPolicyTypeGCPCredentials: | ||
yuzisun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if spec.GCPCredentials != nil { | ||
| return &spec.GCPCredentials.WorkLoadIdentityFederationConfig.WorkloadIdentityProvider.OIDCProvider.OIDC | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
@@ -238,3 +262,28 @@ func (c *BackendSecurityPolicyController) updateBackendSecurityPolicyStatus(ctx | |
| c.logger.Error(err, "failed to update BackendSecurityPolicy status") | ||
| } | ||
| } | ||
|
|
||
| func validateGCPCredentialsParams(gcpCreds *aigv1a1.BackendSecurityPolicyGCPCredentials) error { | ||
|
Member
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. shouldn't all of this condition be part of k8s CEL validation? (If so, it's redundant) |
||
| if gcpCreds == nil { | ||
| return fmt.Errorf("invalid backend security policy, gcp credentials cannot be nil") | ||
| } | ||
| if gcpCreds.ProjectName == "" { | ||
| return fmt.Errorf("invalid GCP credentials configuration: projectName cannot be empty") | ||
| } | ||
| if gcpCreds.Region == "" { | ||
| return fmt.Errorf("invalid GCP credentials configuration: region cannot be empty") | ||
| } | ||
|
|
||
| wifConfig := gcpCreds.WorkLoadIdentityFederationConfig | ||
| if wifConfig.ProjectID == "" { | ||
| return fmt.Errorf("invalid GCP Workload Identity Federation configuration: projectID cannot be empty") | ||
| } | ||
| if wifConfig.WorkloadIdentityPoolName == "" { | ||
| return fmt.Errorf("invalid GCP Workload Identity Federation configuration: workloadIdentityPoolName cannot be empty") | ||
| } | ||
| if wifConfig.WorkloadIdentityProvider.Name == "" { | ||
| return fmt.Errorf("invalid GCP Workload Identity Federation configuration: workloadIdentityProvider.name cannot be empty") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.