Skip to content

[Server] Read the database password from an environment variable - #2080

Merged
yili-db merged 45 commits into
unitycatalog:mainfrom
shba24:stack/ep31-db-password-env
Nov 10, 2026
Merged

yili-db merged 45 commits into
unitycatalog:mainfrom
shba24:stack/ep31-db-password-env

Conversation

@shba24

@shba24 shba24 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

This is part 2 of 4 in a stack; each PR handles one kind of secret end to end (server, Helm chart, docs, tests). Review only this PR's changes with its incremental link above.

Description of changes

The database password can now come from the UC_HIBERNATE_CONNECTION_PASSWORD environment variable. Before, it could only be written in etc/conf/hibernate.properties, and the Helm chart rendered it there from its Kubernetes Secret.

  • The variable takes precedence over hibernate.properties, the same order as for server.properties.
  • A password in hibernate.properties still works. The server logs a deprecation warning at startup, and the docs mark that way as deprecated.
  • The Helm chart passes the password to the server container as an environment variable from server.db.postgresqlConfig.passwordSecretName, instead of rendering it into hibernate.properties.
  • A hibernate.connection.password line in server.properties, where the server never reads it, logs a warning saying it is ignored.
  • Docs that showed the password in hibernate.properties now use the variable and mark the file deprecated: configuration, deployment, Docker Compose, and the Helm db.overrideConfig value.
export UC_HIBERNATE_CONNECTION_PASSWORD=uc_default_password
bin/start-uc-server
📐 Design notes & details
  • The variable name follows the UC_ rule from the previous PR in this stack and gets the same handling: an empty variable is ignored, a line break at the end is dropped, and the startup log names the variable, never the value.
  • Only the password gets the override; the URL, user and driver stay in hibernate.properties.
  • The password comes from the environment only, not from a -Dhibernate.connection.password system property. Hibernate copies all system properties into its own settings, and a password there makes Hibernate ask the Hikari pool for a connection with a user and password, which Hikari does not support, so startup fails. That happens before this PR too.
  • A hibernate.connection.password line in server.properties does not trigger the server.properties deprecation warning, only the "ignored" one.

Compatibility. Users see these in the Upgrading list under Secrets in docs/server/configuration.md.

  • A password in hibernate.properties keeps working, with a warning.
  • Helm with server.deployment.image.tag pinned to an older server image: that image doesn't read the variable, so the PostgreSQL connection fails. The image tag note in values.yaml covers it.
  • Helm: the init container no longer receives DB_PASSWORD. A db.overrideConfig template with hibernate.connection.password=${DB_PASSWORD} still connects (the line is left empty and the variable supplies the password); values.yaml says to remove that line. A container added through extraInitContainers that needs the password must read it from the Kubernetes Secret itself.

Tests.

  • HibernateConfiguratorTest.prefersThePasswordFromTheEnvironmentToTheFile: the file value is kept without an override, the override wins, and setupHibernateProperties takes it from ServerProperties.getEnv.
  • ServerPropertiesTest.testSettingsFromEnvironment also covers UC_HIBERNATE_CONNECTION_PASSWORD.
  • helm/ci/secrets-values.yaml adds a PostgreSQL database with a password Secret, so chart lint renders the variable.
  • Checked by hand against PostgreSQL 18 (Docker), with no password in hibernate.properties (before the variable got its UC_ prefix): with no variable set, startup fails ("no password was provided"); with the variable set, the server serves; with the password only in the file, it serves and logs the deprecation warning. The password never appears in the log.

This pull request and its description were written by Isaac.

@shba24

shba24 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Local AI review run

The CI /review workflow is skipped for this account, so the repository's reviewer roles were run locally once, on the stack before its final fixes (Claude models; the Codex role was not run):

  • uc-domain-reviewer and maintainer-claude-reviewer (one pass)
  • architecture-reviewer, docs-reviewer and test-coverage-reviewer (one pass)
  • a silent-failure pass

Each finding was checked against the code before acting on it.

Finding Outcome
A line break at the end of a Secret value broke env-sourced secrets (the old envsubst path dropped it) Fixed in #2079: dropped for the upper-case names
bin/uc-admin-token could generate a new key when run from another directory, and rewrote certs.json, which the server re-reads for every internal token check Fixed in #2082: reads the key only, fails if missing, writes no files, runs from the install directory
A stale public_key.der in the key directory could mismatch the signing key Fixed in #2081: the public key is always derived from the private key
token.txt deletion described as making the old token invalid Fixed in #2082: the comment, log and docs say copies stay valid until the key changes
Misleading warning for hibernate.connection.password in server.properties Fixed in #2080
Encryption key: untrimmed inline value, invalid base64 reported as wrong length, key file path missing from errors, name-based bean lookup Fixed in #2083
Weak test assertion on the in-memory token Fixed in #2082: the token is verified against the key
No AAD binding a ciphertext to its row; no bulk re-encryption; generic 500 when a key is missing Kept, documented in #2083
Public HibernateConfigurator(Properties) stores plaintext Kept: callers are tests only
PEM key path has no unit test Kept: the secret scanner blocks PEM headers in test sources; covered end to end with an openssl genrsa key and the chart's generated key on kind

Reviewed heads: 2f4bb5a, 690745f, 8b8356b, c0bc199, d7bf525. Current heads: 81e48b4, eba9f92, 99ae5a0, b91905f, b19e7a5.

@shba24
shba24 force-pushed the stack/ep31-db-password-env branch from eba9f92 to cf24a2d Compare October 29, 2026 20:40
@shba24

shba24 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Local AI review run (round 2)

The CI /review workflow is skipped for this account, so the review pipeline was run locally on the reworked stack (two-file signing key, no key ID, no certs.json, encryption dropped). Each finding was checked against the code before acting on it.

  • Repository reviewer roles (.github/omnigent/reviewer, Claude): uc-domain-reviewer, maintainer-claude-reviewer, architecture-reviewer, test-coverage-reviewer, docs-reviewer. The Codex role was not run.
  • Isaac Review, twice.
  • pr-review-toolkit: code, tests, comments, silent failures, plus a docs-completeness pass for the deprecations.
Finding Outcome
bin/uc auth login read the client secret only from server.properties Fixed in #2079: reads SERVER_CLIENT_SECRET first
aws.sessionToken listed as a secret, but the server never reads it Fixed in #2079: dropped from the secret list and docs
docs/server/aws.md showed aws.s3.* keys the server does not read Fixed in #2079
A DB password in server.properties was ignored silently Fixed in #2080: warns that it is ignored
Password precedence test depended on the shell's environment Fixed in #2080
No test rejects an internal token signed with another key Fixed in #2081 (AuthDecoratorTest); deleting the signature check fails it
Deprecation warning for the generated key fired with authorization off Fixed in #2081: only with authorization enabled
Encrypted or malformed PEM keys gave errors without the file Fixed in #2081
Helm init container continued after an openssl failure Fixed in #2081
Advice to delete key_id.txt broke rollback Fixed in #2081: docs say keep it while a rollback is possible
Unused fields and an uncalled method across commits Fixed in #2081 / #2082
bin/uc-admin-token: wrong-directory key generation, rewrote certs.json, logs on stdout in Helm pods, stale-file failure on a read-only folder Fixed in #2082
Missing tests: ADLS env secret, both key settings, PEM public key, loadExisting, stray files after startup Added to existing tests
No check that the two key files are one pair Kept: operator's responsibility, as in Polaris
No PEM private-key unit test Kept: the pre-commit secret scanner blocks PEM private-key headers; covered end to end
Chart CI never renders the secret env vars (defaults only) Kept: checked on kind with PostgreSQL 18, auth, S3 and create-users
Shared owner for the secret lookup; security → utils dependency Kept for now (refactor, not a defect)

Verification on the current heads:

  • build/sbt clean test is green, and server Javadoc builds.
  • Each lower commit builds and passes its tests on its own.
  • Seven deliberate code breaks were each caught by a test.
  • Helm lints, renders and matches helm-docs at every commit.

