Skip to content

Add login: unifi to roster web - #59

Merged
2styx2 merged 1 commit into
devfrom
feat/web-unifi-login
Nov 17, 2026
Merged

2styx2 merged 1 commit into
devfrom
feat/web-unifi-login

Conversation

@2styx2

@2styx2 2styx2 commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Why

UniFi OS consoles log in with a session cookie and a CSRF token, not a header. The Python roster had login: unifi. roster-rs only knew basic, bearer, token and none, so it silently dropped a login: unifi service: roster web HOST GET /... said "has no web service", and agents had to fall back to driving the web UI in a browser.

What

  • login: unifi: POST {username, password, rememberMe: false} to /api/auth/login (stdin config, -D - for the headers). Take the TOKEN cookie and X-CSRF-Token, then send both as header = lines in the request's stdin config. Nothing secret goes in argv.
  • The session is kept for up to 10 minutes in a 0600 file in a 0700 folder, $XDG_RUNTIME_DIR/roster/sessions/HOST-SERVICE.json (else ~/.cache). A file others can read is removed and not used. When a kept session gets a 401, roster logs in again and retries once, printing only the second reply.
  • HTTP 429 says "too many logins" with a hint.
  • roster.1 documents it, and tests/man_page.rs lists it.

New code is src/unifi.rs plus small hooks in web.rs (~190 lines; budget at 5035 of 10000).

Tests

tests/web.rs gets five new tests: login then kept session, 401 relogin, the XDG path and private-mode check, 429 and missing-cookie refusals, and that no secret reaches argv, env, output or other files. Also checked by hand with read-only GETs against a real console.

Next

vsphere and openvpnas, an error with a hint for an unknown login: (it's dropped silently today), and token_header for bearer.

UniFi OS consoles log in with a session cookie, not a header, so
`roster web` couldn't reach them and dropped any service with
`login: unifi` (which the Python roster had). roster now POSTs the
Login to /api/auth/login, takes the TOKEN cookie and X-CSRF-Token from
the reply's headers (curl -D -), and sends both in the stdin config.

The session is kept up to 10 minutes in a 0600 file under
$XDG_RUNTIME_DIR/roster/sessions (or ~/.cache), so a loop of calls
logs in once instead of hitting the console's 429 limit. A kept
session the console answers with 401 logs in again and retries once.
HTTP 429 now says "too many logins" with a hint.
@2styx2
2styx2 merged commit 9386893 into dev Nov 17, 2026
16 checks passed
@2styx2 2styx2 mentioned this pull request Nov 17, 2026
@2styx2
2styx2 deleted the feat/web-unifi-login branch November 17, 2026 21:56
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