← all scripts

scripts/setup-cluster-access.sh

31 of 31 statements covered (100.00%).

coveredmissednever traced by Bash (not counted)A line ending in … continues the statement above it and shares its fate.

1#!/bin/bash
2# Setup script for configuring kubectl access to GCO cluster
3
45set -e
5
65CLUSTER_NAME="${1:-gco-us-east-1}"
75REGION="${2:-us-east-1}"
8
95echo "Setting up access to cluster: $CLUSTER_NAME in region: $REGION"
105echo ""
11
12# Update kubeconfig
135echo "1. Updating kubeconfig..."
145aws eks update-kubeconfig --name "$CLUSTER_NAME" --region "$REGION"
15
16# Get current IAM principal
175echo ""
185echo "2. Getting your IAM principal..."
1910PRINCIPAL_ARN=$(aws sts get-caller-identity --query Arn --output text)
205echo " Principal: $PRINCIPAL_ARN"
21
22# Handle assumed roles
235if [[ "$PRINCIPAL_ARN" == *":assumed-role/"* ]]; then
243 ROLE_NAME=$(echo "$PRINCIPAL_ARN" | sed 's/.*:assumed-role\/\([^\/]*\)\/.*/\1/')
252 ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
261 PRINCIPAL_ARN="arn:aws:iam::${ACCOUNT_ID}:role/${ROLE_NAME}"
271 echo " Using role ARN: $PRINCIPAL_ARN"
28fi
29
30# Create access entry
315echo ""
325echo "3. Creating EKS access entry..."
335aws eks create-access-entry \
34 --cluster-name "$CLUSTER_NAME" \
35 --region "$REGION" \
361 --principal-arn "$PRINCIPAL_ARN" 2>&1 || echo " Access entry may already exist"
37
38# Associate admin policy
395echo ""
405echo "4. Associating cluster admin policy..."
415aws eks associate-access-policy \
42 --cluster-name "$CLUSTER_NAME" \
43 --region "$REGION" \
44 --principal-arn "$PRINCIPAL_ARN" \
45 --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy \
461 --access-scope type=cluster 2>&1 || echo " Policy may already be associated"
47
48# Verify access
495echo ""
505echo "5. Verifying access..."
515echo " Waiting for permissions to propagate..."
525sleep 10
535kubectl get nodes
54
554echo ""
564echo "✓ Setup complete! You can now use kubectl with cluster: $CLUSTER_NAME"