Skip to content

Commit 19c8203

Browse files
committed
enable azure support in kubernetes.js
Signed-off-by: osamamagdy <[email protected]>
1 parent 0c3af2d commit 19c8203

17 files changed

+121
-254
lines changed

azure/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ terraform apply
4545

4646
The storage account name should be in the output. Please use that to configure the Terraform backend in `main.tf` by uncommenting the part on the `backend "azurerm"` inside the `terraform` block. Assign the `storage_account_name` to the one from the output.
4747

48-
**Note**: You'll need to follow the description [below](#wrongsecrets-ctf-party) in step 1 for the "existing resource group" i.e., use the `data.azurerm_resource_group.default` resource.
48+
**Note**: You'll need to follow the description [below](#wrongsecrets-ctf-party) in step 1 for the "existing resource group" i.e., use the `azurerm_resource_group.default` resource.
4949

5050
### WrongSecrets-ctf-party
5151

52-
1. Set either a new resource group or use an existing resource group in `main.tf` (it defaults to the existing `OWASP-Projects` resource group). Note that you'll need to find/replace references to "data.azurerm_resource_group.default" to "arurerm_resource_group.default" if you want to create a new one.
52+
1. Set either a new resource group or use an existing resource group in `main.tf` (it defaults to the existing `OWASP-Projects` resource group). Note that you'll need to find/replace references to "azurerm_resource_group.default" to "arurerm_resource_group.default" if you want to create a new one.
5353
2. check whether you have the right project by doing `az account show` (after `az login`). Want to set the project as your default? Use `az account set --subscription <.id here>`.
5454
3. If not yet enabled, register the required services for the subscription, run:
5555
- `az provider register --namespace Microsoft.ContainerService`
@@ -58,7 +58,19 @@ The storage account name should be in the output. Please use that to configure t
5858
4. Run `terraform init` (if required, use `tfenv` to select TF 0.14.0 or higher )
5959
5. Run `terraform plan` to see what will be created (optional).
6060
6. Run `terraform apply`. Note: the apply will take 5 to 20 minutes depending on the speed of the Azure backplane.
61-
7. Run `./build-and-deploy-azure.sh`. Your kubeconfig file will automatically be updated.
61+
7. Go to the values of the helm chart and replace the wrongsecrets.config with this:
62+
63+
```yaml
64+
K8S_ENV: "azure"
65+
```
66+
67+
and replace the value of wrongsecrets.env having the name 'K8S_ENV' with this:
68+
69+
```yaml
70+
value: "azure"
71+
```
72+
73+
8. Run `./build-and-deploy-azure.sh`. Your kubeconfig file will automatically be updated.
6274

6375
Your AKS cluster should be visible in your resource group. Want a different region? You can modify `terraform.tfvars` or input it directly using the `region` variable in plan/apply.
6476

