Skip to content

Instantly share code, notes, and snippets.

@todd-dsm
Created July 30, 2021 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todd-dsm/74d423689fcfc66a2b9082be3622b9b1 to your computer and use it in GitHub Desktop.
Save todd-dsm/74d423689fcfc66a2b9082be3622b9b1 to your computer and use it in GitHub Desktop.
retrieves service account details from kubernetes for the GitLab pipeline
#!/usr/bin/env bash
#set -x
###----------------------------------------------------------------------------
### FUNCTIONS
###----------------------------------------------------------------------------
function pMsg() {
theMessage="$1"
printf '%s\n' "$theMessage"
}
function pRpt() {
theMessage="$1"
printf '\n%s\n' "$theMessage"
}
###----------------------------------------------------------------------------
### MAIN PROGRAM
###----------------------------------------------------------------------------
# Grab api url from cluster-info
api_url=$(kubectl cluster-info | grep "Kubernetes master" | awk '{print $NF}')
# Grab cert using default token
default_token=$(kubectl get secrets | grep default | awk '{print $1}')
ca_cert=$(kubectl get secret "$default_token" -o jsonpath="{['data']['ca\.crt']}" | base64 --decode)
# Display the token
service_token=$(kubectl -n kube-system describe secret "$(kubectl \
-n kube-system get secret | grep gitlab | awk '{print $1}')" | \
grep token: | awk '{print $NF}')
pMsg "==========================="
pMsg """
API URL:
$api_url
"""
pMsg """
CA Certificate:
$ca_cert"""
pMsg """
Token:
$service_token
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment