-
Notifications
You must be signed in to change notification settings - Fork 204
api: add GCP OIDC auth support in BackendSecurityPolicies #635
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
Changes from all commits
bd5edf3
90121fb
6c7df97
355ad5a
ebc5147
f541e98
40b1477
f7e2634
2414542
f7d5192
c538a45
e101a82
e851bcc
7263be3
622f5f5
3001321
c4208b4
831b6d2
04b7c08
2ae31ec
fa5d02d
2756c32
a4e725c
700dc73
687d29c
a48254b
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 |
|---|---|---|
|
|
@@ -414,7 +414,7 @@ type AIServiceBackendSpec struct { | |
| type VersionedAPISchema struct { | ||
| // Name is the name of the API schema of the AIGatewayRoute or AIServiceBackend. | ||
| // | ||
| // +kubebuilder:validation:Enum=OpenAI;AWSBedrock;AzureOpenAI | ||
| // +kubebuilder:validation:Enum=OpenAI;AWSBedrock;AzureOpenAI;GCPVertexAI;GCPAnthropic | ||
| Name APISchema `json:"name"` | ||
|
|
||
| // Version is the version of the API schema. | ||
|
|
@@ -450,6 +450,17 @@ const ( | |
| // | ||
| // https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#api-specs | ||
| APISchemaAzureOpenAI APISchema = "AzureOpenAI" | ||
| // APISchemaGCPVertexAI is the schema followed by Gemini models hosted on GCP's Vertex AI platform. | ||
| // Note: Using this schema requires a BackendSecurityPolicy to be configured and attached, | ||
| // as the transformation will use the gcp-region and project-name from the BackendSecurityPolicy. | ||
| // | ||
| // https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/generateContent?hl=en | ||
| APISchemaGCPVertexAI APISchema = "GCPVertexAI" | ||
| // APISchemaGCPAnthropic is the schema followed by Anthropic models hosted on GCP's Vertex AI platform. | ||
| // This is majorly the Anthropic API with some GCP specific parameters as described in below URL. | ||
| // | ||
| // https://docs.anthropic.com/en/api/claude-on-vertex-ai | ||
| APISchemaGCPAnthropic APISchema = "GCPAnthropic" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -465,6 +476,7 @@ const ( | |
| BackendSecurityPolicyTypeAPIKey BackendSecurityPolicyType = "APIKey" | ||
| BackendSecurityPolicyTypeAWSCredentials BackendSecurityPolicyType = "AWSCredentials" | ||
| BackendSecurityPolicyTypeAzureCredentials BackendSecurityPolicyType = "AzureCredentials" | ||
| BackendSecurityPolicyTypeGCPCredentials BackendSecurityPolicyType = "GCPCredentials" | ||
| ) | ||
|
|
||
| // BackendSecurityPolicy specifies configuration for authentication and authorization rules on the traffic | ||
|
|
@@ -487,9 +499,9 @@ type BackendSecurityPolicy struct { | |
| // Only one type of BackendSecurityPolicy can be defined. | ||
| // +kubebuilder:validation:MaxProperties=2 | ||
| type BackendSecurityPolicySpec struct { | ||
| // Type specifies the auth mechanism used to access the provider. Currently, only "APIKey", "AWSCredentials", and "AzureCredentials" are supported. | ||
| // Type specifies the type of the backend security policy. | ||
| // | ||
| // +kubebuilder:validation:Enum=APIKey;AWSCredentials;AzureCredentials | ||
| // +kubebuilder:validation:Enum=APIKey;AWSCredentials;AzureCredentials;GCPCredentials | ||
| Type BackendSecurityPolicyType `json:"type"` | ||
|
|
||
| // APIKey is a mechanism to access a backend(s). The API key will be injected into the Authorization header. | ||
|
|
@@ -506,6 +518,10 @@ type BackendSecurityPolicySpec struct { | |
| // | ||
| // +optional | ||
| AzureCredentials *BackendSecurityPolicyAzureCredentials `json:"azureCredentials,omitempty"` | ||
| // GCPCredentials is a mechanism to access a backend(s). GCP specific logic will be applied. | ||
| // | ||
| // +optional | ||
| GCPCredentials *BackendSecurityPolicyGCPCredentials `json:"gcpCredentials,omitempty"` | ||
| } | ||
|
|
||
| // BackendSecurityPolicyList contains a list of BackendSecurityPolicy | ||
|
|
@@ -543,6 +559,72 @@ type BackendSecurityPolicyOIDC struct { | |
| Aud string `json:"aud,omitempty"` | ||
| } | ||
|
|
||
| type GCPWorkLoadIdentityFederationConfig struct { | ||
| // ProjectID is the GCP project ID. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| ProjectID string `json:"projectID"` | ||
|
Contributor
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. Is ProjectID specific to Federation Config? Would it make sense to bubble this field up if it's needed for all GCP auth
Contributor
Author
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. not sure if other authentication methods would need project-id, so keeping it within federation config for now |
||
|
|
||
| // WorkloadIdentityProvider is the external auth provider to be used to authenticate against GCP. | ||
| // https://cloud.google.com/iam/docs/workload-identity-federation?hl=en | ||
| // Currently only OIDC is supported. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| WorkloadIdentityProvider GCPWorkloadIdentityProvider `json:"workloadIdentityProvider"` | ||
|
|
||
| // WorkloadIdentityPoolName is the name of the workload identity pool defined in GCP. | ||
| // https://cloud.google.com/iam/docs/workload-identity-federation?hl=en | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| WorkloadIdentityPoolName string `json:"workloadIdentityPoolName"` | ||
|
|
||
| // ServiceAccountImpersonation is the service account impersonation configuration. | ||
| // This is used to impersonate a service account when getting access token. | ||
| // | ||
| // +optional | ||
| ServiceAccountImpersonation *GCPServiceAccountImpersonationConfig `json:"serviceAccountImpersonation,omitempty"` | ||
| } | ||
|
|
||
| // GCPWorkloadIdentityProvider specifies the external identity provider to be used to authenticate against GCP. | ||
| // The external identity provider can be AWS, Microsoft, etc but must be pre-registered in the GCP project | ||
| // | ||
| // https://cloud.google.com/iam/docs/workload-identity-federation | ||
| type GCPWorkloadIdentityProvider struct { | ||
| // Name of the external identity provider as registered on Google Cloud Platform. | ||
yuzisun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| Name string `json:"name"` | ||
|
|
||
| // OIDCProvider is the generic OIDCProvider fields. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| OIDCProvider BackendSecurityPolicyOIDC `json:"OIDCProvider"` | ||
| } | ||
|
|
||
| type GCPServiceAccountImpersonationConfig struct { | ||
| // ServiceAccountName is the name of the service account to impersonate. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| ServiceAccountName string `json:"serviceAccountName"` | ||
| // ServiceAccountProjectName is the project name in which the service account is registered. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=1 | ||
| ServiceAccountProjectName string `json:"serviceAccountProjectName"` | ||
| } | ||
|
|
||
| // BackendSecurityPolicyGCPCredentials contains the supported authentication mechanisms to access GCP. | ||
| type BackendSecurityPolicyGCPCredentials struct { | ||
| // WorkLoadIdentityFederationConfig is the configuration for the GCP Workload Identity Federation. | ||
| // | ||
| // +kubebuilder:validation:Required | ||
| WorkLoadIdentityFederationConfig GCPWorkLoadIdentityFederationConfig `json:"workLoadIdentityFederationConfig"` | ||
| } | ||
|
|
||
| // BackendSecurityPolicyAzureCredentials contains the supported authentication mechanisms to access Azure. | ||
| // Only one of ClientSecretRef or OIDCExchangeToken must be specified. Credentials will not be generated if | ||
| // neither are set. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,6 +202,8 @@ type BackendAuth struct { | |
| AWSAuth *AWSAuth `json:"aws,omitempty"` | ||
| // AzureAuth specifies the location of Azure access token file. | ||
| AzureAuth *AzureAuth `json:"azure,omitempty"` | ||
| // GCPAuth specifies the location of GCP credential file. | ||
| GCPAuth *GCPAuth `json:"gcp,omitempty"` | ||
| } | ||
|
|
||
| // AWSAuth defines the credentials needed to access AWS. | ||
|
|
@@ -224,6 +226,16 @@ type AzureAuth struct { | |
| AccessToken string `json:"accessToken"` | ||
| } | ||
|
|
||
| // GCPAuth defines the file containing GCP credential that will be mounted to the external proc. | ||
| type GCPAuth struct { | ||
| // AccessToken is the access token as a literal string. | ||
| AccessToken string `json:"accessToken"` | ||
| // Region is the GCP region to use for the request. | ||
| Region string `json:"region"` | ||
| // ProjectName is the GCP project name to use for the request. | ||
| ProjectName string `json:"projectName"` | ||
|
Contributor
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. How will region and project be used in the extproc?
Contributor
Author
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. The region and project-id are required while transforming request path
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. then maybe ProjectID instead of ProjectName
Contributor
Author
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. Tried using project ID in the request url, but kept getting if future project name is found to be acceptable, we can add that as another field and accept either of them as valid config
Contributor
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. looks like it is using the name from the examples
Contributor
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. if project name is currently required on the url path, then it needs to be added to the BackendSecurityPolicy as well?
sukumargaonkar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // UnmarshalConfigYaml reads the file at the given path and unmarshals it into a Config struct. | ||
| func UnmarshalConfigYaml(path string) (*Config, error) { | ||
| raw, err := os.ReadFile(path) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.