Conversation
Add AuditService, which records every audit entry in the audit table as before and, when [platform_api.audit] stdout is on, also writes it to stdout as a JSON line tagged "logType":"audit" for log collectors. It satisfies repository.AuditRepository, so the existing Record call sites are unchanged. Off by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AuditService now generates the record's uuid and UTC time (to the microsecond, the finest every supported database stores) and passes them to AuditRepo.Record, so the audit row and the stdout line carry identical values. The stdout line gains an "id" field to join it to its row. The call sites and the audit table are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record an audit entry for the user-facing operations that change live
gateway traffic or issue/revoke a credential and had none:
- deploy, undeploy and restore for GraphQL APIs, LLM providers, LLM
proxies, MCP proxies, agent proxies, WebSub and WebBroker APIs, and
deploy for REST APIs (resource type "deployment")
- gateway token rotate and revoke ("gateway_token")
- secret create and update ("secret")
- LLM provider and proxy API key create and delete ("api_key")
- WebSub HMAC secret generate, regenerate and delete ("hmac_secret")
Services that did not hold an audit dependency take an *AuditService
(plugins get it through plugin.Deps.AuditService). Undeploy, restore and
HMAC secret delete now take the acting user; handlers resolve it without
failing the request, and the per-kind deployment adapter and MCP server
tools forward the user they already had. Existing audit call sites are
unchanged, and a failed audit write never fails the request.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace [platform_api.audit] stdout with output: "none" (default), "stdout", or "file". With "file", each record is appended as a JSON line to ./data/logs/audit.log (created 0600); if the file cannot be opened, a warning is logged and records go to the audit table only. An unknown output value fails startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
content_type, default application/x-ndjson, sets the Content-Type of each batch, as in traffic logging. Fluent Bit's http input rejects application/x-ndjson and needs application/json; the template no longer says it accepts the default as-is. An empty or invalid value fails startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
|
@coderabbitai approve |
Action performed
|
Renders config.audit as [platform_api.audit] (and its file, http, auth and tls
tables) only when it is set, so a release without it renders byte-for-byte as
before. Keys are camelCase like the rest of config.*.
Secret values never land in the ConfigMap: an http auth credential must be an
{{ env }} or {{ file }} token, and a literal fails the render.
The "file" output gets its own emptyDir (auditLogVolume), mounted when audit is
enabled and outputs contains "file", and the render fails when file.path is
outside it, so the audit log never lands on the data volume.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
The chart defaults auditLogVolume and the README documents config.audit, so values.yaml stays as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t records Cover the stdout, file and http outputs (batching, retries, Retry-After, the queue limit, close, TLS with the receiver's CA and the X25519MLKEM768 key exchange), every [audit] validation rule, mask_pii and a failed identity lookup, a failed output build, and the GraphQL deploy, undeploy and restore records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
|
@coderabbitai approve |
Action performed
|
The fields it masks are listed once, in auditSensitiveFields, and masked by one function. An empty value now stays empty, so "****" always stands for a real value. The Helm value is maskSensitiveFields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
actorIdentity turns the internal user id into the identity the line shows, or "****" when the lookup fails, and masking is then a separate step, as in the gateway. The lookup now also runs when masking is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
"****" now only ever means mask_sensitive_fields. A failed lookup is logged, and the table row still holds the internal user id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
Two blocks run features/management-portal/resources/audit*.feature on SQLite: platform-api-audit with every output on, and platform-api-audit-masked with mask_sensitive_fields. They check that a change reaches the audit table, stdout, the file and the testbench webhook, that reads and rejected requests are not recorded, and that masking hides the user in the outputs only. openEmbeddedSQLite treated a missing -wal file as a failed copy: the Docker client marks a daemon 404 for errors.Is, not with a NotFound method, so a store without a WAL sidecar could not be read. isNotFound now uses errdefs.IsNotFound, which recognises both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
Revoking an already revoked gateway token still returns 200 and updates the row as before, but no longer records a second REVOKE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
d22075a to
91d8bfe
Compare
…udit-sinks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R4Ykia1zPCCS9XjiNMVkVE
Dependency Validation ResultsDependency name: github.com/containerd/errdefs Next Steps
|
containerd/errdefs is not in the approved Go dependency list, so it goes back to an indirect dependency. isNotFound keeps the NotFound method check and also matches the daemon's "Could not find the file" message, the only mark a 404 from the archive endpoint carries. Any other error is still a real copy failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NkCRUwS9ATVCewAE7e97xr
…udit-sinks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…udit-sinks main split the integration suite's blocks into suites/it/blocks/ (wso2#4094), so the two platform-api audit blocks move from it-suite.yaml to blocks/platform-api.yaml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9b45c33 to
b292313
Compare
The Platform API's audit outputs on main (wso2/api-platform#4000) work as in the 1.0.0 update, so the page is the 1.0.0 page with three differences: no update-level note, subscription plan changes from the portal are recorded, and performedBy shows the user's display name, or their sub if none is recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Purpose
Platform API already records user changes in its
audittable, but those records can only be read from the database, and several sensitive operations are not recorded at all: deploying, undeploying and restoring APIs on gateways, and issuing or revoking credentials (gateway tokens, secrets, WebSub HMAC secrets).Goals
enabled, off by default).audittable, its existing record call sites, and every API response unchanged.Approach
AuditService. A new
AuditService(internal/service/audit_service.go) wraps the existingAuditRepoand implementsrepository.AuditRepository, so the 63 existingRecord(...)call sites, and the service-account one added onmainsince, are unchanged and also reach the outputs. For each record it generates the id and UTC time (to the microsecond, the finest every supported database stores) once, writes the row withAuditRepo.Record, then writes the record as one JSON line (tagged"logType":"audit") to every configured output. Theaudittable schema is unchanged.Layout follows the policy engine's traffic logging (
policy-engine/internal/analytics/publishers):config/audit.gointernal/config[platform_api.audit]types and their validation, run when the config loadsinternal/service/audit_service.golog.go,sink_factory.goAuditService: builds one sink per name inoutputs(one that can't be built closes the others and fails startup), writes the table row, builds the JSON line once, writes it to every sink, closes theminternal/service/audit_sink.gosink.goWrite,Close,Name) and a 30s error-log throttleinternal/service/audit_sink_stdout.gosink.go(writerSink)internal/service/audit_sink_file.gosink_file.gointernal/service/audit_sink_http.gosink_http.goConfig validation checks everything that needs no filesystem access, including the output names. Opening the file (and checking its permissions) and reading the TLS files happen once, when the outputs are built during startup, before any listener starts. The traffic-logging validation does that I/O and then its sinks do it again; here it's done once, and a bad output still fails startup.
NewAuditServicereturns an error for that reason. On shutdown the outputs are closed last, with their own 5s limit, so records from requests that just finished are flushed.Configuration (all of it is in
config/config-template.toml):performedByshows the user's identity instead, resolved withIdentityService.DisplayIdentityas API responses do: the token'ssub, or the username for file-based users. The internal id must not leave the process (identity.go). If the identity can't be resolved,performedByis left empty and a warning is logged; the request is unaffected. Withmask_sensitive_fields = truea non-emptyperformedByis****, the same mask traffic logging uses for headers.file: created0600in a0700directory. An existing file that group or others can read fails startup. Rotation renames the live file to<path>.1(logrotate's "create" mode), so at most2 x max_size_mbis on disk. If a rotation can't open the new file (for example, the directory was removed), later writes retry the open, recreating the directory, so writing resumes without a restart. One writer per file: give each replica its own volume.http:Writenever blocks. Records go from a bounded in-memory queue to one sender, which POSTs newline-delimited JSON withcontent_typeas the Content-Type (defaultapplication/x-ndjson; an empty or invalid value fails startup).batch_max_bytescaps the body; only a single record larger than it is sent over it, alone.Retry-Afterreplaces the backoff, capped at 30s;retry_backoffis at most 1h, so the doubling delay can't overflow. Other 4xx are not retried, and redirects are never followed.request_timeoutbounds the whole attempt, including waiting for the response headers.auth.typeselects one header and reads only its own sub-table. Credentials go in{{ env }}/{{ file }}. A header name that isn't valid, a value with characters HTTP doesn't allow (such as a newline), or abasic.usernamecontaining a colon (RFC 7617) fails startup.httpkit/httpclient, the library behind platform-api's shared client.tlstakes a CA bundle and an mTLS pair, uses TLS 1.2–1.3 withX25519MLKEM768preferred, and logs the negotiated key exchange once.on_queue_full(always drop new),retry_abort_queue_ratioorshutdown_timeout, and no Prometheus metrics (platform-api has none). An emptyoutputskeeps records in the table only; traffic logging falls back to stdout. Like traffic logging, the http output doesn't use the SSRF dial guard, because the endpoint comes from operator config.Helm.
config.auditrenders[platform_api.audit]and its sub-tables only when it is set, so a release without it renders as before. Keys are camelCase like the rest ofconfig.*(maskPii,file.maxSizeMb,http.contentType,tls.caFile). Anhttpauth credential must be an{{ env }}or{{ file }}token (add the key to the Secret and inject it throughdeployment.extraEnv); a literal fails the render. Thefileoutput gets its own emptyDir,auditLogVolume(512Mi), mounted when audit is enabled andoutputscontains"file". The render fails whenfile.pathis outside it, so the log never lands on the data volume. Theai-workspaceumbrella passesplatform-api.config.auditthrough.New coverage (17 operations, non-AI resources only). Recorded only on success, with the acting user:
deployment.gateway_token), secret create / update (secret), WebSub HMAC secret generate / regenerate / delete (hmac_secret).Services that did not hold an audit dependency take an
*AuditService; plugins get it through a newplugin.Deps.AuditServicefield (additive). GraphQL, WebSub and WebBroker undeploy / restore and HMAC secret delete now take the acting user: handlers resolve it withInternalUserIDand ignore any error, so actor lookup never fails a request; the per-kind deployment adapter forwards the user it already had for GraphQL. A failed audit write never fails the request.Deliberately not recorded: new records for AI resources (LLM provider and proxy deployments and API keys, MCP proxy and agent proxy deployments; their original audit records are unchanged), deleting a deployment record (non-REST kinds), adding gateways to an API, application keys and associations, LLM template copy / enable / delete, portal publish, meters, and secret delete (the soft delete has only the handle).
User stories
Documentation
config/config-template.tomlandREADME.mddocument[platform_api.audit]enabledandoutputs, and thefileandhttpsub-tables.[platform_api.audit] enabled = truewhen upgrading.outputs(default empty) is new. With auditing enabled, audit rows are now also written for the operations listed above. Under Helm, set them throughconfig.audit(see Helm above).Automation tests
Security checks
Samples
N/A
Related PRs
Test environment
macOS (arm64), Go 1.27.3, SQLite. No schema changes; the audit INSERT statement is unchanged for PostgreSQL and SQL Server.
🤖 Generated with Claude Code