Skip to content

Keep the agent routes out of the API switch (forum 18241) - #1755

Merged
fog-workflows[bot] merged 3 commits into
working-1.6from
fix/agent-routes-ignore-api-switch
Sep 10, 2026
Merged

Keep the agent routes out of the API switch (forum 18241)#1755
fog-workflows[bot] merged 3 commits into
working-1.6from
fix/agent-routes-ignore-api-switch

Conversation

@mastacontrola

@mastacontrola mastacontrola commented Sep 10, 2026

Copy link
Copy Markdown
Member

Problem

With FOG_API_ENABLED off, Route::__construct() sends a 308 to management/index.php before it looks at the path. That includes /agent/v1/. No fog-agent can enroll or poll on a server with the REST API off.

Reported in forum topic 18241:

POST https://192.168.1.100/fog/agent/v1/enroll
HTTP/1.1 308 Permanent Redirect
Location: https://192.168.1.100/fog/management/index.php

That Location shape (absolute, no query) comes only from this gate. The schema redirect carries ?node=schema, and it already skips agent routes.

Workaround until this merges: turn FOG_API_ENABLED on.

Change

The API switch now skips paths under <webroot>/agent/v1/. The agent routes keep their own gate: enroll issues nothing without an approval, and every other agent route needs a certificate bound to a host.

Behavior change: with the API off, /agent/v1/ answers as it does with the API on. Every other API route still gets the 308.

Access change

This widens what is reachable when an admin has turned the API off. Enroll becomes reachable anonymously again (it still needs an approval to issue anything). A maintainer approved this.

Tests

tests/agent-routes-ignore-api-switch.test.php constructs Route in child processes with FOG_API_ENABLED=0:

Case Before After
POST /fog/agent/v1/enroll 308 not a redirect
POST /fog/agent/v1/poll 308 401 no_client_certificate
POST /fog/host 308 308
  • Against unfixed working-1.6: 3 of 4 checks fail, each with the reporter's 308. On this branch: 4 of 4 pass.
  • The first commit broke route-read-path-guards.test.php (2 of 139 failed). It rewrote the agent block's condition, and that test finds the block by that text. The second commit restores the text. It now passes 139 of 139.
  • The first two commits failed CI's phpstan tests pass (6 errors). The new test's helpers shared names with route-read-path-guards.test.php. The third commit prefixes them. Both phpstan passes are clean locally.
  • tests/run-all.sh: 355 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YBAeoaZ3a3chFAvQdfxrh7

mastacontrola and others added 3 commits September 10, 2026 10:21
With FOG_API_ENABLED off, Route answered every request with a 308 to
management/index.php before it looked at the path. That included
/agent/v1/, so no fog-agent could enroll or poll on a server with the
REST API off:

  POST https://192.168.1.100/fog/agent/v1/enroll
  HTTP/1.1 308 Permanent Redirect
  Location: https://192.168.1.100/fog/management/index.php

The setting governs the REST API that people and API tokens use. The
agent routes are FOG's client channel, like service/*.php, which the
setting never governed. They keep their own gate: enroll issues nothing
without an approval, and every other agent route needs a certificate
bound to a host.

Behavior change: with the API off, /agent/v1/ now answers as it does
with the API on. Every other API route still gets the 308.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBAeoaZ3a3chFAvQdfxrh7
route-read-path-guards.test.php finds the agent block by its
`self::AGENT_ROUTE_SEGMENT)` condition. The previous commit rewrote that
condition to reuse $isAgentRoute, so the test found no block and failed
two checks about FOG_MACHINE_REQUEST. The original text goes back; only
the API switch uses $isAgentRoute.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBAeoaZ3a3chFAvQdfxrh7
CI's phpstan tests pass analyses tests/ as one program.
route-read-path-guards.test.php already declares runChild() and child(),
so phpstan read this test's calls against those declarations and
reported six errors. The helpers are now apiSwitchRunChild() and
apiSwitchChild().

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBAeoaZ3a3chFAvQdfxrh7
@mastacontrola
mastacontrola marked this pull request as ready for review September 10, 2026 15:34
@fog-workflows
fog-workflows Bot enabled auto-merge September 10, 2026 15:35
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Sep 10, 2026
Merged via the queue into working-1.6 with commit e69ef2c Sep 10, 2026
11 checks passed
@fog-workflows
fog-workflows Bot deleted the fix/agent-routes-ignore-api-switch branch September 10, 2026 15:40
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.

1 participant