Skip to content

feat: add HTTP Basic Auth for nginx reverse proxies - #171

Open
TimeToBuildBob wants to merge 6 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/basic-auth-carry
Open

TimeToBuildBob wants to merge 6 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/basic-auth-carry

Conversation

@TimeToBuildBob

@TimeToBuildBob TimeToBuildBob commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Carry of #127 onto current master, with credit to @liv10let.

The original replaced aw-client's private _get/_post/_delete. That matches locked aw-client 0.5.14, but would drop API-key headers and the loopback proxy bypass on current aw-client master. This injects auth=(user, password) on the client module's requests calls so whichever kwargs the installed client already sends are preserved.

[aw-watcher-window]
auth_user = "username"
auth_password = "password"

Also:

  • Refuse the default macOS swift strategy (heartbeats come from a separate binary with no auth) — same fail-closed pattern as privacy_filter
  • Refuse combining Basic auth with a server API key (both use Authorization)
  • Do not author auth_user/auth_password into the first-run config template
  • --auth-password is visible in the process list; prefer the TOML config
  • An empty password (auth_password = "") is honoured, not treated as "unset" — None means unset

Verification (2026-11-07, Linux)

Live nginx auth_basic reverse proxy in front of a real aw-server v0.14.1 (isolated --profile, port 5666; nginx on 5667 with an htpasswd file). Three legs:

  1. The proxy really enforces auth. GET /api/0/info → 401 with no credentials, 401 with a wrong password, 200 with correct ones.
  2. The patch is what authenticates. The same aw_client.ActivityWatchClient write path fails with 401 without _enable_basic_auth(...) and succeeds with it — bucket created, heartbeat posted, event read back through the authenticated proxy.
  3. A real watcher process works end to end. xvfb-run .venv/bin/python -m aw_watcher_window --host 127.0.0.1 --port 5667 --auth-user alice --auth-password secret logs HTTP Basic Auth enabled for user: alice, then POST /api/0/buckets/aw-watcher-window_bob → 200 and heartbeats → 200, with nginx's access log showing the authenticated requests and the bucket present on the server.

Unit coverage: 214 passed, 6 skipped; mypy aw_watcher_window/ --ignore-missing-imports clean on 16 source files (the CLI itself is exercised by make test). Both Greptile P2s from the earlier head are addressed: empty passwords no longer disable auth, and the auth tests restore the patched request methods instead of leaking them to later tests.

Rebased onto master (now includes the CI Ubuntu 24.04 pin and the repeatable --exclude-* flags).

Scope

Watcher-local, not first-class aw-client support. That is the only option available today: aw-client master has no Basic Auth support and no open issue or PR for one — its only Authorization use is the local server API key, and the two are mutually exclusive on that header (handled by the refusal above).

Does not merge or close #127; that disposition is #127's own.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

Adds HTTP Basic Auth options for nginx reverse proxies without replacing the client’s HTTP methods.

  • The watcher sends Basic Auth to its configured ActivityWatch server.

No new actionable issues were found. The supplied previous threads are unnumbered, so they have no numbered ledger entries. Tests were inspected, not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Load auth settings] --> B{Auth configured?}
    B -->|No| F[Start watcher normally]
    B -->|Yes| C{Swift strategy or API-key conflict?}
    C -->|Yes| D[Exit with an error]
    C -->|No| E[Wrap client HTTP calls]
    E --> G{Origin and path match?}
    G -->|Yes| H[Attach Basic Auth]
    G -->|No| I[Leave request unchanged]
Loading

Reviews (3) · Last reviewed commit: "fix(auth): scope Basic Auth to the confi..." · Reviewed by Greptile

Comment thread aw_watcher_window/main.py Resolved
Comment thread tests/test_main.py Resolved
TimeToBuildBob and others added 2 commits November 7, 2026 12:46
Adapt ActivityWatch#127 onto current master without
replacing aw-client HTTP methods. Inject auth on the client module's
requests calls so 0.5.14 and current master (API-key headers, loopback
proxy bypass) both keep their kwargs. Refuse the default macOS swift
strategy, which cannot attach credentials, and refuse combining Basic
auth with a server API key. Keep secrets out of the first-run config
template.

Co-Authored-By: Violet Evergarden <2929724643@qq.com>
Git-Session-Id: c21445f7-1f56-4701-aecd-76f905f63912
Git-Session-Id: 896b30ad-dd9a-559f-be4d-516e4c4aa070
@TimeToBuildBob
TimeToBuildBob marked this pull request as ready for review November 7, 2026 12:50
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Adds auth_user and auth_password configuration values and corresponding CLI flags. Adds _auth_configured() and _enable_basic_auth() in main.py, wrapping Requests calls to attach credentials for matching server URLs and reject redirects. Startup rejects Basic Auth combined with a server API key or the macOS swift strategy, and new tests exercise configuration, credential scoping, redirects, and reconfiguration.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (4) — the diff as I read it
  • aw_watcher_window/config.py — Reads optional auth_user and auth_password configuration values and adds --auth-user and --auth-password arguments.
  • aw_watcher_window/main.py — Adds Basic Auth configuration detection, scoped Requests wrappers, redirect rejection, and startup checks for API-key conflicts and the macOS swift strategy.
  • tests/test_config.py — Adds tests for auth keys remaining absent from the initial template, configured passwords including empty strings, and CLI overrides.
  • tests/test_main.py — Adds tests for auth detection, strategy restrictions, request argument preservation, credential scoping, redirects, reconfiguration, API-key conflicts, and monkeypatch teardown.
Previous review passes
commit score findings engine when
a4caf1320dc0 3/5 1 subscription 2026-11-07 13:02 UTC
c23b876fc698 3/5 2 subscription 2026-11-07 13:11 UTC
03d577786d40 3/5 1 panel 2026-11-07 13:26 UTC

Reviewed a68f99871277 · panel: codex:gpt-6.1-sol · subscription engine · 41s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

Comment thread aw_watcher_window/main.py Resolved
Git-Session-Id: cfbdd79b-4769-5866-a6cd-39e8e2d08a93
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread aw_watcher_window/main.py Resolved
Git-Session-Id: bcaf3f21-fecb-5b96-9860-8826b07cbfc2
Git-Session-Id: bcaf3f21-fecb-5b96-9860-8826b07cbfc2
Comment thread aw_watcher_window/main.py Resolved
Git-Session-Id: bcaf3f21-fecb-5b96-9860-8826b07cbfc2
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