Skip to content

Roles can limit the networks their members use the web UI and API from - #2109

Merged
fog-workflows[bot] merged 2 commits into
dev-branchfrom
feat/role-ui-networks
Nov 18, 2026
Merged

fog-workflows[bot] merged 2 commits into
dev-branchfrom
feat/role-ui-networks

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

For #2107.

What changes

A role gets an Allowed Networks field: addresses and CIDR ranges, IPv4 or IPv6, separated by commas, spaces, or new lines. If any role a user holds has a list, that user can sign in to the web UI and use the REST API only from an address in the union of those lists. A role with no list does not lift another role's limit. If no role has a list, nothing changes. That is every existing install.

Not limited: the iPXE menu login, the advanced menu login, and FOS checkcredentials.php. A technician can still start a task from the boot menu on any network, which is the point of the issue.

Behavior to know about

  • The REST API is limited too. User tokens, Bearer tokens, and basic auth from an address outside the list get a 403. Without this, a technician blocked from the UI could do the same work through the API. Scripts and service accounts that hold a limited role are refused outside its networks.
  • The source address is the connecting address only (REMOTE_ADDR). X-Forwarded-For is never read, because the caller writes it. Behind a reverse proxy every request carries the proxy's address, so the feature cannot tell users apart there. The help text on the field says so.
  • Loopback gets no exception. A reverse proxy on the FOG server makes every request arrive from 127.0.0.1. An always-allowed loopback would then pass everyone, silently. A role that must allow the server itself lists 127.0.0.1.
  • Lockout: saving a role is refused when the new list would lock out the user making the change. Recovery from any other lockout is another unrestricted administrator, or clearing roles.rAllowedNetworks in the database. Adding yourself to a limited role from outside its networks is not guarded.
  • Existing sessions are re-checked on every request. A role edited while its members are signed in takes effect on their next request.
  • An existing session of an account marked API-only now ends on its next request. Before, it kept working until it timed out: _isLoggedIn() refused it, but most callers ignore that return. This is the same gap the network check had, on the same call path.
  • A remember-me cookie is now issued only after the sign-in is accepted. A refused sign-in leaves no userAuths row behind.
  • An unrestricted administrator can still impersonate a restricted user from any address. The administrator's own roles are what get checked.

How

Gate Covers
User::establishSession() A new sign-in from any provider: the password form or OIDC. The check runs after the FOGUser rebind, so it tests the account the session is stamped with.
LoadGlobals An existing session, on every request. This covers the UI, AJAX, and REST calls made with a session.
User::_isLoggedIn() plus ProcessLogin The remember-me replay. ProcessLogin now unbinds the cookie's account when isLoggedIn() refuses it. Before, the page rendered anyway, because the pages test only isValid().
Route Token, Bearer, and basic-auth API clients.

passwordValidate() and authenticate() deliberately carry no network check, because iPXE and FOS share them.

Schema 461 adds roles.rAllowedNetworks varchar(2048). OpenAPI needs no hand edit: the field is in $databaseFields and the manifest, and every operation already documents a generic 403.

Tests

  • tests/role-allowed-networks.test.php has 48 checks. The list parser, the matcher, networkAllows(), and the shared session test sessionPermittedHere() all run. The gate placements are checked against the source. I made the test fail on purpose by removing the LoadGlobals gate, the ProcessLogin unbind, and the network clause in turn, and each removal turned it red.
  • tests/api-only-users.test.php now pins the API-only refusal through the shared session test.
  • tests/fixtures/route-column-contract.txt gains the new role column.

🤖 Generated with Claude Code

Issue #2107. A role gets an Allowed Networks list (addresses and CIDR
ranges, IPv4 and IPv6). A user whose roles carry lists may sign in to
the web UI and use the REST API only from an address in the union of
those lists. A role with no list does not lift another role's limit.
Empty everywhere means no restriction, which is every existing install.

The iPXE menu login, the advanced menu, and FOS checkcredentials are
not limited: they prove the credential through passwordValidate() /
authenticate(), which carry no network check, so a technician can still
start a task from the boot menu on any network.

Gates:
- establishSession(): a new sign-in, any provider. After the FOGUser
  rebind, so it tests the account the session is stamped with.
- LoadGlobals: an existing session, on every request. Nothing
  downstream re-checked the account, so a session (or a replayed
  session cookie) kept working from anywhere. This also drops an
  existing session of an account marked API-only, which had the same
  gap.
- _isLoggedIn() plus ProcessLogin: the remember-me replay. ProcessLogin
  now unbinds the cookie's account when isLoggedIn() refuses it; before,
  the pages rendered anyway, because they test only isValid().
- Route: token, Bearer and basic-auth API clients get 403.

validatePw() now mints the remember-me cookie only after
establishSession() accepts the sign-in, so a refused sign-in leaves no
userAuths row behind.

REMOTE_ADDR only, never X-Forwarded-For. Loopback gets no exception: a
reverse proxy on the server would make every request loopback and the
limit would silently pass everyone. Role::save() refuses an edit that
would lock out the user making it.

Schema 461 adds roles.rAllowedNetworks varchar(2048).

OpenAPI: no hand edit. The new role field is in $databaseFields and the
manifest, so _entitySchema() emits it. The new 403 on the token paths is
covered by the generic '403' response every operation already
documents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot enabled auto-merge November 18, 2026 16:11
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Nov 18, 2026
Merged via the queue into dev-branch with commit 3eb30b1 Nov 18, 2026
11 checks passed
@fog-workflows
fog-workflows Bot deleted the feat/role-ui-networks branch November 18, 2026 16:23
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