Skip to content

Commit

Permalink
Migrate to Azure RBAC for Key Vault data plane interactions (#241)
Browse files Browse the repository at this point in the history
* Migrate to KV AAD (WIP Checkpoint)

* WIP

* simplify

* update depends on to be more complete

* fix role assignment deps

* validation step update

* remove commented out bits
  • Loading branch information
ckittel authored Sep 28, 2021
1 parent 76590c6 commit ed5206c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 76 deletions.
6 changes: 3 additions & 3 deletions 03-aad.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Following the steps below you will result in an Azure AD configuration that will
> :book: The organization knows the value of having a break-glass admin user for their critical infrastructure. The app team requests a cluster admin user and Azure AD Admin team proceeds with the creation of the user in Azure AD.
```bash
export TENANTDOMAIN_K8SRBAC=$(az ad signed-in-user show --query 'userPrincipalName' -o tsv | cut -d '@' -f 2 | sed 's/\"//')
export AADOBJECTNAME_USER_CLUSTERADMIN=bu0001a000800-admin
export AADOBJECTID_USER_CLUSTERADMIN=$(az ad user create --display-name=${AADOBJECTNAME_USER_CLUSTERADMIN} --user-principal-name ${AADOBJECTNAME_USER_CLUSTERADMIN}@${TENANTDOMAIN_K8SRBAC} --force-change-password-next-login --password ChangeMebu0001a0008AdminChangeMe --query objectId -o tsv)
TENANTDOMAIN_K8SRBAC=$(az ad signed-in-user show --query 'userPrincipalName' -o tsv | cut -d '@' -f 2 | sed 's/\"//')
AADOBJECTNAME_USER_CLUSTERADMIN=bu0001a000800-admin
AADOBJECTID_USER_CLUSTERADMIN=$(az ad user create --display-name=${AADOBJECTNAME_USER_CLUSTERADMIN} --user-principal-name ${AADOBJECTNAME_USER_CLUSTERADMIN}@${TENANTDOMAIN_K8SRBAC} --force-change-password-next-login --password ChangeMebu0001a0008AdminChangeMe --query objectId -o tsv)
```

1. Add the cluster admin user(s) to the cluster admin security group.
Expand Down
11 changes: 7 additions & 4 deletions 07-workload-prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ The AKS Cluster has been enrolled in [GitOps management](./06-gitops.md), wrappi

> :book: Contoso Bicycle procured a CA certificate, a standard one, to be used with the AKS Ingress Controller. This one is not EV, as it will not be user facing.
1. Obtain the Azure Key Vault details and give the current user permissions to import certificates.
1. Obtain the Azure Key Vault details and give the current user permissions and network access to import certificates.

> :book: Finally the app team decides to use a wildcard certificate of `*.aks-ingress.contoso.com` for the ingress controller. They use Azure Key Vault to import and manage the lifecycle of this certificate.
```bash
export KEYVAULT_NAME_AKS_BASELINE=$(az deployment group show --resource-group rg-bu0001a0008 -n cluster-stamp --query properties.outputs.keyVaultName.value -o tsv)
az keyvault set-policy --certificate-permissions import list get --upn $(az ad signed-in-user show --query 'userPrincipalName' -o tsv) -n $KEYVAULT_NAME_AKS_BASELINE
TEMP_ROLEASSIGNMENT_TO_UPLOAD_CERT=$(az role assignment create --role a4417e6f-fecd-4de8-b567-7b0420556985 --assignee-principal-type user --assignee-object-id $(az ad signed-in-user show --query 'objectId' -o tsv) --scope $(az keyvault show --name $KEYVAULT_NAME_AKS_BASELINE --query 'id' -o tsv) --query 'id' -o tsv)
CURRENT_IP_ADDRESS=$(curl -s https://ifconfig.io)
az keyvault network-rule add -n $KEYVAULT_NAME_AKS_BASELINE --ip-address ${CURRENT_IP_ADDRESS}
```

1. Import the AKS Ingress Controller's Wildcard Certificate for `*.aks-ingress.contoso.com`.
Expand All @@ -28,12 +30,13 @@ The AKS Cluster has been enrolled in [GitOps management](./06-gitops.md), wrappi
az keyvault certificate import -f traefik-ingress-internal-aks-ingress-tls.pem -n traefik-ingress-internal-aks-ingress-tls --vault-name $KEYVAULT_NAME_AKS_BASELINE
```

1. Remove Azure Key Vault import certificates permissions for current user.
1. Remove Azure Key Vault import certificates permissions and network access for current user.

> The Azure Key Vault Policy for your user was a temporary policy to allow you to upload the certificate for this walkthrough. In actual deployments, you would manage these access policies via your ARM templates using [Azure RBAC for Key Vault data plane](https://docs.microsoft.com/azure/key-vault/general/secure-your-key-vault#data-plane-and-access-policies).
```bash
az keyvault delete-policy --upn $(az ad signed-in-user show --query 'userPrincipalName' -o tsv) -n $KEYVAULT_NAME_AKS_BASELINE
az keyvault network-rule remove -n $KEYVAULT_NAME_AKS_BASELINE --ip-address "${CURRENT_IP_ADDRESS}/32"
az role assignment delete --ids $TEMP_ROLEASSIGNMENT_TO_UPLOAD_CERT
```

## Check Azure Policies are in place
Expand Down
6 changes: 3 additions & 3 deletions 08-secret-management-and-ingress-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Previously you have configured [workload prerequisites](./07-workload-prerequisi
1. Get the AKS Ingress Controller Managed Identity details.

```bash
export TRAEFIK_USER_ASSIGNED_IDENTITY_RESOURCE_ID=$(az deployment group show --resource-group rg-bu0001a0008 -n cluster-stamp --query properties.outputs.aksIngressControllerPodManagedIdentityResourceId.value -o tsv)
export TRAEFIK_USER_ASSIGNED_IDENTITY_CLIENT_ID=$(az deployment group show --resource-group rg-bu0001a0008 -n cluster-stamp --query properties.outputs.aksIngressControllerPodManagedIdentityClientId.value -o tsv)
TRAEFIK_USER_ASSIGNED_IDENTITY_RESOURCE_ID=$(az deployment group show --resource-group rg-bu0001a0008 -n cluster-stamp --query properties.outputs.aksIngressControllerPodManagedIdentityResourceId.value -o tsv)
TRAEFIK_USER_ASSIGNED_IDENTITY_CLIENT_ID=$(az deployment group show --resource-group rg-bu0001a0008 -n cluster-stamp --query properties.outputs.aksIngressControllerPodManagedIdentityClientId.value -o tsv)
```

1. Ensure Flux has created the following namespace.
Expand Down Expand Up @@ -100,7 +100,7 @@ Previously you have configured [workload prerequisites](./07-workload-prerequisi
1. Wait for Traefik to be ready.
> During Traefik's pod creation process, AAD Pod Identity will need to retrieve token for Azure Key Vault. This process can take time to complete and it's possible for the pod volume mount to fail during this time but the volume mount will eventually succeed. For more information, please refer to the [Pod Identity documentation](https://github.com/Azure/secrets-store-csi-driver-provider-azure/blob/master/docs/pod-identity-mode.md).
> During Traefik's pod creation process, AAD Pod Identity will need to retrieve a token for Azure Key Vault. This process can take time to complete and it's possible for the pod volume mount to fail during this time but the volume mount will eventually succeed. For more information, please refer to the [Pod Identity documentation](https://azure.github.io/secrets-store-csi-driver-provider-azure/configurations/identity-access-modes/pod-identity-mode/).
```bash
kubectl wait -n a0008 --for=condition=ready pod --selector=app.kubernetes.io/name=traefik-ingress-ilb --timeout=90s
Expand Down
4 changes: 2 additions & 2 deletions 10-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This section will help you to validate the workload is exposed correctly and res
```bash
# query the Azure Application Gateway Public Ip
export APPGW_PUBLIC_IP=$(az deployment group show --resource-group rg-enterprise-networking-spokes -n spoke-BU0001A0008 --query properties.outputs.appGwPublicIpAddress.value -o tsv)
APPGW_PUBLIC_IP=$(az deployment group show --resource-group rg-enterprise-networking-spokes -n spoke-BU0001A0008 --query properties.outputs.appGwPublicIpAddress.value -o tsv)
```

1. Create `A` Record for DNS
Expand All @@ -25,7 +25,7 @@ This section will help you to validate the workload is exposed correctly and res

1. Browse to the site (e.g. <https://bicycle.contoso.com>).

> :bulb: A TLS warning will be present due to using a self-signed certificate.
> :bulb: A TLS warning will be present due to using a self-signed certificate. You can ignore it or import the self-signed cert (`appgw.pfx`) to your user's trusted root store.
## Validate reader access to the a0008 namespace. _Optional._

Expand Down
Loading

0 comments on commit ed5206c

Please sign in to comment.