Skip to content

Commit e29b0df

Browse files
bluewwisra-fel
andauthored
[Storage] support FederatedIdentityClientId (#17365)
* [Storage] support FederatedIdentityClientId * Update src/Storage/Storage.Management/help/New-AzStorageAccount.md Co-authored-by: Yeming Liu <[email protected]> Co-authored-by: Yeming Liu <[email protected]>
1 parent fcfcc03 commit e29b0df

File tree

5 files changed

+129
-33
lines changed

5 files changed

+129
-33
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Supported create/upgrade storage account with Keyvault from another tenant and access Keyvault with FederatedClientId
22+
- `New-AzStorageAccount`
23+
- `Set-AzStorageAccount`
2124
* Supported create storage account with DnsEndpointType
2225
- `New-AzStorageAccount`
2326

src/Storage/Storage.Management/StorageAccount/NewAzureStorageAccount.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ public bool EnableHttpsTrafficOnly
175175
[ValidateNotNull]
176176
public string KeyVaultUserAssignedIdentityId { get; set; }
177177

178+
[Parameter(
179+
Mandatory = false,
180+
HelpMessage = "Set ClientId of the multi-tenant application to be used in conjunction with the user-assigned identity for cross-tenant customer-managed-keys server-side encryption on the storage account.")]
181+
[ValidateNotNull]
182+
public string KeyVaultFederatedClientId { get; set; }
183+
178184
[Parameter(
179185
Mandatory = false,
180186
HelpMessage = "Storage Account encryption keySource KeyVault KeyName")]
@@ -750,7 +756,7 @@ public override void ExecuteCmdlet()
750756
}
751757
}
752758
}
753-
if (this.KeyVaultUri !=null || this.KeyName != null || this.KeyVersion != null || this.KeyVaultUserAssignedIdentityId != null)
759+
if (this.KeyVaultUri !=null || this.KeyName != null || this.KeyVersion != null || this.KeyVaultUserAssignedIdentityId != null || this.KeyVaultFederatedClientId != null)
754760
{
755761
if ((this.KeyVaultUri != null && this.KeyName == null) || (this.KeyVaultUri == null && this.KeyName != null))
756762
{
@@ -762,9 +768,9 @@ public override void ExecuteCmdlet()
762768
throw new ArgumentException("KeyVersion can only be specified when specify KeyVaultUri and KeyName together.", "KeyVersion");
763769
}
764770

765-
if (this.KeyVaultUserAssignedIdentityId != null && (this.KeyVaultUri == null || this.KeyName == null))
771+
if ((this.KeyVaultUserAssignedIdentityId != null || this.KeyVaultFederatedClientId != null) && (this.KeyVaultUri == null || this.KeyName == null))
766772
{
767-
throw new ArgumentException("KeyVaultUserAssignedIdentityId can only be specified when specify KeyVaultUri and KeyName together.", "KeyVaultUserAssignedIdentityId");
773+
throw new ArgumentException("KeyVaultUserAssignedIdentityId, KeyVaultFederatedClientId can only be specified when specify KeyVaultUri and KeyName together.", "KeyVaultUserAssignedIdentityId, KeyVaultFederatedClientId");
768774
}
769775

770776
if (createParameters.Encryption == null)
@@ -785,10 +791,11 @@ public override void ExecuteCmdlet()
785791
createParameters.Encryption.KeyVaultProperties = new KeyVaultProperties(this.KeyName, this.KeyVersion, this.KeyVaultUri);
786792
}
787793

788-
if (this.KeyVaultUserAssignedIdentityId != null)
794+
if (this.KeyVaultUserAssignedIdentityId != null || this.KeyVaultFederatedClientId != null)
789795
{
790796
createParameters.Encryption.EncryptionIdentity = new EncryptionIdentity();
791797
createParameters.Encryption.EncryptionIdentity.EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId;
798+
createParameters.Encryption.EncryptionIdentity.EncryptionFederatedIdentityClientId = this.KeyVaultFederatedClientId;
792799
}
793800
}
794801
if (this.minimumTlsVersion != null)

src/Storage/Storage.Management/StorageAccount/SetAzureStorageAccount.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public string KeyVaultUri
189189
[ValidateNotNull]
190190
public string KeyVaultUserAssignedIdentityId { get; set; }
191191

