secretserver.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Copyright © The ESO Authors
  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 secretserver
  14. import (
  15. "context"
  16. _ "fmt"
  17. "github.com/external-secrets/external-secrets-e2e/framework"
  18. "github.com/external-secrets/external-secrets-e2e/suites/provider/cases/common"
  19. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  20. esmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
  21. . "github.com/onsi/ginkgo/v2"
  22. . "github.com/onsi/gomega"
  23. v1 "k8s.io/api/core/v1"
  24. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  25. )
  26. var _ = PDescribe("[secretserver]", Label("secretserver"), func() {
  27. f := framework.New("eso-secretserver")
  28. // Initialization is deferred so that assertions work.
  29. provider := &secretStoreProvider{}
  30. BeforeEach(func() {
  31. cfg, err := loadConfigFromEnv()
  32. Expect(err).ToNot(HaveOccurred())
  33. provider.init(cfg, f)
  34. createResources(GinkgoT().Context(), f, cfg)
  35. })
  36. DescribeTable("sync secrets", framework.TableFuncWithExternalSecret(f, provider),
  37. Entry(common.JSONDataWithTemplate(f)),
  38. Entry(common.JSONDataWithProperty(f)),
  39. Entry(common.JSONDataWithoutTargetName(f)),
  40. Entry(common.JSONDataWithTemplateFromLiteral(f)),
  41. Entry(common.TemplateFromConfigmaps(f)),
  42. Entry(common.JSONDataFromSync(f)), // <--
  43. Entry(common.JSONDataFromRewrite(f)), // <--
  44. Entry(common.NestedJSONWithGJSON(f)),
  45. Entry(common.DockerJSONConfig(f)),
  46. Entry(common.DataPropertyDockerconfigJSON(f)),
  47. Entry(common.SSHKeySyncDataProperty(f)),
  48. Entry(common.DecodingPolicySync(f)), // <--
  49. )
  50. })
  51. func createResources(ctx context.Context, f *framework.Framework, cfg *config) {
  52. secretName := "secretserver-credential"
  53. secretKey := "password"
  54. // Creating a secret to hold the Delinea client secret.
  55. secretSpec := v1.Secret{
  56. ObjectMeta: metav1.ObjectMeta{
  57. Name: secretName,
  58. Namespace: f.Namespace.Name,
  59. },
  60. StringData: map[string]string{
  61. secretKey: cfg.password,
  62. },
  63. }
  64. err := f.CRClient.Create(ctx, &secretSpec)
  65. Expect(err).ToNot(HaveOccurred())
  66. // Creating SecretStore.
  67. secretStoreSpec := esv1.SecretStore{
  68. ObjectMeta: metav1.ObjectMeta{
  69. Name: f.Namespace.Name,
  70. Namespace: f.Namespace.Name,
  71. },
  72. Spec: esv1.SecretStoreSpec{
  73. Provider: &esv1.SecretStoreProvider{
  74. SecretServer: &esv1.SecretServerProvider{
  75. ServerURL: cfg.serverURL,
  76. Username: &esv1.SecretServerProviderRef{
  77. Value: cfg.username,
  78. },
  79. Password: &esv1.SecretServerProviderRef{
  80. SecretRef: &esmeta.SecretKeySelector{
  81. Name: secretName,
  82. Key: secretKey,
  83. },
  84. },
  85. },
  86. },
  87. },
  88. }
  89. err = f.CRClient.Create(ctx, &secretStoreSpec)
  90. Expect(err).ToNot(HaveOccurred())
  91. }