common.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 common
  12. import (
  13. "context"
  14. "fmt"
  15. "time"
  16. "github.com/onsi/gomega"
  17. v1 "k8s.io/api/core/v1"
  18. "k8s.io/apimachinery/pkg/api/errors"
  19. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  20. esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  21. esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  22. "github.com/external-secrets/external-secrets/e2e/framework"
  23. )
  24. const (
  25. // Constants.
  26. dockerConfigExampleName = "docker-config-example"
  27. dockerConfigJSONKey = ".dockerconfigjson"
  28. mysecretToStringTemplating = "{{ .mysecret }}"
  29. sshPrivateKey = "ssh-privatekey"
  30. secretValue1 = "{\"foo1\":\"foo1-val\",\"bar1\":\"bar1-val\"}"
  31. secretValue2 = "{\"foo2\":\"foo2-val\",\"bar2\":\"bar2-val\"}"
  32. )
  33. // This case creates one secret with json values and syncs them using a single .Spec.DataFrom block.
  34. func SyncV1Alpha1(f *framework.Framework) (string, func(*framework.TestCase)) {
  35. return "[common] should sync secrets from v1alpha1 spec", func(tc *framework.TestCase) {
  36. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  37. targetSecretKey1 := "alpha-name"
  38. targetSecretValue1 := "alpha-great-name"
  39. targetSecretKey2 := "alpha-surname"
  40. targetSecretValue2 := "alpha-great-surname"
  41. secretValue := fmt.Sprintf("{ %q: %q, %q: %q }", targetSecretKey1, targetSecretValue1, targetSecretKey2, targetSecretValue2)
  42. tc.Secrets = map[string]framework.SecretEntry{
  43. secretKey1: {Value: secretValue},
  44. }
  45. tc.ExpectedSecret = &v1.Secret{
  46. Type: v1.SecretTypeOpaque,
  47. Data: map[string][]byte{
  48. targetSecretKey1: []byte(targetSecretValue1),
  49. targetSecretKey2: []byte(targetSecretValue2),
  50. },
  51. }
  52. tc.ExternalSecretV1Alpha1 = &esv1alpha1.ExternalSecret{
  53. ObjectMeta: metav1.ObjectMeta{
  54. Name: "e2e-es",
  55. Namespace: f.Namespace.Name,
  56. },
  57. Spec: esv1alpha1.ExternalSecretSpec{
  58. SecretStoreRef: esv1alpha1.SecretStoreRef{
  59. Name: f.Namespace.Name,
  60. },
  61. Target: esv1alpha1.ExternalSecretTarget{
  62. Name: framework.TargetSecretName,
  63. },
  64. DataFrom: []esv1alpha1.ExternalSecretDataRemoteRef{
  65. {
  66. Key: secretKey1,
  67. },
  68. },
  69. },
  70. }
  71. }
  72. }
  73. // This case creates multiple secrets with simple key/value pairs and syncs them using multiple .Spec.Data blocks.
  74. // Not supported by: vault.
  75. func SimpleDataSync(f *framework.Framework) (string, func(*framework.TestCase)) {
  76. return "[common] should sync simple secrets from .Data[]", func(tc *framework.TestCase) {
  77. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  78. secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "other")
  79. secretValue := "bar"
  80. tc.Secrets = map[string]framework.SecretEntry{
  81. secretKey1: {Value: secretValue},
  82. secretKey2: {Value: secretValue},
  83. }
  84. tc.ExpectedSecret = &v1.Secret{
  85. Type: v1.SecretTypeOpaque,
  86. Data: map[string][]byte{
  87. secretKey1: []byte(secretValue),
  88. secretKey2: []byte(secretValue),
  89. },
  90. }
  91. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  92. {
  93. SecretKey: secretKey1,
  94. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  95. Key: secretKey1,
  96. },
  97. },
  98. {
  99. SecretKey: secretKey2,
  100. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  101. Key: secretKey2,
  102. },
  103. },
  104. }
  105. }
  106. }
  107. // This case creates a secret with empty target name to test if it defaults to external secret name.
  108. // Not supported by: vault.
  109. func SyncWithoutTargetName(f *framework.Framework) (string, func(*framework.TestCase)) {
  110. return "[common] should sync with empty target name.", func(tc *framework.TestCase) {
  111. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  112. secretValue := "bar"
  113. tc.Secrets = map[string]framework.SecretEntry{
  114. secretKey1: {Value: secretValue},
  115. }
  116. tc.ExpectedSecret = &v1.Secret{
  117. Type: v1.SecretTypeOpaque,
  118. Data: map[string][]byte{
  119. secretKey1: []byte(secretValue),
  120. },
  121. }
  122. tc.ExternalSecret.Spec.Target.Name = ""
  123. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  124. {
  125. SecretKey: secretKey1,
  126. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  127. Key: secretKey1,
  128. },
  129. },
  130. }
  131. }
  132. }
  133. // This case creates multiple secrets with json values and syncs them using multiple .Spec.Data blocks.
  134. // The data is extracted from the JSON key using ref.Property.
  135. func JSONDataWithProperty(f *framework.Framework) (string, func(*framework.TestCase)) {
  136. return "[common] should sync multiple secrets from .Data[]", func(tc *framework.TestCase) {
  137. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  138. secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "two")
  139. tc.Secrets = map[string]framework.SecretEntry{
  140. secretKey1: {Value: secretValue1},
  141. secretKey2: {Value: secretValue2},
  142. }
  143. tc.ExpectedSecret = &v1.Secret{
  144. Type: v1.SecretTypeOpaque,
  145. Data: map[string][]byte{
  146. secretKey1: []byte("foo1-val"),
  147. secretKey2: []byte("bar2-val"),
  148. },
  149. }
  150. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  151. {
  152. SecretKey: secretKey1,
  153. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  154. Key: secretKey1,
  155. Property: "foo1",
  156. },
  157. },
  158. {
  159. SecretKey: secretKey2,
  160. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  161. Key: secretKey2,
  162. Property: "bar2",
  163. },
  164. },
  165. }
  166. }
  167. }
  168. // This case creates a secret with empty target name to test if it defaults to external secret name.
  169. // The data is extracted from the JSON key using ref.Property.
  170. func JSONDataWithoutTargetName(f *framework.Framework) (string, func(*framework.TestCase)) {
  171. return "[common] should sync with empty target name, using json.", func(tc *framework.TestCase) {
  172. secretKey := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  173. secretValue := "{\"foo\":\"foo-val\",\"bar\":\"bar-val\"}"
  174. tc.Secrets = map[string]framework.SecretEntry{
  175. secretKey: {Value: secretValue},
  176. }
  177. tc.ExpectedSecret = &v1.Secret{
  178. Type: v1.SecretTypeOpaque,
  179. Data: map[string][]byte{
  180. secretKey: []byte("foo-val"),
  181. },
  182. }
  183. tc.ExternalSecret.Spec.Target.Name = ""
  184. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  185. {
  186. SecretKey: secretKey,
  187. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  188. Key: secretKey,
  189. Property: "foo",
  190. },
  191. },
  192. }
  193. }
  194. }
  195. // This case creates multiple secrets with json values and renders a template.
  196. // The data is extracted from the JSON key using ref.Property.
  197. func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestCase)) {
  198. return "[common] should sync json secrets with template", func(tc *framework.TestCase) {
  199. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  200. secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "other")
  201. tc.Secrets = map[string]framework.SecretEntry{
  202. secretKey1: {Value: secretValue1},
  203. secretKey2: {Value: secretValue2},
  204. }
  205. tc.ExpectedSecret = &v1.Secret{
  206. Type: v1.SecretTypeOpaque,
  207. ObjectMeta: metav1.ObjectMeta{
  208. Annotations: map[string]string{
  209. "example": "annotation",
  210. },
  211. Labels: map[string]string{
  212. "example": "label",
  213. },
  214. },
  215. Data: map[string][]byte{
  216. "my-data": []byte(`executed: foo1-val|bar2-val`),
  217. },
  218. }
  219. tc.ExternalSecret.Spec.Target.Template = &esv1beta1.ExternalSecretTemplate{
  220. Metadata: esv1beta1.ExternalSecretTemplateMetadata{
  221. Annotations: map[string]string{
  222. "example": "annotation",
  223. },
  224. Labels: map[string]string{
  225. "example": "label",
  226. },
  227. },
  228. Data: map[string]string{
  229. "my-data": "executed: {{ .one }}|{{ .two }}",
  230. },
  231. }
  232. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  233. {
  234. SecretKey: "one",
  235. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  236. Key: secretKey1,
  237. Property: "foo1",
  238. },
  239. },
  240. {
  241. SecretKey: "two",
  242. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  243. Key: secretKey2,
  244. Property: "bar2",
  245. },
  246. },
  247. }
  248. }
  249. }
  250. // This case creates one secret with json values and syncs them using a single .Spec.DataFrom block.
  251. func JSONDataFromSync(f *framework.Framework) (string, func(*framework.TestCase)) {
  252. return "[common] should sync secrets with dataFrom", func(tc *framework.TestCase) {
  253. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  254. targetSecretKey1 := "name"
  255. targetSecretValue1 := "great-name"
  256. targetSecretKey2 := "surname"
  257. targetSecretValue2 := "great-surname"
  258. secretValue := fmt.Sprintf("{ %q: %q, %q: %q }", targetSecretKey1, targetSecretValue1, targetSecretKey2, targetSecretValue2)
  259. tc.Secrets = map[string]framework.SecretEntry{
  260. secretKey1: {Value: secretValue},
  261. }
  262. tc.ExpectedSecret = &v1.Secret{
  263. Type: v1.SecretTypeOpaque,
  264. Data: map[string][]byte{
  265. targetSecretKey1: []byte(targetSecretValue1),
  266. targetSecretKey2: []byte(targetSecretValue2),
  267. },
  268. }
  269. tc.ExternalSecret.Spec.DataFrom = []esv1beta1.ExternalSecretDataFromRemoteRef{
  270. {
  271. Extract: &esv1beta1.ExternalSecretDataRemoteRef{
  272. Key: secretKey1,
  273. },
  274. },
  275. }
  276. }
  277. }
  278. // This case creates a secret with a nested json value. It is synced into two secrets.
  279. // The values from the nested data are extracted using gjson.
  280. // not supported by: vault.
  281. func NestedJSONWithGJSON(f *framework.Framework) (string, func(*framework.TestCase)) {
  282. return "[common] should sync nested json secrets and get inner keys", func(tc *framework.TestCase) {
  283. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  284. targetSecretKey1 := "firstname"
  285. targetSecretValue1 := "Tom"
  286. targetSecretKey2 := "first_friend"
  287. targetSecretValue2 := "Roger"
  288. secretValue := fmt.Sprintf(
  289. `{
  290. "name": {"first": "%s", "last": "Anderson"},
  291. "friends":
  292. [
  293. {"first": "Dale", "last": "Murphy"},
  294. {"first": "%s", "last": "Craig"},
  295. {"first": "Jane", "last": "Murphy"}
  296. ]
  297. }`, targetSecretValue1, targetSecretValue2)
  298. tc.Secrets = map[string]framework.SecretEntry{
  299. secretKey1: {Value: secretValue},
  300. }
  301. tc.ExpectedSecret = &v1.Secret{
  302. Type: v1.SecretTypeOpaque,
  303. Data: map[string][]byte{
  304. targetSecretKey1: []byte(targetSecretValue1),
  305. targetSecretKey2: []byte(targetSecretValue2),
  306. },
  307. }
  308. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  309. {
  310. SecretKey: targetSecretKey1,
  311. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  312. Key: secretKey1,
  313. Property: "name.first",
  314. },
  315. },
  316. {
  317. SecretKey: targetSecretKey2,
  318. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  319. Key: secretKey1,
  320. Property: "friends.1.first",
  321. },
  322. },
  323. }
  324. }
  325. }
  326. // This case creates a secret with a Docker json configuration value.
  327. // The values from the nested data are extracted using gjson.
  328. // not supported by: vault.
  329. func DockerJSONConfig(f *framework.Framework) (string, func(*framework.TestCase)) {
  330. return "[common] should sync docker configurated json secrets with template simple", func(tc *framework.TestCase) {
  331. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  332. dockerconfig := `{"auths":{"https://index.docker.io/v1/": {"auth": "c3R...zE2"}}}`
  333. cloudSecretValue := fmt.Sprintf(`{"dockerconfig": %s}`, dockerconfig)
  334. tc.Secrets = map[string]framework.SecretEntry{
  335. cloudSecretName: {Value: cloudSecretValue},
  336. }
  337. tc.ExpectedSecret = &v1.Secret{
  338. Type: v1.SecretTypeOpaque,
  339. Data: map[string][]byte{
  340. dockerConfigJSONKey: []byte(dockerconfig),
  341. },
  342. }
  343. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  344. {
  345. SecretKey: "mysecret",
  346. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  347. Key: cloudSecretName,
  348. Property: "dockerconfig",
  349. },
  350. },
  351. }
  352. tc.ExternalSecret.Spec.Target.Template = &esv1beta1.ExternalSecretTemplate{
  353. Data: map[string]string{
  354. dockerConfigJSONKey: mysecretToStringTemplating,
  355. },
  356. }
  357. }
  358. }
  359. // This case creates a secret with a Docker json configuration value.
  360. // The values from the nested data are extracted using gjson.
  361. // Need to have a key holding dockerconfig to be supported by vault.
  362. func DataPropertyDockerconfigJSON(f *framework.Framework) (string, func(*framework.TestCase)) {
  363. return "[common] should sync docker configurated json secrets with template", func(tc *framework.TestCase) {
  364. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  365. dockerconfigString := `"{\"auths\":{\"https://index.docker.io/v1/\": {\"auth\": \"c3R...zE2\"}}}"`
  366. dockerconfig := `{"auths":{"https://index.docker.io/v1/": {"auth": "c3R...zE2"}}}`
  367. cloudSecretValue := fmt.Sprintf(`{"dockerconfig": %s}`, dockerconfigString)
  368. tc.Secrets = map[string]framework.SecretEntry{
  369. cloudSecretName: {Value: cloudSecretValue},
  370. }
  371. tc.ExpectedSecret = &v1.Secret{
  372. Type: v1.SecretTypeDockerConfigJson,
  373. Data: map[string][]byte{
  374. dockerConfigJSONKey: []byte(dockerconfig),
  375. },
  376. }
  377. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  378. {
  379. SecretKey: "mysecret",
  380. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  381. Key: cloudSecretName,
  382. Property: "dockerconfig",
  383. },
  384. },
  385. }
  386. tc.ExternalSecret.Spec.Target.Template = &esv1beta1.ExternalSecretTemplate{
  387. Type: v1.SecretTypeDockerConfigJson,
  388. Data: map[string]string{
  389. dockerConfigJSONKey: mysecretToStringTemplating,
  390. },
  391. }
  392. }
  393. }
  394. // This case adds an ssh private key secret and synchronizes it.
  395. // Not supported by: vault. Json parsing error.
  396. func SSHKeySync(f *framework.Framework) (string, func(*framework.TestCase)) {
  397. return "[common] should sync ssh key secret", func(tc *framework.TestCase) {
  398. sshSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, "ssh-priv-key-example")
  399. sshSecretValue := `-----BEGIN OPENSSH PRIVATE KEY-----
  400. b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
  401. NhAAAAAwEAAQAAAYEAsARoZUqo6L5dd0WRjZ2QPq/kKlbjtUY1njzJ01UtdC1u1eSJFUnV
  402. K1J+9b1kEqI4lgAaItaYbpJNSgCe97z6DRxEMTUQ3VhB+X+mPfcN2/I0bYklRxh59OTJcL
  403. FsPX0oCR/5eLXz9MCmelxDX7H8XDh9hP6PThooYP60oaDt0xsZvEyo6OQ43n5FuorSg4vL
  404. aMIQYK/znhBq9kR6XKMO8mULoDa+LnhOWsAY8kJ3fowF/UsQmh6PY/w4DJaypm85+a6Sak
  405. Lpn80ur7L6nV7yTqufYqXa4hgNsJHmJ7NGKqOxT/8vcvVRqRadNLl79g9bRRavBiYt/8fy
  406. DJGxOuutcVTzYlzS593Vo95In853cT+HuK4guaWkQdTrThG7jHAi0wVueaEDCTnDkuTk2h
  407. 7PXFBkYTUwE3y+NHo1X+nTE3LhiUJ0RBr3aaj5UBYKHK1uMo1C4zZH3GMvB5K2KmXwG/oB
  408. gCcD1j5hlp6QwOzBVfXsXBF4ewtf7g3RQF8DS3mBAAAFkDc7Drc3Ow63AAAAB3NzaC1yc2
  409. EAAAGBALAEaGVKqOi+XXdFkY2dkD6v5CpW47VGNZ48ydNVLXQtbtXkiRVJ1StSfvW9ZBKi
  410. OJYAGiLWmG6STUoAnve8+g0cRDE1EN1YQfl/pj33DdvyNG2JJUcYefTkyXCxbD19KAkf+X
  411. i18/TApnpcQ1+x/Fw4fYT+j04aKGD+tKGg7dMbGbxMqOjkON5+RbqK0oOLy2jCEGCv854Q
  412. avZEelyjDvJlC6A2vi54TlrAGPJCd36MBf1LEJoej2P8OAyWsqZvOfmukmpC6Z/NLq+y+p
  413. 1e8k6rn2Kl2uIYDbCR5iezRiqjsU//L3L1UakWnTS5e/YPW0UWrwYmLf/H8gyRsTrrrXFU
  414. 82Jc0ufd1aPeSJ/Od3E/h7iuILmlpEHU604Ru4xwItMFbnmhAwk5w5Lk5Noez1xQZGE1MB
  415. N8vjR6NV/p0xNy4YlCdEQa92mo+VAWChytbjKNQuM2R9xjLweStipl8Bv6AYAnA9Y+YZae
  416. kMDswVX17FwReHsLX+4N0UBfA0t5gQAAAAMBAAEAAAGAey4agQiGvJq8fkPJYPnrgHNHkf
  417. nM0YeY7mxMMgFiFfPVpQqShLtu2yqYfxFTf1bXkuHvaIIVmwv32tokZetycspdTrJ8Yurp
  418. ANo8VREYOdx+pEleNSsD7kZOUvdXcJCt+/TMeZWcbKSF3QvEeqvsl/1Qmkorr9TOfVLCxn
  419. oA9cP5drWPX6yXv91OnwWX3UdvyphFLeT08KE8uauilkHmq+va/vxQi+TVsNzOmHu7dGw5
  420. pNFrhO/uGWLhNq4fyCn9l33vpHZdMe2h/N32MnKZgjFOWLqyHy2Cx5BDJTfXyHwjVTqGN1
  421. 8fzrC+o3OuFsR1pPugwlYUW8B9XaxPI6h+Ke6GIxacNtVvOe67GrkdYbQkyrs4/EMqbXTl
  422. /BG/JZIMuchk0Da0TKDDjBwchMjAiwjsFp/wawlL9Y0dJIG0muEuHXxjInEa7xQoisAUCf
  423. B7lasXeUPOy/Z76qFwjVvyfkiVgWygncjGL44b0rgEC81L/dTZUyvNoCM9Bn7wSbuBAAAA
  424. wQDHw6NkJCvGOYa9lt2lMou6hSudokHejOo+J9jJCJdUlMXIbHhBUzrmSh47OSkgpAo4qf
  425. iVGHvBO55pZ5pI7o4woTQxaPFM8a/5BhMWcZ2LDMqU5iov9C2Dz8yKUyQmAodNkOGacQJU
  426. MDAVBJYeBFJSu04bj2EEhEd+9rIazeqVl91qkV1uGTz4aJ360PSmLuLAFT12BYGjIBfHrS
  427. yom+1HbBoUziG4a/kzzbJGTC7U66YTjpHAMEtz4mbpU0AhNg4AAADBANgTs8yjrEkL4pcC
  428. gfUr9oR42/BVl3ZxaFQ7PAvs9m0aut7b/ZRmsSF8F2TAl0H4H9M8uUKTTOhqRtdnTtDqm9
  429. QBUIQBzA6Blb5oP+yL+Eiez4gMFd9HumFXG3JoRu/JmDE19KviHaldV47QcvG6B3p0eb5Q
  430. hgVcNsrOGyBUZA0kBmzQBwv6gUoo++ETQMH89BlljZVCiPW7F6FCrPxHp7EB5txYJ62Qpu
  431. 2U40qgb2ONiUOuiI84EYRAgmDTbboMPQAAAMEA0Inn71l7LsYv81vstbmMQz0qLvhHkBcp
  432. mMhh6tyzI0dvLZabBLTPhIT4R/0VDMJGsH5X1cEaap47XDpu0/g3mfOV6PToUfYA2Ugw7N
  433. bs23UlVH1n0zL2x0QOMHX/Fkfc3OdIuc97ZHoMeW6Nf7Ii0iH7slIpH4hPVYcGXk/bX6wt
  434. PKDc8xGEXdd4A6jnwJBifJs+UpPrHAh0c63KfjO3rryDycvmxeWRnyU1yRCUjIuH31vi+L
  435. OkcGfqTaOoz2KVAAAAFGtpYW5AREVTS1RPUC1TNFI5S1JQAQIDBAUG
  436. -----END OPENSSH PRIVATE KEY-----`
  437. tc.Secrets = map[string]framework.SecretEntry{
  438. sshSecretName: {Value: sshSecretValue},
  439. }
  440. tc.ExpectedSecret = &v1.Secret{
  441. Type: v1.SecretTypeSSHAuth,
  442. Data: map[string][]byte{
  443. sshPrivateKey: []byte(sshSecretValue),
  444. },
  445. }
  446. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  447. {
  448. SecretKey: "mysecret",
  449. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  450. Key: sshSecretName,
  451. },
  452. },
  453. }
  454. tc.ExternalSecret.Spec.Target.Template = &esv1beta1.ExternalSecretTemplate{
  455. Type: v1.SecretTypeSSHAuth,
  456. Data: map[string]string{
  457. sshPrivateKey: mysecretToStringTemplating,
  458. },
  459. }
  460. }
  461. }
  462. // This case adds an ssh private key secret and syncs it.
  463. func SSHKeySyncDataProperty(f *framework.Framework) (string, func(*framework.TestCase)) {
  464. return "[common] should sync ssh key with provider.", func(tc *framework.TestCase) {
  465. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  466. SSHKey := `-----BEGIN OPENSSH PRIVATE KEY-----
  467. b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
  468. NhAAAAAwEAAQAAAYEAsARoZUqo6L5dd0WRjZ2QPq/kKlbjtUY1njzJ01UtdC1u1eSJFUnV
  469. K1J+9b1kEqI4lgAaItaYbpJNSgCe97z6DRxEMTUQ3VhB+X+mPfcN2/I0bYklRxh59OTJcL
  470. FsPX0oCR/5eLXz9MCmelxDX7H8XDh9hP6PThooYP60oaDt0xsZvEyo6OQ43n5FuorSg4vL
  471. aMIQYK/znhBq9kR6XKMO8mULoDa+LnhOWsAY8kJ3fowF/UsQmh6PY/w4DJaypm85+a6Sak
  472. Lpn80ur7L6nV7yTqufYqXa4hgNsJHmJ7NGKqOxT/8vcvVRqRadNLl79g9bRRavBiYt/8fy
  473. DJGxOuutcVTzYlzS593Vo95In853cT+HuK4guaWkQdTrThG7jHAi0wVueaEDCTnDkuTk2h
  474. 7PXFBkYTUwE3y+NHo1X+nTE3LhiUJ0RBr3aaj5UBYKHK1uMo1C4zZH3GMvB5K2KmXwG/oB
  475. gCcD1j5hlp6QwOzBVfXsXBF4ewtf7g3RQF8DS3mBAAAFkDc7Drc3Ow63AAAAB3NzaC1yc2
  476. EAAAGBALAEaGVKqOi+XXdFkY2dkD6v5CpW47VGNZ48ydNVLXQtbtXkiRVJ1StSfvW9ZBKi
  477. OJYAGiLWmG6STUoAnve8+g0cRDE1EN1YQfl/pj33DdvyNG2JJUcYefTkyXCxbD19KAkf+X
  478. i18/TApnpcQ1+x/Fw4fYT+j04aKGD+tKGg7dMbGbxMqOjkON5+RbqK0oOLy2jCEGCv854Q
  479. avZEelyjDvJlC6A2vi54TlrAGPJCd36MBf1LEJoej2P8OAyWsqZvOfmukmpC6Z/NLq+y+p
  480. 1e8k6rn2Kl2uIYDbCR5iezRiqjsU//L3L1UakWnTS5e/YPW0UWrwYmLf/H8gyRsTrrrXFU
  481. 82Jc0ufd1aPeSJ/Od3E/h7iuILmlpEHU604Ru4xwItMFbnmhAwk5w5Lk5Noez1xQZGE1MB
  482. N8vjR6NV/p0xNy4YlCdEQa92mo+VAWChytbjKNQuM2R9xjLweStipl8Bv6AYAnA9Y+YZae
  483. kMDswVX17FwReHsLX+4N0UBfA0t5gQAAAAMBAAEAAAGAey4agQiGvJq8fkPJYPnrgHNHkf
  484. nM0YeY7mxMMgFiFfPVpQqShLtu2yqYfxFTf1bXkuHvaIIVmwv32tokZetycspdTrJ8Yurp
  485. ANo8VREYOdx+pEleNSsD7kZOUvdXcJCt+/TMeZWcbKSF3QvEeqvsl/1Qmkorr9TOfVLCxn
  486. oA9cP5drWPX6yXv91OnwWX3UdvyphFLeT08KE8uauilkHmq+va/vxQi+TVsNzOmHu7dGw5
  487. pNFrhO/uGWLhNq4fyCn9l33vpHZdMe2h/N32MnKZgjFOWLqyHy2Cx5BDJTfXyHwjVTqGN1
  488. 8fzrC+o3OuFsR1pPugwlYUW8B9XaxPI6h+Ke6GIxacNtVvOe67GrkdYbQkyrs4/EMqbXTl
  489. /BG/JZIMuchk0Da0TKDDjBwchMjAiwjsFp/wawlL9Y0dJIG0muEuHXxjInEa7xQoisAUCf
  490. B7lasXeUPOy/Z76qFwjVvyfkiVgWygncjGL44b0rgEC81L/dTZUyvNoCM9Bn7wSbuBAAAA
  491. wQDHw6NkJCvGOYa9lt2lMou6hSudokHejOo+J9jJCJdUlMXIbHhBUzrmSh47OSkgpAo4qf
  492. iVGHvBO55pZ5pI7o4woTQxaPFM8a/5BhMWcZ2LDMqU5iov9C2Dz8yKUyQmAodNkOGacQJU
  493. MDAVBJYeBFJSu04bj2EEhEd+9rIazeqVl91qkV1uGTz4aJ360PSmLuLAFT12BYGjIBfHrS
  494. yom+1HbBoUziG4a/kzzbJGTC7U66YTjpHAMEtz4mbpU0AhNg4AAADBANgTs8yjrEkL4pcC
  495. gfUr9oR42/BVl3ZxaFQ7PAvs9m0aut7b/ZRmsSF8F2TAl0H4H9M8uUKTTOhqRtdnTtDqm9
  496. QBUIQBzA6Blb5oP+yL+Eiez4gMFd9HumFXG3JoRu/JmDE19KviHaldV47QcvG6B3p0eb5Q
  497. hgVcNsrOGyBUZA0kBmzQBwv6gUoo++ETQMH89BlljZVCiPW7F6FCrPxHp7EB5txYJ62Qpu
  498. 2U40qgb2ONiUOuiI84EYRAgmDTbboMPQAAAMEA0Inn71l7LsYv81vstbmMQz0qLvhHkBcp
  499. mMhh6tyzI0dvLZabBLTPhIT4R/0VDMJGsH5X1cEaap47XDpu0/g3mfOV6PToUfYA2Ugw7N
  500. bs23UlVH1n0zL2x0QOMHX/Fkfc3OdIuc97ZHoMeW6Nf7Ii0iH7slIpH4hPVYcGXk/bX6wt
  501. PKDc8xGEXdd4A6jnwJBifJs+UpPrHAh0c63KfjO3rryDycvmxeWRnyU1yRCUjIuH31vi+L
  502. OkcGfqTaOoz2KVAAAAFGtpYW5AREVTS1RPUC1TNFI5S1JQAQIDBAUG
  503. -----END OPENSSH PRIVATE KEY-----`
  504. cloudSecretValue := fmt.Sprintf(`{"ssh-auth": %q}`, SSHKey)
  505. tc.Secrets = map[string]framework.SecretEntry{
  506. cloudSecretName: {Value: cloudSecretValue},
  507. }
  508. tc.ExpectedSecret = &v1.Secret{
  509. Type: v1.SecretTypeSSHAuth,
  510. Data: map[string][]byte{
  511. sshPrivateKey: []byte(SSHKey),
  512. },
  513. }
  514. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  515. {
  516. SecretKey: "mysecret",
  517. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  518. Key: cloudSecretName,
  519. Property: "ssh-auth",
  520. },
  521. },
  522. }
  523. tc.ExternalSecret.Spec.Target.Template = &esv1beta1.ExternalSecretTemplate{
  524. Type: v1.SecretTypeSSHAuth,
  525. Data: map[string]string{
  526. sshPrivateKey: mysecretToStringTemplating,
  527. },
  528. }
  529. }
  530. }
  531. func DeletionPolicyDelete(f *framework.Framework) (string, func(*framework.TestCase)) {
  532. return "[common] should delete secret when provider secret was deleted using .data[]", func(tc *framework.TestCase) {
  533. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  534. secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "other")
  535. secretValue := "bazz"
  536. tc.Secrets = map[string]framework.SecretEntry{
  537. secretKey1: {Value: secretValue},
  538. secretKey2: {Value: secretValue},
  539. }
  540. tc.ExpectedSecret = &v1.Secret{
  541. Type: v1.SecretTypeOpaque,
  542. Data: map[string][]byte{
  543. secretKey1: []byte(secretValue),
  544. secretKey2: []byte(secretValue),
  545. },
  546. }
  547. tc.ExternalSecret.Spec.RefreshInterval = &metav1.Duration{Duration: time.Second * 5}
  548. tc.ExternalSecret.Spec.Target.DeletionPolicy = esv1beta1.DeletionPolicyDelete
  549. tc.ExternalSecret.Spec.Data = []esv1beta1.ExternalSecretData{
  550. {
  551. SecretKey: secretKey1,
  552. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  553. Key: secretKey1,
  554. },
  555. },
  556. {
  557. SecretKey: secretKey2,
  558. RemoteRef: esv1beta1.ExternalSecretDataRemoteRef{
  559. Key: secretKey2,
  560. },
  561. },
  562. }
  563. tc.AfterSync = func(prov framework.SecretStoreProvider, secret *v1.Secret) {
  564. prov.DeleteSecret(secretKey1)
  565. prov.DeleteSecret(secretKey2)
  566. gomega.Eventually(func() bool {
  567. _, err := f.KubeClientSet.CoreV1().Secrets(f.Namespace.Name).Get(context.Background(), secret.Name, metav1.GetOptions{})
  568. return errors.IsNotFound(err)
  569. }, time.Minute, time.Second*5).Should(gomega.BeTrue())
  570. }
  571. }
  572. }