Skip to content

Commit 4dfd9b4

Browse files
committed
fix: several fixes related to service accounts
Fix EBS CSI driver SA Fix load balancer controller SA Clean up scripts and tf
1 parent 8b6d9dd commit 4dfd9b4

File tree

6 files changed

+13
-100
lines changed

6 files changed

+13
-100
lines changed

aws/build-an-deploy-aws.sh

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ echo "CLUSTER_AUTOSCALER_ROLE_ARN=${CLUSTER_AUTOSCALER_ROLE_ARN}"
5353

5454
version="$(uuidgen)"
5555

56+
aws eks update-kubeconfig --region $AWS_REGION --name $CLUSTERNAME --kubeconfig ~/.kube/wrongsecrets
57+
58+
export KUBECONFIG=~/.kube/wrongsecrets
59+
5660
echo "If the below output is different than expected: please hard stop this script (running aws sts get-caller-identity first)"
5761

5862
aws sts get-caller-identity
@@ -61,24 +65,6 @@ echo "Giving you 4 seconds before we add autoscaling"
6165

6266
sleep 4
6367

64-
# echo "Installing policies and service accounts"
65-
66-
# aws iam create-policy \
67-
# --policy-name AmazonEKSClusterAutoscalerPolicy \
68-
# --policy-document file://cluster-autoscaler-policy.json
69-
70-
# echo "Installing iamserviceaccount"
71-
72-
# eksctl create iamserviceaccount \
73-
# --cluster=$CLUSTERNAME \
74-
# --region=$AWS_REGION \
75-
# --namespace=kube-system \
76-
# --name=cluster-autoscaler \
77-
# --role-name=AmazonEKSClusterAutoscalerRole \
78-
# --attach-policy-arn=arn:aws:iam::${ACCOUNT_ID}:policy/AmazonEKSClusterAutoscalerPolicy \
79-
# --override-existing-serviceaccounts \
80-
# --approve
81-
8268
echo "Deploying the k8s autoscaler for eks through kubectl"
8369

8470
curl -o cluster-autoscaler-autodiscover.yaml https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
@@ -156,33 +142,16 @@ helm upgrade --install mj ../helm/wrongsecrets-ctf-party \
156142
--set="balancer.env.REACT_APP_CREATE_TEAM_HMAC_KEY=${CREATE_TEAM_HMAC}" \
157143
--set="balancer.cookie.cookieParserSecret=${COOKIE_PARSER_SECRET}"
158144

159-
# echo "Installing EBS CSI driver"
160-
# eksctl create iamserviceaccount \
161-
# --name ebs-csi-controller-sa \
162-
# --namespace kube-system \
163-
# --cluster $CLUSTERNAME \
164-
# --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
165-
# --approve \
166-
# --role-only \
167-
# --role-name AmazonEKS_EBS_CSI_DriverRole
168-
# --region $AWS_REGION
169-
170-
# echo "managing EBS CSI Driver as a separate eks addon"
171-
# eksctl create addon --name aws-ebs-csi-driver \
172-
# --cluster $CLUSTERNAME \
173-
# --service-account-role-arn arn:aws:iam::${ACCOUNT_ID}:role/AmazonEKS_EBS_CSI_DriverRole \
174-
# --force \
175-
# --region $AWS_REGION
176-
177145
# Install CTFd
178-
179146
echo "Installing CTFd"
180147

181148
export HELM_EXPERIMENTAL_OCI=1
182149
kubectl create namespace ctfd
150+
151+
# Double base64 encoding to prevent weird character errors in ctfd
183152
helm upgrade --install ctfd -n ctfd oci://ghcr.io/bman46/ctfd/ctfd \
184-
--set="redis.auth.password=$(openssl rand -base64 24)" \
185-
--set="mariadb.auth.rootPassword=$(openssl rand -base64 24)" \
186-
--set="mariadb.auth.password=$(openssl rand -base64 24)" \
187-
--set="mariadb.auth.replicationPassword=$(openssl rand -base64 24)" \
153+
--set="redis.auth.password=$(openssl rand -base64 24 | base64)" \
154+
--set="mariadb.auth.rootPassword=$(openssl rand -base64 24 | base64)" \
155+
--set="mariadb.auth.password=$(openssl rand -base64 24 | base64)" \
156+
--set="mariadb.auth.replicationPassword=$(openssl rand -base64 24 | base64)" \
188157
--set="env.open.SECRET_KEY=test" # this key isn't actually necessary in a setup with CTFd

