You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Github action for setting KUBECONFIG using vault
2
-
A custom Github Action that can be used to create a kubernetes-config from vault kubernetes auth and secrets in vault. This custom action was created because the official hashicorp/vault action only supports `GET` requests, while the kubernetes auth method in vault requires `POST`.
3
2
4
-
### Requires permissions: ###
3
+
A custom Github Action that can be used to read environments from vault.
4
+
5
+
### Requires permissions:
6
+
5
7
The following [permissions](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#defining-access-for-the-github_token-scopes) need to be defined in [your GitHub Actions workflow](https://github.com/nrkno/plattform-github-apps/blob/6b6e96ab3824630f728574d0362687d1be96e7f4/.github/workflows/policy-bot.yaml#L28) in order to use this custom action.
6
8
7
9
```yaml
8
10
permissions:
9
11
id-token: write
10
-
actions: read
11
12
contents: read
12
13
```
13
14
14
-
### Note: ###
15
-
The kubeconfig file is stored in the GITHUB_WORKSPACE, same as where the checkout action stores the repo. Use `output-only: true` to not export KUBECONFIG file and env variable.
16
-
*By default the config will be valid for **10 minutes**. Use input vault-sa-ttl to change.*
_You can find additional examples of usage by [searching for usages of the github-action-vault-to-k8s-config action in the nrkno organization on GitHub](https://github.com/search?q=org%3Anrkno+uses%3A+nrkno%2Fgithub-action-vault-to-k8s-config+language%3AYAML&type=code&l=YAML)._
39
18
40
19
### Common issues
41
20
42
-
#### Failed creating vault token
43
-
If github-action-vault-to-k8s-config [fails with the error "Failed creating vault token"](https://github.com/nrkno/valg-valgportal-2023-api/actions/runs/5517809972/job/14938542371), you've probably forgot to add the required permissions to your workflow, as described below.
Copy file name to clipboardExpand all lines: action.yaml
+38-42Lines changed: 38 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -14,22 +14,22 @@ inputs:
14
14
azure:
15
15
description: "Get Azure credentials, exported as ARM_CLIENT_ID and ARM_CLIENT_SECRET"
16
16
required: false
17
-
azure-no-arm:
17
+
azure_no_arm:
18
18
description: "Do not export ARM_CLIENT_ID and ARM_CLIENT_SECRET, only TF_VAR_azure_client_id and TF_VAR_azure_client_secret"
19
19
required: false
20
20
gcp:
21
21
description: 'GCP project names, creates TF_VAR_gcp_project_name for use in "credentials" in google provider'
22
22
required: false
23
-
terraform-registry:
23
+
terraform_registry:
24
24
description: 'Get Terraform registry token, expects to be found in vault under "token" in secret/applications/{name}/{env}/terraform-registry'
25
25
required: false
26
-
no-wait:
26
+
no_wait:
27
27
description: "Do not wait for credentials to propagate"
28
28
required: false
29
29
eval:
30
30
description: "Output as export statements, for use with eval $()"
31
31
required: false
32
-
new-line:
32
+
new_line:
33
33
description: "Output as text separated by newline"
34
34
required: false
35
35
debug:
@@ -38,58 +38,54 @@ inputs:
38
38
token:
39
39
description: "Vault token, defaults to /vault/secrets/token"
40
40
required: false
41
-
vault-role-id-name:
41
+
vault_role_id_name:
42
42
description: 'Name of the environment variable for Vault role ID, defaults to "TF_VAR_vault_role_id"'
43
43
required: false
44
-
vault-secret-id-name:
44
+
vault_secret_id_name:
45
45
description: 'Name of the environment variable for Vault secret ID, defaults to "TF_VAR_vault_secret_id"'
46
46
required: false
47
+
vault_secret_id_cidr:
48
+
description: "CIDR to use for Vault secret ID, defaults to the IP address from --myip-url with /32 suffix"
49
+
required: false
47
50
cache:
48
51
description: "Cache/ use cached credentials"
49
52
required: false
50
-
cache-file:
53
+
cache_file:
51
54
description: "Path and name to cache file, defaults to /tmp/{repo_name}_{workflow_name}.cache.json when running in atlantis, or /tmp/{current_workdir}.cache.json when running from shell"
52
55
required: true
53
56
secret:
54
-
description: 'Every key/value pair in vault applications "setenv" secret is added to env vars'
57
+
description: 'Every key/value pair in vault applications "setenv" secret is added to env vars on hardcoded path secret/applications/{name}/{env}/setenv'
55
58
required: false
56
-
vault-secret:
57
-
description: "Get secret from vault, specify path to secret, key in secret and name of environment variable to export. Can be used multiple times, e.g. --vault-secret secret/applications/myapp/prod:mykey:MY_VAR_NAME. If using * as key, all keys in secret will be exported with the specified var_name as prefix, e.g.: --vault-secret secret/applications/myapp/prod:*:MY_PREFIX_ will export MY_PREFIX_key1, MY_PREFIX_key2 etc."
59
+
vault_secret:
60
+
description: "Get secret from vault, spec path to secret, key in secret and name of environment variable to export. Can be used multiple times, e.g. --vault-secret secret/applications/myapp/prod:mykey:MY_VAR_NAME. using * as key, all keys in secret will be exported with the speced var_name as prefix, e.g.: --vault-secret secret/applications/myapp/prod:*:MY_PREFIX_ will export MY_PREFIX_key1, MY_PREFIX_key2 etc."
58
61
required: false
59
-
myip-url:
62
+
myip_url:
60
63
description: "URL to get current IP address, default is http://icanhazip.com"
61
64
required: false
65
+
62
66
runs:
63
67
using: "docker"
64
68
image: "Dockerfile"
65
-
args:
66
-
- --name
67
-
- ${{ inputs.name }}
68
-
- --env
69
-
- ${{ inputs.env }}
70
-
- --cluster
71
-
- ${{ for cluster in inputs.cluster.split(',').append('--cluster') if cluster.strip() }}
72
-
- ${{ if inputs.azure --azure}}
73
-
- ${{ if inputs.azure-no-arm --azure-no-arm}}
74
-
- --gcp
75
-
- ${{ for gcp in inputs.gcp.split(',').append('--gcp') if gcp.strip() }}
76
-
- --terraform-registry
77
-
- ${{ inputs.terraform-registry }}
78
-
- --no-wait
79
-
- ${{ inputs.no-wait }}
80
-
- ${{ if inputs.eval --eval }}
81
-
- ${{ if inputs.new-line --new-line }}
82
-
- ${{ if inputs.debug --debug }}
83
-
- ${{ if inputs.token --token }}
84
-
- --vault-role-id-name
85
-
- ${{ inputs.vault-role-id-name }}
86
-
- --vault-secret-id-name
87
-
- ${{ inputs.vault-secret-id-name }}
88
-
- ${{ if inputs.cache --cache }}
89
-
- --cache-file
90
-
- ${{ inputs.cache-file }}
91
-
- ${{ if inputs.secret --secret }}
92
-
- --vault-secret
93
-
- ${{ for vault_secret in inputs.vault-secret.split(',').append('--vault-secret') if vault_secret.strip() }}
0 commit comments