简体   繁体   English

有没有一种方法可以在不使用AD身份验证的情况下访问Azure密钥库?

[英]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. 我想使用我的azure凭据访问我的azure密钥库中的机密,而不使用Azure AD App身份验证。 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. 我们可以使用C#代码中的Azure PowerShell脚本来实现。 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. 为此,我们仅需要密钥库的名称,秘密名称和想要访问它的用户的Azure凭据。

    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. 实际上,我想在没有AD应用程序身份验证的情况下访问密钥库。 This was the only way i could think of. 这是我能想到的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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