azureazure-managed-identity

How to use managed identity or some other permanent auth for a VM not on Azure?


I have a Discord bot that I use to turn on/off Azure VMs, and currently this bot authenticates to Azure using an access token I generate using an az CLI command. However this means that every now and then I have to regenerate the token, which is annoying. I'd like to use something permanent like managed identity, but this bot doesn't run on Azure, it runs on a local k8s cluster and I'd like to keep it that way. Is there any way permanent way of authenticating the bot against Azure so that I don't have to keep regenerating an auth token?


Solution

  • Create a Service Principal with either a secret (key) or certificate for authentication. Then store that (securely) on your k8s cluster and use it to log on to Azure and get auth tokens: https://learn.microsoft.com/en-us/azure/developer/java/sdk/identity-service-principal-auth