Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions docs/server/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ values under that pattern can steer JWKS fetches (an SSRF-style surface).
Use wildcard issuers only where necessary, only for domains you control, and avoid patterns that
cover internal or sensitive hosts. Prefer exact issuer URLs and `https://` issuers when possible.

### Permission-check migration

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.

Can we say here that this flag is temporary, and when it goes away? For example: "This setting is temporary and will be removed before the first stable (1.0) release. Set it to false only while you update applications and grants."

Right now the docs say to use false only during a migration but give no deadline, and the PR description says the fallback "can be deleted after the migration" with no date. A removal target tells operators when they must have fixed their grants and scripts. It also tells contributors when the fallback conditions in the follow-up PRs can be deleted. main is at 0.8.0-SNAPSHOT, so the flag first ships in the next release.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added that it’s temporary. I’d leave the removal version open for now.


`server.authorization.strict-privilege-checks` is a temporary migration setting. It defaults to
`true` and will be removed in a future release. Permission fixes that use this setting apply the
corrected rules by default.

The access checks apply only when `server.authorization=enable`.

To keep the previous rules during a migration, set:

```properties
server.authorization.strict-privilege-checks=false
```

The setting does not disable authorization. It selects the previous rules for these checks,
including access that the corrected rules would deny. Use `false` only while updating applications
and grants. Set it back to `true` when the migration is complete.
Comment on lines +127 to +129

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] Which checks are "these checks"? false re-allows access, and the doc asks operators to use it only while updating applications and grants, but they can't tell which grants to update, or whether they need the flag at all. Can we list the checks it covers? From the stack, roughly:

To keep it in sync, this PR could add the heading and each dependent PR its own bullet. Also worth one sentence on scope: the expression-based checks only apply when server.authorization=enable, while the grant validation in #2014 applies either way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, ive added it per dependent PR now.


Use the same value on every server instance. Restart each instance after changing it.

### Multiple server instances

Authorization decisions use an in-memory Casbin policy loaded from the shared `casbin_rule` table.
Expand Down
5 changes: 5 additions & 0 deletions etc/conf/server.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ server.client-id=
server.client-secret=
server.redirect-port=

# Permission-check migration. Stricter checks are on by default.
# Set false temporarily to keep the previous rules, including access those rules allowed.
# Use the same setting on every server instance and restart after changing it.
# server.authorization.strict-privilege-checks=true

# Required when authorization is enabled: Comma-separated list of allowed token issuers
# (exact match or wildcard with *; each * matches a single DNS label). Cannot be "*" alone.
# Wildcard issuers are evaluated before signature verification; see docs/server/auth.md.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private void addSecurityDecorators(
if (serverProperties.isAuthorizationEnabled()) {
LOGGER.info("Enabling security decorators...");
armeriaServerBuilder.withSecurityDecorators(
new UnityAccessDecorator(authorizer, repositories),
new UnityAccessDecorator(authorizer, repositories, serverProperties),
new AuthDecorator(securityContext, repositories));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.unitycatalog.server.persist.Repositories;
import io.unitycatalog.server.persist.UserRepository;
import io.unitycatalog.server.persist.utils.ExternalLocationUtils;
import io.unitycatalog.server.utils.ServerProperties;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
Expand Down Expand Up @@ -96,10 +97,14 @@ public class UnityAccessDecorator implements DecoratingHttpServiceFunction {
public static final AttributeKey<ResultFilter> RESULT_FILTER_ATTR =
AttributeKey.valueOf(ResultFilter.class, "RESULT_FILTER");

public UnityAccessDecorator(UnityCatalogAuthorizer authorizer, Repositories repositories)
public UnityAccessDecorator(
UnityCatalogAuthorizer authorizer,
Repositories repositories,
ServerProperties serverProperties)
throws BaseException {
try {
evaluator = new UnityAccessEvaluator(authorizer);
evaluator =
new UnityAccessEvaluator(authorizer, serverProperties.isStrictPrivilegeChecksEnabled());
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new BaseException(ErrorCode.INTERNAL, "Error initializing access evaluator.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* authorization functions to call the configured authorization backend implementation which can be
* used with SpEL logical operators to define compound authorization rules.
*
* <p>{@code #strict_privilege_checks} is a boolean from server configuration. Request values cannot
* override it.
*
* <p>Example:
*
* <p>#authorize(#principal, #schema, 'USE SCHEMA') || #authorize(#principal, #table, 'OWNER')
Expand All @@ -31,14 +34,16 @@ public class UnityAccessEvaluator {
private static final Logger LOGGER = LoggerFactory.getLogger(UnityAccessEvaluator.class);

private final UnityCatalogAuthorizer authorizer;
private final boolean strictPrivilegeChecks;
private final ExpressionParser parser;
private final MethodHandle authorizeHandle;
private final MethodHandle authorizeAnyHandle;
private final MethodHandle authorizeAllHandle;

public UnityAccessEvaluator(UnityCatalogAuthorizer authorizer)
public UnityAccessEvaluator(UnityCatalogAuthorizer authorizer, boolean strictPrivilegeChecks)
throws NoSuchMethodException, IllegalAccessException {
this.authorizer = authorizer;
this.strictPrivilegeChecks = strictPrivilegeChecks;
this.parser = new SpelExpressionParser();

MethodHandles.Lookup lookup = MethodHandles.lookup();
Expand Down Expand Up @@ -120,6 +125,7 @@ public boolean evaluate(

resourceIds.forEach((k, v) -> context.setVariable(k.name().toLowerCase(), v));
nonResourceValues.forEach(context::setVariable);
context.setVariable("strict_privilege_checks", strictPrivilegeChecks);

if (eval(expression, context)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public enum Property {
SERVER_ENV("server.env", "dev", new EnumValidator(true, "dev", "prod", "test")),
AUTHORIZATION_ENABLED(
"server.authorization", "disable", new EnumValidator(true, "enable", "disable")),
STRICT_PRIVILEGE_CHECKS_ENABLED(
"server.authorization.strict-privilege-checks", "true", BOOLEAN_VALIDATOR),
POLICY_REFRESH_ENABLED("server.authorization.policy-refresh", "false", BOOLEAN_VALIDATOR),
POLICY_REFRESH_INTERVAL(
"server.authorization.policy-refresh-interval", "PT1M", DURATION_VALIDATOR),
Expand Down Expand Up @@ -553,6 +555,11 @@ public boolean isAuthorizationEnabled() {
return isTrueOrEnable(get(Property.AUTHORIZATION_ENABLED));
}

/** Whether permission checks use the stricter rules instead of the previous rules. */
public boolean isStrictPrivilegeChecksEnabled() {
return isTrueOrEnable(get(Property.STRICT_PRIVILEGE_CHECKS_ENABLED));
}

/** Whether cross-instance policy refresh is enabled (poll and deny-path reload). */
public boolean isPolicyRefreshEnabled() {
return isTrueOrEnable(get(Property.POLICY_REFRESH_ENABLED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void responseAuthorizationRejectionIsRecorded() throws Exception {
PrometheusExpositionService.of(metrics.registry().getPrometheusRegistry()))
.annotate("unfiltered", new UnfilteredResponseService())
.withSecurityDecorators(
new UnityAccessDecorator(new AllowingAuthorizer(), repositories),
new UnityAccessDecorator(new AllowingAuthorizer(), repositories, properties),
(delegate, ctx, req) -> delegate.serve(ctx, req))
.meterRegistry(metrics.registry())
.build()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UnityAccessEvaluatorTest {
@Test
void evaluateSkipsRefreshWhenExpressionAllows() throws Exception {
UnityCatalogAuthorizer authorizer = mock(UnityCatalogAuthorizer.class);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer, true);

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.

Should we parameterize these tests so both true and false run until we remove the flag?

These four tests hard-code true, and none of them reads #strict_privilege_checks, so false is only exercised by the new evaluateUsesServerPrivilegeChecksSetting. The refresh and deny logic should behave the same in both modes. A parameterized run would catch a future change that accidentally ties that logic to the flag.

JUnit is 5.13.4 here, so @ParameterizedClass with @ValueSource(booleans = {true, false}) on the class (as in BaseCredRenewITTest) runs every test in both modes with one change. The new test could then use the parameter instead of its manual loop. We would delete the parameter together with the flag.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I’d leave these as is. The flag doesn’t affect refresh, and the new test already checks both values.


assertThat(
evaluator.evaluate(
Expand All @@ -35,7 +35,7 @@ void evaluateSkipsRefreshWhenExpressionAllows() throws Exception {
void evaluateKeepsDenyWhenRefreshReturnsFalse() throws Exception {
UnityCatalogAuthorizer authorizer = mock(UnityCatalogAuthorizer.class);
when(authorizer.refreshAuthorizations(anyLong())).thenReturn(false);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer, true);

assertThat(
evaluator.evaluate(
Expand All @@ -49,7 +49,7 @@ void evaluateKeepsDenyWhenRefreshThrows() throws Exception {
UnityCatalogAuthorizer authorizer = mock(UnityCatalogAuthorizer.class);
when(authorizer.refreshAuthorizations(anyLong()))
.thenThrow(new RuntimeException("reload failed"));
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer, true);

assertThat(
evaluator.evaluate(
Expand All @@ -68,7 +68,7 @@ void evaluateAllowsAfterSuccessfulRefresh() throws Exception {
.thenReturn(false, true);
when(authorizer.refreshAuthorizations(anyLong())).thenReturn(true);

UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer);
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer, true);

assertThat(
evaluator.evaluate(
Expand All @@ -80,4 +80,19 @@ void evaluateAllowsAfterSuccessfulRefresh() throws Exception {
verify(authorizer, times(1)).refreshAuthorizations(anyLong());
verify(authorizer, times(2)).authorize(eq(principal), eq(catalog), eq(Privileges.OWNER));
}

@Test
void evaluateUsesServerPrivilegeChecksSetting() throws Exception {
UnityCatalogAuthorizer authorizer = mock(UnityCatalogAuthorizer.class);
for (boolean strictPrivilegeChecks : new boolean[] {true, false}) {
UnityAccessEvaluator evaluator = new UnityAccessEvaluator(authorizer, strictPrivilegeChecks);
assertThat(
evaluator.evaluate(
UUID.randomUUID(),
"#strict_privilege_checks",
Map.of(),
Map.of("strict_privilege_checks", !strictPrivilegeChecks)))
.isEqualTo(strictPrivilegeChecks);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ public void testBooleanValidator() {
"Allowed values: [true, false]");
}

@Test
public void testStrictPrivilegeChecksSetting() {
ServerProperties properties = new ServerProperties();
assertThat(properties.isStrictPrivilegeChecksEnabled()).isTrue();
properties.set(Property.STRICT_PRIVILEGE_CHECKS_ENABLED, "false");
assertThat(properties.isStrictPrivilegeChecksEnabled()).isFalse();
properties.set(Property.STRICT_PRIVILEGE_CHECKS_ENABLED, "true");
assertThat(properties.isStrictPrivilegeChecksEnabled()).isTrue();
testInvalidProperty(
Property.STRICT_PRIVILEGE_CHECKS_ENABLED,
"yes",
"Invalid value 'yes'",
"server.authorization.strict-privilege-checks");
}

@Test
public void testIcebergTableEnabledCheck() {
ServerProperties serverProperties = new ServerProperties();
Expand Down
Loading