Skip to content

Commit 56836bb

Browse files
yifanz0wyunchi-ms
andauthored
[Storage] Add support for sticky bit (#21528)
* Support for sticky bit * delete redundant file * Update help files * update parameter description format * Update help * Fix the issue of static analysis --------- Co-authored-by: wyunchi-ms <[email protected]>
1 parent 21f2279 commit 56836bb

File tree

11 files changed

+86
-47
lines changed

11 files changed

+86
-47
lines changed

src/Storage/Storage.Management.Test/ScenarioTests/StorageDataPlaneTests.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,9 @@ function Test-DatalakeGen2
854854
$dir1 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath1 -Directory -Permission rwxrwxrwx -Umask ---rwx--- -Property @{"ContentEncoding" = "UDF8"; "CacheControl" = "READ"} -Metadata @{"tag1" = "value1"; "tag2" = "value2" }
855855
Assert-AreEqual $dir1.Path $directoryPath1
856856
Assert-AreEqual $dir1.Permissions.ToSymbolicPermissions() "rwx---rwx"
857-
$dir2 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath2 -Directory
857+
$dir2 = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $directoryPath2 -Directory -Permission r---wx-wT -Umask --x-wx--x
858+
Assert-AreEqual $dir2.Path $directoryPath2
859+
Assert-AreEqual $dir2.Permissions.ToSymbolicPermissions() "r------wT"
858860

859861
# Create (upload) File
860862
$t = New-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $filePath1 -Source $localSrcFile -Force -AsJob
@@ -874,20 +876,20 @@ function Test-DatalakeGen2
874876
## create ACL with 3 ACEs
875877
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rw-
876878
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
877-
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wx" -InputObject $acl
879+
$acl = New-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "-wt" -InputObject $acl
878880
##Update File with pipeline
879881
$file1 = Get-AzDataLakeGen2Item -Context $storageContext -FileSystem $filesystemName -Path $filePath1 | Update-AzDataLakeGen2Item `
880882
-Acl $acl `
881883
-Property @{"ContentType" = $ContentType; "ContentMD5" = $ContentMD5} `
882884
-Metadata @{"tag1" = "value1"; "tag2" = "value2" } `
883-
-Permission rw-rw--wx `
885+
-Permission rw-rw--wt `
884886
-Owner '$superuser' `
885887
-Group '$superuser'
886888
$sas = New-AzDataLakeGen2SasToken -FileSystem $filesystemName -Path $filePath1 -Permission rw -Context $storageContext
887889
$ctxsas = New-AzStorageContext -StorageAccountName $StorageAccountName -SasToken $sas
888890
$file1 = Get-AzDataLakeGen2Item -Context $ctxsas -FileSystem $filesystemName -Path $filePath1
889891
Assert-AreEqual $file1.Path $filePath1
890-
Assert-AreEqual $file1.Permissions.ToSymbolicPermissions() "rw-rw--wx"
892+
Assert-AreEqual $file1.Permissions.ToSymbolicPermissions() "rw-rw--wt"
891893
Assert-AreEqual $file1.Properties.ContentType $ContentType
892894
Assert-AreEqual $file1.Properties.Metadata.Count 2
893895
Assert-AreEqual $file1.Owner '$superuser'

src/Storage/Storage.Management.Test/Storage.Management.Test.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
15-
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.12.0" />
16-
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.0" />
17-
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
14+
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
15+
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.14.0" />
16+
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.14.0" />
17+
<PackageReference Include="Azure.Storage.Queues" Version="12.14.0" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added support for sticky bit
22+
- `New-AzDataLakeGen2Item`
23+
- `New-AzDataLakeGen2ACLObject`
24+
- `Update-AzDataLakeGen2Item`
2125
* Added warning messages for an upcoming cmdlet breaking change
2226
- `New-AzStorageAccount`
2327
- `Set-AzStorageAccount`

src/Storage/Storage.Management/help/New-AzDataLakeGen2Item.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ This cmdlet only works if Hierarchical Namespace is enabled for the Storage acco
3636

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

4242
```output
43-
FileSystem Name: filesystem1
43+
FileSystem Name: filesystem1
4444
4545
Path IsDirectory Length LastModified Permissions Owner Group
4646
---- ----------- ------ ------------ ----------- ----- -----
47-
dir1/dir2 True 2020-03-23 09:15:56Z rwx---rwx $superuser $superuser
47+
dir1/dir2 True 2020-03-23 09:15:56Z rwx---rwT $superuser $superuser
4848
```
4949

5050
This command creates a directory with specified Permission, Umask, properties, and metadata
@@ -55,8 +55,9 @@ $task = New-AzDataLakeGen2Item -FileSystem "testfilesystem" -Path "dir1/dir2/fi
5555
$task | Wait-Job
5656
$task.Output
5757
```
58+
5859
```output
59-
FileSystem Name: filesystem1
60+
FileSystem Name: filesystem1
6061
6162
Path IsDirectory Length LastModified Permissions Owner Group
6263
---- ----------- ------ ------------ ----------- ----- -----
@@ -204,9 +205,9 @@ Accept wildcard characters: False
204205
```
205206
206207
### -Permission
207-
Sets POSIX access permissions for the file owner, the file owning group, and others.
208-
Each class may be granted read, write, or execute permission.
209-
Symbolic (rwxrw-rw-) is supported.
208+
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.
209+
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,
210+
absence of t or T indicates sticky bit not set.
210211
211212
```yaml
212213
Type: System.String
@@ -301,7 +302,7 @@ Accept wildcard characters: False
301302
```
302303
303304
### CommonParameters
304-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
305+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
305306
306307
## INPUTS
307308

src/Storage/Storage.Management/help/Set-AzDataLakeGen2ItemAclObject.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Update-AzDataLakeGen2Item -FileSystem "filesystem1" -Path "dir1/dir3" -ACL $acl
3232
```
3333

3434
```output
35-
FileSystem Name: filesystem1
35+
FileSystem Name: filesystem1
3636
3737
Path IsDirectory Length LastModified Permissions Owner Group
3838
---- ----------- ------ ------------ ----------- ----- -----
@@ -43,18 +43,20 @@ This command creates an ACL object with 3 ACL entries (use -InputObject paramete
4343

4444
### Example 2: Create an ACL object with 4 ACL entries, and update permission of an existing ACL entry
4545
<!-- Skip: Output cannot be splitted from code -->
46+
47+
4648
```
4749
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rwx -DefaultScope
4850
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
49-
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rw-" -InputObject $acl
51+
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rwt" -InputObject $acl
5052
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityId $id -Permission rwx -InputObject $acl
5153
PS C:\>$acl
5254
5355
DefaultScope AccessControlType EntityId Permissions
5456
------------ ----------------- -------- -----------
5557
True User rwx
5658
False Group rw-
57-
False Other rw-
59+
False Other rwt
5860
False User ********-****-****-****-************ rwx
5961
6062
PS C:\>$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -EntityId $id -Permission r-x -InputObject $acl
@@ -137,8 +139,10 @@ Accept wildcard characters: False
137139
```
138140
139141
### -Permission
140-
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.
141-
If access is not granted, the '-' character is used to denote that the permission is denied.
142+
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.
143+
If access is not granted, the '-' character is used to denote that the permission is denied.
144+
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,
145+
absence of t or T indicates sticky bit not set.
142146
143147
```yaml
144148
Type: System.String
@@ -153,7 +157,7 @@ Accept wildcard characters: False
153157
```
154158
155159
### CommonParameters
156-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
160+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
157161
158162
## INPUTS
159163

src/Storage/Storage.Management/help/Update-AzDataLakeGen2Item.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ This cmdlet only works if Hierarchical Namespace is enabled for the Storage acco
3838
```powershell
3939
$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType user -Permission rwx
4040
$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType group -Permission rw- -InputObject $acl
41-
$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rw-" -InputObject $acl
41+
$acl = Set-AzDataLakeGen2ItemAclObject -AccessControlType other -Permission "rwt" -InputObject $acl
4242
Get-AzDataLakeGen2ChildItem -FileSystem "filesystem1" -Recurse | Update-AzDataLakeGen2Item -ACL $acl
4343
```
4444

4545
```output
46-
FileSystem Name: filesystem1
46+
FileSystem Name: filesystem1
4747
4848
Path IsDirectory Length LastModified Permissions Owner Group
4949
---- ----------- ------ ------------ ----------- ----- -----
50-
dir1 True 2020-03-13 13:07:34Z rwxrw-rw- $superuser $superuser
51-
dir1/file1 False 1024 2020-03-23 09:29:18Z rwxrw-rw- $superuser $superuser
52-
dir2 True 2020-03-23 09:28:36Z rwxrw-rw- $superuser $superuser
50+
dir1 True 2020-03-13 13:07:34Z rwxrw-rwt $superuser $superuser
51+
dir1/file1 False 1024 2020-03-23 09:29:18Z rwxrw-rwt $superuser $superuser
52+
dir2 True 2020-03-23 09:28:36Z rwxrw-rwt $superuser $superuser
5353
```
5454

5555
This command first creates an ACL object with 3 acl entry (use -InputObject parameter to add acl entry to existing acl object), then get all items in a filesystem and update acl on the items.
5656

5757
### Example 2: Update all properties on a file, and show them
5858
<!-- Skip: Output cannot be splitted from code -->
59+
60+
5961
```
6062
PS C:\> $file = Update-AzDataLakeGen2Item -FileSystem "filesystem1" -Path "dir1/file1" `
6163
-Acl $acl `
@@ -143,7 +145,7 @@ Update-AzDataLakeGen2Item -FileSystem "filesystem1" -Path 'dir1/dir3/' -ACL $acl
143145
```
144146

145147
```output
146-
FileSystem Name: filesystem1
148+
FileSystem Name: filesystem1
147149
148150
Path IsDirectory Length LastModified Permissions Owner Group
149151
---- ----------- ------ ------------ ----------- ----- -----
@@ -294,10 +296,9 @@ Accept wildcard characters: False
294296
```
295297
296298
### -Permission
297-
Sets POSIX access permissions for the file owner, the file owning group, and others.
298-
Each class may be granted read, write, or execute permission.
299-
Symbolic (rwxrw-rw-) is supported.
300-
Invalid in conjunction with Acl.
299+
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.
300+
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,
301+
absence of t or T indicates sticky bit not set.Invalid in conjunction with ACL.
301302
302303
```yaml
303304
Type: System.String
@@ -360,7 +361,7 @@ Accept wildcard characters: False
360361
```
361362
362363
### CommonParameters
363-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
364+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
364365
365366
## INPUTS
366367

src/Storage/Storage/DatalakeGen2/Cmdlet/NewAzDataLakeGen2ACLObject.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public class SetAzDataLakeGen2ItemAclObjectCommand : AzureDataCmdlet
4646
IgnoreCase = true)]
4747
public AccessControlType AccessControlType;
4848

