Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create token in job #808

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions platform-apps/charts/backstage/templates/secret-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: batch/v1
kind: Job
metadata:
generateName: backstage-token-creator-
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
serviceAccountName: backstage-token-creator
containers:
- name: backstage-token-creator
image: bitnami/kubectl
command:
- "bin/bash"
- "-c"
- |
ARGOCD_AUTH_TOKEN="$( kubectl exec sx-argocd-application-controller-0 -n argocd -- argocd account generate-token --account backstage --core )"
GRAFANA_HOSTNAME=$(kubectl get ingress -o jsonpath='{.items[*].spec.rules[*].host}' -n grafana )
if [ "${GRAFANA_HOSTNAME}" != "" ]; then
ID=$( curl -k -X POST https://${GRAFANA_HOSTNAME}/api/serviceaccounts --user 'admin:prom-operator' -H "Content-Type: application/json" -d '{"name": "backstage","role": "Viewer","isDisabled": false}' | jq -r .id )
GRAFANA_TOKEN=$(curl -k -X POST https://${GRAFANA_HOSTNAME}/api/serviceaccounts/${ID}/tokens --user 'admin:prom-operator' -H "Content-Type: application/json" -d '{"name": "backstage"}' | jq -r .key)
fi

# get backstage-locator token for backstage secret
K8S_SA_TOKEN=$( kubectl get secret backstage-locator -n backstage -o jsonpath='{.data.token}' | base64 -d )

kubectl create secret generic -n backstage access-token-secret \
--from-literal=K8S_SA_TOKEN=${K8S_SA_TOKEN} \
--from-literal=ARGOCD_AUTH_TOKEN=${ARGOCD_AUTH_TOKEN} \
--from-literal=GRAFANA_TOKEN=${GRAFANA_TOKEN}
restartPolicy: Never