Skip to content

Commit c3573e8

Browse files
feat: support IRSA and Pod Identities for Amazon Bedrock (#454)
Signed-off-by: Aaron Miller <millrfz@amazon.com> Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
1 parent 5700a8e commit c3573e8

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,31 @@ EOF
282282
283283
1. Install the operator from the [Installation](#installation) section.
284284
285-
2. Create secret:
285+
2. When running on AWS, you have a number of ways to give permission to the managed K8sGPT workload to access Amazon Bedrock.
286+
* Grant access to Bedrock using the Kubernetes Service Account. This is the [best practices method for assigning permissions to Kubernetes Pods](https://aws.github.io/aws-eks-best-practices/security/docs/iam/#identities-and-credentials-for-eks-pods). There are a few ways to do this:
287+
* On Amazon EKS, using [EKS Pod Identity](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html)
288+
* On Amazon EKS, using [IAM Roles for Service Accounts (IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html)
289+
* On self-managed Kubernetes, using IAM Roles for Service Accounts (IRSA) with the [Pod Identity Webhook](https://github.com/aws/amazon-eks-pod-identity-webhook)
290+
* Grant access to Bedrock using AWS credentials in a Kubernetes Secret. Note this goes [against AWS best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-workloads-use-roles) and should be used with caution.
291+
292+
To grant access to Bedrock using a Kubernetes Service account, create an IAM role with Bedrock permissions. An example policy is included below:
293+
```
294+
{
295+
"Version": "2012-10-17",
296+
"Statement": [
297+
{
298+
"Effect": "Allow",
299+
"Action": [
300+
"bedrock:InvokeModel",
301+
"bedrock:InvokeModelWithResponseStream"
302+
],
303+
"Resource": "*"
304+
}
305+
]
306+
}
307+
```
308+
309+
To grant access to Bedrock using AWS credentials in a Kubernetes secret you can create a secret:
286310
```sh
287311
kubectl create secret generic bedrock-sample-secret --from-literal=AWS_ACCESS_KEY_ID="$(echo $AWS_ACCESS_KEY_ID)" --from-literal=AWS_SECRET_ACCESS_KEY="$(echo $AWS_SECRET_ACCESS_KEY)" -n k8sgpt-operator-system
288312
```
@@ -297,8 +321,8 @@ metadata:
297321
spec:
298322
ai:
299323
enabled: true
300-
secret:
301-
name: bedrock-sample-secret
324+
# secret:
325+
# name: bedrock-sample-secret
302326
model: anthropic.claude-v2
303327
region: eu-central-1
304328
backend: amazonbedrock
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
{{- if or .Values.serviceAccount.create -}}
12
apiVersion: v1
23
kind: ServiceAccount
34
metadata:
4-
name: "k8sgpt"
5+
name: {{ default "k8sgpt" .Values.serviceAccount.name }}
56
labels:
67
app.kubernetes.io/component: rbac
78
app.kubernetes.io/created-by: k8sgpt-operator
89
app.kubernetes.io/part-of: k8sgpt-operator
910
{{- include "chart.labels" . | nindent 4 }}
11+
{{- if .Values.serviceAccount.annotations }}
12+
annotations: {{ toYaml .Values.serviceAccount.annotations | nindent 4 }}
13+
{{- end }}
14+
{{- end }}
15+

chart/operator/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
serviceAccount:
2+
create: true
3+
name: "k8sgpt"
4+
# -- Annotations for the managed k8sgpt workload service account
5+
annotations: {}
16
serviceMonitor:
27
enabled: false
38
additionalLabels: {}

pkg/resources/k8sgpt.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,13 @@ func GetDeployment(config v1alpha1.K8sGPT, outOfClusterMode bool, c client.Clien
295295
}
296296
// Add checks for amazonbedrock
297297
if config.Spec.AI.Backend == v1alpha1.AmazonBedrock {
298-
if config.Spec.AI.Secret == nil {
299-
return &appsv1.Deployment{}, err.New("secret is required for amazonbedrock backend")
300-
}
301-
if err := addSecretAsEnvToDeployment(config.Spec.AI.Secret.Name, "AWS_ACCESS_KEY_ID", config, c, &deployment); err != nil {
302-
return &appsv1.Deployment{}, err
303-
}
304-
if err := addSecretAsEnvToDeployment(config.Spec.AI.Secret.Name, "AWS_SECRET_ACCESS_KEY", config, c, &deployment); err != nil {
305-
return &appsv1.Deployment{}, err
298+
if config.Spec.AI.Secret != nil {
299+
if err := addSecretAsEnvToDeployment(config.Spec.AI.Secret.Name, "AWS_ACCESS_KEY_ID", config, c, &deployment); err != nil {
300+
return &appsv1.Deployment{}, err
301+
}
302+
if err := addSecretAsEnvToDeployment(config.Spec.AI.Secret.Name, "AWS_SECRET_ACCESS_KEY", config, c, &deployment); err != nil {
303+
return &appsv1.Deployment{}, err
304+
}
306305
}
307306
if config.Spec.AI.Region == "" {
308307
return &appsv1.Deployment{}, err.New("default region is required for amazonbedrock backend")

0 commit comments

Comments
 (0)