Skip to content

Commit f8d4df0

Browse files
committed
chore: some updates to entrypoint and dockerfile
1 parent 964f5c3 commit f8d4df0

File tree

5 files changed

+136
-166
lines changed

5 files changed

+136
-166
lines changed

Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
FROM alpine:3.21.3
1+
FROM python:3.13-alpine
22

3-
RUN apk --no-cache add coreutils util-linux-misc bash curl jq github-cli
3+
RUN apk --no-cache add coreutils util-linux-misc bash && adduser -u 1001 -D runuser && pip3 install --no-cache-dir configargparse
44

5-
# Download and install latest version of vault
6-
RUN curl -L -o /tmp/vault.zip https://releases.hashicorp.com/vault/1.12.2/vault_1.12.2_linux_amd64.zip \
7-
&& unzip /tmp/vault.zip -d /usr/local/bin/ \
8-
&& rm -f /tmp/vault.zip
5+
USER runuser
6+
ENV HOME=/home/runuser
7+
COPY --chown=runuser:runuser setenv.py entrypoint.sh $HOME/
8+
RUN chmod +x $HOME/setenv.py $HOME/entrypoint.sh
99

10-
COPY bin/setenv.py /usr/local/bin/setenv.py
10+
WORKDIR ${HOME}
1111

12-
COPY entrypoint.sh /entrypoint.sh
13-
14-
ENTRYPOINT ["/entrypoint.sh"]
12+
ENTRYPOINT ["/home/runuser/entrypoint.sh"]

README.md

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,32 @@
11
# 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`.
32

4-
### Requires permissions: ###
3+
A custom Github Action that can be used to read environments from vault.
4+
5+
### Requires permissions:
6+
57
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.
68

79
```yaml
810
permissions:
911
id-token: write
10-
actions: read
1112
contents: read
1213
```
1314
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.*
15+
### Note:
1716
1817
## Example usage:
19-
Example with deployment to kubernetes cluster.
20-
Vault-role is `appname-environment`
21-
```yaml
22-
- uses: nrkno/github-action-vault-to-k8s-config@v2.0
23-
id: vault-to-k8s-config
24-
with:
25-
vault-address: ${{ secrets.PLATTFORM_VAULT_URL }}
26-
vault-role: plattform-gorgon-api-github-prod
27-
cluster: aks-plattform-int-prod-eno
28-
namespace: gorgon-api-prod
29-
- uses: azure/k8s-deploy@v4.5
30-
with:
31-
manifests: prod/
32-
images: |
33-
plattform.azurecr.io/plattform/gorgon:latest
34-
annotate-namespace: false
35-
action: deploy
36-
```
37-
38-
_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)._
3918
4019
### Common issues
4120
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.
44-
4521
## Inputs
22+
4623
```yaml
4724
inputs:
48-
vault-address:
49-
description: 'address to your vault'
50-
required: true
51-
vault-role:
52-
description: 'Your github applications vault role'
53-
required: true
54-
vault-path:
55-
description: 'Auth path for vault'
56-
default: jwt-github
57-
required: false
58-
vault-sa-ttl:
59-
description: 'How long the service account for the kubeconfig will exist'
60-
default: 10m
61-
required: false
62-
cluster:
63-
description: 'The name of your kubernetes cluster'
64-
required: true
65-
namespace:
66-
description: 'The name of your kubernetes namespace'
67-
required: true
68-
cluster-rolebinding:
69-
description: 'Rolebinding to give ServiceAccount in the cluster'
70-
required: false
71-
default: edit
72-
output-only:
73-
description: "If true, KUBECONFIG env variable wont be set, and kubeconfig file won't be written to GITHUB_WORKSPACE"
74-
required: false
75-
default: "false"
7625
```
7726
7827
## Outputs
79-
```yaml
80-
k8s-config:
81-
description: 'The kube-config for your dynamic service account'
82-
ingress-suffix:
83-
description: 'Ingress suffix for the cluster'
84-
```
8528
8629
## Contributing
30+
8731
Create an issue and optionally a pull-request.
88-
Use semantic commit messages.
32+
Use semantic commit messages.

