Skip to content

Commit 1614c2d

Browse files
committed
Change the data type of ObjectId to string from Guid.
This is required for ADFS scenarios, where (unlike in AAD) object IDs are no longer guaranteed to be Guids. Note that this includes the AccessPolicyEntry change from the Azure SDK for .NET NuGet package (Microsoft.Azure.Management.KeyVault.2.0.1-preview). This change also transitions AKV to use platyPS help files.
1 parent da9324b commit 1614c2d

File tree

47 files changed

+14094
-8689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+14094
-8689
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Commands.KeyVault.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
169169
</Reference>
170170
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
171-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.2.0.0-preview\lib\net45\Microsoft.Azure.Management.KeyVault.dll</HintPath>
171+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.2.0.1-preview\lib\net45\Microsoft.Azure.Management.KeyVault.dll</HintPath>
172172
<Private>True</Private>
173173
</Reference>
174174
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/NewAzureKeyVault.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace Microsoft.Azure.Commands.KeyVault
2323
{
2424
/// <summary>
25-
/// Create a new key vault.
25+
/// Create a new key vault.
2626
/// </summary>
2727
[Cmdlet(VerbsCommon.New, "AzureRmKeyVault",
2828
SupportsShouldProcess = true,
@@ -81,9 +81,9 @@ public class NewAzureKeyVault : KeyVaultManagementCmdletBase
8181

8282
[Parameter(Mandatory = false,
8383
ValueFromPipelineByPropertyName = true,
84-
HelpMessage = "Specifies the SKU of the key vault instance. For information about which features are available for each SKU, see the Azure Key Vault Pricing website (http://go.microsoft.com/fwlink/?linkid=512521).")]
84+
HelpMessage = "Specifies the SKU of the key vault instance. For information about which features are available for each SKU, see the Azure Key Vault Pricing website (http://go.microsoft.com/fwlink/?linkid=512521).")]
8585
public SkuName Sku { get; set; }
86-
86+
8787
[Parameter(Mandatory = false,
8888
ValueFromPipelineByPropertyName = true,
8989
HelpMessage = "A hash table which represents resource tags.")]
@@ -101,7 +101,7 @@ public override void ExecuteCmdlet()
101101
throw new ArgumentException(PSKeyVaultProperties.Resources.VaultAlreadyExists);
102102
}
103103

104-
var userObjectId = Guid.Empty;
104+
var userObjectId = string.Empty;
105105
AccessPolicyEntry accessPolicy = null;
106106

107107
try
@@ -114,7 +114,7 @@ public override void ExecuteCmdlet()
114114
// This is to unblock Key Vault in Fairfax as Graph has issues in this environment.
115115
WriteWarning(ex.Message);
116116
}
117-
if (userObjectId != Guid.Empty)
117+
if (!string.IsNullOrWhiteSpace(userObjectId))
118118
{
119119
accessPolicy = new AccessPolicyEntry()
120120
{

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/RemoveAzureKeyVaultAccessPolicy.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class RemoveAzureKeyVaultAccessPolicy : KeyVaultManagementCmdletBase
8787
ValueFromPipelineByPropertyName = true,
8888
HelpMessage = "Specifies the object ID of the user or service principal in Azure Active Directory for which to remove permissions.")]
8989
[ValidateNotNullOrEmpty()]
90-
public Guid ObjectId { get; set; }
90+
public string ObjectId { get; set; }
9191

9292
/// <summary>
9393
/// Id of the application to which a user delegate to
@@ -117,7 +117,7 @@ public class RemoveAzureKeyVaultAccessPolicy : KeyVaultManagementCmdletBase
117117
public SwitchParameter EnabledForDiskEncryption { get; set; }
118118

119119
/// <summary>
120-
///
120+
///
121121
/// </summary>
122122
[Parameter(Mandatory = false,
123123
HelpMessage = "This Cmdlet does not return an object by default. If this switch is specified, it returns the updated key vault object.")]
@@ -153,11 +153,16 @@ public override void ExecuteCmdlet()
153153
if (ApplicationId.HasValue && ApplicationId.Value == Guid.Empty)
154154
throw new ArgumentException(PSKeyVaultProperties.Resources.InvalidApplicationId);
155155

