Skip to content

Allow project admin to update template/ISO permissions in projects - #14510

Open
DaanHoogland wants to merge 3 commits into
apache:4.20from
shapeblue:ghi14174-projectAdminUpdateTemplatePerms
Open

DaanHoogland wants to merge 3 commits into
apache:4.20from
shapeblue:ghi14174-projectAdminUpdateTemplatePerms

Conversation

@DaanHoogland

@DaanHoogland DaanHoogland commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

Only a CloudStack admin or the template's owner account can change the permissions (ispublic, isextractable, launch permissions) of a template or ISO. For a project-owned template the owner is the project account, which no real account can match. So every project member was rejected by updateTemplateOrIsoPermissions(), including the Project Admin who registered the template.

With this PR, a Project Admin of the project that owns the template passes both ownership checks: the general permission check and the isextractable check. The new isAdminOfOwningProject() looks up the project from the template's owner account and checks the caller's role in that project. A user-level project role, if present, takes precedence over the account-level role. Regular project members are still rejected, as before.

Scope: only members with the project Admin role act as owner. Regular project members are still refused, even though registration lets any member set ispublic/isextractable; the stricter rule on update is intentional. The project role is only looked up when the caller is neither a CloudStack admin nor the owner. The isextractable parameter description is updated to match.

Scope: only members with the project Admin role act as owner. Regular project members are still refused, even though registration lets any member set ispublic/isextractable; the stricter rule on update is intentional. The project role is only looked up when the caller is neither a CloudStack admin nor the owner. The isextractable parameter description is updated to match.

Fixes: #14174

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Unit tests in TemplateManagerImplTest:

  • testUpdateTemplatePermissionsAllowsProjectAdminToActAsOwner: fails with the old code (InvalidParameterValueException) and passes with the fix.
  • testUpdateTemplatePermissionsRejectsProjectMemberThatIsNotProjectAdmin: a regular project member is still rejected.
  • testUpdateTemplatePermissionsOwnerDoesNotConsultProjectRole / testUpdateTemplatePermissionsAdminDoesNotConsultProjectRole: owner and admin callers never look up the project role (ported from server: allow project admins to update permissions of project templates #14529, thanks @HawkForge).
  • isAdminOfOwningProjectTest*: covers a non-project owner, a missing project, and a user-level project role taking precedence over the account-level role.
  • testUpdateTemplatePermissionsOwnerDoesNotConsultProjectRole / testUpdateTemplatePermissionsAdminDoesNotConsultProjectRole: owner and admin callers never look up the project role (ported from server: allow project admins to update permissions of project templates #14529, thanks @HawkForge).

manually tested by having admin upload a template in a project owned by user. user could change permission settings.

(partly 🤖 Generated with Claude Code)

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 16.47%. Comparing base (454bba0) to head (508d3cb).
⚠️ Report is 7 commits behind head on 4.20.

Files with missing lines Patch % Lines
...n/java/com/cloud/template/TemplateManagerImpl.java 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #14510      +/-   ##
============================================
+ Coverage     16.42%   16.47%   +0.04%     
- Complexity    13676    13724      +48     
============================================
  Files          5669     5670       +1     
  Lines        501634   501782     +148     
  Branches      60939    60968      +29     
============================================
+ Hits          82416    82644     +228     
+ Misses       409982   409864     -118     
- Partials       9236     9274      +38     
Flag Coverage Δ
uitests 4.16% <ø> (-0.01%) ⬇️
unittests 17.33% <93.33%> (+0.04%) ⬆️

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.

@DaanHoogland DaanHoogland added this to the 4.20.4 milestone Oct 28, 2026
…ed templates

Only a CloudStack admin or the template's owner account can change
the permissions (ispublic, isextractable, launch permissions) of a
template. For a project-owned template the owner is the project
account, so every project member was rejected, including the Project
Admin who registered the template.

A Project Admin of the project that owns the template now passes both
ownership checks in updateTemplateOrIsoPermissions(). The role is
looked up in the template's owning project, with the user-level
project role taking precedence over the account-level one.

Fixes apache#14174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DaanHoogland
DaanHoogland force-pushed the ghi14174-projectAdminUpdateTemplatePerms branch from b7d3a8c to 378f745 Compare November 3, 2026 09:10
@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@prashanthr2 , this solves an issue you encountered. Can you test/ review it?

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ debian. SL-JID 19884

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@RosiKyu , I monkey tested this as a user creating a project and a template in it.

NOTA BENE: creating a template as root admin in the project will also allow the project admin (a normal user in this case) to edit the permissions of the template. Please consider this from a functional point of view. cc @prashanthr2

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

Following up on my NB above: I think this is the intended behaviour, not a side effect. A template registered into a project is owned by the project account, whoever uploaded it, root admin included. That is how other project resources work too (VMs, volumes, networks created in a project by an admin are managed by the project). The Project Admin is acting for the owner here, so letting them manage the template's permissions is consistent.

To be explicit about scope: only members with the project Admin role get this. Regular project members are still refused, even though registration lets any member set ispublic/isextractable. Being stricter on update seemed the safer choice (wido agreed on #14428).

@RosiKyu @prashanthr2 if you see a functional reason to treat admin-uploaded templates differently, please say so.

Check the Project Admin role of the owning project only for callers
that are neither a CloudStack admin nor the template owner, and fold the
result into a single isOwner flag. Add tests that the owner and admin
paths do not consult the project role, and update the isextractable
parameter description, which still said root admin only.

Tests ported from apache#14529 by HawkForge.

Co-authored-by: HawkForge <75696486+HawkForge@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

Project users can set template permissions at upload but cannot change them afterwards

2 participants