Skip to content

Commit 4eb1c88

Browse files
authored
Merge pull request actions-hub#5 from silverlyra/token-auth
Support bearer token authentication
2 parents 3657737 + b23a65e commit 4eb1c88

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@ To use kubectl put this step into your workflow:
2121
- uses: actions-hub/kubectl@master
2222
env:
2323
KUBE_HOST: ${{ secrets.KUBE_HOST }}
24+
KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
2425
KUBE_USERNAME: ${{ secrets.KUBE_USERNAME }}
2526
KUBE_PASSWORD: ${{ secrets.KUBE_PASSWORD }}
27+
with:
28+
args: get pods
29+
```
30+
31+
### Authorization with a bearer token
32+
```yaml
33+
- uses: actions-hub/kubectl@master
34+
env:
35+
KUBE_HOST: ${{ secrets.KUBE_HOST }}
2636
KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
37+
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
2738
with:
2839
args: get pods
2940
```

entrypoint.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ if [ ! -f "$HOME/.kube/config" ]; then
1919

2020
echo "$KUBE_CERTIFICATE" | base64 -d > $HOME/.kube/certificate
2121
kubectl config set-cluster default --server=https://$KUBE_HOST --certificate-authority=$HOME/.kube/certificate > /dev/null
22-
kubectl config set-credentials cluster-admin --username=$KUBE_USERNAME --password=$KUBE_PASSWORD > /dev/null
22+
23+
if [ ! -z "${KUBE_PASSWORD}" ]; then
24+
kubectl config set-credentials cluster-admin --username=$KUBE_USERNAME --password=$KUBE_PASSWORD > /dev/null
25+
elif [ ! -z "${KUBE_TOKEN}" ]; then
26+
kubectl config set-credentials cluster-admin --token="${KUBE_TOKEN}" > /dev/null
27+
else
28+
echo "No credentials found. Please provide KUBE_TOKEN, or KUBE_USERNAME and KUBE_PASSWORD. Exiting..."
29+
exit 1
30+
fi
31+
2332
kubectl config set-context default --cluster=default --namespace=default --user=cluster-admin > /dev/null
2433
kubectl config use-context default > /dev/null
2534

2635
else
27-
echo "No authorization data found. Please provide CONFIG or HTTPS variables. Exiting...."
36+
echo "No authorization data found. Please provide KUBE_CONFIG or KUBE_HOST variables. Exiting..."
2837
exit 1
2938
fi
3039
fi

0 commit comments

Comments
 (0)