Skip to content

Instantly share code, notes, and snippets.

@markjacksonfishing
Last active August 4, 2024 14:06
Show Gist options
  • Save markjacksonfishing/e5aeafe7c7485544b4041122803994c3 to your computer and use it in GitHub Desktop.
Save markjacksonfishing/e5aeafe7c7485544b4041122803994c3 to your computer and use it in GitHub Desktop.
Backstage aws auth
#!/bin/bash
# Check if AWS environment variables are set
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ] || [ -z "$AWS_SESSION_TOKEN" ]; then
echo "One or more AWS environment variables are missing. Please check your environment."
exit 1
fi
echo "AWS environment variables are set correctly."
# Try to get pods in the default namespace using kubectl
KUBE_CONTEXT="aws-cluster-1"
if kubectl --context="$KUBE_CONTEXT" get pods -n default > /dev/null 2>&1; then
echo "Authentication to Kubernetes cluster '$KUBE_CONTEXT' succeeded."
else
echo "Authentication to Kubernetes cluster '$KUBE_CONTEXT' failed. Please check your configuration."
exit 1
fi
# Additional Debugging Commands
echo "Checking AWS identity..."
aws sts get-caller-identity || { echo "Failed to retrieve AWS identity."; exit 1; }
echo "Listing attached policies for the IAM user (if applicable)..."
aws iam list-attached-user-policies --user-name YOUR_IAM_USER || { echo "Failed to list attached user policies."; }
echo "Listing attached policies for the IAM role (if applicable)..."
aws iam list-attached-role-policies --role-name YOUR_IAM_ROLE || { echo "Failed to list attached role policies."; }
echo "Describing the EKS cluster..."
aws eks describe-cluster --name YOUR_CLUSTER_NAME --region YOUR_AWS_REGION || { echo "Failed to describe EKS cluster."; }
echo "Running kubectl command with increased verbosity..."
kubectl --context="$KUBE_CONTEXT" get pods -n default --v=9 || { echo "Failed to run kubectl command with verbosity."; }
echo "Validating the AWS session token..."
aws sts get-session-token --duration-seconds 900 || { echo "Failed to validate AWS session token."; }
echo "Checking AWS profiles..."
aws configure list-profiles || { echo "Failed to list AWS profiles."; }
echo "Viewing effective kubectl configuration..."
kubectl config view --minify --flatten || { echo "Failed to view kubectl configuration."; }
echo "Debugging completed. Please review the output for any issues."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment