Skip to content

fix(discovery): validate plugin callback resolves to client address - #1725

Merged
andrewazores merged 9 commits into
cryostatio:mainfrom
jtolentino1:fix-1603-plugin-callback-address
Aug 11, 2026
Merged

fix(discovery): validate plugin callback resolves to client address#1725
andrewazores merged 9 commits into
cryostatio:mainfrom
jtolentino1:fix-1603-plugin-callback-address

Conversation

@jtolentino1

@jtolentino1 jtolentino1 commented Aug 7, 2026

Copy link
Copy Markdown
Member

Welcome to Cryostat! 👋

Before contributing, make sure you have:

  • Read the contributing guidelines
  • Linked a relevant issue which this PR resolves
  • Linked any other relevant issues, PR's, or documentation, if any
  • Resolved all conflicts, if any
  • Rebased your branch PR on top of the latest upstream main branch
  • Attached at least one of the following labels to the PR: [chore, ci, docs, feat, fix, test]
  • Signed all commits using a GPG signature

To recreate commits with GPG signature git fetch upstream && git rebase --force --gpg-sign upstream/main


Fixes: #1603

Description of the change:

Validates that a discovery plugin callback resolves to the registering client's address.

Motivation for the change:

Prevents plugins from registering callbacks that target Cryostat or another host.

How to manually test:

  1. Run ./smoketest.bash -O.
  2. Register an agent callback pointing to Cryostat's health endpoint while sending X-Forwarded-For: 192.0.2.1.
  3. Verify the request returns HTTP 400 instead of HTTP 200.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Strengthened callback validation by confirming resolved callback addresses match the connecting client.
    • Discovery requests now return a bad request when callback resolution fails or addresses do not match.
    • Improved client address handling for discovery and JWT validation by using the direct connection address.
    • Configured the authentication proxy as a trusted source for forwarded requests.
  • Improvements

    • Improved schema generation for complex record and class field types, including locally declared types.

Walkthrough

Discovery validates callback host resolution against the request socket address. JWT validation no longer uses X-Forwarded-For. Schema analysis resolves local record types. Agent integration tests use host networking with dynamic ports.

Changes

Discovery address validation

Layer / File(s) Summary
Client address source and proxy configuration
src/main/java/io/cryostat/discovery/Discovery.java, src/main/java/io/cryostat/discovery/DiscoveryJwtValidator.java, compose/auth_proxy.yml
Discovery and JWT validation use the direct request remote address. The auth proxy is configured as trusted.
Callback validation and registration tests
src/main/java/io/cryostat/discovery/Discovery.java, src/test/java/io/cryostat/discovery/DiscoveryPluginTest.java
Callback validation checks all resolved addresses and returns HTTP 400 for failures or mismatches. Registration tests cover forwarded-address mismatches, and the agent test verifies that callback creation is skipped.

Schema field type resolution

Layer / File(s) Summary
AST-aware field type analysis
schema-generator/src/main/java/io/cryostat/schema/PayloadTypeAnalyzer.java
Record and class field analysis passes AST context and checks local record declarations before global type resolution.

Integration container networking

Layer / File(s) Summary
Host-networked agent container
src/test/java/io/cryostat/resources/AgentApplicationResource.java
The test resource allocates dynamic ports, configures callback and base URLs, uses host networking, and waits for agent readiness by log message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: andrewazores

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The schema-generator PayloadTypeAnalyzer changes are unrelated to discovery callback validation and issue #1603. Remove the unrelated PayloadTypeAnalyzer changes or link an issue that requires them.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: validating discovery plugin callback resolution against the client address.
Description check ✅ Passed The description completes the required checklist, issue reference, change summary, motivation, and manual test steps.
Linked Issues check ✅ Passed The implementation validates callback addresses against the registering client address and satisfies the requirements in issue #1603.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@jtolentino1

Copy link
Copy Markdown
Member Author

/build_test

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Workflow started at 8/7/2026, 2:42:14 PM. View Actions Run.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