192+
[Parameter(
193+
Mandatory = false,
194+
HelpMessage = "Set ClientId of the multi-tenant application to be used in conjunction with the user-assigned identity for cross-tenant customer-managed-keys server-side encryption on the storage account.")]
195+
[ValidateNotNull]
196+
public string KeyVaultFederatedClientId { get; set; }
197+
192198
[Parameter(
193199
Mandatory = false,
194200
HelpMessage = "Set the new Storage Account Identity type, the idenetity is for use with key management services like Azure KeyVault.")]
@@ -626,17 +632,18 @@ public override void ExecuteCmdlet()
626632
}
627633
}
628634

629-
if (StorageEncryption || ParameterSetName == KeyvaultEncryptionParameterSet || this.KeyVaultUserAssignedIdentityId != null)
635+
if (StorageEncryption || ParameterSetName == KeyvaultEncryptionParameterSet || this.KeyVaultUserAssignedIdentityId != null || this.KeyVaultFederatedClientId != null)
630636
{
631637
if (ParameterSetName == KeyvaultEncryptionParameterSet)
632638
{
633639
keyvaultEncryption = true;
634640
}
635641
updateParameters.Encryption = ParseEncryption(StorageEncryption, keyvaultEncryption, KeyName, KeyVersion, KeyVaultUri);
636-
if (this.KeyVaultUserAssignedIdentityId != null)
642+
if (this.KeyVaultUserAssignedIdentityId != null || this.KeyVaultFederatedClientId != null)
637643
{
638644
updateParameters.Encryption.EncryptionIdentity = new EncryptionIdentity();
639645
updateParameters.Encryption.EncryptionIdentity.EncryptionUserAssignedIdentity = this.KeyVaultUserAssignedIdentityId;
646+
updateParameters.Encryption.EncryptionIdentity.EncryptionFederatedIdentityClientId = this.KeyVaultFederatedClientId;
640647
}
641648
}
642649

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

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Creates a Storage account.
1818
New-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-SkuName] <String> [-Location] <String>
1919
[-Kind <String>] [-AccessTier <String>] [-CustomDomainName <String>] [-UseSubDomain <Boolean>]
2020
[-Tag <Hashtable>] [-EnableHttpsTrafficOnly <Boolean>] [-AssignIdentity] [-UserAssignedIdentityId <String>]
21-
[-IdentityType <String>] [-KeyVaultUserAssignedIdentityId <String>] [-KeyName <String>] [-KeyVersion <String>]
22-
[-KeyVaultUri <String>] [-NetworkRuleSet <PSNetworkRuleSet>] [-EnableSftp <Boolean>]
23-
[-EnableLocalUser <Boolean>] [-EnableHierarchicalNamespace <Boolean>]
21+
[-IdentityType <String>] [-KeyVaultUserAssignedIdentityId <String>] [-KeyVaultFederatedClientId <String>]
22+
[-KeyName <String>] [-KeyVersion <String>] [-KeyVaultUri <String>] [-NetworkRuleSet <PSNetworkRuleSet>]
23+
[-EnableSftp <Boolean>] [-EnableLocalUser <Boolean>] [-EnableHierarchicalNamespace <Boolean>]
2424
[-EnableAzureActiveDirectoryDomainServicesForFile <Boolean>] [-EnableLargeFileShare]
2525
[-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>] [-AsJob]
2626
[-EncryptionKeyTypeForTable <String>] [-EncryptionKeyTypeForQueue <String>] [-RequireInfrastructureEncryption]
@@ -38,10 +38,10 @@ New-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-SkuName] <
3838
New-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-SkuName] <String> [-Location] <String>
3939
[-Kind <String>] [-AccessTier <String>] [-CustomDomainName <String>] [-UseSubDomain <Boolean>]
4040
[-Tag <Hashtable>] [-EnableHttpsTrafficOnly <Boolean>] [-AssignIdentity] [-UserAssignedIdentityId <String>]
41-
[-IdentityType <String>] [-KeyVaultUserAssignedIdentityId <String>] [-KeyName <String>] [-KeyVersion <String>]
42-
[-KeyVaultUri <String>] [-NetworkRuleSet <PSNetworkRuleSet>] [-EnableSftp <Boolean>]
43-
[-EnableLocalUser <Boolean>] [-EnableHierarchicalNamespace <Boolean>] [-EnableLargeFileShare]
44-
[-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>]
41+
[-IdentityType <String>] [-KeyVaultUserAssignedIdentityId <String>] [-KeyVaultFederatedClientId <String>]
42+
[-KeyName <String>] [-KeyVersion <String>] [-KeyVaultUri <String>] [-NetworkRuleSet <PSNetworkRuleSet>]
43+
[-EnableSftp <Boolean>] [-EnableLocalUser <Boolean>] [-EnableHierarchicalNamespace <Boolean>]
44+
[-EnableLargeFileShare] [-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>]
4545
[-EnableActiveDirectoryDomainServicesForFile <Boolean>] [-ActiveDirectoryDomainName <String>]
4646
[-ActiveDirectoryNetBiosDomainName <String>] [-ActiveDirectoryForestName <String>]
4747
[-ActiveDirectoryDomainGuid <String>] [-ActiveDirectoryDomainSid <String>]
@@ -313,9 +313,33 @@ AAD
313313

314314
The command creates account with AllowedCopyScope as AAD.
315315

316-
### Example 17: Create account with DnsEndpointType as AzureDnsZone
316+
### Example 17: Create a Storage account with Keyvault from another tenant (access Keyvault with FederatedClientId)
317+
```powershell
318+
# create Storage account with Keyvault encryption (access Keyvault with FederatedClientId), then show properties
319+
PS C:\> $account = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName -Kind StorageV2 -SkuName Standard_LRS -Location eastus2euap `
320+
-IdentityType SystemAssignedUserAssigned -UserAssignedIdentityId $useridentityId `
321+
-KeyVaultUri $keyVault.VaultUri -KeyName $keyname -KeyVaultUserAssignedIdentityId $useridentityId -KeyVaultFederatedClientId $federatedClientId
322+
323+
PS C:\> $account.Encryption.EncryptionIdentity
324+
325+
EncryptionUserAssignedIdentity EncryptionFederatedIdentityClientId
326+
------------------------------ -----------------------------------
327+
/subscriptions/{subscription-id}/resourceGroups/myresourcegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myuserid ********-****-****-****-************
328+
329+
PS C:\> $account.Encryption.KeyVaultProperties
330+
331+
KeyName : wrappingKey
332+
KeyVersion :
333+
KeyVaultUri : https://mykeyvault.vault.azure.net:443
334+
CurrentVersionedKeyIdentifier : https://mykeyvault.vault.azure.net/keys/wrappingKey/8e74036e0d534e58b3bd84b319e31d8f
335+
LastKeyRotationTimestamp : 3/3/2022 2:07:34 AM
317336
```
318-
New-AzStorageAccount -ResourceGroupName "MyResourceGroup" -AccountName "mystorageaccount" -SkuName Standard_LRS -Location centraluseuap -Kind StorageV2 -DnsEndpointType AzureDnsZone
337+
338+
This command creates a storage account with Keyvault from another tenant (access Keyvault with FederatedClientId).
339+
340+
### Example 18: Create account with DnsEndpointType as AzureDnsZone
341+
```powershell
342+
New-AzStorageAccount -ResourceGroupName "MyResourceGroup" -AccountName "mystorageaccount" -SkuName Standard_LRS -Location centraluseuap -Kind StorageV2 -DnsEndpointType AzureDnsZone
319343
```
320344

