weizhouapache opened a new pull request, #14346:
URL: https://github.com/apache/cloudstack/pull/14346
### Description
This PR fixes an issue while deleting a network whose owning account is
disabled fails with:
```
com.cloud.exception.PermissionDeniedException: Account Account
[{"accountName":"...","id":...}] is disabled.
at com.cloud.acl.DomainChecker.checkAccess(DomainChecker.java:149)
at
com.cloud.user.AccountManagerImpl.checkAccess(AccountManagerImpl.java:831)
at
com.cloud.network.firewall.FirewallManagerImpl.revokeFirewallRule(FirewallManagerImpl.java:1169)
at
com.cloud.network.firewall.FirewallManagerImpl.revokeAllFirewallRulesForNetwork(FirewallManagerImpl.java:1356)
at
org.apache.cloudstack.engine.orchestration.NetworkOrchestrator.cleanupNetworkResources(NetworkOrchestrator.java:4192)
at
org.apache.cloudstack.engine.orchestration.NetworkOrchestrator.destroyNetwork(NetworkOrchestrator.java:3512)
```
- Root cause
NetworkServiceImpl.deleteNetwork, VpcManagerImpl (private network cleanup),
and KubernetesClusterDestroyWorker each build the ReservationContext used for
destroyNetwork() with the network's *owning* account as the acting account:
ReservationContext context = new ReservationContextImpl(null, null,
callerUser, owner);
That "owner" account is then propagated all the way into
FirewallManagerImpl.revokeFirewallRule() as the checkAccess() caller when
cleaning up the network's firewall rules. DomainChecker.checkAccess()
unconditionally rejects any caller whose account state isn't ENABLED, so if the
network's owner account happens to be disabled (e.g. while it is being cleaned
up, or simply disabled by an admin without removing it), network deletion is
blocked entirely — even for a root admin performing the deletion.
By contrast, AccountManagerImpl.cleanupAccount() (the cascade that runs
during full account deletion) already builds this same ReservationContext with
the actual calling account instead of the owner:
```
ReservationContext context = new ReservationContextImpl(null, null,
getActiveUser(callerUserId), caller);
```
...which is why account deletion itself was never affected — only a direct
deleteNetwork/VPC-network-cleanup call against a disabled-but-not- yet-removed
account.
- Fix
Use the actual calling account (the account performing the operation)
instead of the network's owner account when building the ReservationContext for
destroyNetwork(), in all three call sites, matching the pattern already used by
AccountManagerImpl.cleanupAccount().
<!--- Describe your changes in DETAIL - And how has behaviour functionally
changed. -->
<!-- For new features, provide link to FS, dev ML discussion etc. -->
<!-- In case of bug fix, the expected and actual behaviours, steps to
reproduce. -->
<!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be
closed when this PR gets merged -->
<!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
<!-- Fixes: # -->
<!---
*******************************************************************************
-->
<!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE
DOCUMENTATION. -->
<!--- PLEASE PUT AN 'X' in only **ONE** box -->
<!---
*******************************************************************************
-->
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] Build/CI
- [ ] Test (unit or integration test code)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [ ] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [ ] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
<!-- Please describe in detail how you tested your changes. -->
<!-- Include details of your testing environment, and the tests you ran to
-->
- Reproduced and verified
Reproduced end-to-end against a running management server (pre-fix build)
by: creating a test account, creating an isolated network with the Firewall
service and implementing it (deploy a VM), adding firewall rules on its
source-NAT IP, disabling the account, destroying/expunging the VM, then
attempting to delete the network — which failed with the exact same stack trace
as above. Re-enabling the account allowed the same deleteNetwork call to
succeed immediately, confirming the account's disabled state (via the
owner-as-caller path) as the sole cause.
#### How did you try to break this feature and the system with this change?
<!-- see how your change affects other areas of the code, etc. -->
<!-- Please read the
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
document -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]