Skip to content

DNS Provider URL Validation - #13821

Open
DaanHoogland wants to merge 14 commits into
mainfrom
dnsProviderUrlValidate
Open

DNS Provider URL Validation#13821
DaanHoogland wants to merge 14 commits into
mainfrom
dnsProviderUrlValidate

Conversation

@DaanHoogland

Copy link
Copy Markdown
Contributor

Description

DnsProviderManagerImpl.addDnsServer/updateDnsServer accepted a user-controlled URL and passed it straight to PowerDnsProvider/PowerDnsClient with zero host validation — no egress check at all, unlike the template/webhook paths.
Added validateDnsServerUrl(), called at the top of addDnsServer and whenever updateDnsServer changes the URL.

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?

@DaanHoogland DaanHoogland added this to the 4.23.0 milestone Aug 7, 2026
@DaanHoogland
DaanHoogland requested review from sudo87, weizhouapache and winterhazel and a lite review from Copilot August 7, 2026 10:03
Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.73%. Comparing base (4e4a26b) to head (22ff345).

Files with missing lines Patch % Lines
.../apache/cloudstack/dns/DnsProviderManagerImpl.java 92.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #13821   +/-   ##
=========================================
  Coverage     19.73%   19.73%           
- Complexity    19956    19959    +3     
=========================================
  Files          6371     6371           
  Lines        575765   575784   +19     
  Branches      70478    70478           
=========================================
+ Hits         113642   113654   +12     
- Misses       449766   449778   +12     
+ Partials      12357    12352    -5     
Flag Coverage Δ
uitests 3.41% <ø> (ø)
unittests 21.01% <92.30%> (+<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.

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

This PR hardens DNS provider configuration by adding pre-connection URL validation in DnsProviderManagerImpl so user-supplied DNS provider endpoints are checked (and normalized via trimming) before being persisted or handed to provider clients.

Changes:

  • Add validateDnsServerUrl() and invoke it in addDnsServer and when updateDnsServer changes the URL.
  • Normalize URLs by trimming before duplicate checks and persistence.
  • Update and extend unit tests to cover trimming behavior and rejection of invalid URLs (e.g., loopback, missing scheme).

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/dns/DnsProviderManagerImpl.java Adds URL trimming + validation before duplicate checks/persistence and before provider validation.
server/src/test/java/org/apache/cloudstack/dns/DnsProviderManagerImplTest.java Adjusts existing tests and adds new cases for trimming and invalid URL rejection.

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

Comment on lines +172 to +177
private void validateDnsServerUrl(String url) {
if (StringUtils.isBlank(url)) {
return;
}
UriUtils.validateUrl(url);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this comment makes sense (cc @sudo87 ) however, implementing this like co-pilot suggests makes no sense. ftp: or mailto: or many other scheme prefixes would have to be checked. Would we accept any others than http-like ones? (ref https://en.wikipedia.org/wiki/List_of_URI_schemes) I wouldn’t mind dns: (not listed on the page I shared)

@winterhazel winterhazel Aug 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@DaanHoogland @sudo87 @weizhouapache I think the scheme should be ignored here for this validation. The DNS provider should either use the appropriate scheme automatically, or check whether the provided URL has the expected scheme.

@sudo87

sudo87 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

clgtm, not sure if copilot comment regarding "file" protocol is valid

Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
Copilot AI review requested due to automatic review settings August 10, 2026 12:20

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 1 comment.

Suppressed comments (2)

server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:171

  • The JavaDoc claims UriUtils.validateUrl(String) enforces an http/https scheme, but UriUtils.validateUrl also allows file. Either the JavaDoc should be corrected, or validateDnsServerUrl should explicitly enforce http/https (and document that additional restriction).
     * Rejects a DNS provider URL that resolves to an illegal address before any provider client is given
     * the chance to connect to it. See {@link UriUtils#validateUrl(String)} for the exact rules enforced
     * (including the requirement that the URL declares an {@code http}/{@code https} scheme).
     * Expects {@code url} to already be trimmed.
     */

server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:176

  • UriUtils.validateUrl permits the file scheme (see UriUtils.validateUrl), so the new DNS server URL validation currently still allows file: URLs. For a provider endpoint this is unexpected and can open up local-file / non-HTTP URL handling paths in downstream clients; it also contradicts the intent to require http/https URLs.
    private void validateDnsServerUrl(String url) {
        if (StringUtils.isBlank(url)) {
            throw new IllegalArgumentException("URL cannot be blank.");
        }
        UriUtils.validateUrl(url);

Comment thread server/src/test/java/org/apache/cloudstack/dns/DnsProviderManagerImplTest.java Outdated
Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
Comment on lines +172 to +177
private void validateDnsServerUrl(String url) {
if (StringUtils.isBlank(url)) {
return;
}
UriUtils.validateUrl(url);
}

@winterhazel winterhazel Aug 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@DaanHoogland @sudo87 @weizhouapache I think the scheme should be ignored here for this validation. The DNS provider should either use the appropriate scheme automatically, or check whether the provided URL has the expected scheme.

Copilot AI review requested due to automatic review settings August 15, 2026 07:27

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@DaanHoogland
DaanHoogland requested a lite review from Copilot August 15, 2026 07:28

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

🔴 Test Coverage Grade: D — Marginal

Metric Value
Line coverage 24.51%
Branch coverage 18.67%

Grade Scale

Grade Line Coverage Meaning
🟢 A ≥ 80% Excellent - this code sleeps well at night 😴
🟡 B 60-79% Good - almost there, don't stop now 😉
🟠 C 40-59% Acceptable - your code is wearing a seatbelt, but no airbags 😬
🔴 D 20-39% Marginal - boldly shipping where no test has gone before 🖖
⛔ F < 20% Failing - tests? what tests? 🔥

Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run

@apache apache deleted a comment from github-actions Bot Aug 15, 2026
@apache apache deleted a comment from github-actions Bot Aug 15, 2026
@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated
Comment thread server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java Outdated

@winterhazel winterhazel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't test, but the code looks good

@winterhazel

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@winterhazel 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 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18948

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@winterhazel

Copy link
Copy Markdown
Member

I performed the following tests:

  • As a root admin, register, update and delete a PowerDNS server in a private network: ok
  • As a root admin, attempt to register a DNS server providing a any local/link local/loopback/multicast address: results in an error (illegal URL), ok
  • As a domain admin, attempt to register, update and delete a PowerDNS server in a private network: results in an error (restricted to root admins), ok

@winterhazel
winterhazel marked this pull request as ready for review August 24, 2026 12:42
@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@weizhouapache 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 18970

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@weizhouapache 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 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18971

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18972

@sonarqubecloud

Copy link
Copy Markdown

@weizhouapache

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16813)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 49513 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr13821-t16813-kvm-ol8.zip
Smoke tests completed. 144 look OK, 1 have errors, 11 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_02_ssl_offloading_project_vpc Failure 721.97 test_ssl_offloading.py
all_test_volumes Skipped --- test_volumes.py
all_test_vpc_conserve_mode Skipped --- test_vpc_conserve_mode.py
all_test_vpc_firewall_rules Skipped --- test_vpc_firewall_rules.py
all_test_vpc_ipv6 Skipped --- test_vpc_ipv6.py
all_test_vpc_redundant Skipped --- test_vpc_redundant.py
all_test_vpc_router_nics Skipped --- test_vpc_router_nics.py
all_test_vpc_vpn Skipped --- test_vpc_vpn.py
all_test_webhook_delivery Skipped --- test_webhook_delivery.py
all_test_webhook_lifecycle Skipped --- test_webhook_lifecycle.py
all_test_host_maintenance Skipped --- test_host_maintenance.py
all_test_hostha_kvm Skipped --- test_hostha_kvm.py

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.

8 participants