assume_role.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. limitations under the License.
  10. */
  11. package aws
  12. import (
  13. "fmt"
  14. v1 "k8s.io/api/core/v1"
  15. "github.com/external-secrets/external-secrets-e2e/framework"
  16. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  17. )
  18. // This case creates secret with specific tags which are checked by the assumed IAM policy
  19. func SimpleSyncWithNamespaceTags(prov *Provider) func(f *framework.Framework) (string, func(*framework.TestCase)) {
  20. return func(f *framework.Framework) (string, func(*framework.TestCase)) {
  21. return "[common] should sync tagged simple secrets from .Data[]", func(tc *framework.TestCase) {
  22. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  23. secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "other")
  24. remoteRefKey1 := f.MakeRemoteRefKey(secretKey1)
  25. remoteRefKey2 := f.MakeRemoteRefKey(secretKey2)
  26. secretValue := "bar"
  27. tc.Secrets = map[string]framework.SecretEntry{
  28. // add specific tags to the secret resource. The assumed role only allows access to those
  29. remoteRefKey1: {Value: secretValue, Tags: map[string]string{"namespace": "e2e-test"}},
  30. remoteRefKey2: {Value: secretValue, Tags: map[string]string{"namespace": "e2e-test"}},
  31. }
  32. tc.ExpectedSecret = &v1.Secret{
  33. Type: v1.SecretTypeOpaque,
  34. Data: map[string][]byte{
  35. secretKey1: []byte(secretValue),
  36. secretKey2: []byte(secretValue),
  37. },
  38. }
  39. tc.ExternalSecret.Spec.Data = []esapi.ExternalSecretData{
  40. {
  41. SecretKey: secretKey1,
  42. RemoteRef: esapi.ExternalSecretDataRemoteRef{
  43. Key: remoteRefKey1,
  44. },
  45. },
  46. {
  47. SecretKey: secretKey2,
  48. RemoteRef: esapi.ExternalSecretDataRemoteRef{
  49. Key: remoteRefKey2,
  50. },
  51. },
  52. }
  53. }
  54. }
  55. }