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

add BackendSecurityPolicy for traffic (authN/authZ) from gateway to provider #43

Merged
merged 47 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
08be1f7
Set up API for AUTH api
aabchoo Dec 12, 2024
2ac7698
Signed-off-by: Aaron Choo <[email protected]>
aabchoo Dec 12, 2024
5ff638f
api: make LLMRoute reference HTTPRoute (#39)
mathetake Dec 10, 2024
c625ebe
api: adds BackendRef into LLMBackendSpec (#40)
mathetake Dec 12, 2024
e200702
updating test-cel
aabchoo Dec 12, 2024
43f77fc
add llm provider policy as part of crd
aabchoo Dec 12, 2024
ea69193
Merge remote-tracking branch 'origin/main' into aaron/authorization-api
aabchoo Dec 12, 2024
7e9315c
typo in test-cel
aabchoo Dec 12, 2024
57e0fa1
update llmproviderpolicy -> llmsecuritypolicy
aabchoo Dec 13, 2024
bc0dadd
ref to llmsecuritypolicy in the backend
aabchoo Dec 13, 2024
b071160
update documentation and tests
aabchoo Dec 16, 2024
d2f72ed
update crd name
aabchoo Dec 16, 2024
52ef4f9
update to generalize aws auth
aabchoo Dec 16, 2024
7b811b7
update llmproviderpolicy type
aabchoo Dec 18, 2024
7dbb202
auto gen update
aabchoo Dec 18, 2024
c04ec5e
add oidc as part of security policy spec
aabchoo Dec 18, 2024
e977a3d
update test to make with new changes
aabchoo Dec 18, 2024
a692194
llmsecurity -> backendsecurity and introduced oidc + static key authz
aabchoo Dec 19, 2024
41db68a
drop inline and static key + add backendref in backendsecuritypolicy
aabchoo Dec 20, 2024
6ea6f94
remove inline from llmproviderapikey definition
aabchoo Dec 20, 2024
3e1d587
introduce dedicated types for aws backend security
aabchoo Jan 2, 2025
2a42311
add more context for oidc
aabchoo Jan 2, 2025
191f9a7
added cel-validation for aws_iam types
aabchoo Jan 2, 2025
fbf1c27
add aws region
aabchoo Jan 2, 2025
b0cd4ca
add target ref backendSpec -> backendSecurityPolicy
aabchoo Jan 2, 2025
3d9ff5a
add security policy ref
aabchoo Jan 2, 2025
c91b45f
remove llm from security policy
aabchoo Jan 3, 2025
c5237b3
remove provider type for backend spec
aabchoo Jan 3, 2025
ddfcb33
rename odicCredential to oidcFederation
aabchoo Jan 3, 2025
130b1bf
remove unused fields
aabchoo Jan 3, 2025
6c68980
remove auth bear token
aabchoo Jan 3, 2025
ef3158c
Update api/v1alpha1/api.go
aabchoo Jan 3, 2025
5ff45c2
update prefix for auth mechanism
aabchoo Jan 3, 2025
1f5e736
update oidcFederation -> oidcExchangeToken
aabchoo Jan 3, 2025
658c1dd
update manifest
aabchoo Jan 3, 2025
2bcda7a
update comment
aabchoo Jan 3, 2025
f7ee160
Update api/v1alpha1/api.go
aabchoo Jan 6, 2025
c4f7baf
Update api/v1alpha1/api.go
aabchoo Jan 6, 2025
6b8f698
make secretRef required
aabchoo Jan 6, 2025
1d71e7a
Update api/v1alpha1/api.go
aabchoo Jan 6, 2025
70a4b29
Update api/v1alpha1/api.go
aabchoo Jan 6, 2025
99e8ae3
Add validation and comments to BackendSecurityPolicy
aabchoo Jan 6, 2025
70aa411
credentialFile to ref secret
aabchoo Jan 6, 2025
27df777
Merge branch 'main' into aaron/authorization-api
aabchoo Jan 6, 2025
dbc37e2
update description of oidc audience
aabchoo Jan 7, 2025
21db108
update backendSecurityPolicy type + add CloudProvider type
aabchoo Jan 8, 2025
480b26b
flatten cloudprovivder
aabchoo Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions api/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ type LLMBackendSpec struct {
//
// +kubebuilder:validation:Required
BackendRef egv1a1.BackendRef `json:"backendRef"`

// BackendSecurityPolicyRef is the name of the BackendSecurityPolicy resources this backend
// is being attached to.
//
// +optional
BackendSecurityPolicyRef *gwapiv1.LocalObjectReference `json:"backendSecurityPolicyRef,omitempty"`
mathetake marked this conversation as resolved.
Show resolved Hide resolved
}

// LLMAPISchema defines the API schema of either LLMRoute (the input) or LLMBackend (the output).
Expand Down Expand Up @@ -144,3 +150,120 @@ const (
// This can be used to describe the routing behavior in HTTPRoute referenced by LLMRoute.
LLMModelHeaderKey = "x-envoy-ai-gateway-llm-model"
)

// BackendSecurityPolicyType specifies the type of auth mechanism used to access a backend.
type BackendSecurityPolicyType string

const (
BackendSecurityPolicyTypeAPIKey BackendSecurityPolicyType = "APIKey"
BackendSecurityPolicyTypeAWSIAM BackendSecurityPolicyType = "AWS_IAM"
mathetake marked this conversation as resolved.
Show resolved Hide resolved
)

// +kubebuilder:object:root=true

// BackendSecurityPolicy specifies configuration for authentication and authorization rules on the traffic
// exiting the gateway to the backend.
type BackendSecurityPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BackendSecurityPolicySpec `json:"spec,omitempty"`
}

// BackendSecurityPolicySpec specifies authentication rules on access the provider from the Gateway.
type BackendSecurityPolicySpec struct {
// Type specifies the auth mechanism used to access the provider. Currently, only "APIKey", AND "AWS_IAM" are supported.
Copy link
Member

Choose a reason for hiding this comment

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

well, shouldn't the type be "CloudProviders" instead of AWS_IAM? The "type" field is for union type assertion and this feels a weird because AWS_IAM is not for the union type assertion but for the higher layer. @yuzisun @arkodg

Copy link
Member

Choose a reason for hiding this comment

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

This is relevant to the thread to #43 (comment) I am still not convinced by the "Yaml UX" stuff there. I am fine with that but at least to be consistent could you make this CloudProviders and have a type inside it for a specific cloud provider? (which i think is a worse UX vs the flat one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've flattened it out per req

//
// +kubebuilder:validation:Enum=APIKey;AWS_IAM
Type BackendSecurityPolicyType `json:"type"`

// APIKey is a mechanism to access a backend(s). The API key will be injected into the Authorization header.
//
// +optional
APIKey *AuthenticationAPIKey `json:"apiKey,omitempty"`

// CloudProviderCredentials is a mechanism to access a backend(s). Cloud provider specific logic will be applied.
//
// +optional
mathetake marked this conversation as resolved.
Show resolved Hide resolved
CloudProviderCredentials *AuthenticationCloudProviderCredentials `json:"cloudProviderCredentials,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

so i wonder what kind of logic will make cloud providers special compared to others (currently only apiKey though). how do you envision this additional indirect layer will be used? in other words, what kind of logic will be shared among cloud providers

Copy link
Contributor

@yuzisun yuzisun Jan 4, 2025

Choose a reason for hiding this comment

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

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 get that it's complex, but my question is why this another layer is needed and what kind of logic will be shared among cloud providers? what becomes difficult to achieve when you have *AWSCredentials directly here without another layer of AuthenticationCloudProviderCredentials. How does having AuthenticationCloudProviderCredentials helps implement various cloud providers vs having them in here

Copy link
Contributor

Choose a reason for hiding this comment

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

This is mainly a yaml UX, the additional layer for grouping is there for readability, if we list the individual types then it is not intuitive for user to see the classification. The cloud provider security implementations are different but they share the same high level concepts.

}

// +kubebuilder:object:root=true

// BackendSecurityPolicyList contains a list of BackendSecurityPolicy
type BackendSecurityPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BackendSecurityPolicy `json:"items"`
}

// AuthenticationAPIKey specifies the API key.
type AuthenticationAPIKey struct {
aabchoo marked this conversation as resolved.
Show resolved Hide resolved
// SecretRef is the reference to the secret containing the API key.
// ai-gateway must be given the permission to read this secret.
// The key of the secret should be "apiKey".
//
// +optional
SecretRef *gwapiv1.SecretObjectReference `json:"secretRef"`
aabchoo marked this conversation as resolved.
Show resolved Hide resolved
}

// AuthenticationCloudProviderCredentials specifies supported cloud provider authentication methods
type AuthenticationCloudProviderCredentials struct {
aabchoo marked this conversation as resolved.
Show resolved Hide resolved
AWSCredentials AWSCredentials `json:"awsCredentials"`
aabchoo marked this conversation as resolved.
Show resolved Hide resolved
}

// AWSCredentials contains the supported authentication mechanisms to access aws
type AWSCredentials struct {
// Region specifies the AWS region associated with the policy.
//
// +kubebuilder:validation:MinLength=1
Region string `json:"region"`

// CredentialsFile specifies the credentials file to use for the AWS provider.
//
// +optional
CredentialsFile *AWSCredentialsFile `json:"credentialsFile,omitempty"`

// OIDCExchangeToken specifies the oidc configurations used to obtain an oidc token. The oidc token will be
// used to obtain temporary credentials to access AWS.
//
// +optional
OIDCExchangeToken *AWSOIDCExchangeToken `json:"oidcExchangeToken,omitempty"`
}

// AWSCredentialsFile specifies the credentials file to use for the AWS provider.
// Envoy reads the credentials from the file pointed by the Path field, and the profile to use is specified by the Profile field.
type AWSCredentialsFile struct {
// Path is the path to the credentials file.
//
// +kubebuilder:default=~/.aws/credentials
Path string `json:"path,omitempty"`
aabchoo marked this conversation as resolved.
Show resolved Hide resolved

// Profile is the profile to use in the credentials file.
//
// +kubebuilder:default=default
Profile string `json:"profile,omitempty"`
}

// AWSOIDCExchangeToken specifies credentials to obtain oidc token from a sso server.
// For AWS, the controller will query STS to obtain AWS AccessKeyId, SecretAccessKey, and SessionToken,
// and store them in a temporary credentials file.
type AWSOIDCExchangeToken struct {
// OIDC is used to obtain oidc tokens via an SSO server which will be used to exchange for temporary AWS credentials.
OIDC egv1a1.OIDC `json:"oidc"`

// GrantType is the method application gets access token.
//
// +optional
GrantType string `json:"grantType,omitempty"`

// Aud defines the resource the application can access.
//
// +optional
Aud string `json:"aud,omitempty"`

// AwsRoleArn is the AWS IAM Role with the permission to use specific resources in AWS account
// which maps to the temporary AWS security credentials exchanged using the authentication token issued by OIDC provider.
//
// +optional
AwsRoleArn string `json:"awsRoleArn,omitempty"`
aabchoo marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions api/v1alpha1/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func init() {
SchemeBuilder.Register(&LLMRoute{}, &LLMRouteList{})
SchemeBuilder.Register(&LLMBackend{}, &LLMBackendList{})
SchemeBuilder.Register(&BackendSecurityPolicy{}, &BackendSecurityPolicyList{})
}

const GroupName = "aigateway.envoyproxy.io"
Expand Down
181 changes: 181 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading