Skip to content

Harden CRC daemon REST API - #5462

Open
redbeam wants to merge 3 commits into
crc-org:mainfrom
redbeam:api-hardening
Open

redbeam wants to merge 3 commits into
crc-org:mainfrom
redbeam:api-hardening

Conversation

@redbeam

@redbeam redbeam commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5459

Requires crc-org/routes-controller#65

Changes:

The daemon served the full gvisor-tap-vsock API (vn.Mux()) without authentication on 192.168.127.254:80. Any process in the VM, including any container, could reach it through host.crc.testing and, besides managing port forwards:

  • overwrite DNS zones such as crc.testing. and apps-crc.testing.
  • attach to the virtual switch through /connect
  • open connections through /tunnel
  • read stats, the switch CAM table and DHCP leases

Serve vn.GatewayMux() instead, which only exposes the forwarder /all, /expose and /unexpose endpoints. crc itself sets up port forwards from the host through /network/ on the daemon socket, which is unchanged.

The forwarder endpoints on 192.168.127.254:80 accepted requests from any process in the VM. Pass the REST API token to the virtual network with SetAPIToken() before calling GatewayMux(), so that /all, /expose and /unexpose require the same Authorization: Bearer header as the /hosts endpoints on the gateway. Requests without it, or with a
wrong token, get 401.

routes-controller in existing bundles doesn't send the token yet, so its NodePort forwarding stops working until it is updated to read CRC_REST_API_TOKEN and send it on expose and unexpose.

The virtual network DNS server lets /services/dns/add merge records into an existing zone or replace its default IP. None of the zones crc configures were marked as protected, so anyone who could reach the API could point api.crc.testing, api-int.crc.testing or every *.apps-crc.testing name at another address.

Mark apps-crc.testing., crc.testing., containers.internal. and docker.internal. as Protected, so gvisor-tap-vsock rejects any attempt to modify them through the API. The API is no longer reachable from the VM, so this is defense in depth for the host-side /network/ endpoint and for any future change that exposes the DNS API again.

Summary by CodeRabbit

  • Security
    • Built-in DNS zones are protected from modification.
    • The host network API requires a valid bearer token for forwarding endpoints.
    • The API now serves forwarding endpoints rather than the full virtual network interface.

The daemon served the full gvisor-tap-vsock API (vn.Mux()) without
authentication on 192.168.127.254:80. Any process in the VM, including
any container, could reach it through host.crc.testing and, besides
managing port forwards:

- overwrite DNS zones such as crc.testing. and apps-crc.testing.
- attach to the virtual switch through /connect
- open connections through /tunnel
- read stats, the switch CAM table and DHCP leases

Serve vn.GatewayMux() instead, which only exposes the forwarder /all,
/expose and /unexpose endpoints. crc itself sets up port forwards from
the host through /network/ on the daemon socket, which is unchanged.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: Matus Skvarla <mskvarla@redhat.com>
The forwarder endpoints on 192.168.127.254:80 accepted requests from
any process in the VM. Pass the REST API token to the virtual network
with SetAPIToken() before calling GatewayMux(), so that /all, /expose
and /unexpose require the same Authorization: Bearer <token> header as
the /hosts endpoints on the gateway. Requests without it, or with a
wrong token, get 401.

routes-controller in existing bundles doesn't send the token yet, so
its NodePort forwarding stops working until it is updated to read
CRC_REST_API_TOKEN and send it on expose and unexpose.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: Matus Skvarla <mskvarla@redhat.com>
The virtual network DNS server lets /services/dns/add merge records
into an existing zone or replace its default IP. None of the zones crc
configures were marked as protected, so anyone who could reach the API
could point api.crc.testing, api-int.crc.testing or every
*.apps-crc.testing name at another address.

Mark apps-crc.testing., crc.testing., containers.internal. and
docker.internal. as Protected, so gvisor-tap-vsock rejects any attempt
to modify them through the API. The API is no longer reachable from the
VM, so this is defense in depth for the host-side /network/ endpoint
and for any future change that exposes the DNS API again.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: Matus Skvarla <mskvarla@redhat.com>
@openshift-ci

openshift-ci Bot commented Nov 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign anjannath for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The daemon now protects four built-in DNS zones. The host virtual-IP API passes its REST API token to networkAPIMux and serves vn.GatewayMux(). Tests cover protected-zone modification, endpoint routing, and bearer-token authentication.

Changes

Daemon DNS and API hardening

Layer / File(s) Summary
Protect built-in DNS zones
cmd/crc/cmd/daemon.go, cmd/crc/cmd/daemon_test.go
The apps-crc.testing., crc.testing., containers.internal., and docker.internal. zones are marked protected. Tests check that generated zones are protected and that POST requests cannot modify built-in zones.
Serve authenticated forwarder endpoints
cmd/crc/cmd/daemon.go, cmd/crc/cmd/daemon_test.go
The host virtual-IP server passes the REST API token to networkAPIMux. That mux sets the token on the virtual network and serves vn.GatewayMux(). Tests check forwarder routing and rejection of missing, invalid, or non-Bearer credentials.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant HostVirtualIPServer
  participant networkAPIMux
  participant GatewayMux
  participant HostVM
  HostVirtualIPServer->>networkAPIMux: pass REST API token
  networkAPIMux->>GatewayMux: set token and serve gateway mux
  HostVM->>networkAPIMux: request forwarder endpoint
  networkAPIMux->>GatewayMux: dispatch request
  GatewayMux-->>HostVM: return endpoint response or 401
