gcp_managed.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 gcp
  12. import (
  13. // nolint
  14. . "github.com/onsi/ginkgo/v2"
  15. // nolint
  16. // . "github.com/onsi/gomega"
  17. esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  18. "github.com/external-secrets/external-secrets/e2e/framework"
  19. "github.com/external-secrets/external-secrets/e2e/framework/addon"
  20. "github.com/external-secrets/external-secrets/e2e/suite/common"
  21. )
  22. const (
  23. withPodID = "sync secrets with pod identity"
  24. withSpecifcSA = "sync secrets with specificSA identity"
  25. )
  26. // Deploys eso to the default namespace
  27. // that uses the service account provisioned by terraform
  28. // to test pod-identity authentication.
  29. var _ = Describe("[gcpmanaged] with pod identity", Label("gcp", "secretsmanager", "managed", "pod-identity"), func() {
  30. f := framework.New("eso-gcpmanaged")
  31. prov := NewFromEnv(f, f.BaseName)
  32. // each test case gets its own ESO instance
  33. BeforeEach(func() {
  34. f.Install(addon.NewESO(
  35. addon.WithControllerClass(f.BaseName),
  36. addon.WithServiceAccount(prov.ServiceAccountName),
  37. addon.WithReleaseName(f.Namespace.Name),
  38. addon.WithNamespace("default"),
  39. addon.WithoutWebhook(),
  40. addon.WithoutCertController(),
  41. ))
  42. })
  43. DescribeTable("sync secrets",
  44. framework.TableFunc(f,
  45. prov),
  46. // uses pod id
  47. framework.Compose(withPodID, f, common.SimpleDataSync, usePodIDESReference),
  48. framework.Compose(withPodID, f, common.JSONDataWithProperty, usePodIDESReference),
  49. framework.Compose(withPodID, f, common.JSONDataFromSync, usePodIDESReference),
  50. framework.Compose(withPodID, f, common.NestedJSONWithGJSON, usePodIDESReference),
  51. framework.Compose(withPodID, f, common.JSONDataWithTemplate, usePodIDESReference),
  52. framework.Compose(withPodID, f, common.DockerJSONConfig, usePodIDESReference),
  53. framework.Compose(withPodID, f, common.DataPropertyDockerconfigJSON, usePodIDESReference),
  54. framework.Compose(withPodID, f, common.SSHKeySync, usePodIDESReference),
  55. framework.Compose(withPodID, f, common.SSHKeySyncDataProperty, usePodIDESReference),
  56. framework.Compose(withPodID, f, common.SyncWithoutTargetName, usePodIDESReference),
  57. framework.Compose(withPodID, f, common.JSONDataWithoutTargetName, usePodIDESReference),
  58. )
  59. })
  60. // We're using a namespace scoped ESO
  61. // that runs WITHOUT pod identity (with default sa)
  62. // It uses a specific service account defined in the ClusterSecretStore spec
  63. // to authenticate against cloud provider APIs.
  64. var _ = Describe("[gcpmanaged] with service account", Label("gcp", "secretsmanager", "managed", "service-account"), func() {
  65. f := framework.New("eso-gcpmanaged")
  66. prov := NewFromEnv(f, f.BaseName)
  67. BeforeEach(func() {
  68. f.Install(addon.NewESO(
  69. addon.WithControllerClass(f.BaseName),
  70. addon.WithReleaseName(f.Namespace.Name),
  71. addon.WithNamespace(f.Namespace.Name),
  72. addon.WithoutWebhook(),
  73. addon.WithoutCertController(),
  74. ))
  75. })
  76. DescribeTable("sync secrets",
  77. framework.TableFunc(f,
  78. prov),
  79. // uses specific sa
  80. framework.Compose(withSpecifcSA, f, common.JSONDataFromSync, useSpecifcSAESReference(prov)),
  81. framework.Compose(withSpecifcSA, f, common.JSONDataWithProperty, useSpecifcSAESReference(prov)),
  82. framework.Compose(withSpecifcSA, f, common.JSONDataFromSync, useSpecifcSAESReference(prov)),
  83. framework.Compose(withSpecifcSA, f, common.NestedJSONWithGJSON, useSpecifcSAESReference(prov)),
  84. framework.Compose(withSpecifcSA, f, common.JSONDataWithTemplate, useSpecifcSAESReference(prov)),
  85. framework.Compose(withSpecifcSA, f, common.DockerJSONConfig, useSpecifcSAESReference(prov)),
  86. framework.Compose(withSpecifcSA, f, common.DataPropertyDockerconfigJSON, useSpecifcSAESReference(prov)),
  87. framework.Compose(withSpecifcSA, f, common.SSHKeySync, useSpecifcSAESReference(prov)),
  88. framework.Compose(withSpecifcSA, f, common.SSHKeySyncDataProperty, useSpecifcSAESReference(prov)),
  89. framework.Compose(withSpecifcSA, f, common.SyncWithoutTargetName, useSpecifcSAESReference(prov)),
  90. framework.Compose(withSpecifcSA, f, common.JSONDataWithoutTargetName, useSpecifcSAESReference(prov)),
  91. )
  92. })
  93. func usePodIDESReference(tc *framework.TestCase) {
  94. tc.ExternalSecret.Spec.SecretStoreRef.Name = PodIDSecretStoreName
  95. }
  96. func useSpecifcSAESReference(prov *GcpProvider) func(*framework.TestCase) {
  97. return func(tc *framework.TestCase) {
  98. tc.ExternalSecret.Spec.SecretStoreRef.Kind = esv1beta1.ClusterSecretStoreKind
  99. tc.ExternalSecret.Spec.SecretStoreRef.Name = prov.SAClusterSecretStoreName()
  100. }
  101. }