321345
The command creates account with DnsEndpointType as AzureDnsZone to create a large number of accounts in a single subscription, which creates accounts in an Azure DNS Zone and the endpoint URL will have an alphanumeric DNS Zone identifier.
@@ -900,6 +924,21 @@ Accept pipeline input: False
900924
Accept wildcard characters: False
901925
```
902926
927+
### -KeyVaultFederatedClientId
928+
Set ClientId of the multi-tenant application to be used in conjunction with the user-assigned identity for cross-tenant customer-managed-keys server-side encryption on the storage account.
929+
930+
```yaml
931+
Type: System.String
932+
Parameter Sets: (All)
933+
Aliases:
934+
935+
Required: False
936+
Position: Named
937+
Default value: None
938+
Accept pipeline input: False
939+
Accept wildcard characters: False
940+
```
941+
903942
### -KeyVaultUri
904943
Storage Account encryption keySource KeyVault KeyVaultUri
905944

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

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Modifies a Storage account.
1818
Set-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-Force] [-SkuName <String>]
1919
[-AccessTier <String>] [-CustomDomainName <String>] [-UseSubDomain <Boolean>] [-Tag <Hashtable>]
2020
[-EnableHttpsTrafficOnly <Boolean>] [-StorageEncryption] [-AssignIdentity] [-UserAssignedIdentityId <String>]
21-
[-KeyVaultUserAssignedIdentityId <String>] [-IdentityType <String>] [-NetworkRuleSet <PSNetworkRuleSet>]
22-
[-UpgradeToStorageV2] [-EnableAzureActiveDirectoryDomainServicesForFile <Boolean>] [-EnableLargeFileShare]
21+
[-KeyVaultUserAssignedIdentityId <String>] [-KeyVaultFederatedClientId <String>] [-IdentityType <String>]
22+
[-NetworkRuleSet <PSNetworkRuleSet>] [-UpgradeToStorageV2]
23+
[-EnableAzureActiveDirectoryDomainServicesForFile <Boolean>] [-EnableLargeFileShare]
2324
[-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>] [-AllowBlobPublicAccess <Boolean>]
2425
[-MinimumTlsVersion <String>] [-AllowSharedKeyAccess <Boolean>] [-SasExpirationPeriod <TimeSpan>]
2526
[-KeyExpirationPeriodInDay <Int32>] [-AllowCrossTenantReplication <Boolean>]
@@ -35,8 +36,9 @@ Set-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-Force] [-S
3536
[-AccessTier <String>] [-CustomDomainName <String>] [-UseSubDomain <Boolean>] [-Tag <Hashtable>]
3637
[-EnableHttpsTrafficOnly <Boolean>] [-KeyvaultEncryption] -KeyName <String> [-KeyVersion <String>]
3738
-KeyVaultUri <String> [-AssignIdentity] [-UserAssignedIdentityId <String>]
38-
[-KeyVaultUserAssignedIdentityId <String>] [-IdentityType <String>] [-NetworkRuleSet <PSNetworkRuleSet>]
39-
[-UpgradeToStorageV2] [-EnableAzureActiveDirectoryDomainServicesForFile <Boolean>] [-EnableLargeFileShare]
39+
[-KeyVaultUserAssignedIdentityId <String>] [-KeyVaultFederatedClientId <String>] [-IdentityType <String>]
40+
[-NetworkRuleSet <PSNetworkRuleSet>] [-UpgradeToStorageV2]
41+
[-EnableAzureActiveDirectoryDomainServicesForFile <Boolean>] [-EnableLargeFileShare]
4042
[-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>] [-AllowBlobPublicAccess <Boolean>]
4143
[-MinimumTlsVersion <String>] [-AllowSharedKeyAccess <Boolean>] [-SasExpirationPeriod <TimeSpan>]
4244
[-KeyExpirationPeriodInDay <Int32>] [-AllowCrossTenantReplication <Boolean>]
@@ -51,19 +53,19 @@ Set-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-Force] [-S
5153
Set-AzStorageAccount [-ResourceGroupName] <String> [-Name] <String> [-Force] [-SkuName <String>]
5254
[-AccessTier <String>] [-CustomDomainName <String>] [-UseSubDomain <Boolean>] [-Tag <Hashtable>]
5355
[-EnableHttpsTrafficOnly <Boolean>] [-AssignIdentity] [-UserAssignedIdentityId <String>]
54-
[-KeyVaultUserAssignedIdentityId <String>] [-IdentityType <String>] [-NetworkRuleSet <PSNetworkRuleSet>]
55-
[-UpgradeToStorageV2] [-EnableLargeFileShare] [-PublishMicrosoftEndpoint <Boolean>]
56-
[-PublishInternetEndpoint <Boolean>] -EnableActiveDirectoryDomainServicesForFile <Boolean>
57-
[-ActiveDirectoryDomainName <String>] [-ActiveDirectoryNetBiosDomainName <String>]
58-
[-ActiveDirectoryForestName <String>] [-ActiveDirectoryDomainGuid <String>]
59-
[-ActiveDirectoryDomainSid <String>] [-ActiveDirectoryAzureStorageSid <String>]
60-
[-ActiveDirectorySamAccountName <String>] [-ActiveDirectoryAccountType <String>]
61-
[-AllowBlobPublicAccess <Boolean>] [-MinimumTlsVersion <String>] [-AllowSharedKeyAccess <Boolean>]
62-
[-SasExpirationPeriod <TimeSpan>] [-KeyExpirationPeriodInDay <Int32>] [-AllowCrossTenantReplication <Boolean>]
63-
[-DefaultSharePermission <String>] [-PublicNetworkAccess <String>] [-ImmutabilityPeriod <Int32>]
64-
[-AllowProtectedAppendWrite <Boolean>] [-ImmutabilityPolicyState <String>] [-EnableSftp <Boolean>]
65-
[-EnableLocalUser <Boolean>] [-AllowedCopyScope <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
66-
[-RoutingChoice <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
56+
[-KeyVaultUserAssignedIdentityId <String>] [-KeyVaultFederatedClientId <String>] [-IdentityType <String>]
57+
[-NetworkRuleSet <PSNetworkRuleSet>] [-UpgradeToStorageV2] [-EnableLargeFileShare]
58+
[-PublishMicrosoftEndpoint <Boolean>] [-PublishInternetEndpoint <Boolean>]
59+
-EnableActiveDirectoryDomainServicesForFile <Boolean> [-ActiveDirectoryDomainName <String>]
60+
[-ActiveDirectoryNetBiosDomainName <String>] [-ActiveDirectoryForestName <String>]
61+
[-ActiveDirectoryDomainGuid <String>] [-ActiveDirectoryDomainSid <String>]
62+
[-ActiveDirectoryAzureStorageSid <String>] [-ActiveDirectorySamAccountName <String>]
63+
[-ActiveDirectoryAccountType <String>] [-AllowBlobPublicAccess <Boolean>] [-MinimumTlsVersion <String>]
64+
[-AllowSharedKeyAccess <Boolean>] [-SasExpirationPeriod <TimeSpan>] [-KeyExpirationPeriodInDay <Int32>]
65+
[-AllowCrossTenantReplication <Boolean>] [-DefaultSharePermission <String>] [-PublicNetworkAccess <String>]
66+
[-ImmutabilityPeriod <Int32>] [-AllowProtectedAppendWrite <Boolean>] [-ImmutabilityPolicyState <String>]
67+
[-EnableSftp <Boolean>] [-EnableLocalUser <Boolean>] [-AllowedCopyScope <String>] [-AsJob]
68+
[-DefaultProfile <IAzureContextContainer>] [-RoutingChoice <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
6769
```
6870

