Last active
April 19, 2021 12:35
-
-
Save michelesr/f94a425a52b79e046d8cb7b2115aaaaa to your computer and use it in GitHub Desktop.
Update minikube registry-creds plugin to use latest temporary credentials from MFA profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Use the temporary credentials from the MFA profile to update the | |
# registry-creds plugin credentials used to pull images from AWS Elastic | |
# Container Registry | |
# | |
# NOTE: the script won't request fresh credentials, make sure your credentials | |
# are not expired before running this script | |
# retrieve the profile from the credentials file | |
content=$(grep -F -A 5 '[mfa]' < ~/.aws/credentials) | |
# retrieve the temporary credentials | |
key=$(awk '/aws_access_key_id/ {print $3}' <<<"${content}" | tr -d '\n' | base64 | tr -d '\n') | |
secret=$(awk '/aws_secret_access_key/ {print $3}' <<<"${content}" | tr -d '\n' | base64 | tr -d '\n') | |
token=$(awk '/aws_session_token/ {print $3}' <<<"${content}" | tr -d '\n' | base64 | tr -d '\n') | |
# write the JSON patch into the patch variable | |
read -r patch <<PATCH | |
{"data": {"AWS_ACCESS_KEY_ID": "${key}", "AWS_SECRET_ACCESS_KEY": "${secret}", "AWS_SESSION_TOKEN": "${token}"}} | |
PATCH | |
# deploy the patch | |
kubectl patch secret -n kube-system registry-creds-ecr -p "${patch}" | |
# trigger restart of registry-creds plugin | |
kubectl delete pod -n kube-system -l 'name=registry-creds' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment