Skip to content

SSLCertService: Fix account id requirement by using caller account id as fallback - #13818

Open
resmo wants to merge 9 commits into
apache:mainfrom
resmo:fix/ssl-cert-unneccessary-invalid-param-ex
Open

SSLCertService: Fix account id requirement by using caller account id as fallback#13818
resmo wants to merge 9 commits into
apache:mainfrom
resmo:fix/ssl-cert-unneccessary-invalid-param-ex

Conversation

@resmo

@resmo resmo commented Aug 6, 2026

Copy link
Copy Markdown
Member

Description

While implementing an ansible module for ssl cert (ngine-io/ansible-collection-cloudstack#178). I faced this api and experienced this issue. (As a side note: The ssl cert api is IMHO not consistent with other cloudstack apis: e.g. there are no domainId with accountName param but an accountId.)

SSL cert service requires to set the account id (if no project id or lb id), however, this is inconsistent to other cloudstack APIs where (AFAICS) the caller account name is used instead as a fallack.

UPDATE:
I added another commit on top to streamline the api by adding account and domainid to the list api. Let's discuss which way to go.

This change aligns with this behaviour.

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?

How did you try to break this feature and the system with this change?

Copilot AI lite review requested due to automatic review settings August 6, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Aligns CertService SSL certificate listing behavior with other CloudStack APIs by falling back to the caller’s account when no explicit accountId (and no other filter like project/LB/cert) is provided, removing an unnecessary hard requirement that caused client friction (e.g., automation modules).

Changes:

  • Update listSslCerts to use the caller account ID as the default when accountId is not provided.
  • Add a unit test ensuring the no-filter case queries certificates for the caller’s account.
  • Minor cleanup: parameterized logging and correct string comparison for key algorithm checks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java Implements caller-account fallback for listing certs; minor logging/string-compare adjustments; updates PEM reader close handling.
server/src/test/java/org/apache/cloudstack/network/ssl/CertServiceTest.java Adds a regression test validating caller-account fallback behavior for listSslCerts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java Outdated
Copilot AI review requested due to automatic review settings August 6, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (1)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:375

  • The comment and logic here are misleading: this block is not about "encryption for DSA"; it conditionally performs an RSA signature round-trip to validate that the keypair matches, and it skips validation for any non-RSA algorithm (not just DSA). Consider updating the comment and using a null-safe string comparison for clarity.
        // No encryption for DSA
        if (!pubKey.getAlgorithm().equals("RSA")) {
            return;
        }

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.41%. Comparing base (5a67f19) to head (574b250).
⚠️ Report is 2 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (5a67f19) and HEAD (574b250). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (5a67f19) HEAD (574b250)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               main   #13818       +/-   ##
=============================================
- Coverage     19.64%    3.41%   -16.24%     
=============================================
  Files          6368      487     -5881     
  Lines        574889    41867   -533022     
  Branches      70353     7912    -62441     
=============================================
- Hits         112962     1429   -111533     
+ Misses       449656    40238   -409418     
+ Partials      12271      200    -12071     
Flag Coverage Δ
uitests 3.41% <ø> (ø)
unittests ?

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.

Copilot AI review requested due to automatic review settings August 7, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:206

  • The owner-selection condition can silently ignore a provided accountName when domainId is missing because it uses StringUtils.isNotEmpty(...) as a gate. This bypasses _accountMgr.finalizeOwner(...) validation (which would throw when accountName != null && domainId == null), and the current &&/|| expression is also hard to read due to operator precedence. Consider keying on accountName != null (not non-empty) and grouping the projectId/accountName cases explicitly so invalid parameter combinations are rejected instead of being ignored.
        Account owner = null;
        if (StringUtils.isNotEmpty(listSslCertCmd.getAccountName()) && listSslCertCmd.getDomainId() != null || listSslCertCmd.getProjectId() != null) {
            owner = _accountMgr.finalizeOwner(caller, listSslCertCmd.getAccountName(), listSslCertCmd.getDomainId(), listSslCertCmd.getProjectId());
        } else {
            owner = caller;

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:28

  • import org.apache.cloudstack.api.response.*; introduces a wildcard import, which is inconsistent with the surrounding API command classes in this package that use explicit response imports (e.g. CreateLoadBalancerRuleCmd.java:30-34, DeleteSslCertCmd.java:27-28). Using explicit imports avoids accidental unused dependencies and keeps diffs more readable.
import org.apache.cloudstack.api.response.*;

streamline ssl cert list api, deprecate accountid
@resmo
resmo force-pushed the fix/ssl-cert-unneccessary-invalid-param-ex branch from 1d05a20 to 8a3871f Compare August 7, 2026 07:16
Copilot AI review requested due to automatic review settings August 7, 2026 07:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:203

  • The owner resolution condition mixes && and || without parentheses and only calls finalizeOwner when (accountName && domainId) or projectId is set. This means invalid combinations like specifying accountName without domainId are silently ignored (finalizeOwner would normally throw), and it also allows ambiguous requests when accountId is supplied together with account/domainId or projectId. Consider computing a single hasOwnerParams flag, calling finalizeOwner whenever any owner-related parameter is provided (so validation/permission checks run), and rejecting combinations that include both deprecated accountId and the new owner parameters.
        Account owner = null;
        if (StringUtils.isNotEmpty(listSslCertCmd.getAccountName()) && listSslCertCmd.getDomainId() != null || listSslCertCmd.getProjectId() != null) {
            owner = _accountMgr.finalizeOwner(caller, listSslCertCmd.getAccountName(), listSslCertCmd.getDomainId(), listSslCertCmd.getProjectId());

resmo added 4 commits August 10, 2026 15:20
add a note about mutually exclusive with account
not a common verify in cloudstack but in terms of unexpected results,
it should be verified.
Copilot AI review requested due to automatic review settings August 10, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (5)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:236

  • When accountId is provided, _accountMgr.getAccount(accountId) may return null; owner.getId() will then throw a NullPointerException. Also, listing by another accountId performs the DB query before any access check, which can leak whether that account has certificates (empty list returns normally, non-empty list can throw on checkAccess). Validate the account exists and check caller access to the account before querying.
        Account owner = null;
        if (StringUtils.isNotEmpty(accountName)) {
            owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
        } else if (accountId != null) {
            owner = _accountMgr.getAccount(accountId);
        } else {
            owner = caller;
        }

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:227

  • This change now rejects requests that specify more than one of certificateid, lbid, projectid, or account/accountid. Previously, extra parameters were tolerated (with a defined precedence via the if (certId) ... else if (lbRuleId) ... chain). This is potentially a breaking API behavior change for clients that passed multiple filters.
        // Validate that only one of certid, lbid, projectid, or accountid/account can be specified
        ArrayList<Object> params = new ArrayList<>();
        params.add(certId);
        params.add(accountId != null ? accountId : accountName);
        params.add(lbRuleId);
        params.add(projectId);

        int nonNullIds = 0;
        for (Object param : params) {
            if (param != null) {
                nonNullIds++;
            }
        }
        if (nonNullIds > 1) {
            throw new InvalidParameterValueException("Only one of certid, lbid, projectid, or accountid/account can be specified");
        }

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:232

  • StringUtils.isNotEmpty(accountName) treats whitespace-only values as provided, which will call finalizeOwner with an invalid account name (e.g., " "). Since the intent is to treat "no account filter" as fallback to caller, use isNotBlank here (consistent with validating blank/empty account names as absent).
        if (StringUtils.isNotEmpty(accountName)) {
            owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
        } else if (accountId != null) {

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:91

  • Extra whitespace in the method signature (public String ...) is inconsistent with the surrounding code style and may fail strict formatting/checkstyle rules.
    public  String getAccountName() {
        return accountName;
    }

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:212

  • The account filter validation treats an empty account string as "provided" (accountName != null / param != null), which can incorrectly trigger the mutual-exclusion error and the "only one of" check. Also, domainid can currently be passed without account and will be silently ignored (falls back to caller). Treat blank account names as absent and reject domainid without account.

This issue also appears in the following locations of the same file:

  • line 212
  • line 229
  • line 230
        if (accountId != null && (accountName != null || domainId != null)) {
            throw new InvalidParameterValueException("The accountid and account/domainid are mutually exclusive");
        }

        // Validate that only one of certid, lbid, projectid, or accountid/account can be specified

Copilot AI review requested due to automatic review settings August 10, 2026 13:57
@resmo
resmo force-pushed the fix/ssl-cert-unneccessary-invalid-param-ex branch from 96e51f2 to db72cc6 Compare August 10, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (4)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:402

  • pubKey.getAlgorithm().equals("RSA") can throw if getAlgorithm() ever returns null; using a constant-first equals avoids a potential NPE and is consistent with the surrounding defensive style.
        if (!pubKey.getAlgorithm().equals("RSA")) {

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:91

  • Minor formatting: double space in method signature (public String) is inconsistent with the surrounding accessors.
    public String getAccountName() {
        return accountName;
    }

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:216

  • domainid is accepted even when account is not provided, but it is then ignored by the validation/counting logic (it isn't included in nonNullIds and finalizeOwner is skipped). This can lead to surprising behavior (e.g., domainid + certid passes validation and domainid has no effect). Consider rejecting domainid without account, and count account selection only when account is non-blank so empty strings don't block other filters.

This issue also appears on line 402 of the same file.

        // Validate that only one of certid, lbid, projectid, or accountid/account can be specified
        ArrayList<Object> params = new ArrayList<>();
        params.add(certId);
        params.add(accountId != null ? accountId : accountName);
        params.add(lbRuleId);

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:55

  • The updated accountId parameter description mentions only mutual exclusivity with account, but the implementation also treats domainid as part of that mutually-exclusive pair. Updating the description helps API users understand the constraint.

This issue also appears on line 89 of the same file.

    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, required = false, description = "Account ID and " + ApiConstants.ACCOUNT + " are mutually exclusive.")
    private Long accountId;

Copilot AI review requested due to automatic review settings August 10, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (4)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:234

  • domainId is accepted by the API but is ignored when account is not provided (because finalizeOwner is only called when accountName is non-empty). This can silently drop user input and produce confusing results. Validate that domainId is only allowed together with a non-blank account, and treat blank account as absent.
        Account owner = null;
        if (StringUtils.isNotEmpty(accountName)) {
            owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
        } else {
            owner = caller;
        }

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:216

  • The mutually-exclusive-parameter counting treats accountName as “present” even when it is blank (because it’s added directly to params). This can cause confusing validation failures for inputs like account=" " and can also make it harder to reason about the “only one of …” check. Consider counting accountName only when it is non-blank.
        ArrayList<Object> params = new ArrayList<>();
        params.add(certId);
        params.add(accountId != null ? accountId : accountName);
        params.add(lbRuleId);

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:54

  • The accountid parameter description says it is mutually exclusive with account, but the implementation also rejects combining it with domainid. The API docs should reflect that accountid cannot be used together with account/domainid.
    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, required = false, description = "Account ID and " + ApiConstants.ACCOUNT + " are mutually exclusive.")
    private Long accountId;

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:61

  • The new parameters are marked since = "4.24", but the current project version is 4.23.0.0-SNAPSHOT (pom.xml). Using a future version here makes the generated API docs misleading; set since to the release version that will actually contain this change.
    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, since = "4.24", description = "Account owning the SSL certificate")
    private String accountName;

    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, since = "4.24", entityType = DomainResponse.class, description = "Domain ID of the account owning the SSL certificate")
    private Long domainId;

Unlike in `listSslCerts`, where we have to make a distinction because of the additional `accountId`,
we use `finalizeOwner` early on so that the checks it contains are called. `caller` is returned as a last resort by `finalzieOwner`.
Copilot AI review requested due to automatic review settings August 10, 2026 14:42
@resmo resmo changed the title CertService: Fix account id requirement by using caller account id as fallback SSLCertService: Fix account id requirement by using caller account id as fallback Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:298

  • When accountid is provided for a non-admin caller, the method will return an empty list without any access check if that account currently has no certs. This allows probing other account IDs to distinguish "no certs" vs "permission denied" (when certs exist). Enforce that non-admin callers can only use their own accountid before querying.
        final List<SslCertVO> certVOList = _sslCertDao.listByAccountId(accountId != null ? accountId : owner.getId());
        if (certVOList == null || certVOList.isEmpty()) {
            return certResponseList;
        }
        _accountMgr.checkAccess(caller, SecurityChecker.AccessType.UseEntry, true, certVOList.get(0));

server/src/main/java/org/apache/cloudstack/network/ssl/CertServiceImpl.java:201

  • domainid can currently be provided without account, and blank account values are counted as a filter because the validation checks only for null. This can lead to requests that silently ignore domainid (listing caller certs) or incorrectly fail mutual-exclusion checks. Normalize account to null when blank, and reject domainid without account before doing the mutually-exclusive / single-filter validation.
        final String accountName = listSslCertCmd.getAccountName();
        final Long domainId = listSslCertCmd.getDomainId();

        if (accountId != null && (StringUtils.isNotBlank(accountName) || domainId != null)) {
            throw new InvalidParameterValueException("The accountid and account/domainid are mutually exclusive");

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java:61

  • The new account/domainid parameters are described as independent, but the implementation requires them to be used together and also treats them as mutually exclusive with accountid. Updating the parameter descriptions makes the API contract clearer (and aligns with the server-side validation).
    @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, required = false, description = "Account ID and " + ApiConstants.ACCOUNT + " are mutually exclusive.")
    private Long accountId;

    @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, since = "4.24", description = "Account owning the SSL certificate")
    private String accountName;

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 18820

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.

4 participants