CI build:
Unit tests pass ✅
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
https://github.com/cryostatio/cryostat/actions/runs/31208144609

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/io/cryostat/discovery/Discovery.java`:
- Around line 878-893: Update getRemoteAddress so X-Forwarded-For is honored
only when the immediate socket peer matches a configured trusted proxy;
otherwise always return the socket peer address. Preserve the existing callback
validation flow in Discovery and ensure registerAgent cannot use an untrusted
client-supplied forwarded address.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c774a13-4d7f-4d27-8941-26622a36fadc

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed0a92 and 456c7b0.

📒 Files selected for processing (3)
  • src/main/java/io/cryostat/discovery/Discovery.java
  • src/main/webui
  • src/test/java/io/cryostat/discovery/DiscoveryPluginTest.java

Comment thread src/main/java/io/cryostat/discovery/Discovery.java
@jtolentino1

Copy link
Copy Markdown
Member Author

/build_test

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Workflow started at 8/7/2026, 5:10:19 PM. View Actions Run.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

No OpenAPI schema changes detected.

No GraphQL schema changes detected.

WebSocket notifications schema change detected:

diff --git a/schema/notifications.yaml b/schema/notifications.yaml
index b263685..bce6681 100644
--- a/schema/notifications.yaml
+++ b/schema/notifications.yaml
@@ -1081,43 +1081,39 @@ components:
             properties:
               event:
                 type: object
                 properties:
                   kind:
                     type: object
                     description: Payload of type EventKind
                   serviceRef:
                     type: object
                     properties:
-                      id:
-                        type: integer
                       connectUrl:
                         type: object
                         description: Payload of type URI
                       alias:
                         type: string
                       jvmId:
                         type: string
                       labels:
                         type: object
                         additionalProperties: true
                       annotations:
                         type: object
                         properties:
                           platform:
                             type: object
                             additionalProperties: true
                           cryostat:
                             type: object
                             additionalProperties: true
-                      agent:
-                        type: boolean
                   jvmId:
                     type: string
         required:
         - meta
         - message
     TemplateDeleted:
       name: TemplateDeleted
       title: Template Deleted
       summary: 'Notification: TemplateDeleted'
       description: WebSocket notification for Template Deleted events

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

CI build:
Integration tests pass ✅
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
https://github.com/cryostatio/cryostat/actions/runs/31218943681

@andrewazores

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
compose/auth_proxy.yml (1)

10-10: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Prefer an IP or CIDR for proxy trust when available.

Line 10 uses the Docker hostname auth. Quarkus supports hostnames, but performs DNS lookups for configured hostnames during requests and recommends IP or CIDR values instead. Use a stable proxy address or network CIDR if available. (quarkus.io)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@compose/auth_proxy.yml` at line 10, Update the
QUARKUS_HTTP_PROXY_TRUSTED_PROXIES setting to use the auth proxy’s stable IP
address or network CIDR instead of the Docker hostname “auth”, while preserving
trust for the intended proxy.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@compose/auth_proxy.yml`:
- Line 10: Update the QUARKUS_HTTP_PROXY_TRUSTED_PROXIES setting to use the auth
proxy’s stable IP address or network CIDR instead of the Docker hostname “auth”,
while preserving trust for the intended proxy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e4b57c77-27f8-4da0-bb4f-d0b31a87721a

📥 Commits

Reviewing files that changed from the base of the PR and between f3b8ea1 and 0dea158.

📒 Files selected for processing (4)
  • compose/auth_proxy.yml
  • src/main/java/io/cryostat/discovery/Discovery.java
  • src/main/java/io/cryostat/discovery/DiscoveryJwtValidator.java
  • src/test/java/io/cryostat/discovery/DiscoveryPluginTest.java
💤 Files with no reviewable changes (2)
  • src/main/java/io/cryostat/discovery/DiscoveryJwtValidator.java
  • src/main/java/io/cryostat/discovery/Discovery.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/io/cryostat/discovery/DiscoveryPluginTest.java

Comment thread compose/auth_proxy.yml
@andrewazores

Copy link
Copy Markdown
Member

@jtolentino1 ignore coderabbit's feedback on the compose auth proxy setup and using auth as the hostname. That's fine and certainly doesn't matter in smoketest.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@schema-generator/src/main/java/io/cryostat/schema/PayloadTypeAnalyzer.java`:
- Around line 430-444: Update the contextualRecord lookup in PayloadTypeAnalyzer
to resolve the matching RecordDeclaration within the field’s lexical scope,
rather than selecting the first simple-name match across the compilation unit.
Use available symbol resolution or scope-aware candidate filtering so nested
records with identical names resolve to the declaration visible from the field,
and add a regression test covering same-named nested records.

In `@src/test/java/io/cryostat/resources/AgentApplicationResource.java`:
- Around line 89-90: Update the container configuration in
AgentApplicationResource to set CRYOSTAT_AGENT_WEBSERVER_HOST to 127.0.0.1 and
configure CRYOSTAT_AGENT_CALLBACK with http://127.0.0.1:%d/. Keep API writes
enabled and preserve the existing host network and readiness-wait behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 46f62fe3-c8cc-437e-b3bd-36036d47da7f

📥 Commits

Reviewing files that changed from the base of the PR and between 0dea158 and 74e2fa8.

📒 Files selected for processing (3)
  • schema-generator/src/main/java/io/cryostat/schema/PayloadTypeAnalyzer.java
  • src/main/java/io/cryostat/discovery/DiscoveryJwtValidator.java
  • src/test/java/io/cryostat/resources/AgentApplicationResource.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/io/cryostat/discovery/DiscoveryJwtValidator.java

Comment thread schema-generator/src/main/java/io/cryostat/schema/PayloadTypeAnalyzer.java Outdated
Comment thread src/test/java/io/cryostat/resources/AgentApplicationResource.java
@jtolentino1
jtolentino1 requested a review from a team as a code owner August 10, 2026 20:30
@andrewazores

Copy link
Copy Markdown
Member

/build_test

@github-actions

Copy link
Copy Markdown

Workflow started at 8/10/2026, 4:33:32 PM. View Actions Run.

@github-actions

Copy link
Copy Markdown

No OpenAPI schema changes detected.

No GraphQL schema changes detected.

No WebSocket notifications schema changes detected.

@github-actions

Copy link
Copy Markdown

CI build:
Integration tests pass ✅
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
https://github.com/cryostatio/cryostat/actions/runs/31429583510

@github-actions

Copy link
Copy Markdown

CI build:
Unit tests pass ✅
Tests run: 722, Failures: 0, Errors: 0, Skipped: 4
https://github.com/cryostatio/cryostat/actions/runs/31429583510

@andrewazores
andrewazores merged commit 17ca85e into cryostatio:main Aug 11, 2026
17 checks passed
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.

[Bug] Discovery Plugin registration should validate that the plugin callback URL resolves to the client's address

2 participants