[英]How to get DB password from Azure app vault using python ? I am running this python file on google Dataproc cluster
My Sql server DB password is saved on Azure app vault which has DATAREF ID as a identifier.我的 Sql 服务器数据库密码保存在 Azure 应用程序库中,该库以 DATAREF ID 作为标识符。 I need that password to create spark dataframe from table which is present in SQL server.
我需要该密码才能从 SQL 服务器中存在的表创建 spark dataframe。 I am running this.py file on google Dataproc cluster.
我在 google Dataproc 集群上运行 this.py 文件。 How can I get that password using python?
如何使用 python 获取该密码?
Since you are accessing an Azure service from a non-Azure service, you will need a service principal.由于您正在从非 Azure 服务访问 Azure 服务,因此您将需要一个服务主体。 You can use certificate or secret.
您可以使用证书或秘密。 See THIS link for the different methods.
有关不同方法,请参阅此链接。 You will need to give the service principal proper access and this will depend if you are using RBAC or access policy for your key vault.
您需要为服务主体授予适当的访问权限,这取决于您使用的是 RBAC 还是密钥保管库的访问策略。 So the steps you need to follow are:
因此,您需要遵循的步骤是:
The python link for the code is HERE .代码的 python 链接为HERE 。 The code that will work for you is below:
适合您的代码如下:
from azure.identity import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
tenantid = <your_tenant_id>
clientsecret = <your_client_secret>
clientid = <your_client_id>
my_credentials = ClientSecretCredential(tenant_id=tenantid, client_id=clientid, client_secret=clientsecret)
secret_client = SecretClient(vault_url="https://<your_keyvault_name>.vault.azure.net/", credential=my_credentials)
secret = secret_client.get_secret("<your_secret_name>")
print(secret.name)
print(secret.value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.