6971
## DESCRIPTION
@@ -394,7 +396,7 @@ True
394396
This command updates a Storage account by enable Sftp and localuser.
395397
To run the command succssfully, the Storage account should already enable Hierarchical Namespace.
396398

397-
### Example 21: Update a Storage account by set AllowedCopyScope as PrivateLink
399+
### Example 21: Update a Storage account by set AllowedCopyScope as PrivateLink
398400
```
399401
PS C:\> $account = Set-AzStorageAccount -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -AllowedCopyScope PrivateLink
400402
@@ -404,6 +406,29 @@ PrivateLink
404406

405407
The command updates a Storage account by set AllowedCopyScope as PrivateLink.
406408

409+
### Example 22: Update a Storage account with Keyvault from another tenant (access Keyvault with FederatedClientId)
410+
```powershell
411+
# create Storage account with Keyvault encryption (access Keyvault with FederatedClientId), then show properties
412+
PS C:\> $account = Set-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName `
413+
-KeyVaultUri $keyVault.VaultUri -KeyName $keyname -KeyVaultUserAssignedIdentityId $useridentityId -KeyVaultFederatedClientId $federatedClientId
414+
415+
PS C:\> $account.Encryption.EncryptionIdentity
416+
417+
EncryptionUserAssignedIdentity EncryptionFederatedIdentityClientId
418+
------------------------------ -----------------------------------
419+
/subscriptions/{subscription-id}/resourceGroups/myresourcegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myuserid ********-****-****-****-************
420+
421+
PS C:\> $account.Encryption.KeyVaultProperties
422+
423+
KeyName : wrappingKey
424+
KeyVersion :
425+
KeyVaultUri : https://mykeyvault.vault.azure.net:443
426+
CurrentVersionedKeyIdentifier : https://mykeyvault.vault.azure.net/keys/wrappingKey/8e74036e0d534e58b3bd84b319e31d8f
427+
LastKeyRotationTimestamp : 3/3/2022 2:07:34 AM
428+
```
429+
430+
This command updates a storage account with Keyvault from another tenant (access Keyvault with FederatedClientId).
431+
407432
## PARAMETERS
408433

409434
### -AccessTier
@@ -905,6 +930,21 @@ Accept pipeline input: False
905930
Accept wildcard characters: False
906931
```
907932
933+
### -KeyVaultFederatedClientId
934+
Set ClientId of the multi-tenant application to be used in conjunction with the user-assigned identity for cross-tenant customer-managed-keys server-side encryption on the storage account.
935+
936+
```yaml
937+
Type: System.String
938+
Parameter Sets: (All)
939+
Aliases:
940+
941+
Required: False
942+
Position: Named
943+
Default value: None
944+
Accept pipeline input: False
945+
Accept wildcard characters: False
946+
```
947+
908948
### -KeyVaultUri
909949
When using Key Vault Encryption by specifying the -KeyvaultEncryption parameter, use this option to specify the URI to the Key Vault.
910950

0 commit comments

Comments
 (0)