Skip to content

Instantly share code, notes, and snippets.

@GauntletWizard
Last active July 11, 2018 21:29
Show Gist options
  • Save GauntletWizard/3c5f13c3c98eb68148b7c365ee4b0f43 to your computer and use it in GitHub Desktop.
Save GauntletWizard/3c5f13c3c98eb68148b7c365ee4b0f43 to your computer and use it in GitHub Desktop.
Creating a IAM user/policy for K8s role accounts
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