Skip to content

Commit 2660105

Browse files
authored
Add env var for EKS Pod Identity token audience and service principal (#617)
*Issue #, if available:* N/A *Description of changes:* For testing in internal EKS environments, we may wish to modify the token audience and service principal used. This change allows it to be overridden in the node service and end-to-end tests. The default value is unchanged, and remains `"pods.eks.amazonaws.com"`. We may consider making changes to the Helm chart, however I'm leaving it out for this PR. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 9791c83 commit 2660105

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

charts/aws-mountpoint-s3-csi-driver/templates/node.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ spec:
8181
value: {{ .Values.mountpointPod.namespace }}
8282
- name: EKS_POD_IDENTITY_AGENT_CONTAINER_CREDENTIALS_FULL_URI
8383
value: {{ .Values.eksPodIdentityAgent.containerCredentialsFullURI }}
84+
- name: POD_IDENTITY_TOKEN_AUDIENCE
85+
value: pods.eks.amazonaws.com
8486
{{- with .Values.awsAccessSecret }}
8587
- name: AWS_ACCESS_KEY_ID
8688
valueFrom:

pkg/driver/node/credentialprovider/provider_pod.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"os"
88
"path/filepath"
9+
"strings"
910
"time"
1011

1112
"github.com/google/renameio"
@@ -17,10 +18,11 @@ import (
1718
"github.com/awslabs/mountpoint-s3-csi-driver/pkg/driver/node/envprovider"
1819
)
1920

21+
var serviceAccountTokenAudiencePodIdentity = determineServiceAccountTokenAudienceEKS()
22+
2023
const (
21-
serviceAccountTokenAudienceSTS = "sts.amazonaws.com"
22-
serviceAccountTokenAudiencePodIdentity = "pods.eks.amazonaws.com"
23-
serviceAccountRoleAnnotation = "eks.amazonaws.com/role-arn"
24+
serviceAccountTokenAudienceSTS = "sts.amazonaws.com"
25+
serviceAccountRoleAnnotation = "eks.amazonaws.com/role-arn"
2426
)
2527

2628
const podLevelCredentialsDocsPage = "https://github.com/awslabs/mountpoint-s3-csi-driver/blob/main/docs/CONFIGURATION.md#pod-level-credentials"
@@ -236,3 +238,13 @@ func (c *Provider) createEKSPodIdentityCredentialsEnvironment(provideCtx Provide
236238
envprovider.EnvContainerAuthorizationTokenFile: tokenFile,
237239
}, nil
238240
}
241+
242+
func determineServiceAccountTokenAudienceEKS() string {
243+
const envPodIdentityTokenAudience = "POD_IDENTITY_TOKEN_AUDIENCE"
244+
fromEnv := strings.TrimSpace(os.Getenv(envPodIdentityTokenAudience))
245+
if len(fromEnv) == 0 {
246+
return "pods.eks.amazonaws.com"
247+
} else {
248+
return fromEnv
249+
}
250+
}

tests/e2e-kubernetes/testsuites/credentials.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
goerrors "errors"
77
"fmt"
8+
"os"
89
"slices"
910
"strings"
1011
"time"
@@ -72,7 +73,7 @@ const serviceAccountTokenAudienceSTS = "sts.amazonaws.com"
7273
const roleARNAnnotation = "eks.amazonaws.com/role-arn"
7374
const credentialSecretName = "aws-secret"
7475

75-
const serviceAccountTokenAudienceEKS = "pods.eks.amazonaws.com"
76+
var serviceAccountTokenAudienceEKS = determineServiceAccountTokenAudienceEKS()
7677

7778
// DefaultRegion specifies the STS region explicitly.
7879
var DefaultRegion string
@@ -86,6 +87,16 @@ type s3CSICredentialsTestSuite struct {
8687
tsInfo storageframework.TestSuiteInfo
8788
}
8889

90+
func determineServiceAccountTokenAudienceEKS() string {
91+
const envPodIdentityTokenAudience = "POD_IDENTITY_TOKEN_AUDIENCE"
92+
fromEnv := strings.TrimSpace(os.Getenv(envPodIdentityTokenAudience))
93+
if len(fromEnv) == 0 {
94+
return "pods.eks.amazonaws.com"
95+
} else {
96+
return fromEnv
97+
}
98+
}
99+
89100
func InitS3CSICredentialsTestSuite() storageframework.TestSuite {
90101
return &s3CSICredentialsTestSuite{
91102
tsInfo: storageframework.TestSuiteInfo{
@@ -1013,20 +1024,20 @@ func getARNPartition(arn string) string {
10131024
}
10141025

10151026
func createRole(ctx context.Context, f *framework.Framework, assumeRolePolicyDocument string, policyNames ...string) (*iamtypes.Role, func(context.Context) error) {
1016-
framework.Logf("Creating IAM role")
10171027
identity := stsCallerIdentity(ctx)
10181028

10191029
client := iam.NewFromConfig(awsConfig(ctx))
10201030

10211031
roleName := fmt.Sprintf("%s-%s", f.BaseName, uuid.NewString())
1032+
framework.Logf("Creating IAM role '%s' with assumeRolePolicyDocument \"%s\"", roleName, assumeRolePolicyDocument)
10221033
role, err := client.CreateRole(ctx, &iam.CreateRoleInput{
10231034
RoleName: ptr.To(roleName),
10241035
AssumeRolePolicyDocument: ptr.To(assumeRolePolicyDocument),
10251036
})
10261037
framework.ExpectNoError(err)
10271038

10281039
deleteRole := func(ctx context.Context) error {
1029-
framework.Logf("Deleting IAM role")
1040+
framework.Logf("Deleting IAM role '%s'", roleName)
10301041
_, err := client.DeleteRole(ctx, &iam.DeleteRoleInput{
10311042
RoleName: ptr.To(roleName),
10321043
})

0 commit comments

Comments
 (0)