Skip to content

Commit 80838bc

Browse files
authored
feat: aws auth sdk default chain (#1394)
**Description** This PR updates the AWS authentication handler to support the AWS SDK’s default credential chain, enabling native integration with modern AWS identity providers like IRSA (IAM Roles for Service Accounts) and EKS Pod Identity. Previously, credentials had to be explicitly provided via config literals. Now, if no credential file is set, the handler automatically falls back to config.LoadDefaultConfig, which supports: - IRSA (EKS service accounts) - EKS Pod Identity - EC2 Instance Profiles - Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) - Shared credentials files (~/.aws/credentials) This simplifies AWS deployments and aligns with best practices by avoiding static credentials. This makes it much easier to deploy the AI Gateway on AWS infrastructure while following AWS security best practices by avoiding static credentials. The PR includes: - Refactored AWS authentication handler to use the default credential chain when no credentials file is provided - Added example configs for IRSA and EKS Pod Identity - Updated documentation with setup guides for both methods - Extended tests to cover the new credential resolution logic - Update API documentation **Related Issues/PRs (if applicable)** #568 --------- Signed-off-by: José Luis Jiménez Quereda <[email protected]>
1 parent 0566de3 commit 80838bc

File tree

15 files changed

+1022
-153
lines changed

15 files changed

+1022
-153
lines changed

api/v1alpha1/backendsecurity_policy.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,34 @@ type AzureOIDCExchangeToken struct {
268268
BackendSecurityPolicyOIDC `json:",inline"`
269269
}
270270

