Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
351bbe1
feat(audit): record every change in a central audit log
Diubii Oct 21, 2026
81feff2
Merge branch 'main' into Diubii/audit-log
Diubii Oct 27, 2026
730497e
Merge branch 'main' into Diubii/audit-log
Diubii Nov 2, 2026
de22b39
Merge remote-tracking branch 'origin/main' into Diubii/audit-log
toto04 Nov 8, 2026
b89e297
fix(audit): keep the audit log to accountability, without moderation …
toto04 Nov 8, 2026
aabaa7f
fix(audit): record states only once they are saved, and summarize inv…
toto04 Nov 8, 2026
b0f81d5
fix(audit): read no body for unrecorded calls, and keep caller-chosen…
toto04 Nov 8, 2026
6751649
feat(audit): declare how each mutation is recorded in its procedure m…
toto04 Nov 11, 2026
0976787
fix(audit): resolve member targets and capture project reorder values…
coderabbitai[bot] Nov 11, 2026
b2569ac
fix(audit): Validate mutation targets, enforce input allowlists, and …
coderabbitai[bot] Nov 15, 2026
78ddb86
Merge remote-tracking branch 'origin/main' into Diubii/audit-log
toto04 Nov 17, 2026
b200a45
fix(audit): keep only the declared fields of an e-sign request's output
toto04 Nov 17, 2026
dc16bbf
fix(web): serialize project reorders before reading the order they re…
toto04 Nov 17, 2026
7428d9d
fix(audit): bound copies in UTF-8 bytes, keep only scalar allowlisted…
toto04 Nov 17, 2026
7846704
fix(web): record the documents catalog's targets and states in the au…
toto04 Nov 17, 2026
7793f1d
fix(web): lock projects in EXCLUSIVE mode before reordering them
toto04 Nov 17, 2026
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ The bot's socket.io client authenticates with its service token in `auth.token`

The IdP notifies `POST /internal/events` when access changes; the backend also polls the snapshot every 30 s. The last good signing keys and snapshot are stored in `common_idp_state`, so a restart during an IdP outage resumes from them. Permission checks deny once the snapshot is more than an hour old. Configuration is in `.env.example`.

## Audit log

`common_audit_events` records who used which permission to change what through the backend. The tRPC audit middleware
(`src/audit`) writes one event per mutation: the action (the procedure path), the caller from the token, the target,
the outcome (`success`, `failure` when an error is thrown or returned, `denied` when the policy refuses the caller), the
request id shared by the calls of one HTTP request, and when. Calls without a valid token are not recorded.

Every mutation declares how it is recorded in its procedure meta, and a test walks the router so that none ships
without one, like its policy:

- `.meta(audit.full())`: also the input, the reason and the states before and after that the handler adds with
`ctx.audit.set(...)`. `fields` keeps only those fields of the input, for inputs that carry personal data or free
text not worth keeping; a dotted field (`output.driveId`) keeps one field of a nested object.
- `.meta(audit.minimal({ target }))`: only the actor, the action, the target and the outcome, for areas that keep their
own history behind their own permissions. People records each change in the person's activity history, and the
Libro Soci in `soci_activity`.
- `.meta(audit.none(why))`: not recorded, e.g. the bot's ingestion, or Telegram moderation, which `tg_audit_log` keeps
under its own retention rules.

Handlers call `ctx.audit.skip()` when a call changed nothing. Inputs and states are stored without secrets
(`password`, `token`, `ticket`, `code`, `*Key`, `*Secret` fields) or file contents, and are cut when too large. Denied
calls keep no input.

Events are deleted 24 months after they were written (`AUDIT_EVENTS_RETENTION_MONTHS`). Dashboard users with the IdP
permission `audit:read` read the log with `audit.list`, newest first, paged by `cursor` and filtered by area, outcome,
target, actor, date or text.

Changes made outside the backend's tRPC procedures are not in the log: directly in Telegram or WhatsApp, the cron jobs,
the e-signing agent endpoints (each request keeps its own history) and roles and permissions in the IdP.

## People

The `people` router is the admin dashboard's register of Group Admins, Capo Admins and team members. Each person
Expand Down
26 changes: 26 additions & 0 deletions drizzle/0040_audit_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TABLE "common_audit_events" (
"id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "common_audit_events_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
"action" text NOT NULL,
"request_id" uuid,
"actor_kind" varchar(16) NOT NULL,
"actor_sub" text,
"actor_tg_id" bigint,
"actor_client" text,
"target_type" text,
"target_id" text,
"target_label" text,
"reason" text,
"outcome" varchar(16) NOT NULL,
"error" text,
"input" jsonb,
"before" jsonb,
"after" jsonb,
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE INDEX "common_audit_events_action_idx" ON "common_audit_events" USING btree ("action");--> statement-breakpoint
CREATE INDEX "common_audit_events_actor_sub_idx" ON "common_audit_events" USING btree ("actor_sub");--> statement-breakpoint
CREATE INDEX "common_audit_events_actor_tg_id_idx" ON "common_audit_events" USING btree ("actor_tg_id");--> statement-breakpoint
CREATE INDEX "common_audit_events_target_idx" ON "common_audit_events" USING btree ("target_type","target_id");--> statement-breakpoint
CREATE INDEX "common_audit_events_request_id_idx" ON "common_audit_events" USING btree ("request_id");--> statement-breakpoint
CREATE INDEX "common_audit_events_created_at_idx" ON "common_audit_events" USING btree ("created_at");
Loading
Loading