156+
if (!string.IsNullOrWhiteSpace(this.ObjectId) && !this.IsValidObjectIdSyntax(this.ObjectId))
157+
{
158+
throw new ArgumentException(PSKeyVaultProperties.Resources.InvalidObjectIdSyntax);
159+
}
160+
156161
// Update vault policies
157162
var updatedPolicies = existingVault.AccessPolicies;
158-
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || (ObjectId != Guid.Empty))
163+
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || !string.IsNullOrWhiteSpace(this.ObjectId))
159164
{
160-
if (ObjectId == Guid.Empty)
165+
if (string.IsNullOrWhiteSpace(this.ObjectId))
161166
{
162167
ObjectId = GetObjectId(this.ObjectId, this.UserPrincipalName, this.ServicePrincipalName);
163168
}
@@ -175,12 +180,12 @@ public override void ExecuteCmdlet()
175180
WriteObject(updatedVault);
176181
}
177182
}
178-
private bool ShallBeRemoved(PSKeyVaultModels.PSVaultAccessPolicy ap, Guid objectId, Guid? applicationId)
183+
private bool ShallBeRemoved(PSKeyVaultModels.PSVaultAccessPolicy ap, string objectId, Guid? applicationId)
179184
{
180-
// If both object id and application id are specified, remove the compound identity policy only.
181-
// If only object id is specified, remove all policies refer to the object id including the compound identity policies.
182-
return applicationId.HasValue ? (ap.ApplicationId == applicationId && ap.ObjectId == objectId) :
183-
(ap.ObjectId == objectId);
185+
// If both object id and application id are specified, remove the compound identity policy only.
186+
// If only object id is specified, remove all policies refer to the object id including the compound identity policies.
187+
var sameObjectId = string.Equals(ap.ObjectId, objectId, StringComparison.OrdinalIgnoreCase);
188+
return applicationId.HasValue ? (ap.ApplicationId == applicationId && sameObjectId) : sameObjectId;
184189
}
185190
}
186191
}

src/ResourceManager/KeyVault/Commands.KeyVault/Commands/SetAzureKeyVaultAccessPolicy.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class SetAzureKeyVaultAccessPolicy : KeyVaultManagementCmdletBase
8787
ValueFromPipelineByPropertyName = true,
8888
HelpMessage = "Specifies the object ID of the user or service principal in Azure Active Directory for which to grant permissions.")]
8989
[ValidateNotNullOrEmpty()]
90-
public Guid ObjectId { get; set; }
90+
public string ObjectId { get; set; }
9191

9292
/// <summary>
9393
/// Id of the application to which a user delegate to
@@ -208,11 +208,16 @@ public override void ExecuteCmdlet()
208208
throw new ArgumentException(string.Format(PSKeyVaultProperties.Resources.VaultNotFound, VaultName, ResourceGroupName));
209209
}
210210

211+
if (!string.IsNullOrWhiteSpace(this.ObjectId) && !this.IsValidObjectIdSyntax(this.ObjectId))
212+
{
213+
throw new ArgumentException(PSKeyVaultProperties.Resources.InvalidObjectIdSyntax);
214+
}
215+
211216
// Update vault policies
212217
PSKeyVaultModels.PSVaultAccessPolicy[] updatedListOfAccessPolicies = vault.AccessPolicies;
213-
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || (ObjectId != Guid.Empty))
218+
if (!string.IsNullOrEmpty(UserPrincipalName) || !string.IsNullOrEmpty(ServicePrincipalName) || !string.IsNullOrWhiteSpace(this.ObjectId))
214219
{
215-
Guid objId = this.ObjectId;
220+
var objId = this.ObjectId;
216221
if (!this.BypassObjectIdValidation.IsPresent)
217222
{
218223
objId = GetObjectId(this.ObjectId, this.UserPrincipalName, this.ServicePrincipalName);
@@ -226,7 +231,7 @@ public override void ExecuteCmdlet()
226231
throw new ArgumentException(PSKeyVaultProperties.Resources.PermissionsNotSpecified);
227232
else
228233
{
229-
//Validate
234+
//Validate
230235
if (!IsMeaningfulPermissionSet(PermissionsToKeys))
231236
throw new ArgumentException(string.Format(PSKeyVaultProperties.Resources.PermissionSetIncludesAllPlusOthers, "keys"));
232237
if (!IsMeaningfulPermissionSet(PermissionsToSecrets))
@@ -237,7 +242,7 @@ public override void ExecuteCmdlet()
237242
//Is there an existing policy for this policy identity?
238243
var existingPolicy = vault.AccessPolicies.FirstOrDefault(ap => MatchVaultAccessPolicyIdentity(ap, objId, ApplicationId));
239244

240-
//New policy will have permission arrays that are either from cmdlet input
245+
//New policy will have permission arrays that are either from cmdlet input
241246
//or if that's null, then from the old policy for this object ID if one existed
242247
var keys = PermissionsToKeys ?? (existingPolicy != null && existingPolicy.PermissionsToKeys != null ?
243248
existingPolicy.PermissionsToKeys.ToArray() : null);
@@ -271,9 +276,9 @@ public override void ExecuteCmdlet()
271276
}
272277
}
273278

274-
private bool MatchVaultAccessPolicyIdentity(PSKeyVaultModels.PSVaultAccessPolicy ap, Guid objectId, Guid? applicationId)
279+
private bool MatchVaultAccessPolicyIdentity(PSKeyVaultModels.PSVaultAccessPolicy ap, string objectId, Guid? applicationId)
275280
{
276-
return ap.ApplicationId == applicationId && ap.ObjectId == objectId;
281+
return ap.ApplicationId == applicationId && string.Equals(ap.ObjectId, objectId, StringComparison.OrdinalIgnoreCase);
277282
}
278283

279284
private bool IsMeaningfulPermissionSet(string[] perms)

0 commit comments

Comments
 (0)