Azure 数据湖 - 外部组织应用程序访问 - 身份验证方法
Azure data lake - External org app access - Authentication methods
假设 organisation A
有一个 Azure 数据湖实例 DL1
。 DL1
实例中有两个容器,它们是 container1
和 container2
。现在 org B
的 app A
必须单独访问 container2
才能删除文件。
有哪些可用的身份验证方法?任何带有 Azure Python 或 Java SDK 的示例代码参考都很棒。谢谢。
更新 1210:使用兼容的 azure blob 存储 sdk
您可以使用 azure blob storage sdk
创建一个 container sas token
,然后用户只能访问 this specified container
in ADLS Gen2.
注意:我们可以这样做,因为 azure blob 存储 sdk 与 ADLS Gen2 兼容,请参阅 here 了解更多详细信息..
以python为例,首先安装the latest azure blob storage package.
然后使用下面的代码生成一个container sas token
可以提供给apps
in org B:
from azure.storage.blob import generate_container_sas, ContainerSasPermissions, ContainerClient
from datetime import datetime, timedelta
account_name ="your adls gen2 account name"
account_key="the key"
container_name="the container name"
sas_token = generate_container_sas(
account_name=account_name,
container_name=container_name,
account_key=account_key,
permission=permission = ContainerSasPermissions(read=True,write=True,delete=True,list=True),
expiry= datetime.utcnow() + timedelta(days=3)
)
#build the following container url of ADLS Gen2, then provide it to others to access the specified container.
sas_url="https://" + account_name + ".blob.core.windows.net/" + container_name + "?" + sas_token
#when other users have this sas_url, they can use it to access the specified container.
container = ContainerClient.from_container_url(sas_url)
#for example, they can upload files to the container.
with open("D:\test\ttt.txt","rb") as data:
container.upload_blob(name="test333.txt",data=data)
更新01:使用ADLS Gen2 sdk
您可以创建一个 container sas token
,然后将 container sas token
提供给其他人。所以其他人只能使用它来访问指定的容器。
这是python的例子,请先安装azure-storage-file-datalake 12.2.0包:
from azure.storage.filedatalake import generate_file_system_sas,FileSystemSasPermissions,FileSystemClient
from datetime import datetime, timedelta
account_name ="ADLS Gen2 account name"
account_key="the key"
container_name="the container name"
#build account_url
account_url="https://" + account_name + ".dfs.core.windows.net/"
#generate the container sas token
sas_token = generate_file_system_sas(
account_name=account_name,
file_system_name=container_name,
credential=account_key,
permission=FileSystemSasPermissions(read=True,write=True,delete=True,list=True),
expiry=datetime.utcnow() + timedelta(days=3)
)
#build the sas account url
sas_url = account_url + "?" + sas_token
#then we can provide the sas url to others, and they only allowed to access the specified container
container_client = FileSystemClient(sas_url,container_name)
file_client = container_client.create_file("c333.txt")
local_file = open("D:\test\ttt.txt",'rb')
file_contents = local_file.read()
file_client.append_data(data=file_contents, offset=0, length=len(file_contents))
file_client.flush_data(len(file_contents))
原回答:
您可以直接使用ADLS Gen2
的account name
和account key
进行认证。您可以参考此official document了解更多详情。
例如,您可以导航到 Azure 门户 -> 您的 Azure Data Lake Gen2 -> 访问密钥。从那里,您可以获得帐户名和帐户密钥。这是屏幕截图:
对于python,您可以按照this article建立认证。
java可以关注this article.
假设 organisation A
有一个 Azure 数据湖实例 DL1
。 DL1
实例中有两个容器,它们是 container1
和 container2
。现在 org B
的 app A
必须单独访问 container2
才能删除文件。
有哪些可用的身份验证方法?任何带有 Azure Python 或 Java SDK 的示例代码参考都很棒。谢谢。
更新 1210:使用兼容的 azure blob 存储 sdk
您可以使用 azure blob storage sdk
创建一个 container sas token
,然后用户只能访问 this specified container
in ADLS Gen2.
注意:我们可以这样做,因为 azure blob 存储 sdk 与 ADLS Gen2 兼容,请参阅 here 了解更多详细信息..
以python为例,首先安装the latest azure blob storage package.
然后使用下面的代码生成一个container sas token
可以提供给apps
in org B:
from azure.storage.blob import generate_container_sas, ContainerSasPermissions, ContainerClient
from datetime import datetime, timedelta
account_name ="your adls gen2 account name"
account_key="the key"
container_name="the container name"
sas_token = generate_container_sas(
account_name=account_name,
container_name=container_name,
account_key=account_key,
permission=permission = ContainerSasPermissions(read=True,write=True,delete=True,list=True),
expiry= datetime.utcnow() + timedelta(days=3)
)
#build the following container url of ADLS Gen2, then provide it to others to access the specified container.
sas_url="https://" + account_name + ".blob.core.windows.net/" + container_name + "?" + sas_token
#when other users have this sas_url, they can use it to access the specified container.
container = ContainerClient.from_container_url(sas_url)
#for example, they can upload files to the container.
with open("D:\test\ttt.txt","rb") as data:
container.upload_blob(name="test333.txt",data=data)
更新01:使用ADLS Gen2 sdk
您可以创建一个 container sas token
,然后将 container sas token
提供给其他人。所以其他人只能使用它来访问指定的容器。
这是python的例子,请先安装azure-storage-file-datalake 12.2.0包:
from azure.storage.filedatalake import generate_file_system_sas,FileSystemSasPermissions,FileSystemClient
from datetime import datetime, timedelta
account_name ="ADLS Gen2 account name"
account_key="the key"
container_name="the container name"
#build account_url
account_url="https://" + account_name + ".dfs.core.windows.net/"
#generate the container sas token
sas_token = generate_file_system_sas(
account_name=account_name,
file_system_name=container_name,
credential=account_key,
permission=FileSystemSasPermissions(read=True,write=True,delete=True,list=True),
expiry=datetime.utcnow() + timedelta(days=3)
)
#build the sas account url
sas_url = account_url + "?" + sas_token
#then we can provide the sas url to others, and they only allowed to access the specified container
container_client = FileSystemClient(sas_url,container_name)
file_client = container_client.create_file("c333.txt")
local_file = open("D:\test\ttt.txt",'rb')
file_contents = local_file.read()
file_client.append_data(data=file_contents, offset=0, length=len(file_contents))
file_client.flush_data(len(file_contents))
原回答:
您可以直接使用ADLS Gen2
的account name
和account key
进行认证。您可以参考此official document了解更多详情。
例如,您可以导航到 Azure 门户 -> 您的 Azure Data Lake Gen2 -> 访问密钥。从那里,您可以获得帐户名和帐户密钥。这是屏幕截图:
对于python,您可以按照this article建立认证。
java可以关注this article.