common.go 21 KB

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