Current heads: b2cb578, cf24a2d, 2748528, ccb9bf1.

@shba24

shba24 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@shba24
shba24 force-pushed the stack/ep31-db-password-env branch from cf24a2d to 01ba0eb Compare October 29, 2026 23:26
@shba24
shba24 marked this pull request as ready for review October 29, 2026 23:28
@yili-db

yili-db commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

/review

@shba24
shba24 force-pushed the stack/ep31-db-password-env branch 2 times, most recently from 72bbfef to 94710f1 Compare November 3, 2026 10:17
shba24 and others added 7 commits November 4, 2026 00:19
Operators can now set any setting, including the OAuth client secret,
the AWS secret key, and the per-bucket S3 and ADLS secrets, in an
environment variable a shell can export: UC_, then the key in upper case
with `_` for each other character, such as UC_S3_SECRETKEY_0. The prefix
keeps variables that runtimes set for their own use, such as AWS_REGION,
from changing settings. A variable named exactly as the key still comes
first. At startup the server logs the name of each variable it uses,
never the value. `bin/uc auth login` also reads UC_SERVER_CLIENT_SECRET.

Secrets in server.properties keep working, but the server now logs a
deprecation warning for each one it reads from the file, and the docs
mark that way as deprecated.

The Helm chart passes the S3 and ADLS secrets to the server container as
environment variables instead of rendering them into server.properties,
and no longer gives the server the OAuth client secret, which only the
CLI reads.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The comment on reading UC_SERVER_CLIENT_SECRET repeated what the next lines do; keep the part that says why the name and trimming match the server.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The server never reads server.client-secret, but its deprecation warning told operators to set UC_SERVER_CLIENT_SECRET, and setting it in the server's environment silenced the warning. The warning now says only bin/uc auth login reads it, names the shell that runs that command, and is no longer silenced by the server's environment.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The CLI login tests pass --identity_token, so none reached the UC_SERVER_CLIENT_SECRET lookup in the OAuth flow. Move the lookup into Oauth2CliExchange.clientSecret and test it in CliAuthCrudTest: the variable wins over server.client-secret with a trailing line break dropped, and an absent, empty or line-break-only variable falls back to the file.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The database password could only come from hibernate.properties. The
server now also takes it from the UC_HIBERNATE_CONNECTION_PASSWORD
environment variable, which wins over the file. A system property is not
used for it: Hibernate copies system properties into its own settings,
and a password there makes the connection pool fail.

A password kept in hibernate.properties still works, but the server logs
a deprecation warning, and the docs mark that way as deprecated.

The Helm chart passes the password to the server container as an
environment variable instead of rendering it into hibernate.properties.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
AGENTS.md describes where the backends are configured, and a password in hibernate.properties still works; the configuration and deployment docs cover the environment variable.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
The two-line private method says the same.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24
shba24 force-pushed the stack/ep31-db-password-env branch from 94710f1 to a733445 Compare November 4, 2026 00:58
@shba24
shba24 requested a review from timothyw553 as a code owner November 4, 2026 00:58
shba24 and others added 4 commits November 5, 2026 03:32
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
…plates

A server.config.override or extraProperties template could use the init container's S3_SECRET_KEY_<n>, ADLS_CLIENT_SECRET_<n> or OAUTH_CLIENT_SECRET for any key, for example aws.secretKey=${S3_SECRET_KEY_0}. After the secrets moved to the server's environment, those lines rendered empty. The init container now gets these variables again when either setting is set, which is deprecated. OAUTH_CLIENT_SECRET is optional, and the auth Secret only needs clientId, since nothing else in the chart reads the client secret.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

/review

