✔️ 适用于: 使用 Microsoft.Storage 资源提供程序创建的经典 NFS 文件共享
✔️ 适用于: 由 Microsoft.FileShares 资源提供程序创建的 NFS 文件共享
✖️ 不适用于: SMB 文件共享
客户端操作系统对 NFS 文件共享(而不是Azure 文件存储服务)强制实施权限。 根 Squash 是 NFS 中的一项管理安全功能,可防止客户端计算机对 NFS 服务器进行未经授权的根级别访问。 此功能是保护用户数据和系统设置免遭不受信任的或遭入侵的客户端操纵的重要一环。
管理员应该在多个用户或系统访问 NFS 共享的环境中启用根 Squash,特别是在客户端计算机不是完全受信任的情况下。 通过将根用户转换为匿名用户,根 Squash 可确保即使在客户端计算机遭入侵的情况下,攻击者也无法利用根权限访问或修改 NFS 服务器上的关键文件。
本文介绍如何配置和更改 NFS Azure 文件共享的根 Squash 设置。
如何将根 Squash 与 Azure 文件存储配合使用
Root squash 的工作原理是将 root 用户的用户 ID(UID)和组 ID(GID)重新映射为服务器上匿名用户所属的 UID 和 GID。 访问文件系统的根用户将自动转换为具有有限权限的匿名、低权限用户和组。
尽管根 Squash 是 NFS 中的默认行为,但它不是创建 NFS Azure 文件共享时的默认选项。 必须在文件共享上显式启用根 Squash。 可以在创建 NFS Azure 文件共享时执行此操作,也可以稍后这样做。
根 Squash 设置
从以下三种根压缩设置中进行选择:
-
“无根 Squash”:关闭根 Squash 功能。 此选项主要用于无盘客户端或工作负荷文档指定的工作负荷。 创建新 NFS Azure文件共享时,此设置是默认设置。
-
全部 Squash:将所有 UID 和 GID 映射到匿名用户。 对需要所有客户端进行只读访问的共享使用此设置。
-
根 Squash:将来自 UID/GID 0(根)的请求映射到匿名 UID/GID。 此设置不适用于其他可能同样敏感的 UID 或 GID,例如用户 bin 或组 staff。
下表重点说明了配置特定 root squash 选项时,服务器端表现出的 UID 行为。
|
选项 |
客户端 UID |
服务器 UID |
| root_squash |
0 |
65534 |
| root_squash |
1000 |
1000 |
| no_root_squash |
0 |
0 |
| no_root_squash |
1000 |
1000 |
| all_squash |
0 |
65534 |
| all_squash |
1000 |
65534 |
对于使用 Microsoft.Storage 资源提供程序的 Azure 经典文件共享,可以通过 Azure 门户、Azure PowerShell 或 Azure CLI 配置 root squash 设置。
登录到Azure门户,转到包含 NFS Azure文件共享的 FileStorage 存储帐户。
在服务菜单中的 “数据存储”下,选择 “经典文件共享”。
选择您要更改根压缩设置的文件共享。
在服务菜单中,选择“属性”。 然后根据需要切换“根 Squash”设置。
选择“保存”以更新根 Squash 值。
登录到 Azure,然后选择订阅。
Connect-AzAccount
Select-AzSubscription -SubscriptionId "<your-subscription-id>"
若要在文件共享上启用根 Squash,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
Update-AzRmStorageShare `
-ResourceGroupName <resource-group-name> `
-StorageAccountName <storage-account-name> `
-Name <file-share-name> `
-RootSquash RootSquash
若要在文件共享上禁用根 Squash,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
Update-AzRmStorageShare `
-ResourceGroupName <resource-group-name> `
-StorageAccountName <storage-account-name> `
-Name <file-share-name> `
-RootSquash NoRootSquash
若要强制对所有用户进行 Squash,请运行以下命令,将所有用户 ID 映射到匿名用户。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
Update-AzRmStorageShare `
-ResourceGroupName <resource-group-name> `
-StorageAccountName <storage-account-name> `
-Name <file-share-name> `
-RootSquash AllSquash
若要查看文件共享的根 Squash 属性,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
Get-AzRmStorageShare `
-ResourceGroupName <resource-group-name> `
-StorageAccountName <storage-account-name> `
-Name <file-share-name> | fl -Property ResourceGroupName, StorageAccountName, Name, QuotaGiB,AccessTier,EnabledProtocols,RootSquash
登录到 Azure 并设置订阅。
az login
az account set --subscription "<your-subscription-id>"
若要在文件共享上启用根 Squash,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
az storage share-rm update \
--resource-group <resource-group-name> \
--storage-account <storage-account-name> \
--name <file-share-name> \
--root-squash RootSquash
若要在文件共享上禁用根 Squash,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
az storage share-rm update \
--resource-group <resource-group-name> \
--storage-account <storage-account-name> \
--name <file-share-name> \
--root-squash NoRootSquash
若要强制对所有用户进行 Squash,请运行以下命令,将所有用户 ID 映射到匿名用户。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
az storage share-rm update \
--resource-group <resource-group-name> \
--storage-account <storage-account-name> \
--name <file-share-name> \
--root-squash AllSquash
若要查看文件共享的根 Squash 属性,请运行以下命令。 将 、 和 替换为自己的值<resource-group-name><storage-account-name><file-share-name>。
az storage share-rm show \
--resource-group <resource-group-name> \
--storage-account <storage-account-name> \
--name <file-share-name>
对于使用 Microsoft.FileShares 资源提供程序的 Azure 文件共享,可以通过 Azure 门户、Azure PowerShell 或 Azure CLI 配置 root squash 设置。
登录到 Azure 门户并转到文件共享。
在服务菜单中的“设置”下,选择“配置”。
根据需要切换根压缩设置。
选择“保存”以更新根 Squash 值。
若要使用 Azure PowerShell 更改文件共享的 root squash 设置 (Microsoft.FileShares),请运行以下命令。 将变量替换为你的值。 允许的-RootSquash值为AllSquash和 NoRootSquashRootSquash。
# To learn more about the Az.FileShare module, see https://www.powershellgallery.com/packages/Az.FileShare/1.0.0
Install-Module -Name Az.FileShare -Repository PSGallery -RequiredVersion 1.0.0
$resourceGroup = "<your-resource-group-name>"
$shareName = "<your-file-share-name>"
Update-AzFileShare -ResourceName $shareName -ResourceGroupName $resourceGroup -RootSquash RootSquash
要使用 Azure CLI 更改文件共享 (Microsoft.FileShares) 的 root squash 设置,请运行以下命令。 允许的--root-squash值为AllSquash和 NoRootSquashRootSquash。
# Install the fileshare extension
az extension add --name fileshare
# Specify your values
shareName="<your-file-share-name>"
resourceGroup="<your-resource-group-name>"
# Update the root squash setting
az fileshare update --name $shareName --resource-group $resourceGroup --root-squash RootSquash
另请参阅