aws/cleanup-aws-autoscaling-and-helm.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,3 @@ helm uninstall csi-secrets-store \
3636
echo "Cleanup helm chart projectcalico"
3737
helm uninstall calico \
3838
-n default
39-
40-
echo "cleanup serviceaccont"
41-
echo "Cleanup iam serviceaccount and policy"
42-
eksctl delete iamserviceaccount \
43-
--cluster $CLUSTERNAME \
44-
--name cluster-autoscaler \
45-
--namespace kube-system \
46-
--region $AWS_REGION
47-
48-
49-
sleep 5 # Prevents race condition - command below may error out because it's still 'attached'
50-
51-
aws iam delete-policy \
52-
--policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AmazonEKSClusterAutoscalerPolicy
53-
54-
55-
echo "Cleanup CSI driver SA"
56-
57-
eksctl delete iamserviceaccount \
58-
--cluster $CLUSTERNAME \
59-
--name ebs-csi-controller-sa \
60-
--namespace kube-system \
61-
--region $AWS_REGION

aws/k8s-aws-alb-script-cleanup.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,3 @@ helm uninstall aws-load-balancer-controller \
3434

3535
echo "Cleanup k8s ALB"
3636
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
37-
38-
echo "Cleanup iam serviceaccount and policy"
39-
eksctl delete iamserviceaccount \
40-
--cluster $CLUSTERNAME \
41-
--name aws-load-balancer-controller \
42-
--namespace kube-system \
43-
--region $AWS_REGION
44-
45-
sleep 5 # Prevents race condition - command below may error out because it's still 'attached'
46-
47-
aws iam delete-policy \
48-
--policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AWSLoadBalancerControllerIAMPolicy

aws/k8s-aws-alb-script.sh

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,6 @@ echo "ACCOUNT_ID=${ACCOUNT_ID}"
2626
LBC_VERSION="v2.4.1"
2727
echo "LBC_VERSION=$LBC_VERSION"
2828

29-
# echo "executing eksctl utils associate-iam-oidc-provider"
30-
# eksctl utils associate-iam-oidc-provider \
31-
# --region ${AWS_REGION} \
32-
# --cluster ${CLUSTERNAME} \
33-
# --approve
34-
35-
echo "creating iam policy"
36-
curl -o iam_policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/"${LBC_VERSION}"/docs/install/iam_policy.json
37-
aws iam create-policy \
38-
--policy-name AWSLoadBalancerControllerIAMPolicy \
39-
--policy-document file://iam_policy.json
40-
41-
echo "creating iam service account for cluster ${CLUSTERNAME}"
42-
eksctl create iamserviceaccount \
43-
--cluster $CLUSTERNAME \
44-
--namespace kube-system \
45-
--name aws-load-balancer-controller \
46-
--attach-policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AWSLoadBalancerControllerIAMPolicy \
47-
--override-existing-serviceaccounts \
48-
--region $AWS_REGION \
49-
--approve
50-
5129
echo "setting up kubectl"
5230

5331
aws eks update-kubeconfig --region $AWS_REGION --name $CLUSTERNAME --kubeconfig ~/.kube/wrongsecrets

aws/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ module "eks" {
7272

7373
cluster_addons = {
7474
aws-ebs-csi-driver = {
75-
most_recent = true
75+
most_recent = true
76+
service_account_role_arn = module.ebs_csi_irsa_role.iam_role_arn
7677
}
7778
}
7879

aws/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "region" {
77
variable "cluster_version" {
88
description = "The EKS cluster version to use"
99
type = string
10-
default = "1.23"
10+
default = "1.25"
1111
}
1212

1313
variable "cluster_name" {

0 commit comments

Comments
 (0)