Repository navigation
Secrets Management Integration
As our project is hosted using the azure cloud we will make use of the built in secrets manager Azure Key Vault for any sensitive data i.e. usernames, passwords and connection links, we will also then assign permissions to the managed-user account so that when deploy the app it can retrieve our secrets for the vault and successfully deploy the app.
When granting access to the secrets manager we wanted to use the least access approach and as such have assigned the system managed identity the role of Key Vault Secrets Office meaning that the account can view the content of the secret but is unable to remove or edit the secret which ensures the secret won't be deleted by accident while aiding with the removal from hard coded values within the source code. we have also granted Key Vault Admin to ensure that the necessary permissions were in place to allow for the creation, versioning, editing and removal of the secrets from the key vault
The secrets we have chosen to store with the vault are:
- DB Host
- DB Name
- DB Username
- DB Password
these are all values which will allow for a secure connection to be established to the DB while the use of Key Vault also removes the need to have hard coded values with the code ensuring that it is more secure.
As Part of integrating our AKS deployment with Key Vault we need a service user that would be able to authenticate with the Key Vault and retrieve the credentials that are stored there so we might use them to deploy and connect to the app.
The starting point of setting up this identity was to run the command az aks update --resource-group <resource-group> --name <cluster-name> --enable-managed-identity from here you will receive a prompt asking if you which to switch from a service principal to managed identity, when you enable the managed identity the next step will be to update the node pool for the cluster as when we run the previous command the kubelet will still remain on the service principal.
The command to update the nodepool is az aks nodepool upgrade --resource-group <resource-group> --cluster-name <cluster-name> --name <nodepool-name> --node-image-only this will trigger the nodepool of the cluster to be updated and will allow the update from service principal to managed identity to be applied to the kubelet.
Once our node pool has been updated/upgraded we then seek to find out the client id/principal if of the managed identity and this can be done using az aks show --resource-group <resource-group> --name <aks-cluster-name> --query identityProfile or az identity show --ids <identity-resource-id>
Once we have the identity profile information we can then assign a role to the identity in our case as previous stated we have assigned the role Key Vault Secrets Officer to the managed identity and as such to assign the identity we will use the command `az role assignment create --role "Key Vault Secrets Officer" --assignee --scope /subscriptions//resourceGroups//providers/Microsoft.KeyVault/vaults/
Once the previous command has been executed we can verify the role has been granted by checking the IAM section of Key Vault in the GUI and we should see our kubelet present with the Key Vault Secret Officer role.