-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Role] az ad sp create-for-rbac: Deprecate creating Contributor role assignment by default #16081
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f27078e
Deprecate creating role assignment
jiasli 9040722
Merge branch 'dev' into sp-role
jiasli c15ae85
Merge branch 'dev' into sp-role
jiasli 93e36a9
style
jiasli cf1606b
Update src/azure-cli/azure/cli/command_modules/role/custom.py
jiasli a803c62
Refine message
jiasli fa68140
Wording
jiasli 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,11 @@ | |
| "The output includes credentials that you must protect. Be sure that you do not include these credentials in " | ||
| "your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli") | ||
|
|
||
| ROLE_ASSIGNMENT_CREATE_WARNING = ( | ||
| "In a future release, this command will NOT create a 'Contributor' role assignment by default. " | ||
| "If needed, use the --role argument to explicitly create a role assignment." | ||
| ) | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| # pylint: disable=too-many-lines | ||
|
|
@@ -1401,7 +1406,7 @@ def _validate_app_dates(app_start_date, app_end_date, cert_start_date, cert_end_ | |
| # pylint: disable=inconsistent-return-statements | ||
| def create_service_principal_for_rbac( | ||
| # pylint:disable=too-many-statements,too-many-locals, too-many-branches | ||
| cmd, name=None, years=None, create_cert=False, cert=None, scopes=None, role='Contributor', | ||
| cmd, name=None, years=None, create_cert=False, cert=None, scopes=None, role=None, | ||
| show_auth_for_sdk=None, skip_assignment=False, keyvault=None): | ||
| import time | ||
|
|
||
|
|
@@ -1483,8 +1488,11 @@ def create_service_principal_for_rbac( | |
|
|
||
| # retry while server replication is done | ||
| if not skip_assignment: | ||
| if not role: | ||
| role = "Contributor" | ||
| logger.warning(ROLE_ASSIGNMENT_CREATE_WARNING) | ||
| for scope in scopes: | ||
| logger.warning('Creating a role assignment under the scope of "%s"', scope) | ||
| logger.warning("Creating '%s' role assignment under scope '%s'", role, scope) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Echo the role name to be more explicit and informative. |
||
| for retry_time in range(0, _RETRY_TIMES): | ||
| try: | ||
| _create_role_assignment(cmd.cli_ctx, role, sp_oid, None, scope, resolve_assignee=False) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to detect whether
roleis explicitly set and show the warning if not.If
role='Contributor'is used, it won't be possible to detect ifroleis provided by the user or as the default value.See https://stackoverflow.com/a/14749388
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to check
role.is_default, and show the warning message accordingly. Ifroleis assigned a default value, its type will beknack.validators.DefaultStrwhich hasis_defaultfield indicating whether it is the default value.