Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Add support for sticky bit #21528

Merged
merged 7 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ function Test-DatalakeGen2
$dir1 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath1 -Directory -Permission rwxrwxrwx -Umask ---rwx--- -Property @{"ContentEncoding" = "UDF8"; "CacheControl" = "READ"} -Metadata @{"tag1" = "value1"; "tag2" = "value2" }
Assert-AreEqual $dir1.Path $directoryPath1
Assert-AreEqual $dir1.Permissions.ToSymbolicPermissions() "rwx---rwx"
$dir2 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath2 -Directory
$dir2 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath2 -Directory -Permission r---wx-wT -Umask --x-wx--x
Assert-AreEqual $dir2.Path $directoryPath2
Assert-AreEqual $dir2.Permissions.ToSymbolicPermissions() "r------wT"

# Create (upload) File
$t = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $filePath1 -Source $localSrcFile -Force -AsJob
Expand All @@ -874,20 +876,20 @@ function Test-DatalakeGen2
## create ACL with 3 ACEs
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wt" -InputObject $acl
##Update File with pipeline
$file1 = Get-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $filePath1 | Update-AzDataLakeGen2Item `
-Acl $acl `
-Property @{"ContentType" = $ContentType; "ContentMD5" = $ContentMD5} `
-Metadata @{"tag1" = "value1"; "tag2" = "value2" } `
-Permission rw-rw--wx `
-Permission rw-rw--wt `
-Owner '$superuser' `
-Group '$superuser'
$sas = New-AzDataLakeGen2SasToken -FileSystem $filesystemName -Path $filePath1 -Permission rw -Context $storageContext
$ctxsas = New-AzStorageContext -StorageAccountName $StorageAccountName -SasToken $sas
$file1 = Get-AzDataLakeGen2Item -Context $ctxsas -FileSystem $filesystemName -Path $filePath1
Assert-AreEqual $file1.Path $filePath1
Assert-AreEqual $file1.Permissions.ToSymbolicPermissions() "rw-rw--wx"
Assert-AreEqual $file1.Permissions.ToSymbolicPermissions() "rw-rw--wt"
Assert-AreEqual $file1.Properties.ContentType $ContentType
Assert-AreEqual $file1.Properties.Metadata.Count 2
Assert-AreEqual $file1.Owner '$superuser'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Additional information about change #1
-->
## Upcoming Release
* Added support for sticky bit
- `New-AzDataLakeGen2Item`
- `New-AzDataLakeGen2ACLObject`
- `Update-AzDataLakeGen2Item`
* Added warning messages for an upcoming cmdlet breaking change
- `New-AzStorageAccount`
- `Set-AzStorageAccount`
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Storage.Management/help/New-AzDataLakeGen2Item.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ This cmdlet only works if Hierarchical Namespace is enabled for the Storage acco

### Example 1: Create a directory with specified permission, Umask, properties, and metadata
```powershell
New-AzDataLakeGen2Item -FileSystem "testfilesystem" -Path "dir1/dir2/" -Directory -Permission rwxrwxrwx -Umask ---rw---- -Property @{"CacheControl" = "READ"; "ContentDisposition" = "True"} -Metadata @{"tag1" = "value1"; "tag2" = "value2" }
New-AzDataLakeGen2Item -FileSystem "testfilesystem" -Path "dir1/dir2/" -Directory -Permission rwxrwxrwT -Umask ---rw---- -Property @{"CacheControl" = "READ"; "ContentDisposition" = "True"} -Metadata @{"tag1" = "value1"; "tag2" = "value2" }
```

```output
FileSystem Name: filesystem1

Path IsDirectory Length LastModified Permissions Owner Group
---- ----------- ------ ------------ ----------- ----- -----
dir1/dir2 True 2020-03-23 09:15:56Z rwx---rwx $superuser $superuser
dir1/dir2 True 2020-03-23 09:15:56Z rwx---rwT $superuser $superuser
```

This command creates a directory with specified Permission, Umask, properties, and metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ This command creates an ACL object with 3 ACL entries (use -InputObject paramete
```
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rwx -DefaultScope
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rw-" -InputObject $acl
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rwt" -InputObject $acl
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityId $id -Permission rwx -InputObject $acl
PS C:\>$acl

DefaultScope AccessControlType EntityId Permissions
------------ ----------------- -------- -----------
True User rwx
False Group rw-
False Other rw-
False Other rwt
False User ********-****-****-****-************ rwx

PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityId $id -Permission r-x -InputObject $acl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public class SetAzDataLakeGen2ItemAclObjectCommand : AzureDataCmdlet
IgnoreCase = true)]
public AccessControlType AccessControlType;