action.yaml

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ inputs:
1414
azure:
1515
description: "Get Azure credentials, exported as ARM_CLIENT_ID and ARM_CLIENT_SECRET"
1616
required: false
17-
azure-no-arm:
17+
azure_no_arm:
1818
description: "Do not export ARM_CLIENT_ID and ARM_CLIENT_SECRET, only TF_VAR_azure_client_id and TF_VAR_azure_client_secret"
1919
required: false
2020
gcp:
2121
description: 'GCP project names, creates TF_VAR_gcp_project_name for use in "credentials" in google provider'
2222
required: false
23-
terraform-registry:
23+
terraform_registry:
2424
description: 'Get Terraform registry token, expects to be found in vault under "token" in secret/applications/{name}/{env}/terraform-registry'
2525
required: false
26-
no-wait:
26+
no_wait:
2727
description: "Do not wait for credentials to propagate"
2828
required: false
2929
eval:
3030
description: "Output as export statements, for use with eval $()"
3131
required: false
32-
new-line:
32+
new_line:
3333
description: "Output as text separated by newline"
3434
required: false
3535
debug:
@@ -38,58 +38,51 @@ inputs:
3838
token:
3939
description: "Vault token, defaults to /vault/secrets/token"
4040
required: false
41-
vault-role-id-name:
41+
vault_role_id_name:
4242
description: 'Name of the environment variable for Vault role ID, defaults to "TF_VAR_vault_role_id"'
4343
required: false
44-
vault-secret-id-name:
44+
vault_secret_id_name:
4545
description: 'Name of the environment variable for Vault secret ID, defaults to "TF_VAR_vault_secret_id"'
4646
required: false
4747
cache:
4848
description: "Cache/ use cached credentials"
4949
required: false
50-
cache-file:
50+
cache_file:
5151
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"
5252
required: true
5353
secret:
54-
description: 'Every key/value pair in vault applications "setenv" secret is added to env vars'
54+
description: 'Every key/value pair in vault applications "setenv" secret is added to env vars on hardcoded path secret/applications/{name}/{env}/setenv'
5555
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."
56+
vault_secret:
57+
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."
5858
required: false
59-
myip-url:
59+
myip_url:
6060
description: "URL to get current IP address, default is http://icanhazip.com"
6161
required: false
62+
6263
runs:
6364
using: "docker"
6465
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() }}
94-
- --myip-url
95-
- ${{ inputs.myip-url }}
66+
env:
67+
VAULT_ADDR: ${{ inputs.VAULT_ADDR }}
68+
# args:
69+
# - --name ${{ inputs.name }}
70+
# - --env ${{ inputs.env }}
71+
# - --cluster ${{ inputs.cluster }}
72+
# - --azure ${{ inputs.azure}}
73+
# - --azure-no-arm ${{ inputs.azure-no-arm }}
74+
# - --gcp ${{ inputs.gcp }}
75+
# - --terraform-registry ${{ inputs.terraform-registry }}
76+
# - --no-wait ${{ inputs.no-wait }}
77+
# - --eval ${{ inputs.eval }}
78+
# - --new-line ${{ inputs.new-line }}
79+
# - --debug ${{ inputs.debug }}
80+
# - --token ${{ inputs.token }}
81+
# - --vault-role-id-name ${{ inputs.vault-role-id-name }}
82+
# - --vault-secret-id-name ${{ inputs.vault-secret-id-name }}
83+
# - --cache ${{ inputs.cache }}
84+
# - --cache-file ${{ inputs.cache-file }}
85+
# - --secret ${{ inputs.secret }}
86+
# - --vault-secret ${{ inputs.vault-secret }}
87+
# - --vault-secret ${{ inputs.vault-secret }}
88+
# - --myip-url ${{ inputs.myip-url }}

entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
2-
set -e
2+
33
set -x
44

5-
pipenv run bin/setenv.py $@
5+
VARIABLES="$(python3 /home/runuser/setenv.py)"
6+
7+
if [[ -z "$VARIABLES" ]]; then
8+
echo "No variables set. Exiting."
9+
exit 1
10+
fi
11+
12+
eval "$VARIABLES"

0 commit comments

Comments
 (0)