49-
[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.")]
50-
[ValidatePattern("[r-][w-][x-]")]
49+
[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. " +
50+
"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.")]
51+
[ValidatePattern("[r-][w-][xtT-]")]
5152
public string Permission { get; set; }
5253

5354
[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.")]
@@ -80,7 +81,7 @@ public override void ExecuteCmdlet()
8081
psacls.Remove(entryToRemove);
8182
}
8283

83-
PSPathAccessControlEntry psacl = new PSPathAccessControlEntry(this.AccessControlType, PathAccessControlExtensions.ParseSymbolicRolePermissions(this.Permission), this.DefaultScope, this.EntityId);
84+
PSPathAccessControlEntry psacl = new PSPathAccessControlEntry(this.AccessControlType, PathAccessControlExtensions.ParseSymbolicRolePermissions(this.Permission, true), this.DefaultScope, this.EntityId);
8485
psacls.Add(psacl);
8586

8687
WriteObject(psacls.ToArray(), true);

src/Storage/Storage/DatalakeGen2/Cmdlet/NewAzDataLakeGen2Item.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ public string Source
8383
[ValidatePattern("([r-][w-][x-]){3}")]
8484
public string Umask { get; set; }
8585

86-
[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. ")]
86+
[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. " +
87+
"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.")]
8788
[ValidateNotNullOrEmpty]
88-
[ValidatePattern("([r-][w-][x-]){3}")]
89+
[ValidatePattern("([r-][w-][x-]){2}([r-][w-][xtT-])")]
8990
public string Permission { get; set; }
9091

9192

@@ -384,13 +385,34 @@ protected void SetBlobPermissionWithUMask(CloudBlockBlob blob, string permission
384385
string blobPermission = string.Empty;
385386
for (int i = 0; i < permission.Length; i++)
386387
{
387-
if (umask[i] != '-')
388+
if (Char.ToLower(permission[i]) == 't')
388389
{
389-
blobPermission += '-';
390+
if (permission[i] == 'T')
391+
{
392+
blobPermission += permission[i];
393+
}
394+
else
395+
{
396+
if (umask[i] == '-')
397+
{
398+
blobPermission += 't';
399+
}
400+
else
401+
{
402+
blobPermission += 'T';
403+
}
404+
}
390405
}
391406
else
392407
{
393-
blobPermission += permission[i];
408+
if (umask[i] != '-')
409+
{
410+
blobPermission += '-';
411+
}
412+
else
413+
{
414+
blobPermission += permission[i];
415+
}
394416
}
395417
}
396418

0 commit comments

Comments
 (0)