Steps to connect using service principal to Azure PostgreSQL single server - azure

How to connect securely from AKS cluster to Azure PostgreSQL Single Server using Service principal as the Managed Identity is not supported.

From my point of view you have 2 options (maybe more but lets focus on those 2):
Use Azure AD Workload identity together with federated identity credential linked to you Service Principal. Basically you configure trust between your AKS (OIDC issuer), the Kubernetes Service Account for your Pod and the Azure Service principal to access resources with an Azure AD Token. Here you have to adopt the code running inside your container to leverage the workload identity with the issued Azure AD access token.
Use the Azure Key Vault Provider for Secrets Store CSI Driver. You will configure the Kubelet Identity of your AKS to read the secrets from the KeyVault and mount the Service Principal Client ID & Client Secret (saved as KeVault secrets) during Pod startup as volume into your pod. Here you have to adopt the code running inside your container to read the information (Client ID & Secret) from the filesystem inside the pod. P.s.: You can also use Workload Identity, System assigned identity or a Service Principal instead of managed-identity to access the KeyVault.

Related

What happens to Azure AD Pod identity once the pod dies

I am planning to assign pod identity to one of my applications. However, I am unable to understand the part where what happens to the assigned pod identity when the pod restarts/dies on its own ?
Does the pod get assigned a new identity on its own?
Not sure about your configuring End to end setup however if you are using it with Service Account and annotating it workload idenetiy it will stay there even if POD will restart or so.
AZURE_AUTHORITY_HOST, azure-identity-token will get auto-injected if POD restarting. Instead of using POD you can also use deployment and attach the Service account to it.
As mentioned in the official doc, it's service account to AAD mapping so if you service account is there in config with POD or deployment it will get secret and other values.
Azure AD Workload Identity supports the following mappings:
one-to-one (a service account referencing an AAD object)
many-to-one (multiple service accounts referencing the same AAD object).
one-to-many (a service account referencing multiple AAD objects by changing the client ID annotation).

How to access Azure storage account Via Azure Key Vault by service principal

I have an external web application which has the option to access a storage account using the service principal.
I want to access Azure storage account/blob by the external application loading the data directly into the datalake account.
So here is what I am trying to do:
Set up a service principal (using Azure AD app registration)
Create a Storage account and store the access key in Azure Key Vault.
Add the service principal secret to the same key vault.
Create a policy within Key vault for the service principal to have access to read Keys and Secrets within Key Vault.
Also create a policy within Key Vault for service principal to have contributor role to access storage account.
Also grant access to storage account container to service principal.
But I cannot connect, and I am unable to authorize the connection.
I am confused on which steps I am missing to resolve this.
As you want to access the storage account using service principal, you do not need to store the storage account access in the key vault.
The steps you can follow up to access storage account by service principal:
Create a service principal (Azure AD App Registration)
Create a storage account
Assign Storage Blob Data Contributor role to the service principal
Now you would be able to access the Azure Storage Blob data using your service principal
Note: You do not need to store the service principal client secret in the key vault. Because you need the client secret again to access the key vault first.
Thanks #RamaraoAdapa-MT
This works
Finally, I setup like you said,,
SAS -> service principle -> permission to storage account -> storage account.
In this case, no need for Key vault.
Thanks you Guys,
Anupam Chand, RamaraoAdapa-MT

Azure kubernetes - multiple managed identity?

We are planning to deploy multiple applications on our single Azure kubernetes cluster, each application will have its own set of Azure resources - eg: Key vault, Storage.
I am planning to provision individual managed identities per application and provide access to the relevant resources.
I know that AZURE AAD POD identify is the way to configure the pod to make use of the managed identity to access the Azure resources.
However how do I add multiple managed identity into the Azure kubernetes cluster? and is this the right of implementing?
As I mentioned before, I don't think you can add multiple MSIs to the cluster, you can just use a system-assigned MSI or user-assigned MSI for it.
Reference - Use managed identities in Azure Kubernetes Service
In your case, if you want to use different service principals to authenticate(essentially MSI is also a service principal managed by Azure), you can create multiple AD Apps along with the service principals.
Reference - How to: Use the portal to create an Azure AD application and service principal that can access resources
Then in the code of every application, use ClientSecretCredential to authenticate.
ClientSecretCredential credential1 = new ClientSecretCredentialBuilder()
.tenantId(tenantId)
.clientId(clientId)
.clientSecret(clientSecret)
.build();
Then use the credential to create a client e.g. SecretClient .
SecretClient secretClient = new SecretClientBuilder()
.vaultUrl("<your-key-vault-url>")
.credential(credential1)
.buildClient();

Azure Kubernetes Service- Get kubeconfig for non-admin AD app identity

As per my understanding, Azure Kubernetes Service(AKS) allows getting credentials for admin and user identities. Can the user identity be an AD app or a managed identity?
I'm writing .Net code. Can you provide some sample where we can get the user credentials from AKS cluster by using AD app credentials, assuming I have already done AD integration with my AKS cluster and have already assigned the appropriate role binding for my AD app?
The security section here - https://learn.microsoft.com/en-us/rest/api/aks/managedclusters/getaccessprofile needs implicit flow. How does implicit flow work for AD app credentials?
You can use Implicit grant flow to get access token.
You'll need the Azure Kubernetes Service Cluster User built-in role to access an Azure AD enabled cluster.
Get the user credentials to access the cluster:
az aks get-credentials --resource-group myResourceGroup --name MyManagedCluster
Or use List Cluster User Credentials API.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterUserCredential?api-version=2020-04-01
Because Get Access Profile API will be deprecated in the futhure.

Azure Keyvault to access resources from different azure subscriptions

I am trying to use azure keyvault in my MVC application to get storage account keys. This MVC application is hosted in different azure subscriptions with storage accounts belonging to those subscriptions. Is it possible to have a one Azure Keyvault resource in any subscription and serve keys for storage accounts residing in different subscriptions?
Yes it is possible.
You will need to make identities for the apps using the Key Vault in the Azure AD tenant where the Key Vault's subscription is. And then assign permissions to access the vault to those service principals.
Then you can put the client id, client secret and tenant id to the apps that need to access the Key Vault. They should then be able to call it, since they have an identity that is allowed access. Key Vault uses an HTTP API so whether the apps and the vault are in the same subscription/data center/cloud provider is irrelevant.
Hi you can use below to do via azure CLI
az webapp config ssl import -n 'webappname' -g 'webappresourcegroup' --key-vault "/subscriptions/[provide subscriptionID]/resourceGroups/[Provide resource group Name]/providers/Microsoft.KeyVault/vaults/[Provide Vault Name] --key-vault-certificate 'Provide certificate Name'

Resources