gcp_managed.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package gcp
  14. import (
  15. // nolint
  16. . "github.com/onsi/ginkgo/v2"
  17. // nolint
  18. // . "github.com/onsi/gomega"
  19. "github.com/external-secrets/external-secrets-e2e/framework"
  20. "github.com/external-secrets/external-secrets-e2e/framework/addon"
  21. "github.com/external-secrets/external-secrets-e2e/suites/provider/cases/common"
  22. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  23. )
  24. const (
  25. withPodID = "sync secrets with pod identity"
  26. withSpecifcSA = "sync secrets with specificSA identity"
  27. )
  28. // Deploys eso to the default namespace
  29. // that uses the service account provisioned by terraform
  30. // to test pod-identity authentication.
  31. var _ = Describe("[gcpmanaged] with pod identity", Label("gcp", "secretsmanager", "managed", "pod-identity"), func() {
  32. f := framework.New("eso-gcpmanaged")
  33. prov := NewFromEnv(f, f.BaseName)
  34. // each test case gets its own ESO instance
  35. BeforeEach(func() {
  36. f.Install(addon.NewESO(
  37. addon.WithControllerClass(f.BaseName),
  38. addon.WithServiceAccount(prov.ServiceAccountName),
  39. addon.WithReleaseName(f.Namespace.Name),
  40. addon.WithNamespace("default"),
  41. addon.WithoutWebhook(),
  42. addon.WithoutCertController(),
  43. ))
  44. })
  45. DescribeTable("sync secrets",
  46. framework.TableFuncWithExternalSecret(f,
  47. prov),
  48. // uses pod id
  49. framework.Compose(withPodID, f, common.SimpleDataSync, usePodIDESReference),
  50. framework.Compose(withPodID, f, common.JSONDataWithProperty, usePodIDESReference),
  51. framework.Compose(withPodID, f, common.JSONDataFromSync, usePodIDESReference),
  52. framework.Compose(withPodID, f, common.NestedJSONWithGJSON, usePodIDESReference),
  53. framework.Compose(withPodID, f, common.JSONDataWithTemplate, usePodIDESReference),
  54. framework.Compose(withPodID, f, common.DockerJSONConfig, usePodIDESReference),
  55. framework.Compose(withPodID, f, common.DataPropertyDockerconfigJSON, usePodIDESReference),
  56. framework.Compose(withPodID, f, common.SSHKeySync, usePodIDESReference),
  57. framework.Compose(withPodID, f, common.SSHKeySyncDataProperty, usePodIDESReference),
  58. framework.Compose(withPodID, f, common.SyncWithoutTargetName, usePodIDESReference),
  59. framework.Compose(withPodID, f, common.JSONDataWithoutTargetName, usePodIDESReference),
  60. )
  61. })
  62. // We're using a namespace scoped ESO
  63. // that runs WITHOUT pod identity (with default sa)
  64. // It uses a specific service account defined in the ClusterSecretStore spec
  65. // to authenticate against cloud provider APIs.
  66. var _ = Describe("[gcpmanaged] with service account", Label("gcp", "secretsmanager", "managed", "service-account"), func() {
  67. f := framework.New("eso-gcpmanaged")
  68. prov := NewFromEnv(f, f.BaseName)
  69. BeforeEach(func() {
  70. f.Install(addon.NewESO(
  71. addon.WithControllerClass(f.BaseName),
  72. addon.WithReleaseName(f.Namespace.Name),
  73. addon.WithNamespace(f.Namespace.Name),
  74. addon.WithoutWebhook(),
  75. addon.WithoutCertController(),
  76. ))
  77. })
  78. DescribeTable("sync secrets",
  79. framework.TableFuncWithExternalSecret(f,
  80. prov),
  81. // uses specific sa
  82. framework.Compose(withSpecifcSA, f, common.JSONDataFromSync, useSpecifcSAESReference(prov)),
  83. framework.Compose(withSpecifcSA, f, common.JSONDataWithProperty, useSpecifcSAESReference(prov)),
  84. framework.Compose(withSpecifcSA, f, common.JSONDataFromSync, useSpecifcSAESReference(prov)),
  85. framework.Compose(withSpecifcSA, f, common.NestedJSONWithGJSON, useSpecifcSAESReference(prov)),
  86. framework.Compose(withSpecifcSA, f, common.JSONDataWithTemplate, useSpecifcSAESReference(prov)),
  87. framework.Compose(withSpecifcSA, f, common.DockerJSONConfig, useSpecifcSAESReference(prov)),
  88. framework.Compose(withSpecifcSA, f, common.DataPropertyDockerconfigJSON, useSpecifcSAESReference(prov)),
  89. framework.Compose(withSpecifcSA, f, common.SSHKeySync, useSpecifcSAESReference(prov)),
  90. framework.Compose(withSpecifcSA, f, common.SSHKeySyncDataProperty, useSpecifcSAESReference(prov)),
  91. framework.Compose(withSpecifcSA, f, common.SyncWithoutTargetName, useSpecifcSAESReference(prov)),
  92. framework.Compose(withSpecifcSA, f, common.JSONDataWithoutTargetName, useSpecifcSAESReference(prov)),
  93. )
  94. })
  95. func usePodIDESReference(tc *framework.TestCase) {
  96. tc.ExternalSecret.Spec.SecretStoreRef.Name = PodIDSecretStoreName
  97. }
  98. func useSpecifcSAESReference(prov *GcpProvider) func(*framework.TestCase) {
  99. return func(tc *framework.TestCase) {
  100. tc.ExternalSecret.Spec.SecretStoreRef.Kind = esv1.ClusterSecretStoreKind
  101. tc.ExternalSecret.Spec.SecretStoreRef.Name = prov.SAClusterSecretStoreName()
  102. }
  103. }