|
@@ -35,12 +35,13 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type workloadIdentityFederationTest struct {
|
|
type workloadIdentityFederationTest struct {
|
|
|
- name string
|
|
|
|
|
- wifConfig *esv1.GCPWorkloadIdentityFederation
|
|
|
|
|
- kubeObjects []client.Object
|
|
|
|
|
- genSAToken func(context.Context, []string, string, string) (*authv1.TokenRequest, error)
|
|
|
|
|
- expectError string
|
|
|
|
|
- expectTokenSource bool
|
|
|
|
|
|
|
+ name string
|
|
|
|
|
+ wifConfig *esv1.GCPWorkloadIdentityFederation
|
|
|
|
|
+ kubeObjects []client.Object
|
|
|
|
|
+ genSAToken func(context.Context, []string, string, string) (*authv1.TokenRequest, error)
|
|
|
|
|
+ expectError string
|
|
|
|
|
+ expectTokenSource bool
|
|
|
|
|
+ expectImpersonationURL string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -49,6 +50,7 @@ const (
|
|
|
testServiceAccount = "test-sa"
|
|
testServiceAccount = "test-sa"
|
|
|
testAudience = "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/test-pool/providers/test-provider"
|
|
testAudience = "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/test-pool/providers/test-provider"
|
|
|
testServiceAccountImpersonationURL = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/test@test.iam.gserviceaccount.com:generateAccessToken"
|
|
testServiceAccountImpersonationURL = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/test@test.iam.gserviceaccount.com:generateAccessToken"
|
|
|
|
|
+ testGCPServiceAccountEmail = "test@test.iam.gserviceaccount.com"
|
|
|
testSAToken = "test-sa-token"
|
|
testSAToken = "test-sa-token"
|
|
|
testAwsRegion = "us-west-2"
|
|
testAwsRegion = "us-west-2"
|
|
|
// below values taken from https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html
|
|
// below values taken from https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html
|
|
@@ -365,6 +367,12 @@ func TestWorkloadIdentityFederation(t *testing.T) {
|
|
|
testConfigMapKey: createInvalidK8sExternalAccountConfigWithUnallowedTokenFilePath(testAudience),
|
|
testConfigMapKey: createInvalidK8sExternalAccountConfigWithUnallowedTokenFilePath(testAudience),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
|
|
+ &corev1.ServiceAccount{
|
|
|
|
|
+ ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
+ Name: testServiceAccount,
|
|
|
|
|
+ Namespace: testNamespace,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
genSAToken: func(c context.Context, s1 []string, s2, s3 string) (*authv1.TokenRequest, error) {
|
|
genSAToken: func(c context.Context, s1 []string, s2, s3 string) (*authv1.TokenRequest, error) {
|
|
|
return &authv1.TokenRequest{
|
|
return &authv1.TokenRequest{
|
|
@@ -376,6 +384,49 @@ func TestWorkloadIdentityFederation(t *testing.T) {
|
|
|
expectTokenSource: true,
|
|
expectTokenSource: true,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
|
|
+ name: "fail on missing service account",
|
|
|
|
|
+ wifConfig: &esv1.GCPWorkloadIdentityFederation{
|
|
|
|
|
+ ServiceAccountRef: &esmeta.ServiceAccountSelector{
|
|
|
|
|
+ Name: testServiceAccount,
|
|
|
|
|
+ Namespace: &testNamespace,
|
|
|
|
|
+ Audiences: []string{testAudience},
|
|
|
|
|
+ },
|
|
|
|
|
+ Audience: testAudience,
|
|
|
|
|
+ },
|
|
|
|
|
+ expectError: "failed to fetch serviceaccount \"external-secrets-tests/test-sa\": serviceaccounts \"test-sa\" not found",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "successful kubernetes service account token federation with GCP service account impersonation",
|
|
|
|
|
+ wifConfig: &esv1.GCPWorkloadIdentityFederation{
|
|
|
|
|
+ Audience: testAudience,
|
|
|
|
|
+ ServiceAccountRef: &esmeta.ServiceAccountSelector{
|
|
|
|
|
+ Name: testServiceAccount,
|
|
|
|
|
+ Namespace: &testNamespace,
|
|
|
|
|
+ Audiences: []string{testAudience},
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ kubeObjects: []client.Object{
|
|
|
|
|
+ &corev1.ServiceAccount{
|
|
|
|
|
+ ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
+ Name: testServiceAccount,
|
|
|
|
|
+ Namespace: testNamespace,
|
|
|
|
|
+ Annotations: map[string]string{
|
|
|
|
|
+ gcpSAAnnotation: testGCPServiceAccountEmail,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ genSAToken: func(c context.Context, s1 []string, s2, s3 string) (*authv1.TokenRequest, error) {
|
|
|
|
|
+ return &authv1.TokenRequest{
|
|
|
|
|
+ Status: authv1.TokenRequestStatus{
|
|
|
|
|
+ Token: testSAToken,
|
|
|
|
|
+ },
|
|
|
|
|
+ }, nil
|
|
|
|
|
+ },
|
|
|
|
|
+ expectImpersonationURL: testServiceAccountImpersonationURL,
|
|
|
|
|
+ expectTokenSource: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
name: "valid AWS credentials secret",
|
|
name: "valid AWS credentials secret",
|
|
|
wifConfig: &esv1.GCPWorkloadIdentityFederation{
|
|
wifConfig: &esv1.GCPWorkloadIdentityFederation{
|
|
|
AwsSecurityCredentials: &esv1.AwsCredentialsConfig{
|
|
AwsSecurityCredentials: &esv1.AwsCredentialsConfig{
|
|
@@ -536,6 +587,12 @@ func TestWorkloadIdentityFederation(t *testing.T) {
|
|
|
namespace: testNamespace,
|
|
namespace: testNamespace,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if tc.expectImpersonationURL != "" {
|
|
|
|
|
+ cfg, cfgErr := wif.generateExternalAccountConfig(context.Background(), nil)
|
|
|
|
|
+ assert.NoError(t, cfgErr)
|
|
|
|
|
+ assert.Equal(t, tc.expectImpersonationURL, cfg.ServiceAccountImpersonationURL)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ts, err := wif.TokenSource(context.Background())
|
|
ts, err := wif.TokenSource(context.Background())
|
|
|
if tc.expectError != "" {
|
|
if tc.expectError != "" {
|
|
|
assert.Error(t, err)
|
|
assert.Error(t, err)
|