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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Conventions:
- **Backends:** H2 by default (embedded, file-based). MySQL and PostgreSQL are supported for a persistent deployment, configured in `etc/conf/hibernate.properties` (point at your database and add the JDBC driver); see `docs/server/deployment.md`. Hibernate is configured in `persist/utils/HibernateConfigurator`. Tests run on H2 by default; `build/sbt -J-Xmx6G testPostgres18` or `testMySQL8` (or `UC_TEST_DATABASE=POSTGRES_18` / `MYSQL_8`) runs them on PostgreSQL 18 or MySQL 8.4 in Docker, each test on its own database, and fails rather than skips when Docker is not available. When adding schema, keep any index or column change safe across a server restart on an existing database, and portable across H2, MySQL and PostgreSQL. A schema change:
- is a new Flyway step for each database under `server/src/main/resources/db/migration/{h2,postgresql,mysql}/`, numbered after the last one; never edit a merged step or its effect file;
- is checked for step order against the PR's base by `dev/check-migration-steps.sh`, so two open PRs can each pass with steps out of order: just before a PR that adds a step merges, rebase it or merge main into it so its step is numbered above every merged one (or turn on the branch protection "Require branches to be up to date before merging"); a release branch (`branch-*`) takes no new steps, so add them on main;
- holds one SQL statement per step; `MigrationStepRulesTest` (run with `UC_TEST_MIGRATION_CHECKS=true`) holds the rules for what a step may change (adding a Java enum constant is not supported yet on PostgreSQL, where it means replacing a CHECK constraint);
- holds one SQL statement per step; `MigrationStepRulesTest` (run with `UC_TEST_MIGRATION_CHECKS=true`) holds the rules for what a step may change (adding a Java enum constant on PostgreSQL replaces the column's CHECK constraint, in one `ALTER TABLE ... DROP CONSTRAINT k, ADD CONSTRAINT k CHECK (c IN (...))` that keeps every value);
- comes with an effect file per database, `server/src/main/resources/schema-effects/{h2,postgresql,mysql}/V<n>.txt`, written by `build/sbt updateSchemaDumps` (PostgreSQL and MySQL need Docker), which only writes them: run the tests with `UC_TEST_MIGRATION_CHECKS=true` afterwards to check them; check it in with the step;
- matches the entities: `BaselineMatchesEntitiesTest` (also run with `UC_TEST_MIGRATION_CHECKS=true`) compares the schema the steps build with the one Hibernate builds from the entities.
- **Enforce invariants at the database level** (unique constraints) rather than only in code, where duplicate creation or races are possible.
Expand Down
15 changes: 15 additions & 0 deletions etc/conf/server.properties
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ aws.secretKey=
# The region of AWS. If running on-premises, pick the nearest region.
aws.region=

# Experimental: S3-compatible storage such as MinIO or Ceph, through s3_compatible storage
# credentials. When disabled, such credentials cannot be created, an update cannot set one, and
# none is used to vend credentials; other updates, reads and deletes of existing ones still work.
# Default: false (disabled)
# server.s3-compatible-storage.enabled=false

# The key that the secret_access_key of s3_compatible storage credentials is encrypted with in the
# database (AES-256-GCM): 32 random bytes in base64, such as the output of `openssl rand -base64 32`.
# Required to create or use such credentials. Set it in the UC_SERVER_CREDENTIAL_ENCRYPTION_KEY
# environment variable, not here: setting it in this file logs a deprecation warning. Use the same
# key on every server instance. Values stored with a key cannot be read after it is changed, so
# keep it as long as the credentials exist. It is read only when s3-compatible storage is enabled;
# then a value that is not a base64-encoded 32-byte key stops the server at startup.
# server.credential-encryption-key=

#### The following "s3.*" configs are legacy per-bucket hardcoded credential config

## S3 Storage Config (Multiple configs can be added by incrementing the index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import io.unitycatalog.client.model.CredentialInfo;
import io.unitycatalog.client.model.CredentialPurpose;
import io.unitycatalog.client.model.ListCredentialsResponse;
import io.unitycatalog.client.model.S3AssumeRole;
import io.unitycatalog.client.model.S3CompatibleRequest;
import io.unitycatalog.client.model.UpdateCredentialRequest;
import java.util.List;
import java.util.Optional;
import org.apache.commons.cli.CommandLine;
import org.json.JSONObject;
Expand Down Expand Up @@ -63,14 +66,45 @@ private static Optional<AwsIamRoleRequest> extractAwsIamRole(JSONObject json) {
}
}

/** Builds an {@code s3_compatible} credential from the {@code s3_*} options, if any is given. */
private static Optional<S3CompatibleRequest> extractS3Compatible(JSONObject json) {
List<CliParams> params =
List.of(
CliParams.S3_ACCESS_KEY_ID,
CliParams.S3_SECRET_ACCESS_KEY,
CliParams.S3_ENDPOINT,
CliParams.S3_STS_ENDPOINT,
CliParams.S3_ROLE_ARN,
CliParams.S3_STS_REGION);
if (params.stream().noneMatch(param -> json.has(param.getServerParam()))) {
return Optional.empty();
}
String stsEndpoint = json.optString(CliParams.S3_STS_ENDPOINT.getServerParam(), null);
String roleArn = json.optString(CliParams.S3_ROLE_ARN.getServerParam(), null);
String stsRegion = json.optString(CliParams.S3_STS_REGION.getServerParam(), null);
return Optional.of(
new S3CompatibleRequest()
.accessKeyId(json.optString(CliParams.S3_ACCESS_KEY_ID.getServerParam(), null))
.secretAccessKey(json.optString(CliParams.S3_SECRET_ACCESS_KEY.getServerParam(), null))
.s3Endpoint(json.optString(CliParams.S3_ENDPOINT.getServerParam(), null))
.assumeRole(
stsEndpoint == null && roleArn == null && stsRegion == null
? null
: new S3AssumeRole()
.stsEndpoint(stsEndpoint)
.roleArn(roleArn)
.stsRegion(stsRegion)));
}

private static String createCredential(CredentialsApi credentialsApi, JSONObject json)
throws JsonProcessingException, ApiException {
CreateCredentialRequest createCredentialRequest =
new CreateCredentialRequest()
.name(json.getString(CliParams.NAME.getServerParam()))
.comment(json.optString(CliParams.COMMENT.getServerParam(), null))
.purpose(CredentialPurpose.STORAGE)
.awsIamRole(extractAwsIamRole(json).orElse(null));
.awsIamRole(extractAwsIamRole(json).orElse(null))
.s3Compatible(extractS3Compatible(json).orElse(null));
CredentialInfo credentialInfo = credentialsApi.createCredential(createCredentialRequest);
return objectWriter.writeValueAsString(credentialInfo);
}
Expand Down Expand Up @@ -101,7 +135,8 @@ private static String updateCredential(CredentialsApi credentialsApi, JSONObject
new UpdateCredentialRequest()
.newName(json.optString(CliParams.NEW_NAME.getServerParam(), null))
.comment(json.optString(CliParams.COMMENT.getServerParam(), null))
.awsIamRole(extractAwsIamRole(json).orElse(null));
.awsIamRole(extractAwsIamRole(json).orElse(null))
.s3Compatible(extractS3Compatible(json).orElse(null));
CredentialInfo credentialInfo = credentialsApi.updateCredential(name, updateCredentialRequest);
return objectWriter.writeValueAsString(credentialInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ public enum CliParams {
CREDENTIAL_NAME("credential_name", "The name of the storage credential", "credential_name"),
AWS_IAM_ROLE_ARN(
"aws_iam_role_arn", "The ARN of the AWS IAM role for credential", "aws_iam_role_arn"),
S3_ENDPOINT(
"s3_endpoint",
"The S3 API endpoint of the S3-compatible storage of an s3_compatible credential",
"s3_endpoint"),
S3_ACCESS_KEY_ID(
"s3_access_key_id", "The access key id for S3-compatible storage", "s3_access_key_id"),
S3_SECRET_ACCESS_KEY(
"s3_secret_access_key",
"The secret access key paired with s3_access_key_id",
"s3_secret_access_key"),
S3_STS_ENDPOINT(
"s3_sts_endpoint",
"The STS endpoint to assume s3_role_arn at; defaults to s3_endpoint",
"s3_sts_endpoint"),
S3_ROLE_ARN("s3_role_arn", "The role to assume at s3_sts_endpoint", "s3_role_arn"),
S3_STS_REGION(
"s3_sts_region",
"The region to sign requests to s3_sts_endpoint with; the storage's region if not set",
"s3_sts_region"),
STORAGE_ROOT(
"storage_root",
"The storage root URL for managed tables/volumes within the catalog or schema.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,15 @@ public List<CliParams> getOptionalParams() {
CREATE,
new CliOptions(
List.of(CliParams.NAME),
List.of(CliParams.COMMENT, CliParams.AWS_IAM_ROLE_ARN)));
List.of(
CliParams.COMMENT,
CliParams.AWS_IAM_ROLE_ARN,
CliParams.S3_ACCESS_KEY_ID,
CliParams.S3_ENDPOINT,
CliParams.S3_SECRET_ACCESS_KEY,
CliParams.S3_STS_ENDPOINT,
CliParams.S3_ROLE_ARN,
CliParams.S3_STS_REGION)));
put(
LIST,
new CliOptions(
Expand All @@ -367,7 +375,15 @@ public List<CliParams> getOptionalParams() {
new CliOptions(
List.of(CliParams.NAME),
List.of(
CliParams.NEW_NAME, CliParams.COMMENT, CliParams.AWS_IAM_ROLE_ARN)));
CliParams.NEW_NAME,
CliParams.COMMENT,
CliParams.AWS_IAM_ROLE_ARN,
CliParams.S3_ACCESS_KEY_ID,
CliParams.S3_ENDPOINT,
CliParams.S3_SECRET_ACCESS_KEY,
CliParams.S3_STS_ENDPOINT,
CliParams.S3_ROLE_ARN,
CliParams.S3_STS_REGION)));
put(DELETE, new CliOptions(List.of(CliParams.NAME), List.of(CliParams.FORCE)));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import io.unitycatalog.client.model.CreateCredentialRequest;
import io.unitycatalog.client.model.CredentialInfo;
import io.unitycatalog.client.model.CredentialPurpose;
import io.unitycatalog.client.model.S3CompatibleRequest;
import io.unitycatalog.client.model.UpdateCredentialRequest;
import io.unitycatalog.server.base.ServerConfig;
import io.unitycatalog.server.base.credential.CredentialOperations;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class CliCredentialOperations extends BaseCliOperations implements CredentialOperations {
Expand All @@ -32,6 +35,7 @@ public CredentialInfo createCredential(CreateCredentialRequest createCredentialR
argsList.add("--aws_iam_role_arn");
argsList.add(createCredentialRequest.getAwsIamRole().getRoleArn());
}
addS3CompatibleArgs(argsList, createCredentialRequest.getS3Compatible());
return execute(CredentialInfo.class, "create", argsList);
}

Expand Down Expand Up @@ -68,6 +72,7 @@ public CredentialInfo updateCredential(
argsList.add("--aws_iam_role_arn");
argsList.add(updateCredentialRequest.getAwsIamRole().getRoleArn());
}
addS3CompatibleArgs(argsList, updateCredentialRequest.getS3Compatible());
return executeUpdate(
CredentialInfo.class,
/* catchEmptyUpdateCliException= */ true,
Expand All @@ -84,4 +89,26 @@ public void deleteCredential(String name, Optional<Boolean> force) throws ApiExc
}
execute(Void.class, "delete", argsList);
}

private static void addS3CompatibleArgs(List<String> argsList, S3CompatibleRequest s3Compatible) {
if (s3Compatible == null) {
return;
}
Map<String, Object> args = new LinkedHashMap<>();
args.put("--s3_access_key_id", s3Compatible.getAccessKeyId());
args.put("--s3_secret_access_key", s3Compatible.getSecretAccessKey());
args.put("--s3_endpoint", s3Compatible.getS3Endpoint());
if (s3Compatible.getAssumeRole() != null) {
args.put("--s3_sts_endpoint", s3Compatible.getAssumeRole().getStsEndpoint());
args.put("--s3_role_arn", s3Compatible.getAssumeRole().getRoleArn());
args.put("--s3_sts_region", s3Compatible.getAssumeRole().getStsRegion());
}
args.forEach(
(option, value) -> {
if (value != null) {
argsList.add(option);
argsList.add(value.toString());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ private Server initializeServer(UnityCatalogServer.Builder unityCatalogServerBui
audit);
// Init metastore
repositories.getMetastoreRepository().initMetastoreIfNeeded();
if (unityCatalogServerBuilder.serverProperties.isS3CompatibleStorageEnabled()) {
warnAboutUnreadableSecrets(repositories);
}
// Init authorizer
authorizer =
initializeAuthorizer(
Expand Down Expand Up @@ -338,6 +341,21 @@ private void initializeCleanup(
domainMetrics);
}

/** Warns about each credential whose stored secret the server cannot read, with the reason. */
private static void warnAboutUnreadableSecrets(Repositories repositories) {
repositories
.getCredentialRepository()
.findUnreadableSecrets()
.forEach(
(name, failure) ->
// Not only a missing or changed key: the stored value can also be malformed.
LOGGER.warn(
"Cannot read the stored secret of storage credential '{}': {}",
name,
failure.getMessage(),
failure));
}

private UnityCatalogAuthorizer initializeAuthorizer(
ServerProperties serverProperties,
HibernateConfigurator hibernateConfigurator,
Expand Down
Loading
Loading