action_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. package forms_test
  2. import (
  3. "encoding/base64"
  4. "testing"
  5. "github.com/porter-dev/porter/internal/forms"
  6. "github.com/porter-dev/porter/internal/kubernetes"
  7. "github.com/porter-dev/porter/internal/models"
  8. "github.com/porter-dev/porter/internal/repository/test"
  9. )
  10. func TestPopulateServiceAccountBasic(t *testing.T) {
  11. // create the in-memory repository
  12. repo := test.NewRepository(true)
  13. // create a new project
  14. repo.Project.CreateProject(&models.Project{
  15. Name: "test-project",
  16. })
  17. // create a ServiceAccountCandidate from a kubeconfig
  18. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(ClusterCAWithData), false)
  19. if err != nil {
  20. t.Fatalf("%v\n", err)
  21. }
  22. for _, saCandidate := range saCandidates {
  23. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  24. }
  25. // create a new form
  26. form := forms.ServiceAccountActionResolver{
  27. ServiceAccountCandidateID: 1,
  28. }
  29. err = form.PopulateServiceAccount(repo.ServiceAccount)
  30. if err != nil {
  31. t.Fatalf("%v\n", err)
  32. }
  33. sa, err := repo.ServiceAccount.CreateServiceAccount(form.SA)
  34. decodedStr, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJ=")
  35. if len(sa.Clusters) != 1 {
  36. t.Fatalf("cluster not written\n")
  37. }
  38. if sa.Clusters[0].ServiceAccountID != 1 {
  39. t.Errorf("service account ID of joined cluster is not 1")
  40. }
  41. if string(sa.Clusters[0].CertificateAuthorityData) != string(decodedStr) {
  42. t.Errorf("cluster ca data and input do not match: expected %s, got %s\n",
  43. string(sa.Clusters[0].CertificateAuthorityData), string(decodedStr))
  44. }
  45. if sa.AuthMechanism != "x509" {
  46. t.Errorf("service account auth mechanism is not x509")
  47. }
  48. if string(sa.ClientCertificateData) != string(decodedStr) {
  49. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  50. string(sa.ClientCertificateData), string(decodedStr))
  51. }
  52. if string(sa.ClientKeyData) != string(decodedStr) {
  53. t.Errorf("service account key data and input do not match: expected %s, got %s\n",
  54. string(sa.ClientKeyData), string(decodedStr))
  55. }
  56. }
  57. func TestPopulateServiceAccountClusterDataAction(t *testing.T) {
  58. // create the in-memory repository
  59. repo := test.NewRepository(true)
  60. // create a new project
  61. repo.Project.CreateProject(&models.Project{
  62. Name: "test-project",
  63. })
  64. // create a ServiceAccountCandidate from a kubeconfig
  65. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(ClusterCAWithoutData), false)
  66. if err != nil {
  67. t.Fatalf("%v\n", err)
  68. }
  69. for _, saCandidate := range saCandidates {
  70. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  71. }
  72. // create a new form
  73. form := forms.ClusterCADataAction{
  74. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  75. ServiceAccountCandidateID: 1,
  76. },
  77. ClusterCAData: "LS0tLS1CRUdJTiBDRVJ=",
  78. }
  79. err = form.PopulateServiceAccount(repo.ServiceAccount)
  80. if err != nil {
  81. t.Fatalf("%v\n", err)
  82. }
  83. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  84. decodedStr, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJ=")
  85. if len(sa.Clusters) != 1 {
  86. t.Fatalf("cluster not written\n")
  87. }
  88. if sa.Clusters[0].ServiceAccountID != 1 {
  89. t.Errorf("service account ID of joined cluster is not 1")
  90. }
  91. if string(sa.Clusters[0].CertificateAuthorityData) != string(decodedStr) {
  92. t.Errorf("cluster ca data and input do not match: expected %s, got %s\n",
  93. string(sa.Clusters[0].CertificateAuthorityData), string(decodedStr))
  94. }
  95. if sa.AuthMechanism != "x509" {
  96. t.Errorf("service account auth mechanism is not x509")
  97. }
  98. if string(sa.ClientCertificateData) != string(decodedStr) {
  99. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  100. string(sa.ClientCertificateData), string(decodedStr))
  101. }
  102. if string(sa.ClientKeyData) != string(decodedStr) {
  103. t.Errorf("service account key data and input do not match: expected %s, got %s\n",
  104. string(sa.ClientKeyData), string(decodedStr))
  105. }
  106. }
  107. func TestPopulateServiceAccountClusterLocalhostAction(t *testing.T) {
  108. // create the in-memory repository
  109. repo := test.NewRepository(true)
  110. // create a new project
  111. repo.Project.CreateProject(&models.Project{
  112. Name: "test-project",
  113. })
  114. // create a ServiceAccountCandidate from a kubeconfig
  115. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(ClusterLocalhost), false)
  116. if err != nil {
  117. t.Fatalf("%v\n", err)
  118. }
  119. for _, saCandidate := range saCandidates {
  120. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  121. }
  122. // create a new form
  123. form := forms.ClusterLocalhostAction{
  124. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  125. ServiceAccountCandidateID: 1,
  126. },
  127. ClusterHostname: "host.docker.internal",
  128. }
  129. err = form.PopulateServiceAccount(repo.ServiceAccount)
  130. if err != nil {
  131. t.Fatalf("%v\n", err)
  132. }
  133. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  134. decodedStr, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJ=")
  135. if len(sa.Clusters) != 1 {
  136. t.Fatalf("cluster not written\n")
  137. }
  138. if sa.Clusters[0].ServiceAccountID != 1 {
  139. t.Errorf("service account ID of joined cluster is not 1")
  140. }
  141. if sa.Clusters[0].Server != "https://host.docker.internal:30000" {
  142. t.Errorf("service account cluster server is incorrect: expected %s, got %s\n",
  143. "https://host.docker.internal:30000", sa.Clusters[0].Server)
  144. }
  145. if sa.AuthMechanism != "x509" {
  146. t.Errorf("service account auth mechanism is not x509")
  147. }
  148. if string(sa.ClientCertificateData) != string(decodedStr) {
  149. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  150. string(sa.ClientCertificateData), string(decodedStr))
  151. }
  152. if string(sa.ClientKeyData) != string(decodedStr) {
  153. t.Errorf("service account key data and input do not match: expected %s, got %s\n",
  154. string(sa.ClientKeyData), string(decodedStr))
  155. }
  156. }
  157. func TestPopulateServiceAccountClientCertAction(t *testing.T) {
  158. // create the in-memory repository
  159. repo := test.NewRepository(true)
  160. // create a new project
  161. repo.Project.CreateProject(&models.Project{
  162. Name: "test-project",
  163. })
  164. // create a ServiceAccountCandidate from a kubeconfig
  165. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(ClientWithoutCertData), false)
  166. if err != nil {
  167. t.Fatalf("%v\n", err)
  168. }
  169. for _, saCandidate := range saCandidates {
  170. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  171. }
  172. // create a new form
  173. form := forms.ClientCertDataAction{
  174. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  175. ServiceAccountCandidateID: 1,
  176. },
  177. ClientCertData: "LS0tLS1CRUdJTiBDRVJ=",
  178. }
  179. err = form.PopulateServiceAccount(repo.ServiceAccount)
  180. if err != nil {
  181. t.Fatalf("%v\n", err)
  182. }
  183. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  184. decodedStr, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJ=")
  185. if len(sa.Clusters) != 1 {
  186. t.Fatalf("cluster not written\n")
  187. }
  188. if sa.Clusters[0].ServiceAccountID != 1 {
  189. t.Errorf("service account ID of joined cluster is not 1")
  190. }
  191. if string(sa.Clusters[0].CertificateAuthorityData) != string(decodedStr) {
  192. t.Errorf("cluster ca data and input do not match: expected %s, got %s\n",
  193. string(sa.Clusters[0].CertificateAuthorityData), string(decodedStr))
  194. }
  195. if sa.AuthMechanism != "x509" {
  196. t.Errorf("service account auth mechanism is not x509")
  197. }
  198. if string(sa.ClientCertificateData) != string(decodedStr) {
  199. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  200. string(sa.ClientCertificateData), string(decodedStr))
  201. }
  202. if string(sa.ClientKeyData) != string(decodedStr) {
  203. t.Errorf("service account key data and input do not match: expected %s, got %s\n",
  204. string(sa.ClientKeyData), string(decodedStr))
  205. }
  206. }
  207. func TestPopulateServiceAccountClientCertAndKeyActions(t *testing.T) {
  208. // create the in-memory repository
  209. repo := test.NewRepository(true)
  210. // create a new project
  211. repo.Project.CreateProject(&models.Project{
  212. Name: "test-project",
  213. })
  214. // create a ServiceAccountCandidate from a kubeconfig
  215. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(ClientWithoutCertAndKeyData), false)
  216. if err != nil {
  217. t.Fatalf("%v\n", err)
  218. }
  219. for _, saCandidate := range saCandidates {
  220. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  221. }
  222. // create a new form
  223. form := forms.ClientCertDataAction{
  224. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  225. ServiceAccountCandidateID: 1,
  226. },
  227. ClientCertData: "LS0tLS1CRUdJTiBDRVJ=",
  228. }
  229. err = form.PopulateServiceAccount(repo.ServiceAccount)
  230. if err != nil {
  231. t.Fatalf("%v\n", err)
  232. }
  233. keyForm := forms.ClientKeyDataAction{
  234. ServiceAccountActionResolver: form.ServiceAccountActionResolver,
  235. ClientKeyData: "LS0tLS1CRUdJTiBDRVJ=",
  236. }
  237. err = keyForm.PopulateServiceAccount(repo.ServiceAccount)
  238. if err != nil {
  239. t.Fatalf("%v\n", err)
  240. }
  241. sa, err := repo.ServiceAccount.CreateServiceAccount(keyForm.ServiceAccountActionResolver.SA)
  242. decodedStr, _ := base64.StdEncoding.DecodeString("LS0tLS1CRUdJTiBDRVJ=")
  243. if len(sa.Clusters) != 1 {
  244. t.Fatalf("cluster not written\n")
  245. }
  246. if sa.Clusters[0].ServiceAccountID != 1 {
  247. t.Errorf("service account ID of joined cluster is not 1")
  248. }
  249. if string(sa.Clusters[0].CertificateAuthorityData) != string(decodedStr) {
  250. t.Errorf("cluster ca data and input do not match: expected %s, got %s\n",
  251. string(sa.Clusters[0].CertificateAuthorityData), string(decodedStr))
  252. }
  253. if sa.AuthMechanism != "x509" {
  254. t.Errorf("service account auth mechanism is not x509")
  255. }
  256. if string(sa.ClientCertificateData) != string(decodedStr) {
  257. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  258. string(sa.ClientCertificateData), string(decodedStr))
  259. }
  260. if string(sa.ClientKeyData) != string(decodedStr) {
  261. t.Errorf("service account cert data and input do not match: expected %s, got %s\n",
  262. string(sa.ClientKeyData), string(decodedStr))
  263. }
  264. }
  265. func TestPopulateServiceAccountTokenDataAction(t *testing.T) {
  266. // create the in-memory repository
  267. repo := test.NewRepository(true)
  268. tokenData := "abcdefghijklmnop"
  269. // create a new project
  270. repo.Project.CreateProject(&models.Project{
  271. Name: "test-project",
  272. })
  273. // create a ServiceAccountCandidate from a kubeconfig
  274. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(BearerTokenWithoutData), false)
  275. if err != nil {
  276. t.Fatalf("%v\n", err)
  277. }
  278. for _, saCandidate := range saCandidates {
  279. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  280. }
  281. // create a new form
  282. form := forms.TokenDataAction{
  283. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  284. ServiceAccountCandidateID: 1,
  285. },
  286. TokenData: tokenData,
  287. }
  288. err = form.PopulateServiceAccount(repo.ServiceAccount)
  289. if err != nil {
  290. t.Fatalf("%v\n", err)
  291. }
  292. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  293. if len(sa.Clusters) != 1 {
  294. t.Fatalf("cluster not written\n")
  295. }
  296. if sa.Clusters[0].ServiceAccountID != 1 {
  297. t.Errorf("service account ID of joined cluster is not 1")
  298. }
  299. if sa.AuthMechanism != models.Bearer {
  300. t.Errorf("service account auth mechanism is not %s\n", models.Bearer)
  301. }
  302. if string(sa.Token) != tokenData {
  303. t.Errorf("service account token data is wrong: expected %s, got %s\n",
  304. tokenData, sa.Token)
  305. }
  306. }
  307. func TestPopulateServiceAccountGCPKeyDataAction(t *testing.T) {
  308. // create the in-memory repository
  309. repo := test.NewRepository(true)
  310. gcpKeyData := []byte(`{"key": "data"}`)
  311. // create a new project
  312. repo.Project.CreateProject(&models.Project{
  313. Name: "test-project",
  314. })
  315. // create a ServiceAccountCandidate from a kubeconfig
  316. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(GCPPlugin), false)
  317. if err != nil {
  318. t.Fatalf("%v\n", err)
  319. }
  320. for _, saCandidate := range saCandidates {
  321. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  322. }
  323. // create a new form
  324. form := forms.GCPKeyDataAction{
  325. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  326. ServiceAccountCandidateID: 1,
  327. },
  328. GCPKeyData: string(gcpKeyData),
  329. }
  330. err = form.PopulateServiceAccount(repo.ServiceAccount)
  331. if err != nil {
  332. t.Fatalf("%v\n", err)
  333. }
  334. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  335. if len(sa.Clusters) != 1 {
  336. t.Fatalf("cluster not written\n")
  337. }
  338. if sa.Clusters[0].ServiceAccountID != 1 {
  339. t.Errorf("service account ID of joined cluster is not 1")
  340. }
  341. if sa.AuthMechanism != models.GCP {
  342. t.Errorf("service account auth mechanism is not %s\n", models.GCP)
  343. }
  344. if string(sa.GCPKeyData) != string(gcpKeyData) {
  345. t.Errorf("service account token data is wrong: expected %s, got %s\n",
  346. string(sa.GCPKeyData), string(gcpKeyData))
  347. }
  348. }
  349. func TestPopulateServiceAccountAWSKeyDataAction(t *testing.T) {
  350. // create the in-memory repository
  351. repo := test.NewRepository(true)
  352. // create a new project
  353. repo.Project.CreateProject(&models.Project{
  354. Name: "test-project",
  355. })
  356. // create a ServiceAccountCandidate from a kubeconfig
  357. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(AWSEKSGetTokenExec), false)
  358. if err != nil {
  359. t.Fatalf("%v\n", err)
  360. }
  361. for _, saCandidate := range saCandidates {
  362. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  363. }
  364. // create a new form
  365. form := forms.AWSDataAction{
  366. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  367. ServiceAccountCandidateID: 1,
  368. },
  369. AWSAccessKeyID: "ALSDKJFADSF",
  370. AWSSecretAccessKey: "ASDLFKJALSDKFJ",
  371. AWSClusterID: "cluster-test",
  372. }
  373. err = form.PopulateServiceAccount(repo.ServiceAccount)
  374. if err != nil {
  375. t.Fatalf("%v\n", err)
  376. }
  377. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  378. if len(sa.Clusters) != 1 {
  379. t.Fatalf("cluster not written\n")
  380. }
  381. if sa.Clusters[0].ServiceAccountID != 1 {
  382. t.Errorf("service account ID of joined cluster is not 1")
  383. }
  384. if sa.AuthMechanism != models.AWS {
  385. t.Errorf("service account auth mechanism is not %s\n", models.AWS)
  386. }
  387. if string(sa.AWSAccessKeyID) != "ALSDKJFADSF" {
  388. t.Errorf("service account aws access key id is wrong: expected %s, got %s\n",
  389. "ALSDKJFADSF", sa.AWSAccessKeyID)
  390. }
  391. if string(sa.AWSSecretAccessKey) != "ASDLFKJALSDKFJ" {
  392. t.Errorf("service account aws access secret key is wrong: expected %s, got %s\n",
  393. "ASDLFKJALSDKFJ", sa.AWSSecretAccessKey)
  394. }
  395. if string(sa.AWSClusterID) != "cluster-test" {
  396. t.Errorf("service account aws cluster id is wrong: expected %s, got %s\n",
  397. "cluster-test", sa.AWSClusterID)
  398. }
  399. }
  400. func TestPopulateServiceAccountOIDCAction(t *testing.T) {
  401. // create the in-memory repository
  402. repo := test.NewRepository(true)
  403. // create a new project
  404. repo.Project.CreateProject(&models.Project{
  405. Name: "test-project",
  406. })
  407. // create a ServiceAccountCandidate from a kubeconfig
  408. saCandidates, err := kubernetes.GetServiceAccountCandidates([]byte(OIDCAuthWithoutData), false)
  409. if err != nil {
  410. t.Fatalf("%v\n", err)
  411. }
  412. for _, saCandidate := range saCandidates {
  413. repo.ServiceAccount.CreateServiceAccountCandidate(saCandidate)
  414. }
  415. // create a new form
  416. form := forms.OIDCIssuerDataAction{
  417. ServiceAccountActionResolver: &forms.ServiceAccountActionResolver{
  418. ServiceAccountCandidateID: 1,
  419. },
  420. OIDCIssuerCAData: "LS0tLS1CRUdJTiBDRVJ=",
  421. }
  422. err = form.PopulateServiceAccount(repo.ServiceAccount)
  423. if err != nil {
  424. t.Fatalf("%v\n", err)
  425. }
  426. sa, err := repo.ServiceAccount.CreateServiceAccount(form.ServiceAccountActionResolver.SA)
  427. if len(sa.Clusters) != 1 {
  428. t.Fatalf("cluster not written\n")
  429. }
  430. if sa.Clusters[0].ServiceAccountID != 1 {
  431. t.Errorf("service account ID of joined cluster is not 1")
  432. }
  433. if sa.AuthMechanism != models.OIDC {
  434. t.Errorf("service account auth mechanism is not %s\n", models.OIDC)
  435. }
  436. if string(sa.OIDCCertificateAuthorityData) != "LS0tLS1CRUdJTiBDRVJ=" {
  437. t.Errorf("service account key data and input do not match: expected %s, got %s\n",
  438. string(sa.OIDCCertificateAuthorityData), "LS0tLS1CRUdJTiBDRVJ=")
  439. }
  440. }
  441. const ClusterCAWithData string = `
  442. apiVersion: v1
  443. kind: Config
  444. clusters:
  445. - name: cluster-test
  446. cluster:
  447. server: https://localhost
  448. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  449. contexts:
  450. - context:
  451. cluster: cluster-test
  452. user: test-admin
  453. name: context-test
  454. users:
  455. - name: test-admin
  456. user:
  457. client-certificate-data: LS0tLS1CRUdJTiBDRVJ=
  458. client-key-data: LS0tLS1CRUdJTiBDRVJ=
  459. current-context: context-test
  460. `
  461. const ClusterCAWithoutData string = `
  462. apiVersion: v1
  463. kind: Config
  464. clusters:
  465. - name: cluster-test
  466. cluster:
  467. server: https://localhost
  468. certificate-authority: /fake/path/to/ca.pem
  469. contexts:
  470. - context:
  471. cluster: cluster-test
  472. user: test-admin
  473. name: context-test
  474. users:
  475. - name: test-admin
  476. user:
  477. client-certificate-data: LS0tLS1CRUdJTiBDRVJ=
  478. client-key-data: LS0tLS1CRUdJTiBDRVJ=
  479. current-context: context-test
  480. `
  481. const ClusterLocalhost string = `
  482. apiVersion: v1
  483. kind: Config
  484. clusters:
  485. - name: cluster-test
  486. cluster:
  487. server: https://localhost:30000
  488. contexts:
  489. - context:
  490. cluster: cluster-test
  491. user: test-admin
  492. name: context-test
  493. users:
  494. - name: test-admin
  495. user:
  496. client-certificate-data: LS0tLS1CRUdJTiBDRVJ=
  497. client-key-data: LS0tLS1CRUdJTiBDRVJ=
  498. current-context: context-test
  499. `
  500. const ClientWithoutCertData string = `
  501. apiVersion: v1
  502. kind: Config
  503. clusters:
  504. - name: cluster-test
  505. cluster:
  506. server: https://localhost
  507. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  508. contexts:
  509. - context:
  510. cluster: cluster-test
  511. user: test-admin
  512. name: context-test
  513. users:
  514. - name: test-admin
  515. user:
  516. client-certificate: /fake/path/to/ca.pem
  517. client-key-data: LS0tLS1CRUdJTiBDRVJ=
  518. current-context: context-test
  519. `
  520. const ClientWithoutCertAndKeyData string = `
  521. apiVersion: v1
  522. kind: Config
  523. clusters:
  524. - name: cluster-test
  525. cluster:
  526. server: https://localhost
  527. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  528. contexts:
  529. - context:
  530. cluster: cluster-test
  531. user: test-admin
  532. name: context-test
  533. users:
  534. - name: test-admin
  535. user:
  536. client-certificate: /fake/path/to/ca.pem
  537. client-key: /fake/path/to/ca.pem
  538. current-context: context-test
  539. `
  540. const BearerTokenWithoutData string = `
  541. apiVersion: v1
  542. kind: Config
  543. preferences: {}
  544. current-context: context-test
  545. clusters:
  546. - cluster:
  547. server: https://localhost
  548. name: cluster-test
  549. contexts:
  550. - context:
  551. cluster: cluster-test
  552. user: test-admin
  553. name: context-test
  554. users:
  555. - name: test-admin
  556. user:
  557. tokenFile: /path/to/token/file.txt
  558. `
  559. const GCPPlugin string = `
  560. apiVersion: v1
  561. kind: Config
  562. clusters:
  563. - name: cluster-test
  564. cluster:
  565. server: https://localhost
  566. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  567. users:
  568. - name: test-admin
  569. user:
  570. auth-provider:
  571. name: gcp
  572. contexts:
  573. - context:
  574. cluster: cluster-test
  575. user: test-admin
  576. name: context-test
  577. current-context: context-test
  578. `
  579. const AWSEKSGetTokenExec string = `
  580. apiVersion: v1
  581. clusters:
  582. - cluster:
  583. server: https://localhost
  584. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  585. name: cluster-test
  586. contexts:
  587. - context:
  588. cluster: cluster-test
  589. user: test-admin
  590. name: context-test
  591. current-context: context-test
  592. kind: Config
  593. preferences: {}
  594. users:
  595. - name: test-admin
  596. user:
  597. exec:
  598. apiVersion: client.authentication.k8s.io/v1alpha1
  599. command: aws
  600. args:
  601. - "eks"
  602. - "get-token"
  603. - "--cluster-name"
  604. - "cluster-test"
  605. `
  606. const OIDCAuthWithoutData string = `
  607. apiVersion: v1
  608. clusters:
  609. - cluster:
  610. server: https://localhost
  611. certificate-authority-data: LS0tLS1CRUdJTiBDRVJ=
  612. name: cluster-test
  613. contexts:
  614. - context:
  615. cluster: cluster-test
  616. user: test-admin
  617. name: context-test
  618. current-context: context-test
  619. kind: Config
  620. preferences: {}
  621. users:
  622. - name: test-admin
  623. user:
  624. auth-provider:
  625. config:
  626. client-id: porter-api
  627. id-token: token
  628. idp-issuer-url: https://localhost
  629. idp-certificate-authority: /fake/path/to/ca.pem
  630. name: oidc
  631. `