Skip to content

Commit 1f44693

Browse files
committed
Working version of Azure 9 and 10
1 parent 0c7af20 commit 1f44693

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

azure/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ Make sure you have an active subscription at Azure for which you have configured
2424

2525
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.
2626
1. check whether you have the right project by doing `az account show`.
27-
2. Run `terraform init` (if required, use tfenv to select TF 0.14.0 or higher )
28-
3. Run `terraform plan`
29-
4. Run `terraform apply`. Note: the apply will take 5 to 20 minutes depending on the speed of the AKS backplane.
30-
5. Run `./k8s-vault-azure-start.sh`
27+
1. If not yet enabled, register the required services for the subscription, run:
28+
- `az provider register --namespace Microsoft.ContainerService`
29+
- `az provider register --namespace Microsoft.KeyVault`
30+
- `az provider register --namespace Microsoft.ManagedIdentity`
31+
1. Run `terraform init` (if required, use tfenv to select TF 0.14.0 or higher )
32+
1. Run `terraform plan` to see what will be created (optional).
33+
1. Run `terraform apply`. Note: the apply will take 5 to 20 minutes depending on the speed of the Azure backplane.
34+
1. Run `./k8s-vault-azure-start.sh`. Your kubeconfig file will automatically be updated.
3135

3236
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.
3337

azure/k8s-vault-azure-start.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ if [ $? == 0 ]; then
142142
echo "CSI driver is already installed"
143143
else
144144
echo "Installing CSI driver"
145-
helm install -n kube-system csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --set enableSecretRotation=true --set rotationPollInterval=60s
146-
helm install -n kube-system csi-secrets-store-azure csi-secrets-store-provider-azure/csi-secrets-store-provider-azure
145+
helm install -n kube-system csi-secrets-store-provider-azure csi-secrets-store-provider-azure/csi-secrets-store-provider-azure --set enableSecretRotation=true --set rotationPollInterval=60s
147146
fi
148147

149148
echo "Add Azure pod identity to repo"
@@ -156,10 +155,6 @@ else
156155
helm install aad-pod-identity aad-pod-identity/aad-pod-identity
157156
fi
158157

159-
echo "Install Azure key vault provider"
160-
kubectl apply -f https://raw.githubusercontent.com/Azure/secrets-store-csi-driver-provider-azure/master/deployment/provider-azure-installer.yaml
161-
162-
# TODO change to az cli commands
163158
echo "Generate secret manager challenge secret 2"
164159
az keyvault secret set --name wrongsecret-2 --vault-name "${AZ_KEY_VAULT_NAME}" --value "$(openssl rand -base64 16)" >/dev/null
165160

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spec:
3535
volumeAttributes:
3636
secretProviderClass: "azure-wrongsecrets-vault"
3737
containers:
38-
- image: jeroenwillemsen/wrongsecrets:1.2.0-k8s-vault
38+
- image: jeroenwillemsen/wrongsecrets:azuretest2-k8s-vault
3939
imagePullPolicy: IfNotPresent
4040
ports:
4141
- containerPort: 8080
@@ -47,8 +47,8 @@ spec:
4747
env:
4848
- name: K8S_ENV
4949
value: azure
50-
- name: AzureKeyVaultUri
51-
value: ${AZ_VAULT_URI}
50+
- name: AZ_KEY_VAULT_NAME
51+
value: ${AZ_KEY_VAULT_NAME}
5252
- name: SPECIAL_K8S_SECRET
5353
valueFrom:
5454
configMapKeyRef:

azure/k8s/secret-volume.yml.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
1+
apiVersion: secrets-store.csi.x-k8s.io/v1
22
kind: SecretProviderClass
33
metadata:
44
name: azure-wrongsecrets-vault
@@ -12,11 +12,11 @@ spec:
1212
array:
1313
- |
1414
objectName: wrongsecret
15-
objectAlias: WRONGSECRET
15+
objectAlias: wrongsecret
1616
objectType: secret
1717
objectVersion: ""
1818
- |
1919
objectName: wrongsecret-2
20-
objectAlias: WRONGSECRET_2
20+
objectAlias: wrongsecret-2
2121
objectType: secret
2222
objectVersion: ""

src/main/java/org/owasp/wrongsecrets/challenges/cloud/Challenge11.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ private String getGCPChallenge11Value() {
172172

173173
private String getAzureChallenge11Value() {
174174
if (isAzure()) {
175-
String keyVaultUri = System.getenv("AZ_VAULT_URI");
175+
String keyVaultName = System.getenv("AZ_VAULT_NAME");
176+
String keyVaultUri = "https://" + keyVaultName + ".vault.azure.net";
176177
try {
177178
SecretClient secretClient = new SecretClientBuilder()
178179
.vaultUrl(keyVaultUri)

src/main/resources/explanations/challenge11-azure_hint.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ spec:
1717
containers:
1818
- name: az
1919
image: mcr.microsoft.com/azure-cli:latest
20-
command: ["az", "keyvault", "secret", "show", "--name=wrongsecret-3", "--vault-name=YOUR_VAULT_NAME_HERE"]
20+
command:
21+
[
22+
"sleep", "7200"
23+
]
2124
restartPolicy: Never
2225
```
26+
- Apply the job with `kubectl apply -f job.yaml`
2327

24-
This job executes something like the command `az keyvault secret show --name wrongsecret-3 --vault-name wrongsecrets-vault-00000`. Since the job can access the same vault as the secret challenge pod, it has access to its secrets.
28+
You can now exec into the pod, and execute something like `az login --identity --allow-no-subscriptions && az keyvault secret show --name wrongsecret-3 --vault-name wrongsecrets-vault-00000`. Since the job can access the same vault as the secret challenge pod, it has access to its secrets.
2529

26-
- Apply the job with `kubectl apply -f job.yaml`
27-
- Check the job's logs with `kubectl logs job/wrongsecret-3`. This should show you the solution :)

0 commit comments

Comments
 (0)