271-
// BackendSecurityPolicyAWSCredentials contains the supported authentication mechanisms to access aws.
271+
// BackendSecurityPolicyAWSCredentials contains the supported authentication mechanisms to access AWS.
272+
//
273+
// When neither CredentialsFile nor OIDCExchangeToken is specified, the AWS SDK's default credential chain
274+
// will be used. This automatically supports various authentication methods in the following order:
275+
// 1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN)
276+
// 2. EKS Pod Identity - automatically rotates credentials for pods in EKS clusters
277+
// 3. IAM Roles for Service Accounts (IRSA) - injects credentials via mounted service account tokens
278+
// 4. EC2 instance metadata (IAM instance roles)
279+
// 5. ECS task roles
280+
//
281+
// The default credential chain is recommended for Kubernetes deployments as it supports automatic
282+
// credential rotation without manual configuration. Credentials are refreshed automatically when
283+
// they approach expiration (typically hourly for IRSA and Pod Identity).
272284
type BackendSecurityPolicyAWSCredentials struct {
273285
// Region specifies the AWS region associated with the policy.
274286
//
275287
// +kubebuilder:validation:MinLength=1
276288
Region string `json:"region"`
277289

278290
// CredentialsFile specifies the credentials file to use for the AWS provider.
291+
// When specified, this takes precedence over the default credential chain.
279292
//
280293
// +optional
281294
CredentialsFile *AWSCredentialsFile `json:"credentialsFile,omitempty"`
282295

283296
// OIDCExchangeToken specifies the oidc configurations used to obtain an oidc token. The oidc token will be
284297
// used to obtain temporary credentials to access AWS.
298+
// When specified, this takes precedence over the default credential chain.
285299
//
286300
// +optional
287301
OIDCExchangeToken *AWSOIDCExchangeToken `json:"oidcExchangeToken,omitempty"`

examples/basic/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
This contains the basic example manifest to create an Envoy Gateway that handles
2-
the traffics for both OpenAI and AWS Bedrock at the same time.
1+
This contains the basic example manifests to create an Envoy AI Gateway that handles
2+
traffic for various AI providers.
3+
4+
## Examples
5+
6+
- `basic.yaml` - Basic configuration without any backends
7+
- `openai.yaml` - OpenAI integration
8+
- `aws.yaml` - AWS Bedrock with static credentials
9+
- `aws-irsa.yaml` - AWS Bedrock with IRSA (IAM Roles for Service Accounts)
10+
- `aws-pod-identity.yaml` - AWS Bedrock with EKS Pod Identity
11+
- `azure_openai.yaml` - Azure OpenAI integration
12+
- `gcp_vertex.yaml` - GCP Vertex AI integration
13+
- `tars.yaml` - TARS integration
14+
15+
For AWS Bedrock, we recommend using either `aws-pod-identity.yaml` (EKS 1.24+) or
16+
`aws-irsa.yaml` (all EKS versions) for production deployments instead of static credentials. [Docs](https://docs.aws.amazon.com/eks/latest/best-practices/identity-and-access-management.html#_identities_and_credentials_for_eks_pods)

examples/basic/aws-irsa.yaml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Copyright Envoy AI Gateway Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
# The full text of the Apache license is available in the LICENSE file at
4+
# the root of the repo.
5+
6+
# This example demonstrates how to configure AWS Bedrock with IRSA (IAM Roles for Service Accounts)
7+
# on EKS, eliminating the need for static AWS credentials.
8+
#
9+
# Prerequisites for IRSA:
10+
# 1. EKS cluster with OIDC provider enabled
11+
# 2. IAM role with Bedrock permissions and trust policy for your ServiceAccount
12+
# 3. ServiceAccount annotated with eks.amazonaws.com/role-arn
13+
#
14+
# For EKS Pod Identity (newer, simpler method), see aws-pod-identity.yaml instead.
15+
#
16+
# For AWS IRSA setup instructions, see:
17+
# https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html
18+
#
19+
# For AI Gateway integration instructions, see:
20+
# https://docs.envoyproxy.io/ai-gateway/latest/getting-started/connect-providers/aws-bedrock.html
21+
22+
---
23+
# Step 1: Create a custom ServiceAccount with IRSA annotation for the data plane
24+
apiVersion: v1
25+
kind: ServiceAccount
26+
metadata:
27+
name: ai-gateway-dataplane-aws
28+
namespace: envoy-gateway-system
29+
annotations:
30+
# Replace with your IAM role ARN that has Bedrock permissions
31+
eks.amazonaws.com/role-arn: arn:aws:iam::ACCOUNT_ID:role/ai-gateway-bedrock-role
32+
---
33+
# Step 2: Create minimal RBAC for the ServiceAccount
34+
apiVersion: rbac.authorization.k8s.io/v1
35+
kind: Role
36+
metadata:
37+
name: ai-gateway-dataplane-aws
38+
namespace: envoy-gateway-system
39+
rules:
40+
- apiGroups: [""]
41+
resources: ["secrets"]
42+
verbs: ["get", "list", "watch"]
43+
---
44+
apiVersion: rbac.authorization.k8s.io/v1
45+
kind: RoleBinding
46+
metadata:
47+
name: ai-gateway-dataplane-aws
48+
namespace: envoy-gateway-system
49+
roleRef:
50+
apiGroup: rbac.authorization.k8s.io
51+
kind: Role
52+
name: ai-gateway-dataplane-aws
53+
subjects:
54+
- kind: ServiceAccount
55+
name: ai-gateway-dataplane-aws
56+
namespace: envoy-gateway-system
57+
---
58+
# Step 3: Create custom EnvoyProxy configuration that uses the ServiceAccount
59+
apiVersion: gateway.envoyproxy.io/v1alpha1
60+
kind: EnvoyProxy
61+
metadata:
62+
name: ai-gateway-with-aws
63+
namespace: envoy-gateway-system
64+
spec:
65+
provider:
66+
type: Kubernetes
67+
kubernetes:
68+
envoyDeployment:
69+
pod:
70+
# This tells Envoy Gateway to use our AWS-enabled ServiceAccount
71+
serviceAccountName: ai-gateway-dataplane-aws
72+
---
73+
# Step 4: Create Gateway that references the custom EnvoyProxy
74+
apiVersion: gateway.networking.k8s.io/v1
75+
kind: Gateway
76+
metadata:
77+
name: envoy-ai-gateway-basic
78+
namespace: default
79+
annotations:
80+
# This links the Gateway to use our custom EnvoyProxy with AWS credentials
81+
gateway.envoyproxy.io/envoy-proxy: envoy-gateway-system/ai-gateway-with-aws
82+
spec:
83+
gatewayClassName: envoy-ai-gateway
84+
listeners:
85+
- name: http
86+
protocol: HTTP
87+
port: 80
88+
---
89+
# Step 5: Create AIGatewayRoute for routing to Bedrock
90+
apiVersion: aigateway.envoyproxy.io/v1alpha1
91+
kind: AIGatewayRoute
92+
metadata:
93+
name: envoy-ai-gateway-basic-aws
94+
namespace: default
95+
spec:
96+
parentRefs:
97+
- name: envoy-ai-gateway-basic
98+
kind: Gateway
99+
group: gateway.networking.k8s.io
100+
rules:
101+
- matches:
102+
- headers:
103+
- type: Exact
104+
name: x-ai-eg-model
105+
value: us.meta.llama3-2-1b-instruct-v1:0
106+
backendRefs:
107+
- name: envoy-ai-gateway-basic-aws
108+
---
109+
# Step 6: Create AIServiceBackend for AWS Bedrock
110+
apiVersion: aigateway.envoyproxy.io/v1alpha1
111+
kind: AIServiceBackend
112+
metadata:
113+
name: envoy-ai-gateway-basic-aws
114+
namespace: default
115+
spec:
116+
schema:
117+
name: AWSBedrock
118+
backendRef:
119+
name: envoy-ai-gateway-basic-aws
120+
kind: Backend
121+
group: gateway.envoyproxy.io
122+
---
123+
# Step 7: Create BackendSecurityPolicy using AWS credential chain
124+
# This automatically uses IRSA credentials from the ServiceAccount annotation!
125+
apiVersion: aigateway.envoyproxy.io/v1alpha1
126+
kind: BackendSecurityPolicy
127+
metadata:
128+
name: envoy-ai-gateway-basic-aws
129+
namespace: default
130+
spec:
131+
targetRefs:
132+
- group: aigateway.envoyproxy.io
133+
kind: AIServiceBackend
134+
name: envoy-ai-gateway-basic-aws
135+
type: AWSCredentials
136+
awsCredentials:
137+
region: us-east-1
138+
# No credentialsFile or oidcExchangeToken needed!
139+
# The AWS SDK will automatically use the default credential chain which includes:
140+
# - IRSA (if ServiceAccount has eks.amazonaws.com/role-arn annotation)
141+
# - Other AWS credential sources (environment variables, instance profile, etc.)
142+
---
143+
# Step 8: Create Backend pointing to AWS Bedrock
144+
apiVersion: gateway.envoyproxy.io/v1alpha1
145+
kind: Backend
146+
metadata:
147+
name: envoy-ai-gateway-basic-aws
148+
namespace: default
149+
spec:
150+
endpoints:
151+
- fqdn:
152+
hostname: bedrock-runtime.us-east-1.amazonaws.com
153+
port: 443
154+
---
155+
# Step 9: Create BackendTLSPolicy for HTTPS
156+
apiVersion: gateway.networking.k8s.io/v1alpha3
157+
kind: BackendTLSPolicy
158+
metadata:
159+
name: envoy-ai-gateway-basic-aws-tls
160+
namespace: default
161+
spec:
162+
targetRefs:
163+
- group: "gateway.envoyproxy.io"
164+
kind: Backend
165+
name: envoy-ai-gateway-basic-aws
166+
validation:
167+
wellKnownCACertificates: "System"
168+
hostname: bedrock-runtime.us-east-1.amazonaws.com
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Copyright Envoy AI Gateway Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
# The full text of the Apache license is available in the LICENSE file at
4+
# the root of the repo.
5+
6+
# This example demonstrates how to configure AWS Bedrock with EKS Pod Identity,
7+
# eliminating the need for static AWS credentials or OIDC provider configuration.
8+
#
9+
# Prerequisites for EKS Pod Identity:
10+
# 1. EKS cluster v1.24+
11+
# 2. EKS Pod Identity Agent installed (DaemonSet)
12+
# 3. IAM role with Bedrock permissions and trust policy for pods.eks.amazonaws.com
13+
# 4. Pod Identity association created linking your ServiceAccount to the IAM role
14+
#
15+
# For AWS Pod Identity setup instructions, see:
16+
# https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html
17+
#
18+
# For AI Gateway integration instructions, see:
19+
# https://docs.envoyproxy.io/ai-gateway/latest/getting-started/connect-providers/aws-bedrock.html
20+
21+
---
22+
# Step 1: Create a ServiceAccount for the data plane
23+
# Note: No annotations needed for Pod Identity (unlike IRSA)
24+
apiVersion: v1
25+
kind: ServiceAccount
26+
metadata:
27+
name: ai-gateway-dataplane-aws
28+
namespace: envoy-gateway-system
29+
---
30+
# Step 2: Create minimal RBAC for the ServiceAccount
31+
apiVersion: rbac.authorization.k8s.io/v1
32+
kind: Role
33+
metadata:
34+
name: ai-gateway-dataplane-aws
35+
namespace: envoy-gateway-system
36+
rules:
37+
- apiGroups: [""]
38+
resources: ["secrets"]
39+
verbs: ["get", "list", "watch"]
40+
---
41+
apiVersion: rbac.authorization.k8s.io/v1
42+
kind: RoleBinding
43+
metadata:
44+
name: ai-gateway-dataplane-aws
45+
namespace: envoy-gateway-system
46+
roleRef:
47+
apiGroup: rbac.authorization.k8s.io
48+
kind: Role
49+
name: ai-gateway-dataplane-aws
50+
subjects:
51+
- kind: ServiceAccount
52+
name: ai-gateway-dataplane-aws
53+
namespace: envoy-gateway-system
54+
---
55+
# Step 3: Create custom EnvoyProxy configuration that uses the ServiceAccount
56+
apiVersion: gateway.envoyproxy.io/v1alpha1
57+
kind: EnvoyProxy
58+
metadata:
59+
name: ai-gateway-with-aws
60+
namespace: envoy-gateway-system
61+
spec:
62+
provider:
63+
type: Kubernetes
64+
kubernetes:
65+
envoyDeployment:
66+
pod:
67+
# This tells Envoy Gateway to use our AWS-enabled ServiceAccount
68+
serviceAccountName: ai-gateway-dataplane-aws
69+
---
70+
# Step 4: Create Gateway that references the custom EnvoyProxy
71+
apiVersion: gateway.networking.k8s.io/v1
72+
kind: Gateway
73+
metadata:
74+
name: envoy-ai-gateway-basic
75+
namespace: default
76+
annotations:
77+
# This links the Gateway to use our custom EnvoyProxy with AWS credentials
78+
gateway.envoyproxy.io/envoy-proxy: envoy-gateway-system/ai-gateway-with-aws
79+
spec:
80+
gatewayClassName: envoy-ai-gateway
81+
listeners:
82+
- name: http
83+
protocol: HTTP
84+
port: 80
85+
---
86+
# Step 5: Create AIGatewayRoute for routing to Bedrock
87+
apiVersion: aigateway.envoyproxy.io/v1alpha1
88+
kind: AIGatewayRoute
89+
metadata:
90+
name: envoy-ai-gateway-basic-aws
91+
namespace: default
92+
spec:
93+
parentRefs:
94+
- name: envoy-ai-gateway-basic
95+
kind: Gateway
96+
group: gateway.networking.k8s.io
97+
rules:
98+
- matches:
99+
- headers:
100+
- type: Exact
101+
name: x-ai-eg-model
102+
value: us.meta.llama3-2-1b-instruct-v1:0
103+
backendRefs:
104+
- name: envoy-ai-gateway-basic-aws
105+
---
106+
# Step 6: Create AIServiceBackend for AWS Bedrock
107+
apiVersion: aigateway.envoyproxy.io/v1alpha1
108+
kind: AIServiceBackend
109+
metadata:
110+
name: envoy-ai-gateway-basic-aws
111+
namespace: default
112+
spec:
113+
schema:
114+
name: AWSBedrock
115+
backendRef:
116+
name: envoy-ai-gateway-basic-aws
117+
kind: Backend
118+
group: gateway.envoyproxy.io
119+
---
120+
# Step 7: Create BackendSecurityPolicy using AWS credential chain
121+
# This automatically detects and uses EKS Pod Identity credentials!
122+
apiVersion: aigateway.envoyproxy.io/v1alpha1
123+
kind: BackendSecurityPolicy
124+
metadata:
125+
name: envoy-ai-gateway-basic-aws
126+
namespace: default
127+
spec:
128+
targetRefs:
129+
- group: aigateway.envoyproxy.io
130+
kind: AIServiceBackend
131+
name: envoy-ai-gateway-basic-aws
132+
type: AWSCredentials
133+
awsCredentials:
134+
region: us-east-1
135+
# No credentialsFile or oidcExchangeToken needed!
136+
# The AWS SDK will automatically use the default credential chain which includes:
137+
# - EKS Pod Identity (if Pod Identity association exists)
138+
# - IRSA (if ServiceAccount has eks.amazonaws.com/role-arn annotation)
139+
# - Other AWS credential sources (environment variables, instance profile, etc.)
140+
---
141+
# Step 8: Create Backend pointing to AWS Bedrock
142+
apiVersion: gateway.envoyproxy.io/v1alpha1
143+
kind: Backend
144+
metadata:
145+
name: envoy-ai-gateway-basic-aws
146+
namespace: default
147+
spec:
148+
endpoints:
149+
- fqdn:
150+
hostname: bedrock-runtime.us-east-1.amazonaws.com
151+
port: 443
152+
---
153+
# Step 9: Create BackendTLSPolicy for HTTPS
154+
apiVersion: gateway.networking.k8s.io/v1alpha3
155+
kind: BackendTLSPolicy
156+
metadata:
157+
name: envoy-ai-gateway-basic-aws-tls
158+
namespace: default
159+
spec:
160+
targetRefs:
161+
- group: "gateway.envoyproxy.io"
162+
kind: Backend
163+
name: envoy-ai-gateway-basic-aws
164+
validation:
165+
wellKnownCACertificates: "System"
166+
hostname: bedrock-runtime.us-east-1.amazonaws.com

0 commit comments

Comments
 (0)