Last active
July 11, 2018 21:29
-
-
Save GauntletWizard/3c5f13c3c98eb68148b7c365ee4b0f43 to your computer and use it in GitHub Desktop.
Creating a IAM user/policy for K8s role accounts
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
set -eux -o pipefail | |
IAMUSER="$1" | |
aws iam create-user --user-name "${IAMUSER}" | |
POLICY="$(aws iam create-policy --policy-name "${IAMUSER}" --policy-document file://policy.json)" # "file://${IAMUSER}.policy" | |
ARN="$(echo $POLICY |jq -r .Policy.Arn)" | |
aws iam attach-user-policy --user-name "${IAMUSER}" --policy-arn="${ARN}" | |
# Create the access-key and parse the response to the ID and Secret | |
KEY="$(aws iam create-access-key --user-name "${IAMUSER}")" | |
KEYID="$(echo "${KEY}" |jq -r .AccessKey.AccessKeyId)" | |
KEYSECRET="$(echo "${KEY}" |jq -r .AccessKey.SecretAccessKey)" | |
kubectl create secret generic "aws-${IAMUSER}" --from-literal "AWS_ACCESS_KEY_ID=${KEYID}" --from-literal "AWS_SECRET_ACCESS_KEY=${KEYSECRET}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment