简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM