Repository navigation
[Server] Audit records for issued storage credentials #2028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,487
−131
Merged
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
e84542a
[Server] Audit records for issued storage credentials
shba24 15399f7
[Server] Audit: one error for a sink that can't be loaded
shba24 3084d55
[Server] Audit: drop the unused unreportedFailures accessor
shba24 a631425
[Server] Audit: drop the audit-off wiring IT
shba24 81d6c87
[Helm] Audit: keep the README section to the enabling snippet
shba24 8fbc8df
[Server] Audit: close the sink after Armeria's JVM-shutdown drain
shba24 4fbb2ef
[Server] Audit: rate-limit the lost-record report too
shba24 fa84727
[Server] Audit: report a location that can't be sanitized
shba24 7a5e96c
[Server] Audit: word failure logs as record failures, not sink failures
shba24 06bf638
[Server] Audit: require time and action, and make expires_at an Instant
shba24 e2c85ed
[Docs] Audit: correct the user values, resource_id and sink threads
shba24 4bceff3
[Server] Audit: cover ABFS locations, ignoreExceptions and local clea…
shba24 9980d07
[Server] Audit: say the credential purpose only labels the audit record
shba24 a04d26f
[Server] Audit: drop records after close, and log a missing field on …
shba24 d86843d
[Server] Audit: create the auditor in the server so a failed start cl…
shba24 00bc15e
[Server] Audit: only the server turns auditing on
shba24 e783783
[Server] Audit: say a record can still reach the sink just after close
shba24 637e94e
Merge branch 'main' into uc-audit-records
shba24 5eb0107
[Server] Audit: vend the cleanup test's credentials through the audit…
shba24 9d2923b
[Server] Audit: roll audit.log over hourly and keep 7 days or 1GB, li…
shba24 79b3a79
[Server] Audit: describe the user field as the token's subject, not a…
shba24 bb57288
Merge main into uc-audit-records
shba24 81626c2
[Docs] Audit: list every record field, say records are best effort, a…
shba24 9ecc225
[Server] Audit: pass the cleanup resource ID to the credential, and o…
shba24 760c242
[Server] Audit: redact ABFS user info that is not a container name
shba24 5287506
[Server] Audit: keep an unparseable location out of the log, and test…
shba24 864fef3
[Docs] Audit: fix the user, ABFS and logger wording
shba24 8dbb138
[Server] Audit: refuse to start when the appender reference drops aud…
shba24 b2a1790
[Docs] Audit: add a location bullet and fix the user info wording and…
shba24 176bf2e
[Server] Audit: refuse to start when a filter could drop audit records
shba24 4211d4f
[Docs] Audit: list every Log4j requirement, scope the rollover senten…
shba24 a24cf7c
Merge main into uc-audit-records
shba24 85f92c1
[Server] Audit: require the purpose when vending a credential, and dr…
shba24 bf0d66b
Merge main into uc-audit-records
shba24 dacf303
[Server] Audit: label a vended credential with one CredentialUse value
shba24 86b0e0c
[Server] Audit: review fixes for comments and test placement
shba24 0f7e6dd
[Server] Audit: check only file and console appenders in FileAuditSink
shba24 446762a
[Server] Audit: check only file and console appender classes
shba24 99ba889
[Server] Audit: nest Purpose in AuditRecord
shba24 3beef7a
[Server] Audit: keep one Purpose enum
shba24 a3f4771
[Server] Audit: stop the Log4j configurations AuditorTest builds
shba24 e98ca9b
[Docs] Audit: the user is the token's email or admin, never a service…
shba24 2b9714b
[Server] Audit: let Jackson write enums and UUIDs in FileAuditSink
shba24 ace90e3
[Server] Audit: build FileAuditSink validation errors in one helper
shba24 28288dd
[Server] Audit: drop the unreachable null check in sanitizeLocation
shba24 2632419
[Server] Audit: drop the self-evident expiresAt Javadoc
shba24 6f20820
[Server] Audit: drop the comment that repeats CHECKED_APPENDERS
shba24 2012ae5
[Docs] Audit: describe a custom sink once, in the two-ways list
shba24 f4a3350
[Docs] Audit: shorten the rollover paragraph
shba24 64288dc
[Docs] Audit: shorten the server.properties comment to two lines
shba24 036a80c
[Docs] Audit: shorten the Helm README audit section
shba24 06e3e02
[Server] Audit: find user info in the decoded authority
shba24 e020887
[Server] Audit: test that a credential served from the cache is recorded
shba24 043aad6
[Server] Audit: test the rate-limited failure report
shba24 50d8d99
[Server] Audit: drop the comment's claim that dropped records were re…
shba24 efb86a1
[Docs] Audit: say the Helm chart has no server.log file
shba24 0699deb
[Docs] Audit: say what a record for local file storage means
shba24 d1bb455
[Server] Audit: test that a failure a minute later reports the count
shba24 5ea525b
[Server] Audit: say only an encoded @ ends user info in the test comment
shba24 4da9394
[Server] Audit: share the static S3 test properties in RepositoriesTest
shba24 897832a
[Server] Audit: also check the first vend is a cache miss in the cach…
shba24 fefbad6
[Server] Audit: test what the file sink writes, without reading log f…
shba24 04008ff
[Server] Audit: say the test helper initializes the Log4j config, not…
shba24 f581cca
[Docs] Audit: say which file: accesses are recorded, that access is w…
shba24 cf57b06
[Server] Audit: record Iceberg loads of local tables like other file:…
shba24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,68 @@ The cache is controlled by these keys: | |
|
|
||
| Durations use the ISO-8601 format (for example `PT1M` is one minute, `PT5M` is five minutes). | ||
|
|
||
| ### Audit records | ||
|
|
||
| The server can write an audit record for each storage credential it issues. Audit records are off by default. Set `server.audit.sink` to turn them on: | ||
|
|
||
| | Property | Default | Description | | ||
| | --- | --- | --- | | ||
| | `server.audit.sink` | (unset) | The class that receives audit records. `io.unitycatalog.server.audit.FileAuditSink` writes them to `etc/logs/audit.log`. When unset, no records are written. | | ||
|
|
||
| Each record is one JSON line. Fields that don't apply to a record are left out: | ||
|
|
||
| ```json | ||
| {"time":"2026-10-20T10:02:00.000Z","action":"ISSUE_CREDENTIAL","user":"[email protected]","request_id":"a1b2c3d4","purpose":"CLIENT","location":"s3://bucket/root/tables/7f3a1c2e-5b6d-4e8f-9a0b-1c2d3e4f5a6b","access":"READ","expires_at":"2026-10-20T11:02:00.000Z"} | ||
| ``` | ||
|
|
||
| - `time`: when the record was made, in ISO 8601 UTC. | ||
| - `action`: `ISSUE_CREDENTIAL`. | ||
| - `user`: `system:storage-cleanup` on `CLEANUP` records, whether or not authorization is on. On other | ||
| records, the caller's identity from the token (`sub`): the user's email, or `admin` for the | ||
| bootstrap admin token. It is absent when authorization is off. | ||
| - `purpose`: `CLIENT` for a credential returned to the caller, `SERVER` for one the server uses | ||
| itself while handling the request, and `CLEANUP` for the background storage cleanup. | ||
| - `resource_id`: on a `CLEANUP` credential, the ID of the dropped object. | ||
| - `request_id`: the ID of the request being served, the same as `request_id` in the `server.log` lines of | ||
| that request. It is absent on `CLEANUP` records, which are not made while serving a request. | ||
| - `location`: the storage location, with scheme, authority and path only. The query string and | ||
| fragment are removed. User info is removed too, except that for ABFS the part before the `@` is | ||
| kept when it looks like a container name (3 to 63 lowercase letters, digits and hyphens) and is | ||
| replaced by `[REDACTED]` otherwise. | ||
| - `access` is `READ` or `READ_WRITE`: the access the request asked for. A static credential, such as | ||
| configured S3 keys, is returned as configured and can allow more. `expires_at` is when the | ||
| credential expires. Records never contain credential values. | ||
|
|
||
| A record is written for every credential issued, including ones served from the credential cache. | ||
| For local `file:` storage there is no credential to issue. A request for credentials, through the | ||
| temporary-credentials endpoints, the Delta API or the Iceberg REST catalog, still writes a record of | ||
| the access the server granted, without `expires_at`. The server's own reads, writes and cleanup of | ||
| `file:` storage write no record. Audit records are best effort: one can be lost when the sink fails, | ||
| or when a request is still running as the server shuts down. | ||
|
|
||
| There are two ways to send records: | ||
|
|
||
| - `FileAuditSink`, shipped with the server, writes each record to the Log4j `audit` logger. As | ||
| shipped, that logger writes to `etc/logs/audit.log`, but you can point it at any Log4j appender, | ||
| for example one that ships records to a cloud service. | ||
| - Your own class that implements `io.unitycatalog.server.audit.AuditSink`, for example one that | ||
| sends records to Kinesis or SQS. It needs a public no-arg constructor and must be on the server | ||
| classpath; the server does not start if it can't be loaded. `record` is called concurrently, so | ||
| it must be thread-safe, and should queue records instead of sending them inline. See the | ||
| `AuditSink` Javadoc for the full contract. | ||
|
|
||
| `FileAuditSink` needs the `audit` logger in `etc/conf/server.log4j2.properties`, set to | ||
| `additivity = false` and a level that enables `INFO`. Neither the Log4j configuration nor the `audit` logger may | ||
| have a filter, and the link to the appender (`logger.audit.appenderRef.*`) may have neither a filter | ||
| nor a level above `INFO`, because any of these drops records silently. A file or console appender | ||
| must also set `ignoreExceptions = false` and have no filter; other appenders are not checked. The | ||
| shipped configuration meets all of this. If a requirement is not met, for example in a custom or | ||
| copied log configuration without the `audit` logger, the server does not start. | ||
|
|
||
| `audit.log` rolls over with the same settings as `server.log` in the default distribution. The Helm | ||
| chart has no `server.log` file and rolls `audit.log` the same way. Ship it continuously to your log or | ||
| security service to keep the records longer. | ||
|
|
||
| ## Logging | ||
|
|
||
| The server logs are located at `etc/logs/server.log`. The log level and log rolling policy can be set in log4j2 config | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
server/src/main/java/io/unitycatalog/server/audit/AuditRecord.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package io.unitycatalog.server.audit; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
| import lombok.Builder; | ||
| import lombok.NonNull; | ||
| import lombok.Value; | ||
|
|
||
| /** | ||
| * One audit record. It holds no secrets: no credential values, and storage locations without query | ||
| * or fragment, and without user info except an ABFS container name before the {@code @}. Fields | ||
| * that don't apply to the record's action are null. | ||
| */ | ||
| @Value | ||
| @Builder | ||
| public class AuditRecord { | ||
| /** What the record records. */ | ||
| public enum Action { | ||
| ISSUE_CREDENTIAL | ||
| } | ||
|
|
||
| /** Who a credential is for. */ | ||
| public enum Purpose { | ||
| /** Returned to the API caller. */ | ||
| CLIENT, | ||
| /** Used by the server itself while handling a request. */ | ||
| SERVER, | ||
| /** Used by the background storage cleanup. */ | ||
| CLEANUP | ||
| } | ||
|
|
||
| /** | ||
| * The access the request asked for. A static credential is returned as configured and can allow | ||
| * more. | ||
| */ | ||
| public enum Access { | ||
| READ, | ||
| READ_WRITE | ||
| } | ||
|
|
||
| @NonNull Instant time; | ||
| @NonNull Action action; | ||
|
|
||
| /** | ||
| * The caller's token subject (an email or {@code admin}), {@code system:storage-cleanup}, or | ||
| * null. | ||
| */ | ||
| String user; | ||
|
|
||
| String requestId; | ||
| Purpose purpose; | ||
| String location; | ||
|
|
||
| Access access; | ||
|
|
||
| Instant expiresAt; | ||
|
|
||
| UUID resourceId; | ||
|
|
||
| /** | ||
| * Declared so Javadoc, which runs without Lombok, can resolve the builder type; Lombok fills it. | ||
| */ | ||
| public static class AuditRecordBuilder {} | ||
| } |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/io/unitycatalog/server/audit/AuditSink.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package io.unitycatalog.server.audit; | ||
|
|
||
| /** | ||
| * Receives one {@link AuditRecord} per issued storage credential. Configure an implementation with | ||
| * {@code server.audit.sink}; it needs a public no-arg constructor and must be on the server | ||
| * classpath. | ||
| * | ||
| * <ul> | ||
| * <li>{@link #record} is called concurrently, from request threads and from the server's own | ||
| * threads such as the storage cleanup, so implementations must be thread-safe. | ||
| * <li>{@link #record} runs on the calling thread. A sink that sends records to a remote service | ||
| * should queue them and send asynchronously, and flush in {@link #close}. | ||
| * <li>A failure thrown from {@link #record} or {@link #close} is logged and never fails the | ||
| * request or the shutdown. | ||
| * <li>Compatibility: {@link AuditRecord} may gain new getters and builder methods; existing ones | ||
| * are never removed, renamed or retyped. Its enum fields may gain values, so handle unknown | ||
| * values. New methods on this interface are only added as {@code default} methods. | ||
| * </ul> | ||
| */ | ||
| public interface AuditSink extends AutoCloseable { | ||
| /** Records one audit record. See the threading and failure rules above. */ | ||
| void record(AuditRecord record); | ||
|
|
||
| /** | ||
| * Called once when the server shuts down. The server stops passing records before calling this, | ||
| * but a request that outlived the shutdown drain can still call {@link #record} while this runs | ||
| * or just after it; a sink that stops on close should drop such records. | ||
| */ | ||
| @Override | ||
| default void close() {} | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.