-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Role assignment support #42297
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
Merged
JoshLove-msft
merged 13 commits into
Azure:feature/cdk
from
JoshLove-msft:role-assignment
Feb 29, 2024
Merged
Role assignment support #42297
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fc4a052
save
JoshLove-msft c71f33b
add roleassignment
JoshLove-msft 0227902
Merge branch 'feature/cdk' of https://github.com/Azure/azure-sdk-for-…
JoshLove-msft c487583
support role assignment
JoshLove-msft 5f04801
revert sln change
JoshLove-msft a51420b
updat tests
JoshLove-msft 759791a
fix
JoshLove-msft e8687ff
pr fb
JoshLove-msft 5917e29
regen
JoshLove-msft 8f24136
Add back env var support for subs, PR fb
JoshLove-msft a4f01bf
regen
JoshLove-msft 58d1b10
fix tests
JoshLove-msft 26ed635
regen
JoshLove-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
sdk/provisioning/Azure.Provisioning/src/authorization/RoleAssignment.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using Azure.Core; | ||
| using Azure.ResourceManager.Authorization; | ||
| using Azure.ResourceManager.Authorization.Models; | ||
|
|
||
| namespace Azure.Provisioning.Authorization | ||
| { | ||
| /// <summary> | ||
| /// Role assignment resource. | ||
| /// </summary> | ||
| public class RoleAssignment : Resource<RoleAssignmentData> | ||
| { | ||
| internal static readonly ResourceType ResourceType = "Microsoft.Resources/roleAssignments"; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="RoleAssignment"/>. | ||
| /// </summary> | ||
| /// <param name="scope">The scope.</param> | ||
| /// <param name="resource"></param> | ||
| /// <param name="roleDefinition"></param> | ||
| /// <param name="principalId"></param> | ||
| internal RoleAssignment( | ||
| IConstruct scope, | ||
| Resource resource, | ||
| RoleDefinition roleDefinition, | ||
| Guid? principalId = default) | ||
| : base( | ||
| scope, | ||
| resource, | ||
| resource.Name, | ||
| ResourceType, | ||
| "2022-04-01", | ||
| (name) => ArmAuthorizationModelFactory.RoleAssignmentData( | ||
| name: name, | ||
| roleDefinitionId: ResourceIdentifier.Parse($"/providers/Microsoft.Authorization/roleDefinitions/{roleDefinition}"), | ||
| principalId: principalId)) | ||
| { | ||
| if (scope.Configuration?.UseInteractiveMode != true && principalId == null) | ||
| { | ||
| throw new InvalidOperationException("PrincipalId must be specified when not in interactive mode."); | ||
| } | ||
|
|
||
| if (principalId == null) | ||
| { | ||
| AssignParameter(data => data.PrincipalId, new Parameter("principalId")); | ||
| AssignProperty(data => data.Name, $"guid('{resource.Name}', principalId, '{roleDefinition}')"); | ||
| } | ||
| else | ||
| { | ||
| AssignProperty(data => data.Name, $"guid('{resource.Name}', '{principalId}', '{roleDefinition}')"); | ||
| } | ||
| } | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace Azure.Provisioning.Authorization | ||
| { | ||
| /// <summary> Role definition. </summary> | ||
| public readonly partial struct RoleDefinition : IEquatable<RoleDefinition> | ||
| { | ||
| private readonly string _value; | ||
|
|
||
| /// <summary> Initializes a new instance of <see cref="RoleDefinition"/>. </summary> | ||
| /// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception> | ||
| public RoleDefinition(string value) | ||
| { | ||
| _value = value ?? throw new ArgumentNullException(nameof(value)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Storage blob data contributor role. | ||
| /// </summary> | ||
| public static RoleDefinition StorageBlobDataContributor { get; } = new RoleDefinition("ba92f5b4-2d11-453d-a403-e96b0029c9fe"); | ||
|
|
||
| /// <summary> | ||
| /// Storage queue data contributor role. | ||
| /// </summary> | ||
| public static RoleDefinition StorageQueueDataContributor { get; } = new RoleDefinition("974c5e8b-45b9-4653-ba55-5f855dd0fb88"); | ||
|
|
||
| /// <summary> | ||
| /// Storage table data contributor role. | ||
| /// </summary> | ||
| public static RoleDefinition StorageTableDataContributor { get; } = new RoleDefinition("0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3"); | ||
|
|
||
| /// <summary> Converts a string to a <see cref="RoleDefinition"/>. </summary> | ||
| public static implicit operator RoleDefinition(string value) => new RoleDefinition(value); | ||
|
|
||
| /// <inheritdoc /> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public override bool Equals(object? obj) => obj is RoleDefinition other && Equals(other); | ||
| /// <inheritdoc /> | ||
| public bool Equals(RoleDefinition other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); | ||
|
|
||
| /// <inheritdoc /> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public override int GetHashCode() => _value?.GetHashCode() ?? 0; | ||
| /// <inheritdoc /> | ||
| public override string ToString() => _value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ovisioning/Azure.Provisioning/tests/Infrastructure/RoleAssignmentWithParameter/main.bicep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| targetScope = 'resourceGroup' | ||
|
|
||
| @description('') | ||
| param location string = resourceGroup().location | ||
|
|
||
| @description('') | ||
| param principalId string | ||
|
|
||
|
|
||
| resource storageAccount_d1RlrfJGB 'Microsoft.Storage/storageAccounts@2022-09-01' = { | ||
| name: toLower(take(concat('photoAcct', uniqueString(resourceGroup().id)), 24)) | ||
| location: location | ||
| sku: { | ||
| name: 'Premium_LRS' | ||
| } | ||
| kind: 'StorageV2' | ||
| properties: { | ||
| } | ||
| } | ||
|
|
||
| resource blobService_tjgcRkcbL 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = { | ||
| parent: storageAccount_d1RlrfJGB | ||
| name: 'default' | ||
| properties: { | ||
| } | ||
| } | ||
|
|
||
| resource roleAssignment_XCw6aC1YR 'Microsoft.Resources/roleAssignments@2022-04-01' = { | ||
| scope: storageAccount_d1RlrfJGB | ||
| name: guid('storageAccount_d1RlrfJGB', principalId, 'ba92f5b4-2d11-453d-a403-e96b0029c9fe') | ||
| properties: { | ||
| roleDefinitionId: '/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe' | ||
| principalId: principalId | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.