Is there a way to access azure key vault without using AD authentication?

1k views Asked by At

I want to access the secrets in my azure key vault using my azure credentials without using Azure AD App authentication. Is there a possible way?

Thanks

2

There are 2 answers

0
Newton Sheikh On

You will need the serviceprincipal name to decry-pt the key. Hence the answer is unfortunately NO.

1
Radhika On

We can do it using Azure PowerShell script in C# code. For this we would require only the name of the keyvault, name of secret and Azure credentials of the user who wants to access it.

    static void Main(string[] args)
    {
            Program program = new Program();
            string scriptText = "Login-AzureRmAccount";
            string result = program.RunScript(scriptText);
            Console.WriteLine(result);
            Console.ReadLine();
    }

    private string RunScript(string scriptText)
    {

        Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();        
        Pipeline pipeline = runspace.CreatePipeline();
        pipeline.Commands.AddScript(scriptText);
        pipeline.Commands.AddScript("$secret = Get-AzureKeyVaultSecret -VaultName '[Name_of_keyVault]' -Name '[Name_of_secret]'");
        pipeline.Commands.AddScript("Write $secret.SecretValueText");
        Collection<PSObject> results = pipeline.Invoke();           
        runspace.Close();            
        StringBuilder stringBuilder = new StringBuilder();
        foreach (PSObject obj in results)
        {
            stringBuilder.AppendLine(obj.ToString());
        }
        return stringBuilder.ToString();
    }

Actually, i wanted to access key vault without AD application authentication. This was the only way i could think of.