common.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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.ExternalSecretDataRemoteRef{
  227. {
  228. Key: secretKey1,
  229. },
  230. }
  231. }
  232. }
  233. // This case creates a secret with a nested json value. It is synced into two secrets.
  234. // The values from the nested data are extracted using gjson.
  235. // not supported by: vault.
  236. func NestedJSONWithGJSON(f *framework.Framework) (string, func(*framework.TestCase)) {
  237. return "[common] should sync nested json secrets and get inner keys", func(tc *framework.TestCase) {
  238. secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
  239. targetSecretKey1 := "firstname"
  240. targetSecretValue1 := "Tom"
  241. targetSecretKey2 := "first_friend"
  242. targetSecretValue2 := "Roger"
  243. secretValue := fmt.Sprintf(
  244. `{
  245. "name": {"first": "%s", "last": "Anderson"},
  246. "friends":
  247. [
  248. {"first": "Dale", "last": "Murphy"},
  249. {"first": "%s", "last": "Craig"},
  250. {"first": "Jane", "last": "Murphy"}
  251. ]
  252. }`, targetSecretValue1, targetSecretValue2)
  253. tc.Secrets = map[string]string{
  254. secretKey1: secretValue,
  255. }
  256. tc.ExpectedSecret = &v1.Secret{
  257. Type: v1.SecretTypeOpaque,
  258. Data: map[string][]byte{
  259. targetSecretKey1: []byte(targetSecretValue1),
  260. targetSecretKey2: []byte(targetSecretValue2),
  261. },
  262. }
  263. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  264. {
  265. SecretKey: targetSecretKey1,
  266. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  267. Key: secretKey1,
  268. Property: "name.first",
  269. },
  270. },
  271. {
  272. SecretKey: targetSecretKey2,
  273. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  274. Key: secretKey1,
  275. Property: "friends.1.first",
  276. },
  277. },
  278. }
  279. }
  280. }
  281. // This case creates a secret with a Docker json configuration value.
  282. // The values from the nested data are extracted using gjson.
  283. // not supported by: vault.
  284. func DockerJSONConfig(f *framework.Framework) (string, func(*framework.TestCase)) {
  285. return "[common] should sync docker configurated json secrets with template simple", func(tc *framework.TestCase) {
  286. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  287. dockerconfig := `{"auths":{"https://index.docker.io/v1/": {"auth": "c3R...zE2"}}}`
  288. cloudSecretValue := fmt.Sprintf(`{"dockerconfig": %s}`, dockerconfig)
  289. tc.Secrets = map[string]string{
  290. cloudSecretName: cloudSecretValue,
  291. }
  292. tc.ExpectedSecret = &v1.Secret{
  293. Type: v1.SecretTypeOpaque,
  294. Data: map[string][]byte{
  295. dockerConfigJSONKey: []byte(dockerconfig),
  296. },
  297. }
  298. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  299. {
  300. SecretKey: "mysecret",
  301. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  302. Key: cloudSecretName,
  303. Property: "dockerconfig",
  304. },
  305. },
  306. }
  307. tc.ExternalSecret.Spec.Target.Template = &esv1alpha1.ExternalSecretTemplate{
  308. Data: map[string]string{
  309. dockerConfigJSONKey: mysecretToStringTemplating,
  310. },
  311. }
  312. }
  313. }
  314. // This case creates a secret with a Docker json configuration value.
  315. // The values from the nested data are extracted using gjson.
  316. // Need to have a key holding dockerconfig to be supported by vault.
  317. func DataPropertyDockerconfigJSON(f *framework.Framework) (string, func(*framework.TestCase)) {
  318. return "[common] should sync docker configurated json secrets with template", func(tc *framework.TestCase) {
  319. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  320. dockerconfigString := `"{\"auths\":{\"https://index.docker.io/v1/\": {\"auth\": \"c3R...zE2\"}}}"`
  321. dockerconfig := `{"auths":{"https://index.docker.io/v1/": {"auth": "c3R...zE2"}}}`
  322. cloudSecretValue := fmt.Sprintf(`{"dockerconfig": %s}`, dockerconfigString)
  323. tc.Secrets = map[string]string{
  324. cloudSecretName: cloudSecretValue,
  325. }
  326. tc.ExpectedSecret = &v1.Secret{
  327. Type: v1.SecretTypeDockerConfigJson,
  328. Data: map[string][]byte{
  329. dockerConfigJSONKey: []byte(dockerconfig),
  330. },
  331. }
  332. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  333. {
  334. SecretKey: "mysecret",
  335. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  336. Key: cloudSecretName,
  337. Property: "dockerconfig",
  338. },
  339. },
  340. }
  341. tc.ExternalSecret.Spec.Target.Template = &esv1alpha1.ExternalSecretTemplate{
  342. Type: v1.SecretTypeDockerConfigJson,
  343. Data: map[string]string{
  344. dockerConfigJSONKey: mysecretToStringTemplating,
  345. },
  346. }
  347. }
  348. }
  349. // This case adds an ssh private key secret and synchronizes it.
  350. // Not supported by: vault. Json parsing error.
  351. func SSHKeySync(f *framework.Framework) (string, func(*framework.TestCase)) {
  352. return "[common] should sync ssh key secret", func(tc *framework.TestCase) {
  353. sshSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, "ssh-priv-key-example")
  354. sshSecretValue := `-----BEGIN OPENSSH PRIVATE KEY-----
  355. b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
  356. NhAAAAAwEAAQAAAYEAsARoZUqo6L5dd0WRjZ2QPq/kKlbjtUY1njzJ01UtdC1u1eSJFUnV
  357. K1J+9b1kEqI4lgAaItaYbpJNSgCe97z6DRxEMTUQ3VhB+X+mPfcN2/I0bYklRxh59OTJcL
  358. FsPX0oCR/5eLXz9MCmelxDX7H8XDh9hP6PThooYP60oaDt0xsZvEyo6OQ43n5FuorSg4vL
  359. aMIQYK/znhBq9kR6XKMO8mULoDa+LnhOWsAY8kJ3fowF/UsQmh6PY/w4DJaypm85+a6Sak
  360. Lpn80ur7L6nV7yTqufYqXa4hgNsJHmJ7NGKqOxT/8vcvVRqRadNLl79g9bRRavBiYt/8fy
  361. DJGxOuutcVTzYlzS593Vo95In853cT+HuK4guaWkQdTrThG7jHAi0wVueaEDCTnDkuTk2h
  362. 7PXFBkYTUwE3y+NHo1X+nTE3LhiUJ0RBr3aaj5UBYKHK1uMo1C4zZH3GMvB5K2KmXwG/oB
  363. gCcD1j5hlp6QwOzBVfXsXBF4ewtf7g3RQF8DS3mBAAAFkDc7Drc3Ow63AAAAB3NzaC1yc2
  364. EAAAGBALAEaGVKqOi+XXdFkY2dkD6v5CpW47VGNZ48ydNVLXQtbtXkiRVJ1StSfvW9ZBKi
  365. OJYAGiLWmG6STUoAnve8+g0cRDE1EN1YQfl/pj33DdvyNG2JJUcYefTkyXCxbD19KAkf+X
  366. i18/TApnpcQ1+x/Fw4fYT+j04aKGD+tKGg7dMbGbxMqOjkON5+RbqK0oOLy2jCEGCv854Q
  367. avZEelyjDvJlC6A2vi54TlrAGPJCd36MBf1LEJoej2P8OAyWsqZvOfmukmpC6Z/NLq+y+p
  368. 1e8k6rn2Kl2uIYDbCR5iezRiqjsU//L3L1UakWnTS5e/YPW0UWrwYmLf/H8gyRsTrrrXFU
  369. 82Jc0ufd1aPeSJ/Od3E/h7iuILmlpEHU604Ru4xwItMFbnmhAwk5w5Lk5Noez1xQZGE1MB
  370. N8vjR6NV/p0xNy4YlCdEQa92mo+VAWChytbjKNQuM2R9xjLweStipl8Bv6AYAnA9Y+YZae
  371. kMDswVX17FwReHsLX+4N0UBfA0t5gQAAAAMBAAEAAAGAey4agQiGvJq8fkPJYPnrgHNHkf
  372. nM0YeY7mxMMgFiFfPVpQqShLtu2yqYfxFTf1bXkuHvaIIVmwv32tokZetycspdTrJ8Yurp
  373. ANo8VREYOdx+pEleNSsD7kZOUvdXcJCt+/TMeZWcbKSF3QvEeqvsl/1Qmkorr9TOfVLCxn
  374. oA9cP5drWPX6yXv91OnwWX3UdvyphFLeT08KE8uauilkHmq+va/vxQi+TVsNzOmHu7dGw5
  375. pNFrhO/uGWLhNq4fyCn9l33vpHZdMe2h/N32MnKZgjFOWLqyHy2Cx5BDJTfXyHwjVTqGN1
  376. 8fzrC+o3OuFsR1pPugwlYUW8B9XaxPI6h+Ke6GIxacNtVvOe67GrkdYbQkyrs4/EMqbXTl
  377. /BG/JZIMuchk0Da0TKDDjBwchMjAiwjsFp/wawlL9Y0dJIG0muEuHXxjInEa7xQoisAUCf
  378. B7lasXeUPOy/Z76qFwjVvyfkiVgWygncjGL44b0rgEC81L/dTZUyvNoCM9Bn7wSbuBAAAA
  379. wQDHw6NkJCvGOYa9lt2lMou6hSudokHejOo+J9jJCJdUlMXIbHhBUzrmSh47OSkgpAo4qf
  380. iVGHvBO55pZ5pI7o4woTQxaPFM8a/5BhMWcZ2LDMqU5iov9C2Dz8yKUyQmAodNkOGacQJU
  381. MDAVBJYeBFJSu04bj2EEhEd+9rIazeqVl91qkV1uGTz4aJ360PSmLuLAFT12BYGjIBfHrS
  382. yom+1HbBoUziG4a/kzzbJGTC7U66YTjpHAMEtz4mbpU0AhNg4AAADBANgTs8yjrEkL4pcC
  383. gfUr9oR42/BVl3ZxaFQ7PAvs9m0aut7b/ZRmsSF8F2TAl0H4H9M8uUKTTOhqRtdnTtDqm9
  384. QBUIQBzA6Blb5oP+yL+Eiez4gMFd9HumFXG3JoRu/JmDE19KviHaldV47QcvG6B3p0eb5Q
  385. hgVcNsrOGyBUZA0kBmzQBwv6gUoo++ETQMH89BlljZVCiPW7F6FCrPxHp7EB5txYJ62Qpu
  386. 2U40qgb2ONiUOuiI84EYRAgmDTbboMPQAAAMEA0Inn71l7LsYv81vstbmMQz0qLvhHkBcp
  387. mMhh6tyzI0dvLZabBLTPhIT4R/0VDMJGsH5X1cEaap47XDpu0/g3mfOV6PToUfYA2Ugw7N
  388. bs23UlVH1n0zL2x0QOMHX/Fkfc3OdIuc97ZHoMeW6Nf7Ii0iH7slIpH4hPVYcGXk/bX6wt
  389. PKDc8xGEXdd4A6jnwJBifJs+UpPrHAh0c63KfjO3rryDycvmxeWRnyU1yRCUjIuH31vi+L
  390. OkcGfqTaOoz2KVAAAAFGtpYW5AREVTS1RPUC1TNFI5S1JQAQIDBAUG
  391. -----END OPENSSH PRIVATE KEY-----`
  392. tc.Secrets = map[string]string{
  393. sshSecretName: sshSecretValue,
  394. }
  395. tc.ExpectedSecret = &v1.Secret{
  396. Type: v1.SecretTypeSSHAuth,
  397. Data: map[string][]byte{
  398. sshPrivateKey: []byte(sshSecretValue),
  399. },
  400. }
  401. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  402. {
  403. SecretKey: "mysecret",
  404. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  405. Key: sshSecretName,
  406. },
  407. },
  408. }
  409. tc.ExternalSecret.Spec.Target.Template = &esv1alpha1.ExternalSecretTemplate{
  410. Type: v1.SecretTypeSSHAuth,
  411. Data: map[string]string{
  412. sshPrivateKey: mysecretToStringTemplating,
  413. },
  414. }
  415. }
  416. }
  417. // This case adds an ssh private key secret and syncs it.
  418. func SSHKeySyncDataProperty(f *framework.Framework) (string, func(*framework.TestCase)) {
  419. return "[common] should sync ssh key with provider.", func(tc *framework.TestCase) {
  420. cloudSecretName := fmt.Sprintf("%s-%s", f.Namespace.Name, dockerConfigExampleName)
  421. SSHKey := `-----BEGIN OPENSSH PRIVATE KEY-----
  422. b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
  423. NhAAAAAwEAAQAAAYEAsARoZUqo6L5dd0WRjZ2QPq/kKlbjtUY1njzJ01UtdC1u1eSJFUnV
  424. K1J+9b1kEqI4lgAaItaYbpJNSgCe97z6DRxEMTUQ3VhB+X+mPfcN2/I0bYklRxh59OTJcL
  425. FsPX0oCR/5eLXz9MCmelxDX7H8XDh9hP6PThooYP60oaDt0xsZvEyo6OQ43n5FuorSg4vL
  426. aMIQYK/znhBq9kR6XKMO8mULoDa+LnhOWsAY8kJ3fowF/UsQmh6PY/w4DJaypm85+a6Sak
  427. Lpn80ur7L6nV7yTqufYqXa4hgNsJHmJ7NGKqOxT/8vcvVRqRadNLl79g9bRRavBiYt/8fy
  428. DJGxOuutcVTzYlzS593Vo95In853cT+HuK4guaWkQdTrThG7jHAi0wVueaEDCTnDkuTk2h
  429. 7PXFBkYTUwE3y+NHo1X+nTE3LhiUJ0RBr3aaj5UBYKHK1uMo1C4zZH3GMvB5K2KmXwG/oB
  430. gCcD1j5hlp6QwOzBVfXsXBF4ewtf7g3RQF8DS3mBAAAFkDc7Drc3Ow63AAAAB3NzaC1yc2
  431. EAAAGBALAEaGVKqOi+XXdFkY2dkD6v5CpW47VGNZ48ydNVLXQtbtXkiRVJ1StSfvW9ZBKi
  432. OJYAGiLWmG6STUoAnve8+g0cRDE1EN1YQfl/pj33DdvyNG2JJUcYefTkyXCxbD19KAkf+X
  433. i18/TApnpcQ1+x/Fw4fYT+j04aKGD+tKGg7dMbGbxMqOjkON5+RbqK0oOLy2jCEGCv854Q
  434. avZEelyjDvJlC6A2vi54TlrAGPJCd36MBf1LEJoej2P8OAyWsqZvOfmukmpC6Z/NLq+y+p
  435. 1e8k6rn2Kl2uIYDbCR5iezRiqjsU//L3L1UakWnTS5e/YPW0UWrwYmLf/H8gyRsTrrrXFU
  436. 82Jc0ufd1aPeSJ/Od3E/h7iuILmlpEHU604Ru4xwItMFbnmhAwk5w5Lk5Noez1xQZGE1MB
  437. N8vjR6NV/p0xNy4YlCdEQa92mo+VAWChytbjKNQuM2R9xjLweStipl8Bv6AYAnA9Y+YZae
  438. kMDswVX17FwReHsLX+4N0UBfA0t5gQAAAAMBAAEAAAGAey4agQiGvJq8fkPJYPnrgHNHkf
  439. nM0YeY7mxMMgFiFfPVpQqShLtu2yqYfxFTf1bXkuHvaIIVmwv32tokZetycspdTrJ8Yurp
  440. ANo8VREYOdx+pEleNSsD7kZOUvdXcJCt+/TMeZWcbKSF3QvEeqvsl/1Qmkorr9TOfVLCxn
  441. oA9cP5drWPX6yXv91OnwWX3UdvyphFLeT08KE8uauilkHmq+va/vxQi+TVsNzOmHu7dGw5
  442. pNFrhO/uGWLhNq4fyCn9l33vpHZdMe2h/N32MnKZgjFOWLqyHy2Cx5BDJTfXyHwjVTqGN1
  443. 8fzrC+o3OuFsR1pPugwlYUW8B9XaxPI6h+Ke6GIxacNtVvOe67GrkdYbQkyrs4/EMqbXTl
  444. /BG/JZIMuchk0Da0TKDDjBwchMjAiwjsFp/wawlL9Y0dJIG0muEuHXxjInEa7xQoisAUCf
  445. B7lasXeUPOy/Z76qFwjVvyfkiVgWygncjGL44b0rgEC81L/dTZUyvNoCM9Bn7wSbuBAAAA
  446. wQDHw6NkJCvGOYa9lt2lMou6hSudokHejOo+J9jJCJdUlMXIbHhBUzrmSh47OSkgpAo4qf
  447. iVGHvBO55pZ5pI7o4woTQxaPFM8a/5BhMWcZ2LDMqU5iov9C2Dz8yKUyQmAodNkOGacQJU
  448. MDAVBJYeBFJSu04bj2EEhEd+9rIazeqVl91qkV1uGTz4aJ360PSmLuLAFT12BYGjIBfHrS
  449. yom+1HbBoUziG4a/kzzbJGTC7U66YTjpHAMEtz4mbpU0AhNg4AAADBANgTs8yjrEkL4pcC
  450. gfUr9oR42/BVl3ZxaFQ7PAvs9m0aut7b/ZRmsSF8F2TAl0H4H9M8uUKTTOhqRtdnTtDqm9
  451. QBUIQBzA6Blb5oP+yL+Eiez4gMFd9HumFXG3JoRu/JmDE19KviHaldV47QcvG6B3p0eb5Q
  452. hgVcNsrOGyBUZA0kBmzQBwv6gUoo++ETQMH89BlljZVCiPW7F6FCrPxHp7EB5txYJ62Qpu
  453. 2U40qgb2ONiUOuiI84EYRAgmDTbboMPQAAAMEA0Inn71l7LsYv81vstbmMQz0qLvhHkBcp
  454. mMhh6tyzI0dvLZabBLTPhIT4R/0VDMJGsH5X1cEaap47XDpu0/g3mfOV6PToUfYA2Ugw7N
  455. bs23UlVH1n0zL2x0QOMHX/Fkfc3OdIuc97ZHoMeW6Nf7Ii0iH7slIpH4hPVYcGXk/bX6wt
  456. PKDc8xGEXdd4A6jnwJBifJs+UpPrHAh0c63KfjO3rryDycvmxeWRnyU1yRCUjIuH31vi+L
  457. OkcGfqTaOoz2KVAAAAFGtpYW5AREVTS1RPUC1TNFI5S1JQAQIDBAUG
  458. -----END OPENSSH PRIVATE KEY-----`
  459. cloudSecretValue := fmt.Sprintf(`{"ssh-auth": "%s"}`, SSHKey)
  460. tc.Secrets = map[string]string{
  461. cloudSecretName: cloudSecretValue,
  462. }
  463. tc.ExpectedSecret = &v1.Secret{
  464. Type: v1.SecretTypeSSHAuth,
  465. Data: map[string][]byte{
  466. sshPrivateKey: []byte(SSHKey),
  467. },
  468. }
  469. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  470. {
  471. SecretKey: "mysecret",
  472. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  473. Key: cloudSecretName,
  474. Property: "ssh-auth",
  475. },
  476. },
  477. }
  478. tc.ExternalSecret.Spec.Target.Template = &esv1alpha1.ExternalSecretTemplate{
  479. Type: v1.SecretTypeSSHAuth,
  480. Data: map[string]string{
  481. sshPrivateKey: mysecretToStringTemplating,
  482. },
  483. }
  484. }
  485. }