common.go 19 KB

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