Visitar URL original
network: use calling account instead of network owner for destroy context by weizhouapache · Pull Request #14346 · apache/cloudstack · GitHub
Skip to content

network: use calling account instead of network owner for destroy context - #14346

Open
weizhouapache wants to merge 1 commit into
4.22from
4.22-fix-network-removal-with-firewall
Open

weizhouapache wants to merge 1 commit into
4.22from
4.22-fix-network-removal-with-firewall

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

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().

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?

  • 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?

…text

Symptom
-------
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().

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.
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.02%. Comparing base (2974af8) to head (eb3cb11).

Files with missing lines Patch % Lines
.../actionworkers/KubernetesClusterDestroyWorker.java 0.00% 1 Missing ⚠️
...ain/java/com/cloud/network/NetworkServiceImpl.java 0.00% 1 Missing ⚠️
...ain/java/com/cloud/network/vpc/VpcManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14346      +/-   ##
============================================
- Coverage     18.02%   18.02%   -0.01%     
+ Complexity    16250    16246       -4     
============================================
  Files          5936     5936              
  Lines        535823   535823              
  Branches      65612    65612              
============================================
- Hits          96582    96557      -25     
- Misses       428242   428275      +33     
+ Partials      10999    10991       -8     
Flag Coverage Δ
uitests 4.04% <ø> (ø)
unittests 19.09% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
final Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, CallContext.current().getCallingAccount());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to change this one too? it already used the system account so it never hit the disabled account problem, and now a normal user deleting the gateway could fail the permission checks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants