Compare commits

...
Author SHA1 Message Date
1sonhador 8f7ff6b1d5 chore: limit CODEOWNERS to active Gitea reviewers
CI / Test ingest-api (pull_request) Successful in 28s
CI / Test api (pull_request) Successful in 34s
CI / Lint and typecheck admin-ui (pull_request) Successful in 59s
CI / Validate Docker build (pull_request) Successful in 4m16s
Only owners that review in practice are listed, so official review
requests from code owners never block merges on protected branches.
2026-10-22 04:45:10 +01:00
spark dc1aa3365e Merge branch 'master' into chore/codeowners-fix
CI / Test ingest-api (pull_request) Successful in 36s
CI / Test api (pull_request) Successful in 36s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m3s
CI / Validate Docker build (pull_request) Successful in 3m2s
2026-10-22 01:16:24 +01:00
spark d987d2aaf4 Merge pull request 'fix(hub): BIT-31442 route /v1/paperclip alias to admin API + accept X-Api-Key header' (#17) from fix/BIT-31442-recent-errors-alias-proxy-and-xapikey into master
CI / Test ingest-api (push) Successful in 25s
CI / Test api (push) Successful in 29s
CI / Lint and typecheck admin-ui (push) Successful in 59s
CI / Validate Docker build (push) Successful in 4m24s
2026-10-21 20:40:24 +01:00
David Santos d4059d801a fix(hub): BIT-31442 route /v1/paperclip alias to admin API + accept X-Api-Key header
CI / Test ingest-api (pull_request) Successful in 41s
CI / Test api (pull_request) Successful in 44s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m24s
CI / Validate Docker build (pull_request) Successful in 6m2s
The recent-errors handler (api/src/routes/public/recentErrors.ts) registers
both GET /api/error-monitoring/recent-errors and the alias
GET /v1/paperclip/recent-errors on the admin API (port 3200). However the
admin-ui Next.js rewrite sent all /v1/* to ingest-api (port 3041), which has
no such route, so the alias returned 404 in production while the
/api/error-monitoring path worked (401 without a key).

Changes:
- admin-ui/next.config.ts: add a specific /v1/paperclip/:path* -> admin API
  rewrite before the generic /v1/:path* -> ingest-api rule (rewrite order
  matters; first match wins).
- api/src/lib/errorMonitoringAuth.ts: authorizeReadQuery now also accepts an
  X-Api-Key header carrying either ERROR_RESOLVE_API_KEY/ERROR_REPORTING_API_KEY
  or DEBUG_VIEW_ERRORS_KEY, so programmatic callers avoid leaking keys in
  URLs/access logs. Backward compatible with the existing query params.
- api/src/routes/public/recentErrors.test.ts: cover the alias path and the
  X-Api-Key header (resolve key, view key, invalid key).
- docs/HTTP_CONTRACTS.md, docs/permission-matrix.md: document the header and
  the proxy ordering requirement.
2026-10-21 18:16:05 +01:00
1sonhador 9e318b5b9a chore: corrige CODEOWNERS para contas existentes no Gitea
CI / Test ingest-api (pull_request) Successful in 2m12s
CI / Test api (pull_request) Successful in 2m2s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m37s
CI / Validate Docker build (pull_request) Successful in 4m59s
2026-10-21 17:33:02 +01:00
6 changed files with 93 additions and 5 deletions

No files matched your search

+4 -4
View File
@@ -2,11 +2,11 @@
# Replace/add owners as needed per repository domain.
# CI and forge metadata
/.gitea/ @tiago-neves @david-santos
/.gitea/workflows/ @tiago-neves @david-santos
/.gitea/ @devops-engineer @founding-engineer
/.gitea/workflows/ @devops-engineer @founding-engineer
# Documentation
/docs/ @david-santos @planner
/docs/ @founding-engineer
# Catch-all
* @david-santos
* @founding-engineer
+9
View File
@@ -23,6 +23,15 @@ const nextConfig: NextConfig = {
async rewrites() {
return [
{ source: "/health", destination: `${INGEST_API_URL}/health` },
// BIT-31442: the recent-errors handler (api/src/routes/public/recentErrors.ts)
// registers the /v1/paperclip/recent-errors alias on the admin API (port 3200),
// not on ingest-api. The generic /v1/* rule below would otherwise send it to
// ingest-api (port 3041), which has no such route and returns 404. This more
// specific rule must come first; Next.js evaluates rewrites in order.
{
source: "/v1/paperclip/:path*",
destination: `${ADMIN_API_URL}/v1/paperclip/:path*`,
},
{ source: "/v1/:path*", destination: `${INGEST_API_URL}/v1/:path*` },
{
source: "/api/error-monitoring/:path*",
+16
View File
@@ -45,6 +45,22 @@ export function authorizeReadQuery(request: FastifyRequest, reply: FastifyReply)
return true;
}
// BIT-31442: accept X-Api-Key header as an alternative to the query param so
// programmatic callers (Paperclip, QA) can avoid leaking the key in URLs/logs.
// The header may carry either the resolve/reporting key or the read-only
// DEBUG_VIEW_ERRORS_KEY, mirroring the query-param semantics.
const headerRaw = request.headers['x-api-key'];
const headerVal = Array.isArray(headerRaw) ? headerRaw[0] : headerRaw;
const providedHeader = typeof headerVal === 'string' ? headerVal.trim() : '';
if (providedHeader !== '') {
if (apiKey && safeEqual(providedHeader, apiKey)) {
return true;
}
if (viewKey && safeEqual(providedHeader, viewKey)) {
return true;
}
}
reply.code(401).send({
success: false,
message: 'Unauthorized',
@@ -171,4 +171,60 @@ describe('GET /api/error-monitoring/recent-errors', () => {
// ['resolved', '%boom%', '%boom%', '%boom%', limit, offset]
expect(params).toEqual(['resolved', '%boom%', '%boom%', '%boom%', 10, 0]);
});
it('serves the /v1/paperclip/recent-errors alias from the same handler (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/v1/paperclip/recent-errors?api_key=test-recent-errors-key',
});
expect(res.statusCode).toBe(200);
expect(execute).toHaveBeenCalledTimes(1);
});
it('accepts the resolve key via X-Api-Key header (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'test-recent-errors-key' },
});
expect(res.statusCode).toBe(200);
expect(execute).toHaveBeenCalledTimes(1);
});
it('accepts the read-only view key via X-Api-Key header (BIT-31442)', async () => {
const prevView = process.env.DEBUG_VIEW_ERRORS_KEY;
process.env.DEBUG_VIEW_ERRORS_KEY = 'test-view-key';
try {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'test-view-key' },
});
expect(res.statusCode).toBe(200);
} finally {
if (prevView === undefined) {
delete process.env.DEBUG_VIEW_ERRORS_KEY;
} else {
process.env.DEBUG_VIEW_ERRORS_KEY = prevView;
}
}
});
it('rejects an invalid X-Api-Key header with 401 (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'wrong-key' },
});
expect(res.statusCode).toBe(401);
expect(execute).not.toHaveBeenCalled();
});
});
+4
View File
@@ -59,6 +59,10 @@ Alias: `GET /v1/paperclip/recent-errors` (same handler).
**Query:** `api_key` *or* `view_errors`, plus optional `limit`, `offset`, `status`, `severity`, `project_slug`, `q`, `order`.
**Header (BIT-31442):** `X-Api-Key: <key>` is accepted as an alternative to the `api_key`/`view_errors` query params, so programmatic callers can avoid leaking the key in URLs and access logs. The header may carry either `ERROR_RESOLVE_API_KEY`/`ERROR_REPORTING_API_KEY` or the read-only `DEBUG_VIEW_ERRORS_KEY`.
> **Proxy note (BIT-31442):** the `/v1/paperclip/*` alias is served by the admin API (port 3200), not ingest-api (port 3041). The `admin-ui` Next.js rewrite routes `/v1/paperclip/:path*` to the admin API *before* the generic `/v1/:path*` → ingest-api rule. If the alias returns 404 in production, verify that rewrite order in `admin-ui/next.config.ts`.
**Response 200**
```json
+4 -1
View File
@@ -50,11 +50,14 @@ These routes mirror the CRM error-monitoring module for Paperclip and automation
### Read: `GET /api/error-monitoring/recent-errors`
Alias: `GET /v1/paperclip/recent-errors` (same handler; served by the admin API via the `admin-ui` rewrite — BIT-31442).
| Credential | Notes |
|------------|--------|
| `api_key` query | Must match `ERROR_RESOLVE_API_KEY` or `ERROR_REPORTING_API_KEY` |
| `view_errors` query | Must match `DEBUG_VIEW_ERRORS_KEY` (read-oriented) |
| Admin session | Not used on this path; query credentials only |
| `X-Api-Key` header (BIT-31442) | Carries either the resolve/reporting key or `DEBUG_VIEW_ERRORS_KEY`; alternative to the query params to avoid key leakage in URLs/logs |
| Admin session | Not used on this path; query/header credentials only |
At least one of the server secrets above must be configured or the endpoint returns **503**.