-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Create role assignment for MSI when enable_vnet_integration is true #9153
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
Create role assignment for MSI when enable_vnet_integration is true #9153
Conversation
️✔️Azure CLI Extensions Breaking Change Test
|
Hi @MuhammadAliFleet, |
Thank you for your contribution! We will review the pull request and get back to you soon. |
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
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.
Pull Request Overview
This PR removes the preview flag from VNet integration functionality and adds proper role assignment management for managed service identities when VNet integration is enabled. The changes enable production use of VNet integration features and ensure proper network permissions are granted.
- Remove
is_preview=True
from VNet integration parameters to promote them to general availability - Add role assignments for managed service identity on API server and agent subnets when VNet integration is enabled
- Refactor subnet role assignment logic to support different identity types
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/fleet/azext_fleet/custom.py | Updates fleet creation logic to assign network contributor roles for MSI when VNet integration is enabled |
src/fleet/azext_fleet/_params.py | Removes preview flags from enable_vnet_integration and apiserver_subnet_id parameters |
src/fleet/azext_fleet/_helpers.py | Refactors role assignment function and adds MSI object ID retrieval functionality |
src/fleet/azext_fleet/_client_factory.py | Adds MSI client factory function for managed identity operations |
src/fleet/azext_fleet/custom.py
Outdated
assign_network_contributor_role_to_subnet(cmd, resource_group_name, agent_subnet_id) | ||
assign_network_contributor_role_to_subnet(cmd, FLEET_1P_APP_ID, agent_subnet_id) | ||
|
||
if enable_vnet_integration: |
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.
The code calls get_msi_object_id(cmd, assign_identity)
without checking if assign_identity
is None. This will cause an error when enable_vnet_integration
is True but no user-assigned identity is provided.
if enable_vnet_integration: | |
if enable_vnet_integration: | |
if assign_identity is None: | |
raise CLIError("User-assigned identity must be provided for VNet integration.") |
Copilot uses AI. Check for mistakes.
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.
This is good feedback.
1- we should validate that MSI is not nil if enable_vnet_integration is set
2- we should call assign_network_contributor_role_to_subnet here only if we know it's a user MSI
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.
- now validating that MSI is not nil if enable_vnet_integration is set
- call assign_network_contributor_role_to_subnet here only if we know it's a user MSI. I tested creating private fleet v2 with system assigned msi and it fails due to missing perm action. We would need the role on the system MSI as well.
Release SuggestionsModule: fleet
Notes
|
src/fleet/azext_fleet/custom.py
Outdated
assign_network_contributor_role_to_subnet(cmd, resource_group_name, agent_subnet_id) | ||
assign_network_contributor_role_to_subnet(cmd, FLEET_1P_APP_ID, agent_subnet_id) | ||
|
||
if enable_vnet_integration: |
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.
This is good feedback.
1- we should validate that MSI is not nil if enable_vnet_integration is set
2- we should call assign_network_contributor_role_to_subnet here only if we know it's a user MSI
src/fleet/azext_fleet/custom.py
Outdated
assign_network_contributor_role_to_subnet(cmd, FLEET_1P_APP_ID, agent_subnet_id) | ||
|
||
if enable_vnet_integration: | ||
assign_network_contributor_role_to_subnet(cmd, get_msi_object_id(cmd, assign_identity), apiserver_subnet_id) |
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.
calling get_msi_object_id twice is 2 API calls. Call once and save the result for the second add_role call
src/fleet/azext_fleet/_helpers.py
Outdated
|
||
def get_msi_object_id(cmd, msi_resource_id): | ||
try: | ||
if not is_valid_resource_id(msi_resource_id): |
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.
this should be in a validator
6b3cb6f
to
5d9f635
Compare
src/fleet/azext_fleet/custom.py
Outdated
raise CLIError("Cannot assign identity without enabling managed identity.") | ||
|
||
if enable_vnet_integration: | ||
if not enable_managed_identity and assign_identity is None: |
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.
- shouldn't this just be
if not enable_managed_identity:
? - can this test be moved to _validators.py (i.e. add a new
validate_enable_vnet_integration
function and update _params.py withc.argument('enable_vnet_integration', validator=validate_enable_vnet_integration, ...
)?
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.
moved to _validators.py
src/fleet/azext_fleet/_helpers.py
Outdated
def assign_network_contributor_role_to_subnet(cmd, subnet_id): | ||
def assign_network_contributor_role_to_subnet(cmd, object_id, subnet_id): | ||
if not add_role_assignment(cmd, 'Network Contributor', object_id, scope=subnet_id): | ||
logger.warning("Failed to create Network Contributor role assignment on the subnet.\n" |
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.
Could you provide a more detailed error? Maybe even ideally to the point at which someone could copy/paste an az role assignment create
command and ask their admin to run that for them?
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.
Added detailed error with command
src/fleet/azext_fleet/_validators.py
Outdated
|
||
def validate_enable_vnet_integration(namespace): | ||
if namespace.enable_vnet_integration and not namespace.enable_managed_identity: | ||
raise CLIError("--enable-vnet-integration requires managed identity to be enabled. " |
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.
although it's theoretically possible to do vnet integration with system MSI, it's a real pain. I'm worried this message will send people down that painful path. I'm tempted to require they use user MSI in the CLI, i.e. validate both enable_managed_identity and assign_identity, and update the error message to include adding --assign-identity as well?
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.
now validating both enable_managed_identity and assign_identity
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.
LGTM
@kairu-ms please merge? |
This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
This PR:
General Guidelines
azdev style <YOUR_EXT>
locally? (pip install azdev
required)python scripts/ci/test_index.py -q
locally? (pip install wheel==0.30.0
required)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.json
automatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json
.