|
@@ -25,11 +25,13 @@ import (
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
awssm "github.com/aws/aws-sdk-go/service/secretsmanager"
|
|
awssm "github.com/aws/aws-sdk-go/service/secretsmanager"
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
+ corev1 "k8s.io/api/core/v1"
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
|
|
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
|
|
|
fakesm "github.com/external-secrets/external-secrets/pkg/provider/aws/secretsmanager/fake"
|
|
fakesm "github.com/external-secrets/external-secrets/pkg/provider/aws/secretsmanager/fake"
|
|
|
"github.com/external-secrets/external-secrets/pkg/provider/aws/util"
|
|
"github.com/external-secrets/external-secrets/pkg/provider/aws/util"
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/pkg/provider/testing/fake"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type secretsManagerTestCase struct {
|
|
type secretsManagerTestCase struct {
|
|
@@ -365,23 +367,16 @@ func ErrorContains(out error, want string) bool {
|
|
|
return strings.Contains(out.Error(), want)
|
|
return strings.Contains(out.Error(), want)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type fakeRef struct {
|
|
|
|
|
- key string
|
|
|
|
|
- property string
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (f fakeRef) GetRemoteKey() string {
|
|
|
|
|
- return f.key
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (f fakeRef) GetProperty() string {
|
|
|
|
|
- return f.property
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func TestSetSecret(t *testing.T) {
|
|
func TestSetSecret(t *testing.T) {
|
|
|
managedBy := managedBy
|
|
managedBy := managedBy
|
|
|
notManagedBy := "not-managed-by"
|
|
notManagedBy := "not-managed-by"
|
|
|
|
|
+ secretKey := "fake-secret-key"
|
|
|
secretValue := []byte("fake-value")
|
|
secretValue := []byte("fake-value")
|
|
|
|
|
+ fakeSecret := &corev1.Secret{
|
|
|
|
|
+ Data: map[string][]byte{
|
|
|
|
|
+ secretKey: secretValue,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
externalSecrets := externalSecrets
|
|
externalSecrets := externalSecrets
|
|
|
noPermission := errors.New("no permission")
|
|
noPermission := errors.New("no permission")
|
|
|
arn := "arn:aws:secretsmanager:us-east-1:702902267788:secret:foo-bar5-Robbgh"
|
|
arn := "arn:aws:secretsmanager:us-east-1:702902267788:secret:foo-bar5-Robbgh"
|
|
@@ -461,13 +456,13 @@ func TestSetSecret(t *testing.T) {
|
|
|
ARN: &arn,
|
|
ARN: &arn,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- remoteRefWithoutProperty := fakeRef{key: "fake-key", property: ""}
|
|
|
|
|
- remoteRefWithProperty := fakeRef{key: "fake-key", property: "other-fake-property"}
|
|
|
|
|
|
|
+ pushSecretDataWithoutProperty := fake.PushSecretData{SecretKey: secretKey, RemoteKey: "fake-key", Property: ""}
|
|
|
|
|
+ pushSecretDataWithProperty := fake.PushSecretData{SecretKey: secretKey, RemoteKey: "fake-key", Property: "other-fake-property"}
|
|
|
|
|
|
|
|
type args struct {
|
|
type args struct {
|
|
|
- store *esv1beta1.AWSProvider
|
|
|
|
|
- client fakesm.Client
|
|
|
|
|
- remoteRef fakeRef
|
|
|
|
|
|
|
+ store *esv1beta1.AWSProvider
|
|
|
|
|
+ client fakesm.Client
|
|
|
|
|
+ pushSecretData fake.PushSecretData
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type want struct {
|
|
type want struct {
|
|
@@ -488,7 +483,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
PutSecretValueWithContextFn: fakesm.NewPutSecretValueWithContextFn(putSecretOutput, nil),
|
|
PutSecretValueWithContextFn: fakesm.NewPutSecretValueWithContextFn(putSecretOutput, nil),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
@@ -502,28 +497,28 @@ func TestSetSecret(t *testing.T) {
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil),
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretWithPropertySucceedsWithNewSecret": {
|
|
"SetSecretWithPropertySucceedsWithNewSecret": {
|
|
|
- reason: "if a new secret is pushed to aws sm and a remoteRef property is specified, create a json secret with the remoteRef property as a key",
|
|
|
|
|
|
|
+ reason: "if a new secret is pushed to aws sm and a pushSecretData property is specified, create a json secret with the pushSecretData property as a key",
|
|
|
args: args{
|
|
args: args{
|
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil, []byte(`{"other-fake-property":"fake-value"}`)),
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(secretOutput, nil, []byte(`{"other-fake-property":"fake-value"}`)),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyBinary": {
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyBinary": {
|
|
|
- reason: "when a remoteRef property is specified, this property will be added to the sm secret if it is currently absent (sm secret is binary)",
|
|
|
|
|
|
|
+ reason: "when a pushSecretData property is specified, this property will be added to the sm secret if it is currently absent (sm secret is binary)",
|
|
|
args: args{
|
|
args: args{
|
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
@@ -534,7 +529,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &defaultUpdatedVersion,
|
|
Version: &defaultUpdatedVersion,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
@@ -555,7 +550,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &randomUUIDVersionIncremented,
|
|
Version: &randomUUIDVersionIncremented,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
@@ -576,7 +571,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &initialVersion,
|
|
Version: &initialVersion,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: fmt.Errorf("expected secret version in AWS SSM to be a UUID but got '%s'", unparsableVersion),
|
|
err: fmt.Errorf("expected secret version in AWS SSM to be a UUID but got '%s'", unparsableVersion),
|
|
@@ -597,14 +592,14 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &initialVersion,
|
|
Version: &initialVersion,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyString": {
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyString": {
|
|
|
- reason: "when a remoteRef property is specified, this property will be added to the sm secret if it is currently absent (sm secret is a string)",
|
|
|
|
|
|
|
+ reason: "when a pushSecretData property is specified, this property will be added to the sm secret if it is currently absent (sm secret is a string)",
|
|
|
args: args{
|
|
args: args{
|
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
@@ -615,14 +610,14 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &defaultUpdatedVersion,
|
|
Version: &defaultUpdatedVersion,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyWithDot": {
|
|
"SetSecretWithPropertySucceedsWithExistingSecretAndNewPropertyWithDot": {
|
|
|
- reason: "when a remoteRef property is specified, this property will be added to the sm secret if it is currently absent (remoteRef property is a sub-object)",
|
|
|
|
|
|
|
+ reason: "when a pushSecretData property is specified, this property will be added to the sm secret if it is currently absent (pushSecretData property is a sub-object)",
|
|
|
args: args{
|
|
args: args{
|
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
@@ -633,24 +628,24 @@ func TestSetSecret(t *testing.T) {
|
|
|
Version: &defaultUpdatedVersion,
|
|
Version: &defaultUpdatedVersion,
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- remoteRef: fakeRef{key: "fake-key", property: "fake-property.other-fake-property"},
|
|
|
|
|
|
|
+ pushSecretData: fake.PushSecretData{SecretKey: secretKey, RemoteKey: "fake-key", Property: "fake-property.other-fake-property"},
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretWithPropertyFailsExistingNonJsonSecret": {
|
|
"SetSecretWithPropertyFailsExistingNonJsonSecret": {
|
|
|
- reason: "setting a remoteRef property is only supported for json secrets",
|
|
|
|
|
|
|
+ reason: "setting a pushSecretData property is only supported for json secrets",
|
|
|
args: args{
|
|
args: args{
|
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
store: makeValidSecretStore().Spec.Provider.AWS,
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutputFrom(params{s: `non-json-secret`}), nil),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutputFrom(params{s: `non-json-secret`}), nil),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
- err: errors.New("PushSecret for aws secrets manager with a remoteRef property requires a json secret"),
|
|
|
|
|
|
|
+ err: errors.New("PushSecret for aws secrets manager with a pushSecretData property requires a json secret"),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
"SetSecretCreateSecretFails": {
|
|
"SetSecretCreateSecretFails": {
|
|
@@ -661,7 +656,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretCorrectErr),
|
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(nil, noPermission),
|
|
CreateSecretWithContextFn: fakesm.NewCreateSecretWithContextFn(nil, noPermission),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: noPermission,
|
|
err: noPermission,
|
|
@@ -674,7 +669,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, noPermission),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, noPermission),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: noPermission,
|
|
err: noPermission,
|
|
@@ -688,7 +683,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput2, nil),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput2, nil),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: nil,
|
|
err: nil,
|
|
@@ -703,7 +698,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
PutSecretValueWithContextFn: fakesm.NewPutSecretValueWithContextFn(nil, noPermission),
|
|
PutSecretValueWithContextFn: fakesm.NewPutSecretValueWithContextFn(nil, noPermission),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutput, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: noPermission,
|
|
err: noPermission,
|
|
@@ -716,7 +711,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
client: fakesm.Client{
|
|
client: fakesm.Client{
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretWrongErr),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(blankSecretValueOutput, &getSecretWrongErr),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: &getSecretWrongErr,
|
|
err: &getSecretWrongErr,
|
|
@@ -730,7 +725,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(nil, noPermission),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(nil, noPermission),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: noPermission,
|
|
err: noPermission,
|
|
@@ -744,7 +739,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
|
|
GetSecretValueWithContextFn: fakesm.NewGetSecretValueWithContextFn(secretValueOutput, nil),
|
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutputFaulty, nil),
|
|
DescribeSecretWithContextFn: fakesm.NewDescribeSecretWithContextFn(tagSecretOutputFaulty, nil),
|
|
|
},
|
|
},
|
|
|
- remoteRef: remoteRefWithoutProperty,
|
|
|
|
|
|
|
+ pushSecretData: pushSecretDataWithoutProperty,
|
|
|
},
|
|
},
|
|
|
want: want{
|
|
want: want{
|
|
|
err: fmt.Errorf("secret not managed by external-secrets"),
|
|
err: fmt.Errorf("secret not managed by external-secrets"),
|
|
@@ -757,7 +752,7 @@ func TestSetSecret(t *testing.T) {
|
|
|
sm := SecretsManager{
|
|
sm := SecretsManager{
|
|
|
client: &tc.args.client,
|
|
client: &tc.args.client,
|
|
|
}
|
|
}
|
|
|
- err := sm.PushSecret(context.Background(), []byte("fake-value"), "", nil, tc.args.remoteRef)
|
|
|
|
|
|
|
+ err := sm.PushSecret(context.Background(), fakeSecret, tc.args.pushSecretData)
|
|
|
|
|
|
|
|
// Error nil XOR tc.want.err nil
|
|
// Error nil XOR tc.want.err nil
|
|
|
if ((err == nil) || (tc.want.err == nil)) && !((err == nil) && (tc.want.err == nil)) {
|
|
if ((err == nil) || (tc.want.err == nil)) && !((err == nil) && (tc.want.err == nil)) {
|
|
@@ -897,7 +892,7 @@ func TestDeleteSecret(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
for name, tc := range tests {
|
|
for name, tc := range tests {
|
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Run(name, func(t *testing.T) {
|
|
|
- ref := fakeRef{key: "fake-key"}
|
|
|
|
|
|
|
+ ref := fake.PushSecretData{RemoteKey: "fake-key"}
|
|
|
sm := SecretsManager{
|
|
sm := SecretsManager{
|
|
|
client: &tc.args.client,
|
|
client: &tc.args.client,
|
|
|
}
|
|
}
|