Skip to content

Commit 70585b1

Browse files
authored
release: v2.2.0
See CHANGELOG.md [2.2.0].
1 parent e7504ba commit 70585b1

26 files changed

Lines changed: 1945 additions & 245 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,197 @@ target.
1111

1212
## [Unreleased]
1313

14+
## [2.2.0] — 2026-10-01
15+
16+
This release fixes authorization. The gateways never checked
17+
`ai_gateway:use` or `mcp_gateway:use`, so a user with no role, or with
18+
only roles that grant neither, could call every model and MCP tool; a
19+
role granted at the scope of one team widened model and tool access
20+
platform-wide; and an API key whose allow-list came out empty could
21+
call any model. The gateways now require the permission and count only
22+
the roles that grant it. The seeded `team_manager` role now works when
23+
granted at team scope, and seven permissions that nothing ever checked
24+
are retired. Some users lose gateway access on upgrade: read the first
25+
section before deploying. There is one manual database script and no
26+
schema, setting, environment variable or Helm value change.
27+
28+
### Read before upgrading
29+
30+
- **Users without a role that grants gateway use lose gateway access.**
31+
A request to the AI gateway is refused with `403` unless a role held
32+
by the key's owner grants `ai_gateway:use`, and a request to the MCP
33+
gateway unless one grants `mcp_gateway:use`. The body names the
34+
missing permission, in the error format of the caller's API. The
35+
built-in `developer`, `admin`, `super_admin` and `team_manager` roles
36+
grant both; `viewer` grants neither. Three groups of users are
37+
refused after the upgrade where 2.1.0 let them through:
38+
- users with no role at all;
39+
- users whose roles are only `viewer`, or custom roles without these
40+
actions;
41+
- users whose only gateway role is assigned at team scope (see the
42+
third item below).
43+
44+
Find them before upgrading. This query lists every active user with a
45+
live key for a gateway that none of their roles will grant (it counts
46+
global assignments and roles attached to the user's teams, which is
47+
what the gateways now read; it does not account for `Deny`
48+
statements):
49+
50+
```sql
51+
WITH grants AS (
52+
SELECT id AS role_id,
53+
jsonb_path_exists(policy_document,
54+
'$.Statement[*] ? (@.Effect == "Allow").Action[*] ? (@ == "*" || @ == "ai_gateway:*" || @ == "ai_gateway:use")') AS ai,
55+
jsonb_path_exists(policy_document,
56+
'$.Statement[*] ? (@.Effect == "Allow").Action[*] ? (@ == "*" || @ == "mcp_gateway:*" || @ == "mcp_gateway:use")') AS mcp
57+
FROM rbac_roles
58+
),
59+
held AS (
60+
SELECT user_id, role_id FROM rbac_role_assignments WHERE scope_kind = 'global'
61+
UNION
62+
SELECT tm.user_id, tra.role_id
63+
FROM team_members tm JOIN team_role_assignments tra USING (team_id)
64+
),
65+
access AS (
66+
SELECT h.user_id, bool_or(g.ai) AS ai, bool_or(g.mcp) AS mcp
67+
FROM held h JOIN grants g USING (role_id) GROUP BY h.user_id
68+
)
69+
SELECT u.email, s.surface
70+
FROM api_keys k
71+
JOIN users u ON u.id = k.user_id
72+
CROSS JOIN LATERAL unnest(k.surfaces) AS s(surface)
73+
LEFT JOIN access a ON a.user_id = u.id
74+
WHERE k.is_active AND k.deleted_at IS NULL
75+
AND u.is_active AND u.deleted_at IS NULL
76+
AND NOT COALESCE(CASE s.surface WHEN 'ai_gateway' THEN a.ai
77+
WHEN 'mcp_gateway' THEN a.mcp END, false)
78+
GROUP BY u.email, s.surface
79+
ORDER BY u.email, s.surface;
80+
```
81+
82+
Give each of them `developer` (or a custom role with the actions)
83+
either at global scope (Users → edit the user's roles, scope
84+
*Global*), or by attaching the role to a team they belong to (Teams →
85+
the team → Roles), which every member of that team inherits. The
86+
change takes effect within a minute; each user's permissions are
87+
cached for 60 seconds.
88+
89+
If SSO users are meant to use the gateway from their first sign-in,
90+
set *Default Role for New Users* (`auth.default_role`) in Settings to
91+
`developer`. It is empty by default, and it applies only to accounts
92+
created after it is set; existing users need the grant above.
93+
- **A role that does not grant gateway use no longer widens model or
94+
tool access.** Model and MCP tool scopes are now the union over the
95+
roles that grant `ai_gateway:use` / `mcp_gateway:use` only. A role
96+
without those actions (such as `viewer`) used to count as
97+
"unrestricted", so adding it to a user limited to some models opened
98+
every model to them. Users relying on that lose the extra models.
99+
- **A role assigned at team scope no longer grants gateway access.** An
100+
assignment with scope `team:<id>` administers that team from the
101+
console (team roster, team limits); it no longer contributes models,
102+
MCP tools or gateway use, which it used to do for every request the
103+
user made, member of the team or not. Roles attached to a team itself
104+
(Teams → Roles), which every member inherits, still count. A user
105+
whose only gateway role was a team-scoped `developer` or
106+
`team_manager` needs that role at global scope, or attached to their
107+
team. The role assignment editor now says this under the scope
108+
picker.
109+
- **An empty model allow-list allows nothing.** A key whose
110+
`allowed_models` is `[]`, or whose list shares no model with what its
111+
owner's roles grant, used to call any model; it now calls none, as
112+
`allowed_mcp_tools: []` already did on the MCP gateway. The console
113+
never saves `[]` (clearing the picker sends `null`), so only keys
114+
written through the API are affected. To find them:
115+
`SELECT id, name, user_id FROM api_keys WHERE allowed_models = '{}' AND is_active AND deleted_at IS NULL;`
116+
Set such a key's list to `null` to leave it bounded by its owner's
117+
roles only. Model entries still match by prefix, and a key narrowed to
118+
`gpt-4o-mini` under a role granting `gpt-4o` keeps `gpt-4o-mini`.
119+
- **Run `db/release_migrations/2026-09-30_retire_unchecked_permissions.sql`
120+
once, after deploying.** The server does not apply it. It adds
121+
`teams:read` to the `team_manager` role and removes the seven retired
122+
permissions (see *Changed*) from every role, system and custom. It is
123+
idempotent and changes no access for any other role, since nothing
124+
checked the removed keys. Without it, the server still starts and
125+
works, but:
126+
- `team_manager` keeps the old `team:read` it cannot use, so a team
127+
manager who is not a member of the team they manage still gets
128+
`403` opening it, its roster or its roles;
129+
- every start logs a warning listing the roles that still name
130+
retired permissions.
131+
132+
*Reset to defaults* on a system role in the console has the same
133+
effect for that one role, but does not clean custom roles.
134+
- **A team-scoped `rate_limits:write` now takes effect.** It used to
135+
require global scope for every subject, so the seeded `team_manager`
136+
granted at team scope could not touch any limit. It now covers the
137+
rate limits and budget caps of users in that team and of the API keys
138+
they own, never the holder's own user or keys; role subjects still
139+
need global scope. Anyone holding `team_manager` (or a custom role
140+
with `rate_limits:write`) at team scope can now change, lift or
141+
delete the limits of every member of that team, administrators
142+
included. Review team-scoped assignments of these roles before
143+
upgrading.
144+
145+
### Security
146+
147+
- **Gateway use is checked, and a missing grant means no access.** See
148+
the first three items above: a user with no role, or only roles
149+
without gateway use, could call every model and MCP tool; a
150+
`viewer`-style role widened a restricted user to every model; a role
151+
granted at the scope of any team, even one the user was not a member
152+
of, widened model and tool access platform-wide. An explicit `Deny`
153+
on `ai_gateway:use` or `mcp_gateway:use` now closes that gateway.
154+
Action wildcards (`ai_gateway:*`, `*`) grant it, as they already did
155+
for console permissions.
156+
- **A key narrowed inside a prefix grant is no longer unrestricted.**
157+
The key's allow-list was intersected with its owner's role grants
158+
entry by entry, as literal strings. A key limited to `gpt-4o-mini`
159+
under a role granting `gpt-4o` (a prefix) came out with an empty list,
160+
which the gateway read as "no restriction", so the key could call
161+
every model. The intersection now keeps an entry of either side that
162+
the other side covers, by prefix for models and by `<server>__*`
163+
pattern for MCP tools, and an empty result allows nothing.
164+
165+
### Fixed
166+
167+
- **The seeded `team_manager` role works at team scope.** It granted
168+
`team:read`, but the team handlers check `teams:read`, so a team
169+
manager got `403` listing teams and opening the team, its roster or
170+
its roles. It now grants `teams:read`, and opening a team accepts
171+
`teams:read` scoped to that team, where it used to require global
172+
scope. Existing installations need the release migration above.
173+
- **Bulk disable and delete work on API keys' limits.** The bulk
174+
disable and delete routes for rate-limit rules and budget caps
175+
rejected every row stored for an API key (`api_key_lineage`, the kind
176+
a key's limits are stored under) as an unknown subject kind.
177+
- **The console's effective-permissions preview shows real gateway
178+
access.** It now counts only roles that grant gateway use and skips
179+
team-scoped assignments, as the gateways do, where it used to count
180+
every assigned role.
181+
182+
### Changed
183+
184+
- **Seven permissions that nothing checked are retired**: `team:read`,
185+
`team:write`, `logs:read_own`, `logs:read_team`,
186+
`audit_logs:read_own`, `audit_logs:read_team` and
187+
`audit_logs:read_all`. Every log endpoint, audit logs included, is
188+
gated on `logs:read_all` at global scope, and no own- or team-filtered
189+
log view exists, so these grants never did anything. They are gone
190+
from the permission catalog, the role editor and the seeded roles.
191+
Roles that still name them load, and the server logs a warning at
192+
start instead of refusing to boot.
193+
- **Deleting one rate-limit rule or budget cap is bound to the subject
194+
in the path.** `DELETE` on
195+
`/api/admin/limits/{kind}/{id}/rules/{rule_id}` and
196+
`/api/admin/limits/{kind}/{id}/budgets/{cap_id}` now answers `404` when the rule or cap belongs to a different
197+
subject; it used to delete any row id once the path's subject was
198+
authorized.
199+
- **Creating or editing a key with an explicit allow-list checks it
200+
against gateway-granting roles only.** An `allowed_models` or
201+
`allowed_mcp_tools` entry is refused with `400` when no role of the
202+
owner that grants the gateway covers it, so a user without a gateway
203+
role can no longer save a non-empty list.
204+
14205
## [2.1.0] — 2026-09-30
15206

16207
Amazon Bedrock becomes a provider you can run from the console. It
@@ -716,7 +907,8 @@ unreleased builds should: stop the gateway, run `db/schema.sql`
716907
against PostgreSQL, restart against this tag. The schema is
717908
idempotent end-to-end, so the apply is safe to repeat.
718909

719-
[Unreleased]: https://github.com/ThinkWatchProject/ThinkWatch/compare/v2.1.0...HEAD
910+
[Unreleased]: https://github.com/ThinkWatchProject/ThinkWatch/compare/v2.2.0...HEAD
911+
[2.2.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v2.2.0
720912
[2.1.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v2.1.0
721913
[2.0.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v2.0.0
722914
[1.1.0]: https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v1.1.0

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = [
1010
]
1111

1212
[workspace.package]
13-
version = "2.1.0"
13+
version = "2.2.0"
1414
edition = "2024"
1515
# Pin the MSRV to the first stable rustc that ships edition 2024 (1.85,
1616
# released 2025-02-20). Without this, contributors on older toolchains

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
- **One key for AI and MCP.** Users receive `tw-` virtual keys that can be scoped to the AI gateway, the MCP gateway or both. Keys are stored only as hashes and rotate with a grace period.
4242
- **Rate limits and budgets.** Sliding windows from one minute to one week limit requests or tokens, and daily, weekly or monthly budgets cap spending. Both attach to users, API keys or roles, and rate limits apply to MCP tool calls as well as model requests.
4343
- **Cost accounting that finance can use.** Spend is reported by model, user, provider and cost center, with CSV chargeback reports and a month-end forecast. Per-model weights make expensive models count for more against the same quota.
44-
- **Audit trail in ClickHouse.** Every model request and tool call is recorded with user, parameters, response, latency and errors, with PII redacted before storage. Events can be forwarded to a SIEM over Syslog, Kafka (through a REST proxy) or signed webhooks.
44+
- **Audit trail in ClickHouse.** Every model request and tool call is recorded with user, parameters, response, latency and errors, and request bodies can be PII-redacted before storage (off by default). Events can be forwarded to a SIEM over Syslog, Kafka (through a REST proxy) or signed webhooks.
4545
- **One endpoint for every client.** OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Gemini requests are served on one port and converted to whatever the upstream speaks. Routing spreads traffic by weight, latency or health, and a circuit breaker takes failing upstreams out of rotation.
4646

4747
## Quick start
@@ -60,7 +60,7 @@ cd web && pnpm install && pnpm dev
6060
# 4. Complete the setup wizard at http://localhost:5173/setup
6161
```
6262

63-
The setup wizard creates the first Super Admin account and can add the first provider and API key. The console then has copy-paste setup instructions for Claude Code, Cursor, Continue, Cline, the OpenAI and Anthropic SDKs, and cURL.
63+
The setup wizard creates the first Super Admin account, sets the site name and issues a first API key; providers are added in the console afterwards. The console then has copy-paste setup instructions for Claude Code, Cursor, Continue, Cline, the OpenAI and Anthropic SDKs, and cURL.
6464

6565
## Deployment
6666

@@ -75,7 +75,7 @@ The gateway (port `3000`) is the only part that clients need to reach. The conso
7575

7676
**MCP identity**
7777
- A user may connect several accounts to one server (work and personal, for example) and pin each `tw-` key to one of them.
78-
- Adding a server takes its URL: the gateway discovers the OAuth endpoints and registers itself when the upstream supports dynamic client registration. The MCP Store ships 36 ready-made templates.
78+
- Adding a server takes its URL: the gateway discovers the OAuth endpoints and registers itself when the upstream supports dynamic client registration. The MCP Store ships 37 ready-made templates.
7979
- A user who has not yet connected an account still sees the tool list; calling a tool returns JSON-RPC error `-32050` with the authorization URL, which compliant MCP clients can show.
8080
- Responses from servers that use per-user credentials are cached per user and account, never shared.
8181

‎README.zh-CN.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
- **AI 与 MCP 共用一把密钥。** 用户获得 `tw-` 虚拟密钥,可限定用于 AI 网关、MCP 网关或两者。密钥只以哈希形式保存,轮换时保留宽限期。
4242
- **限流与预算。** 从一分钟到一周的滑动窗口可限制请求数或 Token 数,按日、周、月的预算控制总用量。两者均可设置在用户、API Key 或角色上,限流同样适用于 MCP 工具调用。
4343
- **可用于财务核算的费用统计。** 费用可按模型、用户、上游和成本中心汇总,支持导出 CSV 分摊报表,并给出月末费用预测。按模型设置的权重使价格较高的模型在同一配额中计入更多用量。
44-
- **审计记录存入 ClickHouse。** 每一次模型请求和工具调用都记录用户、参数、响应、延迟与错误,个人信息在写入前即已脱敏。审计事件可通过 Syslog、Kafka(经 REST 代理)或签名 Webhook 转发至 SIEM。
44+
- **审计记录存入 ClickHouse。** 每一次模型请求和工具调用都记录用户、参数、响应、延迟与错误,请求正文可在写入前做个人信息脱敏(默认关闭)。审计事件可通过 Syslog、Kafka(经 REST 代理)或签名 Webhook 转发至 SIEM。
4545
- **所有客户端共用一个入口。** OpenAI Chat Completions、OpenAI Responses、Anthropic Messages 与 Gemini 请求在同一端口提供,并转换为上游所用的格式。路由可按权重、延迟或健康状况分配流量,熔断器会将持续出错的上游移出轮转。
4646

4747
## 快速开始
@@ -60,7 +60,7 @@ cd web && pnpm install && pnpm dev
6060
# 4. 在 http://localhost:5173/setup 完成设置向导
6161
```
6262

63-
设置向导会创建首个超级管理员账号,并可添加首个上游和 API Key。此后控制台提供 Claude Code、Cursor、Continue、Cline、OpenAI 与 Anthropic SDK 以及 cURL 的配置说明,可直接复制使用。
63+
设置向导会创建首个超级管理员账号、设置站点名称并签发第一把 API Key;上游在之后的控制台中添加。此后控制台提供 Claude Code、Cursor、Continue、Cline、OpenAI 与 Anthropic SDK 以及 cURL 的配置说明,可直接复制使用。
6464

6565
## 部署方式
6666

@@ -75,7 +75,7 @@ cd web && pnpm install && pnpm dev
7575

7676
**MCP 身份**
7777
- 同一用户可为一个服务器连接多个账号(例如工作账号与个人账号),并将每把 `tw-` 密钥固定到其中一个。
78-
- 添加服务器只需填写地址:网关自动发现 OAuth 端点,上游支持动态客户端注册时自动完成注册。MCP 应用商店内置 36 个现成模板。
78+
- 添加服务器只需填写地址:网关自动发现 OAuth 端点,上游支持动态客户端注册时自动完成注册。MCP 应用商店内置 37 个现成模板。
7979
- 尚未连接账号的用户仍能看到工具列表;调用工具时返回 JSON-RPC 错误 `-32050` 并附带授权地址,符合规范的 MCP 客户端可据此引导授权。
8080
- 使用每用户凭据的服务器,其响应按用户和账号分别缓存,不会共用。
8181

0 commit comments

Comments
 (0)