shba24 and others added 4 commits November 6, 2026 03:06
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
timothyw553 pushed a commit that referenced this pull request Nov 6, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2079/files) to
review incremental changes.
-
[**stack/ep31-config-secrets-env**](#2079)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2079/files)]
← _this PR_
-
[stack/ep31-db-password-env](#2080)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2080/files/6af48d7037ce77ff96e920c539c9d770d6ef830a..52be2ac3336ec008692a713804031a9779cac524)]
-
[stack/ep31-signing-key-dir](#2081)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2081/files/52be2ac3336ec008692a713804031a9779cac524..2b96c369d6a90b52461eb617050dd7b35d3b1bb0)]
-
[stack/ep31-admin-token-in-memory](#2082)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2082/files/2b96c369d6a90b52461eb617050dd7b35d3b1bb0..576ec307a689978e488eb7b36ae8c6f01d8fccc8)]

---------

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This is part 1 of 4 in a stack; each PR handles one kind of secret end
to end (server, Helm chart, docs, tests). Review only this PR's changes
with its incremental link above.

**Description of changes**

Operators can now set any server setting, and so every secret, in an
environment variable that a shell or a Kubernetes Secret can supply.
Before, UC looked only for a variable named exactly like the key
(`s3.secretKey.0`), which no shell can export, so secrets lived in
`server.properties` in plaintext, and the Helm chart rendered them
there.

- A setting's variable is `UC_`, then the key in upper case, with `_`
for every character that is not a letter or digit:
`UC_S3_SECRETKEY_<n>`, `UC_S3_SESSIONTOKEN_<n>`,
`UC_ADLS_CLIENTSECRET_<n>`, `UC_AWS_SECRETKEY`,
`UC_SERVER_CLIENT_SECRET`. It takes precedence over `server.properties`.
- At startup the server logs the name of each environment variable it
uses for a setting, never its value.
- Secrets in `server.properties` still work. The server logs a
deprecation warning at startup for each one (key name only), and the
docs mark that way as deprecated. The warning for `server.client-secret`
says that only `bin/uc auth login` reads it and to set
`UC_SERVER_CLIENT_SECRET` in the shell that runs that command; setting
the variable for the server does not silence it.
- The Helm chart passes the S3 and ADLS secrets to the server container
as environment variables from the same Kubernetes Secrets, instead of
rendering them into `server.properties`. Chart values are unchanged. The
OAuth client secret is no longer passed to the server at all: only
`bin/uc auth login` reads it.
- `bin/uc auth login` reads `UC_SERVER_CLIENT_SECRET` before
`etc/conf/server.properties`.
- `docs/server/aws.md` also gets the master user keys right: the server
reads `aws.masterRoleArn` / `aws.accessKey` / `aws.secretKey`, not the
`aws.s3.*` names the page showed.
- Docs that showed secrets in `server.properties` now use the
environment variables and mark the file deprecated: configuration, auth,
AWS, Docker Compose, the Spark and XTable integrations, the
integration-test setup, the sample `server.properties` files, and the
Helm `config.override` / `extraProperties` values.

```sh
export UC_S3_SECRETKEY_0='<secret key>'
bin/start-uc-server
```

<details><summary><b>📐 Design notes &amp; details</b></summary>

**Why this shape.** Apache Polaris reads settings from environment
variables under the property name in upper case (SmallRye config rules),
and its chart passes Kubernetes Secrets in with `secretKeyRef`. This PR
follows the same model. No generic "read any secret from a file" option
is added.

**Why the `UC_` prefix, for every key.** One rule for all keys is easier
to use than a list of secret keys. Without a prefix, variables that
runtimes set for their own use would change UC settings: `aws.region`
would map to `AWS_REGION`, which AWS runtimes set, and `server.env` to
`SERVER_ENV`. With the prefix, only variables meant for UC count.

**Details.**
- Lookup order: system property, then the variable under the exact key,
then the `UC_` name, then `server.properties`.
- An empty `UC_` variable is ignored, like an empty value in
`server.properties`.
- A line break at the end of a `UC_` value is dropped. Before, the
chart's envsubst wrote the value into `server.properties`, and
`Properties.load` ended it at the line break; Secrets made from a file
often end with one.
- The deprecation warning fires only when a secret's value really comes
from the file. A secret also set in the environment does not warn,
except `server.client-secret`: the server never reads it, so a variable
in the server's environment is not a fix.
- Kubernetes service links: the variables Kubernetes adds for each
Service end in `_SERVICE_HOST`, `_SERVICE_PORT` or `_PORT[...]`. The
only key whose `UC_` name has that shape is `server.redirect-port`, and
only for a Service named `uc-server-redirect`; the chart's Services are
named `<fullname>-server` and `<fullname>-ui`. A wrong value there fails
startup validation.
- Helm: a `server.config.override` or `extraProperties` template that
uses the chart's old `${OAUTH_CLIENT_SECRET}`, `${S3_SECRET_KEY_<n>}` or
`${ADLS_CLIENT_SECRET_<n>}` keeps working, for any key (for example
`aws.secretKey=${S3_SECRET_KEY_0}`): when either setting is set, the
init container still gets those variables. That is deprecated, and
`values.yaml` says so. `OAUTH_CLIENT_SECRET` is an optional ref, since
nothing else in the chart reads the client secret; the auth Secret only
needs `clientId`.

**Compatibility.** Users see these in the new Upgrading list under
Secrets in `docs/server/configuration.md`.
- A `UC_` variable already set in the server's environment now takes
precedence over the same key in `server.properties`.
- Secrets in `server.properties` keep working, with a warning.
- Helm with `server.deployment.image.tag` pinned to an older server
image: that image doesn't read these variables, so S3 and ADLS lose
their secrets. The image tag note in `values.yaml` says to use the
server image from the chart's release (the default).
- Helm: the rendered `server.properties` no longer holds these secrets,
and without a custom template the init container no longer has
`OAUTH_CLIENT_SECRET`, `S3_SECRET_KEY_<n>` or `ADLS_CLIENT_SECRET_<n>`.
A container added through `extraInitContainers` or `extraContainers`
that needs them must read them from the Kubernetes Secret itself.

**Tests.**
- `ServerPropertiesTest.testSettingsFromEnvironment`: `UC_` variables
for the client secret, S3 secret key and session token, ADLS client
secret and a non-secret key (`s3.region.0`); a trailing CR/LF is
dropped; an empty `UC_` variable is ignored; `AWS_REGION` does not
change `aws.region`; the exact-name variable wins over the `UC_` one.
-
`CliAuthCrudTest.testAuthLoginReadsTheClientSecretFromTheEnvironmentBeforeTheFile`:
`bin/uc auth login` takes `UC_SERVER_CLIENT_SECRET` over
`server.client-secret`, drops a trailing line break, and falls back to
the file when the variable is absent, empty or only a line break. The
other CLI login tests pass `--identity_token`, so they skip this path.
- `helm/ci/secrets-values.yaml` renders the S3 and ADLS secret variables
in chart lint, plus the deprecated init container variables through
`extraProperties`; `helm template` renders with and without auth, S3 and
ADLS, and with none of them no `env:` block is emitted.
- Checked by hand on a local server: a secret in `server.properties`
logs the warning; with `UC_S3_SECRETKEY_0` set, the log names the
variable and only the remaining file secrets warn; no value appears in
the log.

</details>

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
unitycatalog#2079 landed as d31fa8b, whose tree is unitycatalog#2079's head, which this branch already holds.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@yili-db

yili-db commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

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] The server change looks right: the variable wins over the file, the value is never logged, and the chart stops rendering the password into hibernate.properties. The gaps are in tests, where every new branch has existing scaffolding that was not extended. Inline comments below, plus one that has no diff anchor:

.github/workflows/helm-chart-tests.yml: secrets-values.yaml now has a password Secret, but the render check knows nothing about it. Can you add UC_HIBERNATE_CONNECTION_PASSWORD:ci-db-password:password to the for ref loop, hibernate\.connection\.password to the "none in the file" grep, and assert DB_PASSWORD is gone from the init container? Without that the chart half of this PR is only lint-covered.

Comment thread helm/templates/server/_config.tpl Resolved
shba24 and others added 3 commits November 6, 2026 22:36
…sets it

The server reads the database password only from UC_HIBERNATE_CONNECTION_PASSWORD,
so a system property no longer silences the "is ignored" warning. The key is
one constant, and the hibernate.properties warning derives the variable name.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@yili-db

yili-db commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

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] Thanks for the fixes. The Helm render check, the system-property handling, the shared key constant and the template comment all look good. Still open: tests for both warnings and the test subclass (replied on those threads). Two small things from the new commits are inline.

shba24 and others added 3 commits November 7, 2026 00:42
A system property does not silence it; UC_HIBERNATE_CONNECTION_PASSWORD does.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
MySQL from unitycatalog#2119 takes the same password path as PostgreSQL: the chart passes
UC_HIBERNATE_CONNECTION_PASSWORD to the server, and neither hibernate.properties
nor the init container gets the password.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

@yili-db Thanks for the reviews. On the Helm render check from your first review: it now covers the password Secret (0ed1bdf). It checks that UC_HIBERNATE_CONNECTION_PASSWORD comes from ci-db-password, that no hibernate.connection.password is rendered, and that DB_PASSWORD is gone. I also merged main (a81ad0b): MySQL from #2119 now takes the same path as PostgreSQL, so the chart passes UC_HIBERNATE_CONNECTION_PASSWORD and nothing goes into hibernate.properties or the init container.

@shba24

shba24 commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

/review

The server container had two env lists on MySQL: the secrets and the
JDK_JAVA_OPTIONS for the driver. YAML keeps the last key, so the
database password variable was dropped, the server could not log in and
the chart install timed out. Render both into one env list.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@yili-db

yili-db commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

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] Three small nits inline; no blockers.

Comment thread .github/workflows/helm-chart-tests.yml Resolved
shba24 and others added 2 commits November 10, 2026 01:49
The password is not a secret the server reads from server.properties, so it
leaves SECRET_KEY and gets its own check after the loop; the override branch
holds the warning. The render check comment says it covers the whole chart.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
@shba24

shba24 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

/review

@yili-db
yili-db merged commit 642cb5c into unitycatalog:main Nov 10, 2026
23 checks passed
yili-db pushed a commit that referenced this pull request Nov 19, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)
to review incremental changes.
-
[stack/uc-flyway-schema](#2045)
(merged)
-
[stack/uc-upgrade-adopt](#2112)
(merged)
-
[stack/uc-upgrade-merge-checks](#2113)
(merged)
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files)]
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/d4c1b003a0e576debded4b91a28b256d02507f67..0028bc22bb2e6ebd02e11048a2d7560ad023be19)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/0028bc22bb2e6ebd02e11048a2d7560ad023be19..727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f)]
-
[**stack/uc-flyway-owns-schema**](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/727e167d1206b36e7bbb1e30fb18bd5ee0d4be7f..0a120a3c682986c926845a85ad249df1720e5d4c)]
← _this PR_
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/0a120a3c682986c926845a85ad249df1720e5d4c..97bc44b5dfb75eb27fdddc33db6ea208680234ac)]

---------
This PR makes the schema steps the only way Unity Catalog's schema
changes. The server no longer lets Hibernate build or change the schema
at start. Instead, it checks that the database is at this release's
schema, and refuses to start otherwise. The Helm chart runs
`--upgrade-schema` in an init container before each server pod starts.

### What you see

- Before the first start on a new database, run `bin/start-uc-server
--upgrade-schema` once. A source checkout's quickstart sample database
needs none. An in-memory database (`server.env=test`, or a named
`jdbc:h2:mem:<name>;DB_CLOSE_DELAY=-1` URL; unnamed in-memory URLs are
refused) is the exception: it lasts only as long as the server, so the
server sets it up itself, and `--upgrade-schema` succeeds on it without
doing anything.
- The server refuses to start on a database that is not at this
release's last step, or whose schema history fails Flyway's check (a
failed step, also a newer release's, or an edited or missing step). The
start refuses what `--check-schema` and `--upgrade-schema` refuse. The
message says what to do: the command to run, or, for a history the
commands refuse too, to run the release that applied the steps or
restore the backup. For example:

    ```console
The database schema is at version none, and this release needs version
2. Stop every server of the previous release, run bin/start-uc-server
--upgrade-schema with this release, then start the server.
    ```

- To upgrade from 0.7.0, stop the servers, back up the database, run
`--upgrade-schema` with the new release, then start it. See
`docs/server/upgrades.md`.
- `etc/conf/hibernate.properties` no longer sets
`hibernate.hbm2ddl.auto=update`. If your file still sets
`hibernate.hbm2ddl.auto` (to `update` or another value), the server sets
it to `none` and logs a warning. Any other schema action setting that
isn't `none` (`jakarta.persistence.schema-generation.database.action`,
its `javax.` form, or a suffixed form such as
`hibernate.hbm2ddl.auto.orm`) makes the start refuse, also when it comes
from a JVM system property or a `hibernate.properties` on the classpath.
- The start also refuses what `--upgrade-schema` refuses:
`hibernate.default_schema` or `hibernate.default_catalog`, H2 in server
mode, and a database other than H2, PostgreSQL and MySQL. Before,
Hibernate built a schema on any database.
- With authorization enabled, the authorization library runs `CREATE
TABLE IF NOT EXISTS casbin_rule` at every start, so the database user
keeps the CREATE privilege.
- A server that sets up its own test database (`server.env=test`, or no
`hibernate.properties`) gives it a name of its own and shuts it down
when it closes, so a later server in the same JVM starts on an empty
one. A database the configuration names is left as it is.
- Helm chart:
- An `upgrade-schema` init container runs `bin/start-uc-server
--upgrade-schema` in each server pod, after
`server.deployment.extraInitContainers`. For an in-memory database it
does nothing.
- The update strategy defaults to `Recreate`, so all old server pods
stop before new ones start, which an upgrade with schema steps needs.
The server is unavailable during an upgrade until the new pods are
ready. `RollingUpdate` can still be set, for an upgrade without schema
steps.
- `server.deployment.replicaCount` above 1 with the file database fails
to render.
  - The chart no longer renders `hibernate.hbm2ddl.auto=update`.
- `docs/server/helm.md` covers backups, the init container's log,
database proxies as native sidecars, scaling to 0 and restoring the
backup before `helm rollback`, and why not to use `helm upgrade
--atomic`.

### Compatibility

- A database not at this release's schema no longer starts: run
`bin/start-uc-server --upgrade-schema` first.
- `hibernate.hbm2ddl.auto` in `hibernate.properties` is ignored with a
warning. Any other schema action setting that isn't `none` is refused,
also from a JVM system property or a classpath `hibernate.properties`.
- `hibernate.default_schema` and `hibernate.default_catalog` are
refused: put the schema in the JDBC URL.
- The Helm chart's update strategy defaults to `Recreate` (a values file
that sets `RollingUpdate` keeps it), and the file database allows one
replica.

### What doesn't change yet

- There is no way back to Hibernate's `update` yet. #2118 adds
`server.schema-management=hibernate` as a temporary fallback.
- The Helm upgrade test covers H2 and PostgreSQL. Once the MySQL Helm PR
#2119 lands, it should cover MySQL too.

### Tests

- `SchemaMigratorTest`: the start refuses a history the commands refuse
(a newer release's failed step, edited and missing steps), with advice
that gets past each refusal.
- `SchemaGateTest`: the start and both commands on a missing H2 file, an
empty database, and each in-memory URL form (`mem:`, `.`, `memFS:`,
`memLZF:`, `nioMemFS:`, `nioMemLZF:`), where `--upgrade-schema` succeeds
without doing anything.
- `UnityCatalogServerTest`: a server built from its own configuration
refuses a mistyped H2 path without creating a file; two servers with
their own test databases don't share one, and a closed one's database is
gone; a configured in-memory database, and a file database behind a
leftover in-memory URL setting, are left alone; an injected database
keeps its tables.
- `HibernateConfiguratorTest`: a schema action set as a JVM system
property is refused (in a child JVM).
- Helm render checks: `Recreate` renders by default and `RollingUpdate`
when set, `replicaCount` above 1 is rejected for the file database, and
the init container renders for an in-memory configuration and mounts the
configuration and database volume.
- Ran on H2, PostgreSQL 18 and MySQL 8 locally: the start-gate,
migrator, server and configurator tests and the schema migration tests;
the full server suite on H2. CI runs the full suite on all three
databases and the Helm install and upgrade tests.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- Start runs `requireCurrentSchema()` on the migrator's own small pool:
the recorded version must be this build's last step, and Flyway's
validation must pass. It takes no run lock and changes nothing. A
database newer than this release gets the "newer than this release"
refusal; an empty one gets "The database has no Unity Catalog schema
yet".
- `HibernateConfigurator` refuses every schema action but `none`
(`hibernate.hbm2ddl.auto`,
`jakarta.persistence.schema-generation.database.action` and its `javax.`
form, also with a contributor suffix such as
`hibernate.hbm2ddl.auto.orm`) before the pool or the session factory
exists, and reads JVM system properties and a classpath
`hibernate.properties` the way Hibernate does. `validate` is refused
too. Only the server's own `etc/conf/hibernate.properties` gets the
lenient path (its schema action turned to `none` with a warning, which
also overrides a JVM system property for it), so an old file keeps
working.
- The whole test suite now builds its schemas with the steps:
`TemplateDatabases`, `TestDatabases`, `MySqlDatabases` and
`TestDatabase` (with `hbm2ddl` set to `none`), plus `KeyMapperTest` and
`BaseAccessControlCRUDTest`. `BaselineMatchesEntitiesTest` keeps
checking that the steps match the entities.
- Helm: the init container shares the server container's volume mounts
through a new `unitycatalog.server.volumeMounts` helper. It runs after
`extraInitContainers`, so a database proxy run there as a native sidecar
(`restartPolicy: Always`) is up first; a proxy in `extraContainers`
starts only after the init containers. The update strategy defaults to
`Recreate`, also when an upgrade with `--reuse-values` carries no value
from an older release: an upgrade with schema steps changes the database
schema, so the old servers must stop before the new ones start.
`RollingUpdate` can be set for an upgrade without schema steps.
- Helm CI: the "Upgrade from the base chart" step builds the server
image from the pull request's base (`HEAD^1`), installs the base chart
with it, creates a catalog, runs `helm upgrade` to this chart and image,
and checks the catalog is still there. It runs on H2 and on PostgreSQL
with two replicas, whose init containers both run the upgrade under the
run lock. The workflow now also triggers on changes to the migration
code, the steps, the effect files, `UnityCatalogServer.java`,
`OptionParser.java` and `bin/start-uc-server`.
- Helm: the init container's environment has only what
`--upgrade-schema` needs to reach the database: the database password as
`UC_HIBERNATE_CONNECTION_PASSWORD` (the way #2080 passes it to the
server) and, on MySQL, the driver mount and `JDK_JAVA_OPTIONS` from
#2119, through the new `unitycatalog.server.dbPasswordEnv` and
`unitycatalog.server.mysqlDriverEnv` helpers. Its environment has no
storage credentials. It shares the server container's volume mounts,
including the GCS key files, through `unitycatalog.server.volumeMounts`,
so the two can't drift apart. The server container keeps one `env` list.
- `docs/server/deployment.md` drops the manual `ALTER` statements for
`uc_properties.property_value`: new installs get the wide column from
the steps, and a pre-0.7.0 database gets it from starting 0.7.0 once.

### Test coverage

-
`SchemaMigratorTest.serverRefusesToStartOnADatabaseNotAtThisReleasesSchema`:
a pending step, a failed step, an edited step, a step missing below the
recorded one, and a newer schema.
- `SchemaGateTest`: refuses to start on a database that is not set up,
and sets up an in-memory database at start.
- `HibernateConfiguratorTest`: `neverLetsHibernateChangeTheSchema`,
`refusesASchemaActionOtherThanNone` (each setting form), and
`refusesHibernatesOwnDefaultSchema`.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### Stack

Part 7 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema (this PR)
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
shba24 added a commit to shba24/unitycatalog that referenced this pull request Nov 19, 2026
unitycatalog#2080 landed as 642cb5c, whose tree is unitycatalog#2080's head, which this branch already holds.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants