Skip to content

Instantly share code, notes, and snippets.

@innovia
Last active March 12, 2019 12:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save innovia/6641a9505e9258d075d644d785d00499 to your computer and use it in GitHub Desktop.
Save innovia/6641a9505e9258d075d644d785d00499 to your computer and use it in GitHub Desktop.
# Set these names before you start.
CLUSTER_NAME={{cluster name}}
GROUP={{group name}}
# Get your account ID
ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
# Build a role name
ROLE_NAME="Kubernetes${CLUSTER_NAME}${GROUP_NAME}Group
# Define a role trust policy that opens the role to users in your account (limited by IAM policy)
POLICY=$(echo -n '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::'; echo -n "$ACCOUNT_ID"; echo -n ':root"},"Action":"sts:AssumeRole","Condition":{}}]}')
# Create a role named KubernetesAdmin (will print the new role's ARN)
aws iam create-role \
--role-name $ROLE_NAME \
--description "Kubernetes ${GROUP} role (for Heptio Authenticator for AWS)." \
--assume-role-policy-document "$POLICY" \
--output text \
--query 'Role.Arn'
@StevenACoffman
Copy link

StevenACoffman commented Jun 29, 2018

Handy. After running this, to apply for EKS, see https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment