common.go 24 KB

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