|
|
@@ -29,7 +29,6 @@ import (
|
|
|
|
|
|
// nolint
|
|
|
. "github.com/onsi/gomega"
|
|
|
- v1 "k8s.io/api/core/v1"
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
|
|
|
|
@@ -37,24 +36,19 @@ import (
|
|
|
esmetav1 "github.com/external-secrets/external-secrets/apis/meta/v1"
|
|
|
"github.com/external-secrets/external-secrets/e2e/framework"
|
|
|
"github.com/external-secrets/external-secrets/e2e/framework/log"
|
|
|
+ common "github.com/external-secrets/external-secrets/e2e/suite/aws"
|
|
|
)
|
|
|
|
|
|
-type SMProvider struct {
|
|
|
+type Provider struct {
|
|
|
ServiceAccountName string
|
|
|
ServiceAccountNamespace string
|
|
|
|
|
|
- kid string
|
|
|
- sak string
|
|
|
region string
|
|
|
client *secretsmanager.SecretsManager
|
|
|
framework *framework.Framework
|
|
|
}
|
|
|
|
|
|
-const (
|
|
|
- staticCredentialsSecretName = "provider-secret"
|
|
|
-)
|
|
|
-
|
|
|
-func NewSMProvider(f *framework.Framework, kid, sak, region, saName, saNamespace string) *SMProvider {
|
|
|
+func NewProvider(f *framework.Framework, kid, sak, region, saName, saNamespace string) *Provider {
|
|
|
sess, err := session.NewSessionWithOptions(session.Options{
|
|
|
Config: aws.Config{
|
|
|
Credentials: credentials.NewStaticCredentials(kid, sak, ""),
|
|
|
@@ -65,18 +59,16 @@ func NewSMProvider(f *framework.Framework, kid, sak, region, saName, saNamespace
|
|
|
Fail(err.Error())
|
|
|
}
|
|
|
sm := secretsmanager.New(sess)
|
|
|
- prov := &SMProvider{
|
|
|
+ prov := &Provider{
|
|
|
ServiceAccountName: saName,
|
|
|
ServiceAccountNamespace: saNamespace,
|
|
|
- kid: kid,
|
|
|
- sak: sak,
|
|
|
region: region,
|
|
|
client: sm,
|
|
|
framework: f,
|
|
|
}
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
- prov.SetupStaticStore()
|
|
|
+ common.SetupStaticStore(f, kid, sak, region, esv1alpha1.AWSServiceSecretsManager)
|
|
|
prov.SetupReferencedIRSAStore()
|
|
|
prov.SetupMountedIRSAStore()
|
|
|
})
|
|
|
@@ -85,7 +77,7 @@ func NewSMProvider(f *framework.Framework, kid, sak, region, saName, saNamespace
|
|
|
// Cleanup ClusterSecretStore
|
|
|
err := prov.framework.CRClient.Delete(context.Background(), &esv1alpha1.ClusterSecretStore{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: prov.ReferencedIRSAStoreName(),
|
|
|
+ Name: common.ReferencedIRSAStoreName(f),
|
|
|
},
|
|
|
})
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
@@ -94,17 +86,17 @@ func NewSMProvider(f *framework.Framework, kid, sak, region, saName, saNamespace
|
|
|
return prov
|
|
|
}
|
|
|
|
|
|
-func NewFromEnv(f *framework.Framework) *SMProvider {
|
|
|
+func NewFromEnv(f *framework.Framework) *Provider {
|
|
|
kid := os.Getenv("AWS_ACCESS_KEY_ID")
|
|
|
sak := os.Getenv("AWS_SECRET_ACCESS_KEY")
|
|
|
region := "eu-west-1"
|
|
|
saName := os.Getenv("AWS_SA_NAME")
|
|
|
saNamespace := os.Getenv("AWS_SA_NAMESPACE")
|
|
|
- return NewSMProvider(f, kid, sak, region, saName, saNamespace)
|
|
|
+ return NewProvider(f, kid, sak, region, saName, saNamespace)
|
|
|
}
|
|
|
|
|
|
// CreateSecret creates a secret at the provider.
|
|
|
-func (s *SMProvider) CreateSecret(key, val string) {
|
|
|
+func (s *Provider) CreateSecret(key, val string) {
|
|
|
// we re-use some secret names throughout our test suite
|
|
|
// due to the fact that there is a short delay before the secret is actually deleted
|
|
|
// we have to retry creating the secret
|
|
|
@@ -129,7 +121,7 @@ func (s *SMProvider) CreateSecret(key, val string) {
|
|
|
// DeleteSecret deletes a secret at the provider.
|
|
|
// There may be a short delay between calling this function
|
|
|
// and the removal of the secret on the provider side.
|
|
|
-func (s *SMProvider) DeleteSecret(key string) {
|
|
|
+func (s *Provider) DeleteSecret(key string) {
|
|
|
log.Logf("deleting secret %s", key)
|
|
|
_, err := s.client.DeleteSecret(&secretsmanager.DeleteSecretInput{
|
|
|
SecretId: aws.String(key),
|
|
|
@@ -140,10 +132,10 @@ func (s *SMProvider) DeleteSecret(key string) {
|
|
|
|
|
|
// MountedIRSAStore is a SecretStore without auth config
|
|
|
// ESO relies on the pod-mounted ServiceAccount when using this store.
|
|
|
-func (s *SMProvider) SetupMountedIRSAStore() {
|
|
|
+func (s *Provider) SetupMountedIRSAStore() {
|
|
|
secretStore := &esv1alpha1.SecretStore{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: s.MountedIRSAStoreName(),
|
|
|
+ Name: common.MountedIRSAStoreName(s.framework),
|
|
|
Namespace: s.framework.Namespace.Name,
|
|
|
},
|
|
|
Spec: esv1alpha1.SecretStoreSpec{
|
|
|
@@ -160,17 +152,13 @@ func (s *SMProvider) SetupMountedIRSAStore() {
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
}
|
|
|
|
|
|
-func (s *SMProvider) MountedIRSAStoreName() string {
|
|
|
- return "irsa-mounted-" + s.framework.Namespace.Name
|
|
|
-}
|
|
|
-
|
|
|
// ReferncedIRSAStore is a ClusterStore
|
|
|
// that references a (IRSA-) ServiceAccount in the default namespace.
|
|
|
-func (s *SMProvider) SetupReferencedIRSAStore() {
|
|
|
+func (s *Provider) SetupReferencedIRSAStore() {
|
|
|
log.Logf("creating IRSA ClusterSecretStore %s", s.framework.Namespace.Name)
|
|
|
secretStore := &esv1alpha1.ClusterSecretStore{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: s.ReferencedIRSAStoreName(),
|
|
|
+ Name: common.ReferencedIRSAStoreName(s.framework),
|
|
|
},
|
|
|
}
|
|
|
_, err := controllerutil.CreateOrUpdate(context.Background(), s.framework.CRClient, secretStore, func() error {
|
|
|
@@ -192,53 +180,3 @@ func (s *SMProvider) SetupReferencedIRSAStore() {
|
|
|
})
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
}
|
|
|
-
|
|
|
-func (s *SMProvider) ReferencedIRSAStoreName() string {
|
|
|
- return "irsa-ref-" + s.framework.Namespace.Name
|
|
|
-}
|
|
|
-
|
|
|
-// StaticStore is namespaced and references
|
|
|
-// static credentials from a secret.
|
|
|
-func (s *SMProvider) SetupStaticStore() {
|
|
|
- awsCreds := &v1.Secret{
|
|
|
- ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: staticCredentialsSecretName,
|
|
|
- Namespace: s.framework.Namespace.Name,
|
|
|
- },
|
|
|
- StringData: map[string]string{
|
|
|
- "kid": s.kid,
|
|
|
- "sak": s.sak,
|
|
|
- },
|
|
|
- }
|
|
|
- err := s.framework.CRClient.Create(context.Background(), awsCreds)
|
|
|
- Expect(err).ToNot(HaveOccurred())
|
|
|
-
|
|
|
- secretStore := &esv1alpha1.SecretStore{
|
|
|
- ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: s.framework.Namespace.Name,
|
|
|
- Namespace: s.framework.Namespace.Name,
|
|
|
- },
|
|
|
- Spec: esv1alpha1.SecretStoreSpec{
|
|
|
- Provider: &esv1alpha1.SecretStoreProvider{
|
|
|
- AWS: &esv1alpha1.AWSProvider{
|
|
|
- Service: esv1alpha1.AWSServiceSecretsManager,
|
|
|
- Region: s.region,
|
|
|
- Auth: esv1alpha1.AWSAuth{
|
|
|
- SecretRef: &esv1alpha1.AWSAuthSecretRef{
|
|
|
- AccessKeyID: esmetav1.SecretKeySelector{
|
|
|
- Name: staticCredentialsSecretName,
|
|
|
- Key: "kid",
|
|
|
- },
|
|
|
- SecretAccessKey: esmetav1.SecretKeySelector{
|
|
|
- Name: staticCredentialsSecretName,
|
|
|
- Key: "sak",
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- }
|
|
|
- err = s.framework.CRClient.Create(context.Background(), secretStore)
|
|
|
- Expect(err).ToNot(HaveOccurred())
|
|
|
-}
|