common.go 20 KB

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