Created
October 21, 2023 21:09
-
-
Save suhussai/dc139c4d15f4445686781c172b914bc9 to your computer and use it in GitHub Desktop.
Add another role to aws-auth configmap using kubectl and jq
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
ROLE_ARN="arn:aws:iam::123456789123:role/my-role" | |
GROUP="system:masters" | |
# 1. read ".data.mapRoles" from aws-auth | |
# 2. convert it to json | |
# 3. add the role as a value to the json array | |
# 4. convert the json back to a string | |
MAP_ROLES=$(kubectl get configmap aws-auth -n kube-system -o json \ | |
| jq --arg role "$ROLE_ARN" --arg group "$GROUP" -r '.data.mapRoles | fromjson | . += [{"rolearn": $role,"groups": [$group]} ] | tojson') | |
# 5. overwrite the existing value for ".data.mapRoles" with the one computed above | |
kubectl get configmap aws-auth -n kube-system -o json \ | |
| jq --arg m "$MAP_ROLES" '.data.mapRoles = $m' | kubectl apply -f - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment