Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ ENCRYPTION_KEY=__SECRET_HEX_32__
# Larger values effectively lengthen every token's exp window — fix
# time sync first, this knob second.
# JWT_LEEWAY_SECS=10

# Extra ID-token audiences to trust, comma-separated. Leave unset unless
# your IdP puts something besides the client ID in `aud` — Zitadel, for
# one, includes the parent project ID. Unset means the stock
# `openidconnect` verifier runs untouched. Set, it widens exactly one
# check: the extra audiences on a multi-audience token are matched
# against this exact-string allowlist (no wildcards, no prefixes). The
# client ID must still appear in `aud` regardless, and any token with
# more than one audience must carry `azp` equal to the client ID.
# OIDC_ADDITIONAL_TRUSTED_AUDIENCES=my-project-id,another-trusted-aud
SERVER_HOST=0.0.0.0
GATEWAY_PORT=3000
CONSOLE_PORT=3001
Expand Down
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
Base branch: `dev`, not `main`.

GitHub pre-fills the base with this repo's default branch (`main`),
which is the release-only line — protected, linear, and tagged on every
commit. A PR opened against it will be asked to retarget. Use the "Edit"
button next to the title to switch the base to `dev`; with the CLI, pass
`--base dev`.

The only PRs that belong on `main` are the release PR (`dev` -> `main`,
titled `release: vX.Y.Z`) and a `hotfix/*` branch. See
docs/operations/release.md for the branch contract.
-->

## What this changes

<!-- One or two sentences. What behavior is different after this merges? -->

## Why

<!-- The problem, not the patch. If it fixes an issue, link it. -->

## How it was verified

<!--
What you actually ran, and what it printed. "cargo test passes" is
weaker than "the 3 new tests in crates/auth/src/oidc.rs cover the
multi-audience case; full workspace suite green".

If it touches auth, the gateway data path, audit rows, or anything that
handles a key or a token, say what you did to convince yourself it
doesn't leak or weaken a check.
-->

## Notes for review

<!-- Anything you're unsure about, deliberately left out, or want argued with. -->
49 changes: 49 additions & 0 deletions .github/workflows/pr-base-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Nudge PRs that were opened against `main` toward `dev`.
#
# GitHub pre-fills a new PR's base with the repo's default branch, which
# here is `main` — the release-only line (see docs/operations/release.md).
# A contributor following the UI therefore lands on the wrong branch by
# default, and the first signal they get today is a human asking them to
# retarget. This says it immediately instead.
#
# `pull_request_target` rather than `pull_request` because a PR from a
# fork gets a read-only token under the latter, so it could not comment
# — and a fork PR is exactly the case this exists for. That trigger runs
# with the base repository's token, so this workflow **must never check
# out or execute PR code**. It doesn't: no actions/checkout, no build,
# nothing but one API call against metadata GitHub already gave us.
name: PR base guard

on:
pull_request_target:
types: [opened, reopened]
branches: [main]

permissions:
pull-requests: write

jobs:
nudge:
runs-on: ubuntu-latest
# The two legitimate ways to target `main`: the release PR (`dev` ->
# `main`) and a hotfix branch. Everything else is a mis-targeted
# contribution.
if: >-
github.event.pull_request.head.ref != 'dev' &&
!startsWith(github.event.pull_request.head.ref, 'hotfix/') &&
!startsWith(github.event.pull_request.head.ref, 'release/')
steps:
- name: Ask for a retarget to dev
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
gh pr comment "$PR" --repo "$REPO" --body \
'Thanks for the PR. One thing before review: **this targets `main`, and it should target `dev`.**

`main` is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on `dev` and reaches `main` with the next release. GitHub pre-filled `main` here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click **Edit** next to the PR title and change the base branch to `dev`. The commits and the discussion carry over.

See [CONTRIBUTING.md](../blob/main/CONTRIBUTING.md) and [docs/operations/release.md](../blob/main/docs/operations/release.md) for the branch contract.'
84 changes: 83 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,87 @@ target.

## [Unreleased]

## [1.0.2] — 2026-09-13

The shared gateway layer moves out into its own repository, and OIDC
learns to accept an ID token whose `aud` carries more than the client
ID. Mostly a fix release otherwise — the deploy and auth items below are
the ones worth reading before you upgrade.

### Added

- **`OIDC_ADDITIONAL_TRUSTED_AUDIENCES`** — a comma-separated allowlist
of extra ID-token audiences to trust. Some IdPs put something besides
the client ID in `aud`; Zitadel includes the parent project ID, and
`openidconnect`'s stock verifier rejects every non-client-ID audience,
so login failed outright. Leave it unset and verification is
byte-for-byte what it was. Set, it widens exactly one check: the extra
audiences on a multi-audience token are matched against this list as
exact strings — no wildcards, no prefixes. The client ID must still
appear in `aud` regardless. Documented in `.env.example`. Thanks to
@DaniW42 for the report and the patch (#12).
- **Automatic upstream protocol detection** — the gateway learns an
upstream's dialect and relearns it when the upstream changes, instead
of relying on a static guess. Protocol is now a property of the route.
- **Reverse-proxy identification** — the server recognizes its own
reverse proxy, which is what makes the dashboard WebSocket and the API
docs work behind nginx.

### Changed

- **`azp` is validated whenever it is present**, per OIDC Core 3.1.3.7
step 5, which has no audience-count precondition. Previously it was
only checked when a multi-audience token made it mandatory, so a
single-audience token naming this client with `azp` pointing at a
*different* client was accepted — the IdP stating plainly that the
token was authorized for somebody else. **This can reject a token that
1.0.1 accepted.** If your IdP sets `azp` to something other than your
client ID, logins will start failing and the message will say so;
that is the IdP to fix, not this setting.
- **The shared gateway layer now comes from
[ThinkWatch-Core](https://github.com/ThinkWatchProject/ThinkWatch-Core)**
as a git dependency rather than living in this tree. Six crates —
types, protocol, provider, resilience, crypto, and the JSON secret
envelope — are one implementation shared with the desktop edition
instead of two copies drifting apart. No runtime or API change; it
affects you only if you build from source, where the build now needs
network access to resolve that dependency. The published images are
unaffected.
- **Stored secrets are redacted on read and decrypted on use.** Provider
credentials no longer travel in plaintext through code paths that
merely display or list them.

### Fixed

- **Deploy** — nginx broke the API docs three separate ways; the
dashboard WebSocket wasn't proxied; the prod stack's healthchecks were
wrong; and the dev stack could overwrite production's ClickHouse
credentials. The last one is the reason to read this list.
- **Auth** — the console logged itself out after every token refresh.
Rate-limit counters could be created without an expiry and sit in
Redis forever.
- **Models** — the gateway no longer offers models the upstream refuses,
no longer imports models it won't serve, and reports every dialect
that was refused rather than only the last. Provider `base_url`
trailing slashes are normalized.
- **Analytics** — spend is attributed to a person, not a UUID.
- **Audit** — a syslog forwarder formatting fix that had CI red on
clippy 1.98 (#11, thanks @DaniW42). Two more instances of the same
lint, plus a `result_large_err` false positive in the MCP lifecycle
stages, measured rather than boxed: the `Ok` variant is 296 bytes
against the `Err`'s 152, so boxing saves nothing and adds an
allocation.
- **UI** — the brand mark stays inside the collapsed sidebar rail.

### Contributing

`CONTRIBUTING.md` and a PR template now state the branch contract that
had only lived in `docs/operations/release.md`: routine work targets
`dev`, and `main` is the release line. A workflow comments on PRs opened
against `main` from anything other than `dev` or a `hotfix/*` branch,
because GitHub pre-fills the base with the default branch and walks
contributors into it.

### Added
- _(nothing yet)_

Expand Down Expand Up @@ -139,7 +220,8 @@ unreleased builds should: stop the gateway, run `db/schema.sql`
against PostgreSQL, restart against this tag. The schema is
idempotent end-to-end, so the apply is safe to repeat.

[Unreleased]: https://github.com/ThinkWatchProject/ThinkWatch/compare/v1.0.1...HEAD
[Unreleased]: https://github.com/ThinkWatchProject/ThinkWatch/compare/v1.0.2...HEAD
[1.0.2]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v1.0.2
[1.0.1]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v1.0.1
[1.0.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v1.0.0
[0.5.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v0.5.0
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Contributing to ThinkWatch

Thanks for taking the time. This file covers the two things that most
often need a second round on a PR: **which branch to target** and **what
"verified" means here**.

## Open PRs against `dev`

```bash
gh pr create --base dev --head your-branch
```

`main` is a release-only line: branch-protected, linear history, no
force-push, and every commit on it is a release snapshot that gets
tagged immediately. `dev` is where everything routine lands — features,
fixes, refactors, dependency bumps.

GitHub pre-fills a new PR's base with the repo's default branch, which
is `main`, so **the default is not the one you want**. If you've already
opened against `main`, no need to close anything: click *Edit* next to
the PR title and change the base to `dev`. A bot will remind you.

Two exceptions, both maintainer-only: the release PR (`dev` → `main`,
titled `release: vX.Y.Z`) and a `hotfix/*` branch when `dev` has
diverged too far to carry a fix cleanly. The full branch contract is in
[docs/operations/release.md](docs/operations/release.md).

Automation follows the same rule — Renovate is pinned to `dev` via
`baseBranches` in `renovate.json`.

## Commit messages

Conventional Commits (`fix(scope): subject`), because `git-cliff`
renders the CHANGELOG from them and `chore(release):` is the prefix it
skips. Write them in **English**; this is a public repository and the
history is documentation.

Say *why* in the body, not just *what* — the diff already shows what
changed. A commit that explains the reasoning behind a non-obvious
choice saves the next person from re-deriving it or "fixing" it back.

## What CI will check

```bash
make precommit
```

That is the same gate CI runs, and it exits 0 on a clean tree. Two
required status checks: `Rust Check & Test` and `Frontend Build`.

Warnings are errors — `clippy -D warnings` across the workspace, all
targets. Note that the toolchain is `stable`, so a newer stable than
your local one can surface lints you can't see; `rustup update stable`
before blaming CI.

## Security-relevant changes

If a change touches authentication, the gateway data path, audit rows,
redaction, or anything that handles a key or a token, the PR description
should say how you convinced yourself it doesn't leak a credential or
weaken an existing check. "The tests pass" doesn't answer that — the
tests didn't know about the hole either.

Please don't open a public PR or issue for a vulnerability. See
[SECURITY.md](SECURITY.md) if present, or contact the maintainer
directly.
Loading
Loading