@@ -173,6 +185,7 @@ No modules.
173185
| [azurerm_key_vault_secret.wrongsecret_2](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
174186
| [azurerm_key_vault_secret.wrongsecret_3](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource |
175187
| [azurerm_kubernetes_cluster.cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster) | resource |
188+
| [azurerm_resource_group.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
176189
| [azurerm_role_assignment.aks_extra_identity_operator](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
177190
| [azurerm_role_assignment.aks_identity_operator](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
178191
| [azurerm_role_assignment.aks_vm_contributor](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
@@ -182,7 +195,6 @@ No modules.
182195
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
183196
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
184197
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
185-
| [azurerm_resource_group.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
186198
| [http_http.ip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
187199

188200
## Inputs
@@ -191,6 +203,7 @@ No modules.
191203
|------|-------------|------|---------|:--------:|
192204
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The AKS cluster name | `string` | `"wrongsecrets-exercise-cluster"` | no |
193205
| <a name="input_cluster_version"></a> [cluster\_version](#input\_cluster\_version) | The AKS cluster version to use | `string` | `"1.25"` | no |
206+
| <a name="input_region"></a> [region](#input\_region) | The Azure region to use | `string` | `"East US"` | no |
194207

195208
## Outputs
196209

azure/build-and-deploy-azure.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ export AZ_KEY_VAULT_NAME="$(terraform output -raw vault_name)"
6060
# Set the kubeconfig
6161
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
6262

63-
64-
# Install the secrets store CSI driver
65-
helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts
66-
helm list --namespace kube-system | grep 'csi-secrets-store' &>/dev/null
67-
if [ $? == 0 ]; then
68-
echo "CSI driver is already installed"
69-
else
70-
helm upgrade --install -n kube-system csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --set enableSecretRotation=true --set rotationPollInterval=60s
71-
fi
72-
7363
# Patch the default namespace to use the secrets store CSI driver
7464
echo "Patching default namespace"
7565
kubectl apply -f k8s/workspace-psa.yml
@@ -80,7 +70,7 @@ helm repo add csi-secrets-store-provider-azure https://azure.github.io/secrets-s
8070

8171
helm list --namespace kube-system | grep 'csi-secrets-store' &>/dev/null
8272
if [ $? == 0 ]; then
83-
echo "CSI driver is already installed"
73+
echo "CSI driver provider is already installed"
8474
else
8575
echo "Installing CSI driver"
8676
helm install csi csi-secrets-store-provider-azure/csi-secrets-store-provider-azure --namespace kube-system
@@ -154,13 +144,19 @@ else
154144
echo "Cookie parser secret already set"
155145
fi
156146

157-
echo "App password is ${APP_PASSWORD}"
147+
echo "App password is ${APP_PASSWORD}" > password.txt
148+
149+
echo "You can find the app password in password.txt"
150+
158151
helm upgrade --install mj ../helm/wrongsecrets-ctf-party \
159152
--set="balancer.env.K8S_ENV=azure" \
160-
--set="balancer.env.REACT_APP_S3_BUCKET_URL='Azure Storage Account: ${AZ_STORAGE_ACCOUNT}'" \
161153
--set="balancer.env.REACT_APP_ACCESS_PASSWORD=${APP_PASSWORD}" \
162154
--set="balancer.env.REACT_APP_CREATE_TEAM_HMAC_KEY=${CREATE_TEAM_HMAC}" \
163-
--set="balancer.cookie.cookieParserSecret=${COOKIE_PARSER_SECRET}"
155+
--set="balancer.env.AZ_KEY_VAULT_NAME=${AZ_KEY_VAULT_NAME}" \
156+
--set="balancer.env.AZ_KEY_VAULT_TENANT_ID=${AZ_KEY_VAULT_TENANT_ID}" \
157+
--set="balancer.env.AZ_VAULT_URI=${AZ_VAULT_URI}" \
158+
--set="balancer.env.AZ_POD_CLIENT_ID=${AZ_POD_CLIENT_ID}" \
159+
--set="balancer.cookie.cookieParserSecret=${COOKIE_PARSER_SECRET}" \
164160

165161
# Install CTFd
166162
echo "Installing CTFd"

azure/iam.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resource "azurerm_user_assigned_identity" "aks_pod_identity" {
2-
resource_group_name = data.azurerm_resource_group.default.name
3-
location = data.azurerm_resource_group.default.location
2+
resource_group_name = azurerm_resource_group.default.name
3+
location = azurerm_resource_group.default.location
44
name = "wrongsecrets-identity"
55
}
66

77
resource "azurerm_user_assigned_identity" "aks_extra_pod_identity" {
8-
resource_group_name = data.azurerm_resource_group.default.name
9-
location = data.azurerm_resource_group.default.location
8+
resource_group_name = azurerm_resource_group.default.name
9+
location = azurerm_resource_group.default.location
1010
name = "wrongsecrets-extra-identity"
1111
}
1212

azure/k8s-nginx-lb-script.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
1616

1717
echo "Installing the nginx ingress controller chart"
1818

19-
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace
19+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml
2020

2121

22-
echo "apply -f k8s/wrongsecrets-balancer-service.yml in 10 s"
23-
sleep 10
24-
kubectl apply -f k8s/wrongsecrets-balancer-service.yml
25-
2622
echo "apply -f k8s/wrongsecrets-balancer-ingress.yml in 10 s"
2723
sleep 10
2824
kubectl apply -f k8s/wrongsecrets-balancer-ingress.yml

azure/k8s/pod-id.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

azure/k8s/secret-challenge-vault-deployment.yml

Lines changed: 0 additions & 127 deletions
This file was deleted.

azure/k8s/secret-challenge-vault-deployment.yml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
driver: secrets-store.csi.k8s.io
4040
readOnly: true
4141
volumeAttributes:
42-
secretProviderClass: "wrongsecrets-azure-keyvault"
42+
secretProviderClass: "azure-wrongsecrets-vault"
4343
containers:
4444
- image: jeroenwillemsen/wrongsecrets:1.6.7-k8s-vault
4545
imagePullPolicy: IfNotPresent

azure/k8s/secret-volume.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

azure/k8s/secret-volume.yml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: secrets-store.csi.x-k8s.io/v1
22
kind: SecretProviderClass
33
metadata:
4-
name: wrongsecrets-azure-keyvault
4+
name: azure-wrongsecrets-vault
55
spec:
66
provider: azure
77
parameters:

azure/k8s/wrongsecrets-balancer-ingress.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ spec:
1616
service:
1717
name: wrongsecrets-balancer
1818
port:
19-
number: 80
19+
number: 3000

0 commit comments

Comments
 (0)