[Parameter(Mandatory = true, HelpMessage = "The permission field is a 3-character sequence where the first character is 'r' to grant read access, the second character is 'w' to grant write access, and the third character is 'x' to grant execute permission. If access is not granted, the '-' character is used to denote that the permission is denied.")]
[ValidatePattern("[r-][w-][x-]")]
[Parameter(Mandatory = true, HelpMessage = "The permission field is a 3-character sequence where the first character is 'r' to grant read access, the second character is 'w' to grant write access, and the third character is 'x' to grant execute permission. If access is not granted, the '-' character is used to denote that the permission is denied. " +
"The sticky bit is also supported and its represented either by the letter t or T in the final character-place depending on whether the execution bit for the others category is set or unset respectively, absence of t or T indicates sticky bit not set.")]
[ValidatePattern("[r-][w-][xtT-]")]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "If input the PSPathAccessControlEntry[] object, will add the new ACL entry as a new element of the input PSPathAccessControlEntry[] object. If an ACL entry when same AccessControlType, EntityId, DefaultScope exist, will update permission of it.")]
Expand Down Expand Up @@ -80,7 +81,7 @@ public override void ExecuteCmdlet()
psacls.Remove(entryToRemove);
}

PSPathAccessControlEntry psacl = new PSPathAccessControlEntry(this.AccessControlType, PathAccessControlExtensions.ParseSymbolicRolePermissions(this.Permission), this.DefaultScope, this.EntityId);
PSPathAccessControlEntry psacl = new PSPathAccessControlEntry(this.AccessControlType, PathAccessControlExtensions.ParseSymbolicRolePermissions(this.Permission, true), this.DefaultScope, this.EntityId);
psacls.Add(psacl);

WriteObject(psacls.ToArray(), true);
Expand Down
32 changes: 27 additions & 5 deletions src/Storage/Storage/DatalakeGen2/Cmdlet/NewAzDataLakeGen2Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ public string Source
[ValidatePattern("([r-][w-][x-]){3}")]
public string Umask { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Sets POSIX access permissions for the file owner, the file owning group, and others. Each class may be granted read, write, or execute permission. Symbolic (rwxrw-rw-) is supported. ")]
[Parameter(Mandatory = false, HelpMessage = "Sets POSIX access permissions for the file owner, the file owning group, and others. Each class may be granted read, write, or execute permission. Symbolic (rwxrw-rw-) is supported. " +
"The sticky bit is also supported and its represented either by the letter t or T in the final character-place depending on whether the execution bit for the others category is set or unset respectively, absence of t or T indicates sticky bit not set.")]
[ValidateNotNullOrEmpty]
yifanz0 marked this conversation as resolved.
Show resolved Hide resolved
[ValidatePattern("([r-][w-][x-]){3}")]
[ValidatePattern("([r-][w-][x-]){2}([r-][w-][xtT-])")]
public string Permission { get; set; }


Expand Down Expand Up @@ -384,13 +385,34 @@ protected void SetBlobPermissionWithUMask(CloudBlockBlob blob, string permission
string blobPermission = string.Empty;
for (int i = 0; i < permission.Length; i++)
{
if (umask[i] != '-')
if (Char.ToLower(permission[i]) == 't')
{
blobPermission += '-';
if (permission[i] == 'T')
{
blobPermission += permission[i];
}
else
{
if (umask[i] == '-')
{
blobPermission += 't';
}
else
{
blobPermission += 'T';
}
}
}
else
{
blobPermission += permission[i];
if (umask[i] != '-')
{
blobPermission += '-';
}
else
{
blobPermission += permission[i];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public class SetAzDataLakeGen2ItemCommand : StorageCloudBlobCmdletBase
[ValidateNotNull]
public AzureDataLakeGen2Item InputObject { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Sets POSIX access permissions for the file owner, the file owning group, and others. Each class may be granted read, write, or execute permission. Symbolic (rwxrw-rw-) is supported. Invalid in conjunction with ACL.")]
[Parameter(Mandatory = false, HelpMessage = "Sets POSIX access permissions for the file owner, the file owning group, and others. Each class may be granted read, write, or execute permission. Symbolic (rwxrw-rw-) is supported." +
"The sticky bit is also supported and its represented either by the letter t or T in the final character-place depending on whether the execution bit for the others category is set or unset respectively, absence of t or T indicates sticky bit not set." +
"Invalid in conjunction with ACL.")]
[ValidateNotNullOrEmpty]
[ValidatePattern("([r-][w-][x-]){3}")]
[ValidatePattern("([r-][w-][x-]){2}[r-][w-][xtT-]")]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Sets the owner of the item.")]
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/Storage/Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.2.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.14.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.2" />
Expand Down