[英]Grant access to Azure Data Lake Gen2 using a parameterized script
我們正在嘗試授予對 Azure data Lake gen 2 容器中許多文件夾的讀/寫訪問權限,盡管我們可以通過 UI 執行此操作,但它非常乏味,並且必須在所有環境中重復。 有沒有人使用 Powershell 使用更好的方法來自動化或至少參數化授予對 Azure Data Lake gen 2 容器的訪問權限的過程並避免手動授予訪問權限?
不幸的是,我無法使用以下鏈接或其他文檔使其工作,因為它適用於第 1 代,但它與我需要為第 2 代所做的非常相似。https://www.sqlchick.com/entries/2018/3 /17/assigning-data-permissions-for-azure-data-lake-store-part-3
根據我的測試,我們可以使用PowerShell來管理Azure Data Lake Gen2權限。 更多詳情請參考文檔
install-Module PowerShellGet –Repository PSGallery –Force
install-Module Az.Storage -Repository PSGallery -RequiredVersion 1.9.1-preview –AllowPrerelease –AllowClobber –Force
另外請注意,如果要安裝模塊,需要滿足一些條件
- .NET Framework 已安裝
4.7.2
或更高版本- PowerShell 為
5.1
或更高版本
Connect-AzAccount
$groupName=""
$accountName=""
$account= Get-AzStorageAccount -ResourceGroupName $groupName -Name $accountName
$ctx = $account.Context
$filesystemName = "test"
$dirname="template/"
$Id = "<the Object ID of user, group or service principal>"
$dir=Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityId $id -Permission "rw-" -InputObject $dir.ACL
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname -Acl $acl
$dir=Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path $dirname
$dir.ACL
感謝 Jim Xu 提供上述腳本。 我只是用以下項目補充代碼:
$groupName="resource group name"
$accountName="storage account name"
$account= Get-AzStorageAccount -ResourceGroupName $groupName -Name $accountName
$ctx = $account.Context
$filesystemName = "container name"
$Id = (Get-AzADGroup -DisplayName '<type user / group name here>').Id
$items = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $filesystemName
foreach ( $item in $items) {
$dir = Get-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path "$($item.Path)/"
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -EntityId $id -Permission "rwx" -InputObject $dir.ACL -DefaultScope
# Update ACL on blob item
Update-AzDataLakeGen2Item -Context $ctx -FileSystem $filesystemName -Path "$($item.Path)/" -Acl $acl
# Propagate ACL to child blob items
Set-AzDataLakeGen2AclRecursive -Context $ctx -FileSystem $filesystemName -Path "$($item.Path)/" -Acl $acl
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.