Skip to content

Commit

Permalink
fix: change strategy to fetch the basic auth secret to increase compa…
Browse files Browse the repository at this point in the history
…tibility (#70)
  • Loading branch information
Monska85 authored Aug 27, 2024
1 parent 4cc1f5a commit 02a3bdc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ function print-basic-auth() {

for INGRESS in $(kubectl --namespace "${CURRENT_NAMESPACE}" get ingresses -o jsonpath='{.items[*].metadata.name}'); do
FIRST_HOST="https://$(kubectl --namespace "${CURRENT_NAMESPACE}" get ingress "${INGRESS}" -o jsonpath="{.spec.rules[0].host}")"
SECRET=$(kubectl --namespace "${CURRENT_NAMESPACE}" get ingress "${INGRESS}" -o jsonpath="{.metadata.annotations.nginx\\.ingress\\.kubernetes\\.io/auth-secret}")
# We can't use the jsonpath directly because the 'auth-secret' annotation could be prefixed with custom prefix.
SECRET="$(kubectl --namespace "${CURRENT_NAMESPACE}" get ingress "${INGRESS}" -o yaml | grep "ingress.kubernetes.io/auth-secret:" | awk '{print $2}')"
if [ -z "${SECRET}" ]; then
echo "No auth secret found for ingress ${INGRESS} (${FIRST_HOST})"
continue
fi
USERNAME=$(kubectl --namespace "${CURRENT_NAMESPACE}" get secret "${SECRET}" -o jsonpath="{.data.username}" | base64 --decode)
PASSWORD=$(kubectl --namespace "${CURRENT_NAMESPACE}" get secret "${SECRET}" -o jsonpath="{.data.password}" | base64 --decode)
USERNAME=$(kubectl --namespace "${CURRENT_NAMESPACE}" get secret "${SECRET}" -o jsonpath="{.data.username}" | base64 -d)
PASSWORD=$(kubectl --namespace "${CURRENT_NAMESPACE}" get secret "${SECRET}" -o jsonpath="{.data.password}" | base64 -d)
if [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "No auth credentials found in secret ${SECRET} (${INGRESS} - ${FIRST_HOST})"
continue
Expand Down

0 comments on commit 02a3bdc

Please sign in to comment.