Loading

Suggested reviewers: praveenkumar, evidolob

Merge Risk: Minimal · up to 7c1fb

The change restricts the host virtual-IP API to the forwarder endpoints and requires a bearer token on them, and it protects the built-in DNS zones. The PR notes that existing bundles whose routes-controller does not send the token will lose NodePort forwarding until that component is updated. This is a documented, intentional rollout step. No unresolved defect remains in the reviewed code.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Harden CRC daemon REST API" is short and specific. It names the main change: the daemon's virtual network API is restricted to forwarder endpoints, protected DNS zones are added, and the to…
Linked Issues check Passed Issue #5459 (direct) asks that the gvisor-tap-vsock REST API hardening be carried over to the crc daemon. It sets no further acceptance criteria. Evidence in cmd/crc/cmd/daemon.go at head:
- networkAP…
Out of Scope Changes check Passed All production changes are in cmd/crc/cmd/daemon.go and their tests are in cmd/crc/cmd/daemon_test.go. Each change maps to the hardening request in #5459:
- Protected flags on the four DNS zones.
- Sw…
Description check Passed The description follows the repository template and explains the change clearly. It links the issue (Fixes #5459) and names the dependency on routes-controller PR #65. It describes the problem, the fi…
Full details: Title check

Explanation

The title "Harden CRC daemon REST API" is short and specific. It names the main change: the daemon's virtual network API is restricted to forwarder endpoints, protected DNS zones are added, and the token is enforced. It is related to the changeset and matches the linked objective of hardening the daemon API.

Full details: Linked Issues check

Explanation

Issue #5459 (direct) asks that the gvisor-tap-vsock REST API hardening be carried over to the crc daemon. It sets no further acceptance criteria. Evidence in cmd/crc/cmd/daemon.go at head:

  • networkAPIMux now calls vn.SetAPIToken(restAPIToken) and serves vn.GatewayMux() instead of vn.Mux(). Only /all, /expose and /unexpose remain on 192.168.127.254:80. The previous code exposed the full API.
  • The apps-crc.testing., crc.testing., containers.internal. and docker.internal. zones are marked Protected: true in createNewVirtualNetworkConfig.
  • The /network/ host-side endpoint and the /connect path (vsockListener) keep their existing behavior, as the PR description states.
    The change set includes tests (cmd/crc/cmd/daemon_test.go, per the change summary) for protected zones, endpoint restriction and bearer token rejection. Test contents were not inspected in this review. The requirement is coding-only and the implementation is present at head.
Full details: Out of Scope Changes check

Explanation

All production changes are in cmd/crc/cmd/daemon.go and their tests are in cmd/crc/cmd/daemon_test.go. Each change maps to the hardening request in #5459:

  • Protected flags on the four DNS zones.
  • Switch from vn.Mux() to vn.GatewayMux() with SetAPIToken for the host virtual IP API.
  • Updated comments that describe the API's reachability and token requirement.
    The PR description notes that routes-controller in existing bundles does not send CRC_REST_API_TOKEN, so its NodePort forwarding fails until updated. This is a direct consequence of the requested hardening and is disclosed by the author. It is not an unrelated change. The diff was not checked against the vendored gvisor-tap-vsock source for SetAPIToken or GatewayMux, but those calls belong to the in-scope API change.
Full details: Description check

Explanation

The description follows the repository template and explains the change clearly. It links the issue (Fixes #5459) and names the dependency on routes-controller PR #65. It describes the problem, the fix (serving vn.GatewayMux() instead of vn.Mux(), requiring the REST API bearer token on forwarder endpoints, and marking four DNS zones as Protected), and the compatibility impact on existing routes-controller bundles. Gaps: the 'Type of change' checkboxes are not ticked, the 'Testing' section is missing (it has no verifiable test steps), and the contribution checklist is not filled in, including the platform tested. These are important gaps, but the core content is present.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit hops beside the zone,
Four DNS names are guarded now.
A token rides the gateway path,
Forwarder routes answer in turn,
My paws applaud the tests that check.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0f80608-cfd7-4db7-a8ae-faa5b5bac8a2
Commits

Reviewing files that changed from the base of the PR and between d937281 and 7c1fbd1.

Files selected for processing: 2

  • cmd/crc/cmd/daemon.go
  • cmd/crc/cmd/daemon_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@openshift-ci

openshift-ci Bot commented Nov 12, 2026

Copy link
Copy Markdown

@redbeam: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-crc 7c1fbd1 link true /test e2e-crc

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crc daemon API hardening

1 participant