Repository navigation
Add login: unifi to roster web - #59
Merged
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 knewbasic,bearer,tokenandnone, so it silently dropped alogin: unifiservice: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 theTOKENcookie andX-CSRF-Token, then send both asheader =lines in the request's stdin config. Nothing secret goes in argv.0600file in a0700folder,$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.roster.1documents it, andtests/man_page.rslists it.New code is
src/unifi.rsplus small hooks inweb.rs(~190 lines; budget at 5035 of 10000).Tests
tests/web.rsgets 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
vsphereandopenvpnas, an error with a hint for an unknownlogin:(it's dropped silently today), andtoken_headerforbearer.