Skip to content

Commit 7bbfe00

Browse files
authored
Merge pull request #209 from OWASP/feat/k8s-1.25
Feat(#199): restricted PSS/PSA with K8s 1.25
2 parents f2dbe50 + c4ba598 commit 7bbfe00

File tree

20 files changed

+331
-142
lines changed

20 files changed

+331
-142
lines changed

.github/workflows/minikube-k8s-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
minikube-version: 1.29.0
2727
driver: docker
28-
kubernetes-version: v1.23.12
28+
kubernetes-version: v1.25.6
2929
- name: test script
3030
run: |
3131
eval $(minikube docker-env)

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Terraform
22
kubeconfig_wrongsecrets-exercise-cluster
33
.terraform
4-
.terraform.lock.hcl
5-
.terraform*
4+
.terraform
65
terraform.tfstate*
6+
.terraform.tfstate*
77
aws/terraform.tfstate.*
88
aws/terraform.tfstate.backup
99
aws/.terraform.tfstate.lock.info

aws/.terraform.lock.hcl

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@ The documentation below is auto-generated to give insight on what's created via
135135

136136
| Name | Version |
137137
|------|---------|
138-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.1 |
139-
| <a name="provider_http"></a> [http](#provider\_http) | ~> 3.1 |
140-
| <a name="provider_random"></a> [random](#provider\_random) | ~> 3.0 |
138+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.58.0 |
139+
| <a name="provider_http"></a> [http](#provider\_http) | 3.2.1 |
140+
| <a name="provider_random"></a> [random](#provider\_random) | 3.4.3 |
141141

142142
## Modules
143143

144144
| Name | Source | Version |
145145
|------|--------|---------|
146-
| <a name="module_cluster_autoscaler_irsa_role"></a> [cluster\_autoscaler\_irsa\_role](#module\_cluster\_autoscaler\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.9.0 |
147-
| <a name="module_ebs_csi_irsa_role"></a> [ebs\_csi\_irsa\_role](#module\_ebs\_csi\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.9.0 |
148-
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | 19.7.0 |
149-
| <a name="module_load_balancer_controller_irsa_role"></a> [load\_balancer\_controller\_irsa\_role](#module\_load\_balancer\_controller\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.9.0 |
146+
| <a name="module_cluster_autoscaler_irsa_role"></a> [cluster\_autoscaler\_irsa\_role](#module\_cluster\_autoscaler\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.11.2 |
147+
| <a name="module_ebs_csi_irsa_role"></a> [ebs\_csi\_irsa\_role](#module\_ebs\_csi\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.11.2 |
148+
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | 19.10.0 |
149+
| <a name="module_load_balancer_controller_irsa_role"></a> [load\_balancer\_controller\_irsa\_role](#module\_load\_balancer\_controller\_irsa\_role) | terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks | ~> 5.11.2 |
150150
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.19.0 |
151151

152152
## Resources
@@ -190,7 +190,7 @@ The documentation below is auto-generated to give insight on what's created via
190190
| Name | Description | Type | Default | Required |
191191
|------|-------------|------|---------|:--------:|
192192
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The EKS cluster name | `string` | `"wrongsecrets-exercise-cluster"` | no |
193-
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | The EKS cluster version to use | `string` | `"1.23"` | no |
193+
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | The EKS cluster version to use | `string` | `"1.25"` | no |
194194
| <a name="input_extra_allowed_ip_ranges"></a> [extra\_allowed\_ip\_ranges](#input\_extra\_allowed\_ip\_ranges) | Allowed IP ranges in addition to creator IP | `list(string)` | `[]` | no |
195195
| <a name="input_region"></a> [region](#input\_region) | The AWS region to use | `string` | `"eu-west-1"` | no |
196196
| <a name="input_state_bucket_arn"></a> [state\_bucket\_arn](#input\_state\_bucket\_arn) | ARN of the state bucket to grant access to the s3 user | `string` | n/a | yes |
@@ -199,6 +199,8 @@ The documentation below is auto-generated to give insight on what's created via
199199

200200
| Name | Description |
201201
|------|-------------|
202+
| <a name="output_cluster_autoscaler_role"></a> [cluster\_autoscaler\_role](#output\_cluster\_autoscaler\_role) | Cluster autoscaler role |
203+
| <a name="output_cluster_autoscaler_role_arn"></a> [cluster\_autoscaler\_role\_arn](#output\_cluster\_autoscaler\_role\_arn) | Cluster autoscaler role arn |
202204
| <a name="output_cluster_endpoint"></a> [cluster\_endpoint](#output\_cluster\_endpoint) | Endpoint for EKS control plane. |
203205
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | The id of the cluster |
204206
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | The EKS cluster name |
@@ -207,6 +209,8 @@ The documentation below is auto-generated to give insight on what's created via
207209
| <a name="output_ebs_role_arn"></a> [ebs\_role\_arn](#output\_ebs\_role\_arn) | EBS CSI driver role |
208210
| <a name="output_irsa_role"></a> [irsa\_role](#output\_irsa\_role) | The role name used in the IRSA setup |
209211
| <a name="output_irsa_role_arn"></a> [irsa\_role\_arn](#output\_irsa\_role\_arn) | The role ARN used in the IRSA setup |
212+
| <a name="output_load_balancer_controller_role"></a> [load\_balancer\_controller\_role](#output\_load\_balancer\_controller\_role) | Load balancer controller role |
213+
| <a name="output_load_balancer_controller_role_arn"></a> [load\_balancer\_controller\_role\_arn](#output\_load\_balancer\_controller\_role\_arn) | Load balancer controller role arn |
210214
| <a name="output_secrets_manager_secret_name"></a> [secrets\_manager\_secret\_name](#output\_secrets\_manager\_secret\_name) | The name of the secrets manager secret |
211215
| <a name="output_state_bucket_name"></a> [state\_bucket\_name](#output\_state\_bucket\_name) | Terraform s3 state bucket name |
212216
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

aws/build-an-deploy-aws.sh

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ CLUSTERNAME="$(terraform output -raw cluster_name)"
4343
STATE_BUCKET="$(terraform output -raw state_bucket_name)"
4444
IRSA_ROLE_ARN="$(terraform output -raw irsa_role_arn)"
4545
EBS_ROLE_ARN="$(terraform output -raw ebs_role_arn)"
46+
CLUSTER_AUTOSCALER_ROLE_ARN="$(terraform output -raw cluster_autoscaler_role_arn)"
4647

4748
echo "CLUSTERNAME=${CLUSTERNAME}"
4849
echo "STATE_BUCKET=${STATE_BUCKET}"
4950
echo "IRSA_ROLE_ARN=${IRSA_ROLE_ARN}"
5051
echo "EBS_ROLE_ARN=${EBS_ROLE_ARN}"
52+
echo "CLUSTER_AUTOSCALER_ROLE_ARN=${CLUSTER_AUTOSCALER_ROLE_ARN}"
5153

5254
version="$(uuidgen)"
5355

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

5662
aws sts get-caller-identity
@@ -59,24 +65,6 @@ echo "Giving you 4 seconds before we add autoscaling"
5965

6066
sleep 4
6167

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

8270
curl -o cluster-autoscaler-autodiscover.yaml https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
@@ -86,8 +74,8 @@ kubectl apply -f cluster-autoscaler-autodiscover.yaml
8674

8775
echo "annotating service account for cluster-autoscaler"
8876
kubectl annotate serviceaccount cluster-autoscaler \
89-
-n kube-system \
90-
eks.amazonaws.com/role-arn=${CLUSTER_AUTOSCALER}
77+
-n kube-system --overwrite \
78+
eks.amazonaws.com/role-arn=${CLUSTER_AUTOSCALER_ROLE_ARN}
9179

9280
kubectl patch deployment cluster-autoscaler \
9381
-n kube-system \
@@ -105,6 +93,9 @@ else
10593
helm upgrade --install -n kube-system csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --set enableSecretRotation=true --set rotationPollInterval=60s
10694
fi
10795

96+
echo "Patching default namespace"
97+
kubectl apply -f k8s/workspace-psa.yml
98+
10899
echo "Install ACSP"
109100
kubectl apply -f https://raw.githubusercontent.com/aws/secrets-store-csi-driver-provider-aws/main/deployment/aws-provider-installer.yaml
110101

@@ -154,33 +145,16 @@ helm upgrade --install mj ../helm/wrongsecrets-ctf-party \
154145
--set="balancer.env.REACT_APP_CREATE_TEAM_HMAC_KEY=${CREATE_TEAM_HMAC}" \
155146
--set="balancer.cookie.cookieParserSecret=${COOKIE_PARSER_SECRET}"
156147

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

179151
export HELM_EXPERIMENTAL_OCI=1
180152
kubectl create namespace ctfd
153+
154+
# Double base64 encoding to prevent weird character errors in ctfd
181155
helm upgrade --install ctfd -n ctfd oci://ghcr.io/bman46/ctfd/ctfd \
182-
--set="redis.auth.password=$(openssl rand -base64 24)" \
183-
--set="mariadb.auth.rootPassword=$(openssl rand -base64 24)" \
184-
--set="mariadb.auth.password=$(openssl rand -base64 24)" \
185-
--set="mariadb.auth.replicationPassword=$(openssl rand -base64 24)" \
156+
--set="redis.auth.password=$(openssl rand -base64 24 | base64)" \
157+
--set="mariadb.auth.rootPassword=$(openssl rand -base64 24 | base64)" \
158+
--set="mariadb.auth.password=$(openssl rand -base64 24 | base64)" \
159+
--set="mariadb.auth.replicationPassword=$(openssl rand -base64 24 | base64)" \
186160
--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: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424
ACCOUNT_ID=$(aws sts get-caller-identity | jq '.Account' -r)
2525
echo "ACCOUNT_ID=${ACCOUNT_ID}"
2626

27-
kubectl delete -f k8s/wrongsecrets-balancer-ingress.yaml
27+
kubectl delete -f k8s/wrongsecrets-balancer-ingress.yml
2828
kubectl delete -f k8s/ctfd-ingress.yaml
2929

3030
sleep 5 # Give the controller some time to catch the ingress 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: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,16 @@ echo "cleanup k8s ingress and service. This may take a while"
2828
kubectl delete service wrongsecrets-balancer
2929
kubectl delete ingress wrongsecrets-balancer
3030

31+
kubectl delete ingress ctfd -n ctfd
32+
33+
# Give some time for the controller to remove cleaned ingresses
34+
sleep 5
35+
3136
echo "Cleanup helm chart"
3237
helm uninstall aws-load-balancer-controller \
3338
-n kube-system
3439

3540
echo "Cleanup k8s ALB"
3641
kubectl delete -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
3742

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
43+
kubectl delete serviceaccount -n kube-system aws-load-balancer-controller

0 commit comments

Comments
 (0)