Commit 33cb29c
feat(console): SOC2 audit log + account activity alerts (#1288)
* feat(console): SOC2 audit log + account activity alerts
- Add Audit Log settings page (owner-only) with filter + cursor pagination
- Log auth events (NextAuth login/logout, Firebase login/logout, OIDC login/logout)
- Log membership events (invite, accept, role-change, remove)
- New "account" event type in notification channels
- Immediate email dispatcher for security-severity events (no cron)
- Extend AuditLog with severity column + (workspaceId, timestamp) index
* fix(console): redact audit log + UX polish
Security:
- Stop persisting raw config object versions (prevVersion/newVersion) to
AuditLog.changes — these can contain API keys, passwords and OAuth tokens.
Only objectType + objectName are stored now.
- API allow-lists safe fields in the response, so any pre-existing rows with
raw config payloads are also redacted on read.
UX:
- Audit log table is full-width
- Time column shows relative time (with absolute UTC tooltip)
- Drop the auth-method chip from the actor cell
- Drop the expandable raw-changes JSON row
- Render config-object events as 'Updated <type> <name>' with a link to the
entity edit page (no link for delete)
* fix(console): mask secrets via outputFilter, keep full diff in audit log
Reuse the per-type outputFilter (the same one used by the config editor) to
mask sensitive fields, so prevVersion / newVersion can stay in the audit log:
- destinations: secrets at credentialsUi paths replaced with MASKED_SECRET
- services: airbyte_secret-marked fields masked
- streams: privateKey/publicKey plaintext + hash stripped
- types without a registered outputFilter (link, profilebuilder, function code):
fall back to a generic name-based scrubber that masks fields whose key matches
password / secret / token / apiKey / etc.
Rows written through this helper are tagged `_redacted: true`. The read API only
exposes prevVersion / newVersion when that flag is present, so any rows already
in the DB from before this fix continue to be redacted on read (objectType +
objectName only).
UI: expandable row shows the masked Before / After diff side-by-side.
* fix(console): break import cycle in audit-log helper
audit-log.ts imported config-objects.ts at module load, which transitively
pulls pages/api/[workspaceId]/domain-check.ts -> lib/api.ts -> nextauth.config
-> back to audit-log.ts. The cycle surfaced as 'Cannot access httpMethods
before initialization' on the first /api request.
Lazy-require config-objects on first call, and inline the MASKED_SECRET
constant so we don't need to pull lib/schema/destinations at load time.
* feat(console): audit log diff view + better link/time rendering
- API computes a flat diff [{ field, description }] from the masked
prevVersion/newVersion server-side and returns it as `diff`. The raw
prev/next blobs are no longer sent to the client. Masked secrets are
surfaced as 'changed (secret value)' so the sentinel doesn't leak.
- API enriches connection (link) entries with a synthesized
'from.name → to.name' display name (links have no name field of their own).
- UI Time column shows absolute UTC + relative ('ago') stacked.
- Entity name is the visible label; the underlying ID lives in a tooltip.
- Expandable row renders the diff as a small Field / Change table.
* fix(console): show entity names for old audit rows + +/- expand icon
- API derives objectName from prevVersion/newVersion server-side when the
stored 'objectName' is empty. Pre-fix rows still showed entity IDs because
they don't have the dedicated field — this fallback fixes that without
exposing the raw versions to the client.
- Expand toggle uses an explicit +/- icon (lucide Plus/Minus) so the
expandable rows are obvious. Rows without a diff render a fixed-width
spacer so columns stay aligned.
* fix(console): default expand icon + diff for old rows too
- Drop the custom +/- expand icon. Use Antd's default chevron — it's the
same widget shown elsewhere in the app and avoids a fragile manual layout.
- Compute the diff for non-redacted rows too. Re-run a name-based scrubber
on the way out so credentials in legacy rows never reach the client.
Without this, only post-fix rows showed an expand handle.
* fix(console): drop id/workspaceId noise + flatten diff UI
- API strips id, workspaceId, type, cloneId from prev/new before diffing.
These are identity / metadata fields that the write path strips before
saving (legacy audit-log payloads sometimes captured them inline, which
surfaced as confusing 'id removed' rows).
- Replace the nested Antd Table in the expandable row with a plain
two-column grid — same field/change information, no header bar, no row
borders or stripes. Field name in monospace, description plain text.
* feat(console): extract AuditLogDiff component, polish layout
- New components/AuditLogDiff/AuditLogDiff.tsx — self-contained, full-width,
responsive (stacks field/change on narrow widths). Card with header
('Changes' + N fields summary), thin row separators, no per-cell borders.
- Expanded row indents the card to align with the Time column (past Antd's
expand-chevron gutter), with a subtle neutral-50 backdrop.
* feat(console): flatten create/delete diffs leaf-by-leaf
Recurse into plain objects even when one side is undefined, so creating an
entity produces:
data.mode added: "batch"
data.batchSize added: 10000
data.dataLayout added: "segment-single-table"
…
instead of one '(root) → added: {…}' blob. Same for deletes — every leaf is
listed as 'removed (was …)'. Arrays stay atomic, so 'foo.bar → added: []'.
* feat(console): mask ssh_key, middle-truncate diff values + tooltip
- Add ssh_key, ssl_key, signing_key, encryption_key to the redaction patterns
on both the write side (lib/server/audit-log.ts) and the read-side scrubber
(pages/api/[workspaceId]/audit-log.ts). credentials.tunnel_method.ssh_key
on Airbyte connectors is now masked even on legacy rows that didn't go
through outputFilter at write time.
- Server: relax the per-value cap from 80 to 2000 chars so the client gets
the full string to display.
- AuditLogDiff: middle-truncate long descriptions to ~100 chars and show the
full text in an Antd Tooltip on hover. Truncated values get a 'help'
cursor as a hover affordance.
* feat(console): icon-based diff + outputFilter on read
- Revert the regex extension (ssh_key etc). Use the per-type outputFilter on
the read side instead — same masking the editor UI does. Pulls
config-objects via lazy require so the leaf API route doesn't reintroduce
the api.ts cycle. credentials.tunnel_method.ssh_key on Airbyte sources is
now masked via airbyte_secret on legacy rows.
- API returns structured diff entries: { field, kind, prev?, next? } where
kind is added | removed | changed | secret-changed | noop.
- AuditLogDiff renders each kind with an icon (+, −, →, key, no-change).
changed rows show prev → next, both middle-truncated with full-text tooltip.
- For 'config-object-update' rows whose prev and next end up byte-identical
(the user clicked Save without editing — produces a real audit row but
empty diff), show a single 'no field-level changes' noop entry so the row
is still expandable and the situation is explicit.
* fix(console): denylist for changes, mask sentinel parity, load-more loading
- Replace ALWAYS_SAFE_FIELDS allow-list with a small deny-list:
prevVersion, newVersion (rendered server-side via 'diff' instead) and the
internal _redacted marker. Everything else our audit-log helpers write is
safe summary metadata; we shouldn't have to enumerate it here.
- Add isMasked() that recognizes both the local display sentinel
('*********') and the canonical sentinel ('__MASKED_BY_JITSU__') emitted
by lib/schema/secrets#maskSecrets via outputFilter. Without this the
secret-changed kind never fires for legacy rows masked through the
per-type filter.
- UI: while a Load-more fetch is in flight, show a disabled loading
button. The previous logic briefly fell through to 'End of log' because
query.data is undefined during the in-flight request.
* refactor(console): pick summary fields explicitly, drop deny-list
The audit-log API never sent prev/new on the wire, but the previous code
expressed that as 'pass r.changes through, strip prev/new on the way out',
which inverted the intent. Switch to an explicit allow-list of summary
fields (objectType, objectName, actorEmail, …) — the raw config blobs
simply aren't enumerated, so they can't accidentally leak. The diff is the
only place the per-field changes show up.
* feat(console): admin-level audit log + reusable component
- Move /api/[workspaceId]/audit-log -> /api/audit-log with workspaceId as
an optional query param. With workspaceId: workspace-scoped, requires
manageUsers in that workspace. Without: cross-workspace, requires admin
(verifyAdmin). API also bulk-fetches workspace name+slug per row and
returns it as 'workspace' so the admin view can render a workspace
column.
- Extract the table into components/AuditLog/AuditLog.tsx. When workspaceId
is undefined the component runs in admin mode: adds a Workspace column
with name + link to /<slug-or-id>, and uses each row's per-workspace
slug to build entity edit links.
- /admin/audit-log: new page that renders <AuditLog /> in admin mode.
- /[workspaceId]/settings/audit-log: now a thin wrapper around <AuditLog
workspaceId={...} workspaceSlug={...} />.
- Add 'Admin Audit Log' entry next to 'Admin Workspaces' in the workspace
selector menu (admin users only).
* fix(console): throttle auth-login audit rows per (user, authType)
/api/fb-auth/create-session is called every time Firebase mints or
refreshes a session cookie — every short-lived ID-token rotation, every
reload after a long idle — not just on actual sign-in. That flooded the
audit log with dozens of 'Logged in' rows per user per day.
Suppress duplicate auth-login rows for the same (userId, authType)
inside a 30-minute window. Logouts still fire on every signout — they
are explicit user actions, not implicit refreshes.
* fix(console): replicas-safe auth-login dedup via Firebase auth_time
The previous in-memory throttle didn't work across replicas. Switch to a
DB-backed check keyed on the auth event's actual timestamp:
- authAuditLog gains an opts.authTime parameter. When provided, it queries
for any auth-login row for this user with timestamp >= authTime; if
found, it skips the write. Firebase rotates ID tokens on a schedule but
auth_time only changes on actual re-authentication, so refresh calls
collapse onto the original row instead of creating duplicates.
- create-session decodes the ID token (already does, for the user
identity), pulls auth_time, and passes it through.
- NextAuth and OIDC don't need this — their callbacks only fire on actual
auth flows, not on token refreshes.
- Drop the in-memory map and the per-(userId, authType) 30-min throttle.
* fix(console): hook firebase audit-login at the actual sign-in moment
Drop the dedup logic entirely. Replace it with explicit instrumentation
on the two client entry points users actually hit:
- New endpoint /api/fb-auth/audit-login that takes an idToken in the body,
verifies it via Firebase Admin, and writes the auth-login row.
- firebase-client signIn (email/password) and signInWith (popup OAuth)
both call audit-login right after Firebase reports success.
- create-session no longer logs — it's the cookie-mint endpoint and runs
on every ID-token rotation, which is what was flooding the audit log.
- authAuditLog reverts to the simple (user, op, authType, workspaceId?)
signature; no opts, no auth_time, no DB lookup. The signOut path was
already correct (revoke-session is only hit at sign-out), so logout
needs no changes.
Net: one audit row per actual user-driven sign-in, zero per token
refresh / session re-establish.
* fix(console): address audit-log + account-alerts review (#1288)
- show auth events in workspace-scoped audit-log via member-id OR clause
- gate member-removed audit on confirmed deletion + reject empty target
- skip role-changed audit when role is unchanged
- wire workspace-deleted (DELETE) and workspace-updated (PUT) audit rows
- account-alerts: also fan out to workspace members with notifications.account on
- detect secret rotations at write time (_rotatedSecrets) and surface them as secret-changed on read
- prettier reformat across the 9 files CI flagged
* fix(console): include members of deleted workspace in workspace-deleted alert
The recipient query had `w.deleted = false`, which silently dropped all
member recipients exactly for workspace-deleted events (the workspace
is flagged deleted before the alert dispatches).
* review fixes
* review fixes
---------
Co-authored-by: Ildar Nurislamov <absorbb@gmail.com>1 parent f87821a commit 33cb29c
29 files changed
Lines changed: 1893 additions & 8 deletions
File tree
- libs/juava/src
- webapps/console
- components
- AuditLogDiff
- AuditLog
- PageLayout
- UserNotificationSettings
- emails
- lib
- schema
- server
- pages
- [workspaceId]/settings
- admin
- api
- [workspaceId]/config/[type]
- auth/dynamic-oidc
- fb-auth
- user
- workspace
- [workspaceIdOrSlug]
- users
- [userId]
- prisma
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
14 | 32 | | |
15 | 33 | | |
16 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
0 commit comments