Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
e84542a
[Server] Audit records for issued storage credentials
shba24 Oct 21, 2026
15399f7
[Server] Audit: one error for a sink that can't be loaded
shba24 Oct 27, 2026
3084d55
[Server] Audit: drop the unused unreportedFailures accessor
shba24 Oct 27, 2026
a631425
[Server] Audit: drop the audit-off wiring IT
shba24 Oct 27, 2026
81d6c87
[Helm] Audit: keep the README section to the enabling snippet
shba24 Oct 27, 2026
8fbc8df
[Server] Audit: close the sink after Armeria's JVM-shutdown drain
shba24 Oct 27, 2026
4fbb2ef
[Server] Audit: rate-limit the lost-record report too
shba24 Oct 27, 2026
fa84727
[Server] Audit: report a location that can't be sanitized
shba24 Oct 27, 2026
7a5e96c
[Server] Audit: word failure logs as record failures, not sink failures
shba24 Oct 27, 2026
06bf638
[Server] Audit: require time and action, and make expires_at an Instant
shba24 Oct 27, 2026
e2c85ed
[Docs] Audit: correct the user values, resource_id and sink threads
shba24 Oct 27, 2026
4bceff3
[Server] Audit: cover ABFS locations, ignoreExceptions and local clea…
shba24 Oct 27, 2026
9980d07
[Server] Audit: say the credential purpose only labels the audit record
shba24 Oct 27, 2026
532358e
[Server] Audit records for permission changes
shba24 Oct 21, 2026
a04d26f
[Server] Audit: drop records after close, and log a missing field on …
shba24 Oct 28, 2026
d2414f4
[Server] Audit: cover REVOKE in the permission IT
shba24 Oct 27, 2026
d86843d
[Server] Audit: create the auditor in the server so a failed start cl…
shba24 Oct 28, 2026
8986ec3
[Server] Audit: name server-internal work system:server
shba24 Oct 27, 2026
00bc15e
[Server] Audit: only the server turns auditing on
shba24 Oct 28, 2026
ebb1b6c
[Docs] Audit: document principal_id and what the authorizer wrapper r…
shba24 Oct 27, 2026
e783783
[Server] Audit: say a record can still reach the sink just after close
shba24 Oct 28, 2026
2d9f0ef
[Server] Audit: cover principal_id and the user-delete clear in the p…
shba24 Oct 27, 2026
637e94e
Merge branch 'main' into uc-audit-records
shba24 Oct 29, 2026
b750a16
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 29, 2026
5eb0107
[Server] Audit: vend the cleanup test's credentials through the audit…
shba24 Oct 30, 2026
9d2923b
[Server] Audit: roll audit.log over hourly and keep 7 days or 1GB, li…
shba24 Oct 30, 2026
79b3a79
[Server] Audit: describe the user field as the token's subject, not a…
shba24 Oct 30, 2026
bb57288
Merge main into uc-audit-records
shba24 Oct 30, 2026
bca133b
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
5d625b1
[Server] Audit: record every revoke and clear, and say which records …
shba24 Oct 30, 2026
81626c2
[Docs] Audit: list every record field, say records are best effort, a…
shba24 Oct 30, 2026
ff632a0
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
996484c
[Server] Audit: say in the Javadocs that revokes and clears are alway…
shba24 Oct 30, 2026
9ecc225
[Server] Audit: pass the cleanup resource ID to the credential, and o…
shba24 Oct 30, 2026
760c242
[Server] Audit: redact ABFS user info that is not a container name
shba24 Oct 30, 2026
820ba3a
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
5287506
[Server] Audit: keep an unparseable location out of the log, and test…
shba24 Oct 30, 2026
864fef3
[Docs] Audit: fix the user, ABFS and logger wording
shba24 Oct 30, 2026
c7bd7a1
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
8dbb138
[Server] Audit: refuse to start when the appender reference drops aud…
shba24 Oct 30, 2026
b2a1790
[Docs] Audit: add a location bullet and fix the user info wording and…
shba24 Oct 30, 2026
e9cada6
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
2c475da
[Server] Audit: state the revoke and clear contract in the Javadoc
shba24 Oct 30, 2026
176bf2e
[Server] Audit: refuse to start when a filter could drop audit records
shba24 Oct 30, 2026
4211d4f
[Docs] Audit: list every Log4j requirement, scope the rollover senten…
shba24 Oct 30, 2026
01ddf30
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
cbc5461
Merge main into stack/uc-audit-permissions
shba24 Oct 30, 2026
a24cf7c
Merge main into uc-audit-records
shba24 Oct 30, 2026
87ab99d
[Server] Audit: pass the resource type through the authorizer decorator
shba24 Oct 30, 2026
b4a7f31
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 30, 2026
85f92c1
[Server] Audit: require the purpose when vending a credential, and dr…
shba24 Oct 31, 2026
f1ab118
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Oct 31, 2026
c254428
[Server] Audit: wrap the authorizer with the server's own auditor
shba24 Oct 31, 2026
bf0d66b
Merge main into uc-audit-records
shba24 Nov 2, 2026
dacf303
[Server] Audit: label a vended credential with one CredentialUse value
shba24 Nov 2, 2026
2e303a8
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 2, 2026
86b0e0c
[Server] Audit: review fixes for comments and test placement
shba24 Nov 2, 2026
0f7e6dd
[Server] Audit: check only file and console appenders in FileAuditSink
shba24 Nov 2, 2026
446762a
[Server] Audit: check only file and console appender classes
shba24 Nov 2, 2026
99ba889
[Server] Audit: nest Purpose in AuditRecord
shba24 Nov 2, 2026
3beef7a
[Server] Audit: keep one Purpose enum
shba24 Nov 2, 2026
95726ab
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 3, 2026
4a29cb4
[Server] Audit: use AuditRecord.Purpose in the permission IT
shba24 Nov 3, 2026
0f832c5
[Server] Audit: make AuditingAuthorizer package-private and fix two d…
shba24 Nov 3, 2026
5d1d997
[Server] Audit: say a revoke or clear record means it was attempted
shba24 Nov 3, 2026
5f1d0a9
[Server] Audit: a failed revoke or clear delete throws, so it is not …
shba24 Nov 3, 2026
1e2b0aa
[Server] Audit: say a revoke or clear is recorded once it finishes wi…
shba24 Nov 3, 2026
05c3a79
[Server] Audit: test that a revoke or clear that throws writes no record
shba24 Nov 3, 2026
d0f7d06
[Build] Pin Failsafe 3.2.3 so a failed jCasbin policy write is not a …
shba24 Nov 3, 2026
a3f4771
[Server] Audit: stop the Log4j configurations AuditorTest builds
shba24 Nov 3, 2026
7a8769f
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 3, 2026
529e9db
[Build] Note to re-check the Failsafe pin when bumping Iceberg
shba24 Nov 3, 2026
cdf90e3
[Build] Declare Failsafe 3.2.3 directly so the published POM carries …
shba24 Nov 3, 2026
5478e64
[Server] Audit: put the default-method Javadoc back on its test
shba24 Nov 3, 2026
e98ca9b
[Docs] Audit: the user is the token's email or admin, never a service…
shba24 Nov 3, 2026
f94da72
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 3, 2026
2b9714b
[Server] Audit: let Jackson write enums and UUIDs in FileAuditSink
shba24 Nov 3, 2026
ace90e3
[Server] Audit: build FileAuditSink validation errors in one helper
shba24 Nov 3, 2026
28288dd
[Server] Audit: drop the unreachable null check in sanitizeLocation
shba24 Nov 3, 2026
2632419
[Server] Audit: drop the self-evident expiresAt Javadoc
shba24 Nov 3, 2026
6f20820
[Server] Audit: drop the comment that repeats CHECKED_APPENDERS
shba24 Nov 3, 2026
2012ae5
[Docs] Audit: describe a custom sink once, in the two-ways list
shba24 Nov 3, 2026
f4a3350
[Docs] Audit: shorten the rollover paragraph
shba24 Nov 3, 2026
64288dc
[Docs] Audit: shorten the server.properties comment to two lines
shba24 Nov 3, 2026
036a80c
[Docs] Audit: shorten the Helm README audit section
shba24 Nov 3, 2026
b7911b7
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 3, 2026
9403266
[Server] Audit: move the permission audit test into SdkTableAccessCon…
shba24 Nov 3, 2026
efd7c75
[Docs] Audit: drop the reason a revoke is recorded without a removed …
shba24 Nov 3, 2026
cd3b9d9
[Docs] Audit: drop the note that parent and child links are not recorded
shba24 Nov 3, 2026
1f4b974
[Server] Audit: state the authorizer record contract once, on Auditor…
shba24 Nov 3, 2026
06e3e02
[Server] Audit: find user info in the decoded authority
shba24 Nov 4, 2026
e020887
[Server] Audit: test that a credential served from the cache is recorded
shba24 Nov 4, 2026
043aad6
[Server] Audit: test the rate-limited failure report
shba24 Nov 4, 2026
50d8d99
[Server] Audit: drop the comment's claim that dropped records were re…
shba24 Nov 4, 2026
efb86a1
[Docs] Audit: say the Helm chart has no server.log file
shba24 Nov 4, 2026
26ffb3a
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 4, 2026
0699deb
[Docs] Audit: say what a record for local file storage means
shba24 Nov 4, 2026
1809cde
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 4, 2026
d1bb455
[Server] Audit: test that a failure a minute later reports the count
shba24 Nov 4, 2026
5ea525b
[Server] Audit: say only an encoded @ ends user info in the test comment
shba24 Nov 4, 2026
4da9394
[Server] Audit: share the static S3 test properties in RepositoriesTest
shba24 Nov 4, 2026
36f5c7c
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 4, 2026
897832a
[Server] Audit: also check the first vend is a cache miss in the cach…
shba24 Nov 4, 2026
fefbad6
[Server] Audit: test what the file sink writes, without reading log f…
shba24 Nov 4, 2026
04008ff
[Server] Audit: say the test helper initializes the Log4j config, not…
shba24 Nov 5, 2026
91f0884
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 5, 2026
f581cca
[Docs] Audit: say which file: accesses are recorded, that access is w…
shba24 Nov 5, 2026
bbed4f7
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 5, 2026
cf57b06
[Server] Audit: record Iceberg loads of local tables like other file:…
shba24 Nov 5, 2026
fad9e62
Merge uc-audit-records (#2028) into stack/uc-audit-permissions
shba24 Nov 5, 2026
9c3a95b
Merge main into stack/uc-audit-permissions
shba24 Nov 6, 2026
549edb0
[Server] Audit: address review on the permission records
shba24 Nov 6, 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
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ lazy val sparkVersion = CrossSparkVersions.getSparkArtifactVersion()
lazy val hadoopVersion = sys.props.getOrElse("hadoopVersion", "3.4.2")

// Library versions
// When bumping Iceberg, re-check the Failsafe pin in the server dependencyOverrides: iceberg-aws
// must not need a Failsafe API that the pinned version lacks.
lazy val icebergVersion = "1.11.0"
lazy val jacksonVersion = "2.18.10"
lazy val openApiToolsJacksonBindNullableVersion = "0.2.11"
Expand Down Expand Up @@ -469,6 +471,9 @@ lazy val server = (project in file("server"))
"org.casbin" % "jdbc-adapter" % "2.13.0"
exclude("com.microsoft.sqlserver", "mssql-jdbc")
exclude("com.oracle.database.jdbc", "ojdbc6"),
// Also a direct dependency so the published POM carries the Failsafe pin from
// dependencyOverrides below; see the TODO there.
"dev.failsafe" % "failsafe" % "3.2.3",
"org.postgresql" % "postgresql" % postgresqlVersion,
"org.springframework" % "spring-expression" % "6.2.19",
"com.auth0" % "java-jwt" % "4.6.1",
Expand Down Expand Up @@ -498,6 +503,14 @@ lazy val server = (project in file("server"))
dependencyOverrides ++= Seq(
// One PostgreSQL driver: jdbc-adapter brings 42.7.2. Keep in step with the direct dependency.
"org.postgresql" % "postgresql" % postgresqlVersion,
// jdbc-adapter 2.13.0 calls ExecutionContext.getLastFailure, which Failsafe 3.3.0 removed, so on
// the 3.3.2 that iceberg-aws brings a failed policy write throws NoSuchMethodError. iceberg-aws
// only uses Failsafe APIs that 3.2.3 has.
// TODO(https://github.com/apache/casbin-jcasbin-jdbc-adapter/pull/94): drop this pin once a
// jdbc-adapter release includes that change. The pin applies to this project only: serverShaded
// ships 3.2.3 because its assembly classpath is this project's, and any other module that depends
// on server resolves 3.3.2 unless it pins Failsafe too.
"dev.failsafe" % "failsafe" % "3.2.3",
Comment thread
shba24 marked this conversation as resolved.
Resolved
"software.amazon.awssdk" % "sso" % awsSdkV2Version,
"software.amazon.awssdk" % "ssooidc" % awsSdkV2Version,
"software.amazon.awssdk" % "s3" % awsSdkV2Version,
Expand Down
29 changes: 22 additions & 7 deletions docs/server/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ Durations use the ISO-8601 format (for example `PT1M` is one minute, `PT5M` is f

### 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:
The server can write an audit record for each storage credential it issues and each permission
change. Audit records are off by default. Set `server.audit.sink` to turn them on:

| Property | Default | Description |
| --- | --- | --- |
Expand All @@ -155,15 +156,24 @@ Each record is one JSON line. Fields that don't apply to a record are left out:
```

- `time`: when the record was made, in ISO 8601 UTC.
- `action`: `ISSUE_CREDENTIAL`.
- `action`: `ISSUE_CREDENTIAL`, `GRANT`, `REVOKE`, `CLEAR_RESOURCE_GRANTS` (a dropped object's
grants), or `CLEAR_PRINCIPAL_GRANTS` (a deleted user's grants).
- `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.
bootstrap admin token. It is `system:server` for work the server does outside a request,
such as the admin grant made at first start, and 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.
- `resource_id`: on a permission change, the object whose grants changed (absent for
`CLEAR_PRINCIPAL_GRANTS`). On a `CLEANUP` credential, the ID of the dropped object. Other
credential records do not carry it.
- `principal_id`: on `GRANT`, `REVOKE` and `CLEAR_PRINCIPAL_GRANTS`, the ID of the user whose grants
changed.
- `privilege`: on `GRANT` and `REVOKE`, the privilege name, for example `USE CATALOG`, or `OWNER` for the
ownership grant made when an object is created.
- `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.
that request. It is absent on records not made while serving a request: `CLEANUP` records and
`system:server` records.
- `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
Expand All @@ -176,8 +186,13 @@ A record is written for every credential issued, including ones served from the
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.
`file:` storage write no record.

Permission changes are recorded only when authorization is on. A `GRANT` is recorded when it adds a grant.
Comment thread
shba24 marked this conversation as resolved.
Resolved
`REVOKE` and the two `CLEAR_*` actions are recorded once the server has run them without an error, whether or
not they removed a grant. If the database delete fails, the request fails and nothing is recorded.
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:

Expand Down
5 changes: 3 additions & 2 deletions etc/conf/server.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ server.access-token-timeout=PT24H
# The longest a vended credential is reused, counted from when it was vended.
# server.storage-credential-cache.max-age=PT5M

# The class that receives audit records, one per issued storage credential; unset (default) = off.
# FileAuditSink writes to the Log4j audit logger (etc/logs/audit.log as shipped). See the docs.
# The class that receives audit records, one per issued storage credential and permission change;
# unset (default) = off. FileAuditSink writes to the Log4j audit logger (etc/logs/audit.log as
# shipped). See the docs.
# server.audit.sink=io.unitycatalog.server.audit.FileAuditSink

#### AWS credential configs
Expand Down
8 changes: 4 additions & 4 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ delete both to remove the data.

## Audit records
Turn on [audit records](https://github.com/unitycatalog/unitycatalog/blob/main/docs/server/configuration.md#audit-records)
to write one JSON line per issued storage credential to `/home/unitycatalog/etc/logs/audit.log`; the
chart already configures the `audit` logger. The file is lost when the pod restarts, so ship it
continuously (for example from a sidecar in `server.deployment.extraContainers`) or keep the
directory on a volume:
to write one JSON line per issued storage credential and permission change to
`/home/unitycatalog/etc/logs/audit.log`; the chart already configures the `audit` logger. The file
is lost when the pod restarts, so ship it continuously (for example from a sidecar in
`server.deployment.extraContainers`) or keep the directory on a volume:

```yaml
server:
Expand Down
8 changes: 4 additions & 4 deletions helm/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ delete both to remove the data.

## Audit records
Turn on [audit records](https://github.com/unitycatalog/unitycatalog/blob/main/docs/server/configuration.md#audit-records)
to write one JSON line per issued storage credential to `/home/unitycatalog/etc/logs/audit.log`; the
chart already configures the `audit` logger. The file is lost when the pod restarts, so ship it
continuously (for example from a sidecar in `server.deployment.extraContainers`) or keep the
directory on a volume:
to write one JSON line per issued storage credential and permission change to
`/home/unitycatalog/etc/logs/audit.log`; the chart already configures the `audit` logger. The file
is lost when the pod restarts, so ship it continuously (for example from a sidecar in
`server.deployment.extraContainers`) or keep the directory on a volume:

```yaml
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ private UnityCatalogAuthorizer initializeAuthorizer(
JCasbinAuthorizer authorizer =
new JCasbinAuthorizer(hibernateConfigurator, serverProperties);
try {
new UnityAccessUtil(repositories).initializeAdmin(authorizer);
return authorizer;
UnityCatalogAuthorizer effective =
Optional.ofNullable(auditor).map(a -> a.wrap(authorizer)).orElse(authorizer);
new UnityAccessUtil(repositories).initializeAdmin(effective);
return effective;
} catch (Exception e) {
authorizer.close();
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
public class AuditRecord {
/** What the record records. */
public enum Action {
ISSUE_CREDENTIAL
ISSUE_CREDENTIAL,
GRANT,
REVOKE,
CLEAR_RESOURCE_GRANTS,
CLEAR_PRINCIPAL_GRANTS
}

/** Who a credential is for. */
Expand All @@ -42,8 +46,8 @@ public enum Access {
@NonNull Action action;

/**
* The caller's token subject (an email or {@code admin}), {@code system:storage-cleanup}, or
* null.
* The caller's token subject (an email or {@code admin}), {@code system:storage-cleanup}, {@code
* system:server}, or null.
*/
String user;

Expand All @@ -56,6 +60,10 @@ public enum Access {
Instant expiresAt;

UUID resourceId;
UUID principalId;

/** Privilege in its public spelling, for example {@code USE CATALOG} or {@code OWNER}. */
String privilege;

/**
* Declared so Javadoc, which runs without Lombok, can resolve the builder type; Lombok fills it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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.
* Receives one {@link AuditRecord} per issued storage credential and permission change. 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package io.unitycatalog.server.audit;

import io.unitycatalog.server.auth.UnityCatalogAuthorizer;
import io.unitycatalog.server.model.SecurableType;
import io.unitycatalog.server.persist.model.Privileges;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/** Records each permission change, as described on {@link Auditor#wrap(UnityCatalogAuthorizer)}. */
final class AuditingAuthorizer implements UnityCatalogAuthorizer, AutoCloseable {
private final UnityCatalogAuthorizer delegate;
private final Auditor auditor;

AuditingAuthorizer(UnityCatalogAuthorizer delegate, Auditor auditor) {
this.delegate = delegate;
this.auditor = auditor;
}

@Override
public boolean grantAuthorization(UUID principal, UUID resource, Privileges action) {
boolean changed = delegate.grantAuthorization(principal, resource, action);
if (changed) {
auditor.recordPermission(AuditRecord.Action.GRANT, principal, resource, action);
}
return changed;
}

@Override
public boolean revokeAuthorization(UUID principal, UUID resource, Privileges action) {
boolean changed = delegate.revokeAuthorization(principal, resource, action);
// Recorded whatever the flag says. In jCasbin, removePolicy and removeFilteredPolicy
// delete the rows through the adapter before they check the in-memory model, so a server that
// has not reloaded the policy deletes the rows and still returns false. A failed delete throws.
auditor.recordPermission(AuditRecord.Action.REVOKE, principal, resource, action);
return changed;
}

@Override
public boolean clearAuthorizationsForPrincipal(UUID principal) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Not a blocker, the behavior is right today. Only revoke is tested with a false return (the second revoke in the SDK test). Both clears return true in the tests, so wrapping either emission in if (changed) would still pass and silently drop records on a server with a stale policy. Can we pin it with a small AuditorTest case: a mock whose four mutators return false, asserting the grant records nothing, revoke and both clears each record one, and false is still returned?

boolean changed = delegate.clearAuthorizationsForPrincipal(principal);
auditor.recordPermission(AuditRecord.Action.CLEAR_PRINCIPAL_GRANTS, principal, null, null);
return changed;
}

@Override
public boolean clearAuthorizationsForResource(UUID resource) {
boolean changed = delegate.clearAuthorizationsForResource(resource);
auditor.recordPermission(AuditRecord.Action.CLEAR_RESOURCE_GRANTS, null, resource, null);
return changed;
}

@Override
public boolean addHierarchyChild(UUID parent, UUID child) {
return delegate.addHierarchyChild(parent, child);
}

@Override
public boolean removeHierarchyChild(UUID parent, UUID child) {
return delegate.removeHierarchyChild(parent, child);
}

@Override
public boolean removeHierarchyChildren(UUID resource) {
return delegate.removeHierarchyChildren(resource);
}

@Override
public UUID getHierarchyParent(UUID resource) {
return delegate.getHierarchyParent(resource);
}

@Override
public boolean authorize(
UUID principal, SecurableType resourceType, UUID resource, Privileges action) {
return delegate.authorize(principal, resourceType, resource, action);
}

@Override
public boolean authorizeAny(
UUID principal, SecurableType resourceType, UUID resource, Privileges... actions) {
return delegate.authorizeAny(principal, resourceType, resource, actions);
}

@Override
public boolean authorizeAll(
UUID principal, SecurableType resourceType, UUID resource, Privileges... actions) {
return delegate.authorizeAll(principal, resourceType, resource, actions);
}

@Override
public List<Privileges> listAuthorizations(UUID principal, UUID resource) {
return delegate.listAuthorizations(principal, resource);
}

@Override
public Map<UUID, List<Privileges>> listAuthorizations(UUID resource) {
return delegate.listAuthorizations(resource);
}

@Override
public boolean refreshAuthorizations(long operationStartNanos) {
return delegate.refreshAuthorizations(operationStartNanos);
}

@Override
public void close() throws Exception {
if (delegate instanceof AutoCloseable closeable) {
closeable.close();
}
}
}
30 changes: 29 additions & 1 deletion server/src/main/java/io/unitycatalog/server/audit/Auditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.auth0.jwt.interfaces.DecodedJWT;
import com.linecorp.armeria.server.ServiceRequestContext;
import io.unitycatalog.server.auth.UnityCatalogAuthorizer;
import io.unitycatalog.server.model.TemporaryCredentials;
import io.unitycatalog.server.persist.model.Privileges;
import io.unitycatalog.server.security.JwtClaim;
import io.unitycatalog.server.service.AuthDecorator;
import io.unitycatalog.server.service.credential.CredentialContext;
Expand All @@ -16,6 +18,7 @@
import java.time.Instant;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
Expand All @@ -31,6 +34,9 @@
public final class Auditor implements AutoCloseable {
static final String CLEANUP_USER = "system:storage-cleanup";

/** Work the server does outside any request, such as the admin grant at first start. */
static final String SERVER_USER = "system:server";

private static final Logger LOGGER = LoggerFactory.getLogger(Auditor.class);
private static final long REPORT_INTERVAL_MS = 60_000;
// An Azure container name: 3 to 63 lowercase letters, digits and hyphens.
Expand Down Expand Up @@ -90,6 +96,14 @@ public StorageCredentialVendor wrap(StorageCredentialVendor delegate) {
return new AuditingStorageCredentialVendor(delegate, this);
}

/**
* Wraps an authorizer so each permission change is recorded: a grant when it adds one, and a
* revoke or clear once it finishes without throwing, whether or not it removed a grant.
*/
public UnityCatalogAuthorizer wrap(UnityCatalogAuthorizer delegate) {
return new AuditingAuthorizer(delegate, this);
}

void recordCredential(
NormalizedURL path,
Set<CredentialContext.Privilege> privileges,
Expand All @@ -111,6 +125,17 @@ void recordCredential(
.build());
}

void recordPermission(
AuditRecord.Action action, UUID principalId, UUID resourceId, Privileges privilege) {
emit(
() ->
base(action, null)
.principalId(principalId)
.resourceId(resourceId)
.privilege(privilege == null ? null : privilege.getValue())
.build());
}

/**
* Keeps scheme, authority and path, so query strings, fragments and user info (which can carry
* secrets) never reach a sink. ABFS keeps its {@code container@account} authority, with anything
Expand Down Expand Up @@ -174,7 +199,10 @@ private static String user(AuditRecord.Purpose purpose, ServiceRequestContext ct
if (purpose == AuditRecord.Purpose.CLEANUP) {
return CLEANUP_USER;
}
DecodedJWT jwt = ctx == null ? null : ctx.attr(AuthDecorator.DECODED_JWT_ATTR);
if (ctx == null) {
return SERVER_USER;
}
DecodedJWT jwt = ctx.attr(AuthDecorator.DECODED_JWT_ATTR);
return jwt == null ? null : jwt.getClaim(JwtClaim.SUBJECT.key()).asString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ static String toJson(AuditRecord r) {
put(m, "access", r.getAccess());
put(m, "expires_at", r.getExpiresAt() == null ? null : TIME.format(r.getExpiresAt()));
put(m, "resource_id", r.getResourceId());
put(m, "principal_id", r.getPrincipalId());
put(m, "privilege", r.getPrivilege());
try {
return MAPPER.writeValueAsString(m);
} catch (JsonProcessingException e) {
Expand Down
Loading
Loading