Repository navigation
feat: new audit log - #3864
feat: new audit log#3864micbar wants to merge 7 commits into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 335 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
chi's ClientIPFrom* header middlewares trust the header from anyone who can
reach us. Pick the middleware per request instead: headers are only read
when the peer is a trusted proxy, everyone else gets their network address.
- PROXY_TRUSTED_PROXIES, defaults to loopback and private ranges
- PROXY_CLIENT_IP_HEADER, defaults to X-Forwarded-For, e.g. CF-Connecting-IP
- drop the strategy setting and xff_trusted_hops
- pass the client address to the services in X-Forwarded-For instead of
X-Client-Ip, reva reads it e.g. for OCM
- same check in collaboration, traefik routes to it directly
- OC_TRUSTED_PROXIES and OC_CLIENT_IP_HEADER set both services
- the other services only drop RealIP, none of them reads the address
Taken from opencloud-eu#3864 and opencloud-eu#3464 (comment)
chi's ClientIPFrom* header middlewares trust the header from anyone who can
reach us. Pick the middleware per request instead: headers are only read
when the peer is a trusted proxy, everyone else gets their network address.
- PROXY_TRUSTED_PROXIES, defaults to loopback and private ranges
- PROXY_CLIENT_IP_HEADER, defaults to X-Forwarded-For, e.g. CF-Connecting-IP
- drop the strategy setting and xff_trusted_hops
- pass the client address to the services in X-Forwarded-For instead of
X-Client-Ip, reva reads it e.g. for OCM
- same check in collaboration, traefik routes to it directly
- OC_TRUSTED_PROXIES and OC_CLIENT_IP_HEADER set both services
- the other services only drop RealIP, none of them reads the address
Taken from opencloud-eu#3864 and opencloud-eu#3464 (comment)
# Conflicts:
# services/proxy/README.md
chi's ClientIPFrom* header middlewares trust the header from anyone who can
reach us. Pick the middleware per request instead: headers are only read
when the peer is a trusted proxy, everyone else gets their network address.
- PROXY_TRUSTED_PROXIES, defaults to loopback and private ranges
- PROXY_CLIENT_IP_HEADER, defaults to X-Forwarded-For, e.g. CF-Connecting-IP
- drop the strategy setting and xff_trusted_hops
- pass the client address to the services in X-Forwarded-For instead of
X-Client-Ip, reva reads it e.g. for OCM
- same check in collaboration, traefik routes to it directly
- OC_TRUSTED_PROXIES and OC_CLIENT_IP_HEADER set both services
- the other services only drop RealIP, none of them reads the address
Taken from #3864 and #3464 (comment)
# Conflicts:
# services/proxy/README.md
9da196a to
a72ba7b
Compare
|
rebased, the realIP middleware changes have been merged to |
422fe98 to
fdd3127
Compare
|
Hi Michael, I reviewed the reva part in opencloud-eu/reva#956 and looked at how the services here use it. I know this one is still a draft, so take these as early notes, mostly about how a service gets its emitter: 1. Creating an emitter takes a lot of code in each service graph and proxy each build the emitter by hand, with the same ~20 lines: the NATS connection name from The Keeping the per-service env var overrides is in line with how the other settings work, but the struct, its defaults and building the emitter could live in one place, e.g. a shared emitter, err := audit.NewEmitter(ctx, cfg.Service.Name, cfg.Audit, cfg.Events, logger)
if err != nil {
return err
}
defer emitter.Close()Adding audit events to another service later would then be a few lines instead of copying the setup again. 2. Audit without an events endpoint is silently off in graph and proxy Both only create the emitter when 3. The mode isn't validated An unknown 4. With the current reva code, a request that still emits while the service shuts down panics after I only looked at the parts that touch the reva API, not the whole PR. One thing I checked and liked: the proxy drops an |
The audit service reads the JetStream stream `audit` and writes every record as one line of JSON to stdout and, if configured, to an OTLP endpoint, with the emitting service in the resource. A record is acknowledged only when all outputs have it, so an output outage keeps the records in the stream, in order and without duplicates. The old audit log stays available with AUDIT_LEGACY_ENABLED. Adds the OpenTelemetry log packages for the OTLP output.
The HTTP services put the X-Audit-Context header of the proxy into the request context, so it reaches reva with the next call.
The proxy builds the audit request context: client address (PROXY_CLIENT_IP_HEADER behind trusted proxies), user agent, auth method, session and OIDC client. A value a client sent in X-Audit-Context is dropped. A login is recorded once per OIDC session and client, not per access token. Public link access is recorded with the client address, failed attempts every time.
Also records denied space creation and data exports of other users.
frontend, sharing and storage-users pass the audit settings and the service version to the reva audit emitters. `best_effort` is the only mode for now, any other value stops the service. The frontend keeps the events endpoint the archiver needs for its records.
target and path semantics, the public link as actor, roles and recipients in share records, one login per OIDC session, the link access dedupe, the output ordering and why strict comes later.
|
@pbleser-oc Thanks! 2. to 4. are done with the fixes from the reva review: graph and proxy use
|
|
Thanks Michael, |
Description
First part of the audit log from ADR 0006. The services emit audit events into the JetStream stream
audit, the audit service writes them as JSON lines to stdout and, if configured, to an OpenTelemetry Collector.Off by default. Enable it with
OC_AUDIT_ENABLED=trueandOC_ADD_RUN_SERVICES=audit. The old audit log stays available withAUDIT_LEGACY_ENABLED.Needs opencloud-eu/reva#956. The reva bump is not in the PR yet, so the build fails until it is merged.
flowchart LR client([client]) --> proxy proxy -- X-Audit-Context --> services[graph, frontend,<br/>sharing, storage-users] proxy -- events --> stream[(JetStream<br/>audit)] services -- events --> stream stream --> auditsvc[audit service] auditsvc --> stdout[stdout] auditsvc --> otlp[OTLP Collector]Implementation
One commit per part, best reviewed commit by commit.
feat(audit): write audit records from the audit streamopencloud_audit_consumer_lagalso counts records waiting for a failed outputpkg/middleware.AuditContextputsX-Audit-Contextinto the request context, so it reaches revafeat(proxy): logins, public link access and backchannel logoutsX-Audit-Contextsent by a clientsidfeat(graph): user, group and role changesdocs(adr): the decisions from the first implementation, see belowrefactor(audit): build the audit emitter in one placepkg/auditemitterfor graph and proxy, from the reviewNot in this part: syslog output, the policy, pseudonymization and the events the README lists as not emitted yet.
ADR 0006
The first implementation added these decisions:
targetis the object before the action, new values go intochange.aftertarget.pathis the path in the space, also through a share or a linkpublic_link.accessonce per link and client within 30 minutes, every failed attemptbest_effortis the only mode,strictcomes back when it can refuse a request before it actsactor.impersonated_bybecomes an ID and a name, not filled yetWhat changes for developers
pkg/auditauditemitter.New, see graph and proxyaudit_enabled,audit_mode,audit_serviceandaudit_service_versionin its revaconfig, see sharing and storage-usersmiddleware.AuditContext. Only the proxy sets itauditEvents(services/graph/pkg/service/v0/audit.go). Routes without a domain event useauditOnError,auditOnDeniedorauditAlwayswriter.Sink. Return the error, the writer retries the record on this output onlyRelated Issue
Motivation and Context
The old audit log is built from the domain events. It only sees successful actions, has no client address and its records have no stable format for a SIEM.
How Has This Been Tested?
opencloud serverwithOC_AUDIT_ENABLED=true, the audit service in its own process, built-in IdPpkg/auditemitterand revapkg/auditScreenshots (if appropriate):
Types of changes
Checklist: