Repository navigation
[Server] Read the token signing key from an operator key file - #2081
Conversation
|
Local AI review run The CI
Each finding was checked against the code before acting on it.
Reviewed heads: 2f4bb5a, 690745f, 8b8356b, c0bc199, d7bf525. Current heads: 81e48b4, eba9f92, 99ae5a0, b91905f, b19e7a5. |
99ae5a0 to
2748528
Compare
|
Local AI review run (round 2) The CI
Verification on the current heads:
|
|
/review |
2748528 to
b25ef87
Compare
e417179 to
43bb125
Compare
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]>
The server signed its tokens with a key it generated into etc/conf, and the Helm chart copied its key Secret into etc/conf because the location was fixed. The new server.token-signing-private-key-file setting names the operator's RSA private key, in PEM or DER; the server only reads it and derives the public key from it once, at startup. Without it the server keeps using the key in etc/conf, generating it on first start (a newly generated private key is now readable by its owner only), and with authorization enabled logs a deprecation warning. The server now checks its own tokens with that key directly, with RS512 only. It no longer writes certs.json, and it no longer uses a key ID: new tokens carry none and checks ignore it. Existing tokens keep working, since they are signed with the same key, and a server on the previous version accepts the new tokens, since its certs.json holds one key. A token signed with another key is now rejected with 401 instead of a 500. The Helm chart points the setting at the private key in its Secret mount and no longer needs key_id.txt or openssl in the init container. Generating the key Secret (server.jwtKeypairSecret.create) still works but is deprecated, and the install notes say how to keep the current key. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Kubernetes always mounts Secret volumes read-only, so the flag changed nothing. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
UnityCatalogServerTest.startupUsesTheTokenSigningKeyFileSettings already starts the server with a key file that does not exist and checks the message. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The PKCS unitycatalog#1 PEM case of readsTheOperatorsKeyFile already reads a PKCS unitycatalog#1 key and checks it equals the original, so pkcs1ToPkcs8 can be private. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Only the holder of the server's key can sign an internal token, so accepting another RS algorithm from it would harm nobody; the RS512-only change stays documented in the auth upgrade notes. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The rollback steps for key_id.txt and certs.json are in the Upgrading section of auth.md; the configuration page now links there instead of repeating part of them. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…he startup test The empty configuration folder case writes token.txt into the working directory, which the test then deleted, losing a file that was already there. It now restores the file's earlier content. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
Brings in the tests for more unusable key files. SecurityContext and UnityCatalogServerTest keep this branch's version: the server here writes no token.txt, so unitycatalog#2081's folder creation before that write, and its steps checking the written file, do not apply. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
No conflicts. Brings in ownership transfer (unitycatalog#2149), pool metrics (unitycatalog#2284) and the check that tests leave the checkout clean (unitycatalog#2334). Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
| Algorithm.RSA512( | ||
| (RSAPublicKey) otherKey.getPublic(), (RSAPrivateKey) otherKey.getPrivate())); | ||
|
|
||
| assertThatThrownBy(this::serve).isInstanceOf(SignatureVerificationException.class); |
There was a problem hiding this comment.
this tests a different key with RS512, not a different signing algorithm. could we also add parameterized cases with the server's own key for RS512 (succeeds) vs RS256, RS384, HS512, and unsigned tokens, and assert verifyNotDelegated() on the rejected ones? otherwise a later change could silently bring back RS256/RS384 acceptance.
| .hibernateConfigurator(hibernateConfigurator) | ||
| .configurationFolder(missing) | ||
| .build()) { | ||
| assertThat(missing.resolve("token.txt")).isNotEmptyFile(); |
There was a problem hiding this comment.
a server that ignored the setting and generated a fresh key would also write a non-empty token.txt here. could we verify the token's signature against the configured key's public key, and check that no fallback keys were created?
assertThat(missing.resolve("token.txt")).isNotEmptyFile();
+assertThat(missing.resolve("private_key.der")).doesNotExist();
+assertThat(missing.resolve("public_key.der")).doesNotExist();| throw new IllegalStateException( | ||
| "Cannot read the RSA private key in " | ||
| + file.toAbsolutePath() | ||
| + "; expected a PEM key, or a PKCS #8 DER one", |
There was a problem hiding this comment.
EC, DSA, and OpenSSH keys hit this message even when they're already PEM, so an operator following it can still pass an unsupported key. could we spell out the full accepted format and maybe add an EC-key case to check the message?
- + "; expected a PEM key, or a PKCS #8 DER one",
+ + "; expected an unencrypted RSA private key in PKCS #8 PEM or DER, or PKCS #1 PEM",…pdir The step used the working directory, the repository root, which tests must not write to (AGENTS.md). An empty path in a zip file system has no parent either, so the step still fails without the fix. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
…s tokens Tokens signed with the server's own key but another algorithm (RS256, RS384, HS512 or none) are rejected without reaching the service. The startup test checks that token.txt is signed with the configured key and that no fallback key is generated. A key that is not an RSA key now gets a message that says which keys the server reads. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Brings in main (ownership transfer, pool metrics, the checkout-clean test check) through unitycatalog#2081. No conflicts. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Brings in the tests that only RS512 and the configured key sign the server's tokens, and the clearer message for a key that is not RSA. UnityCatalogServerTest keeps this branch's version: its new steps check the token.txt that the server here does not write. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Approving at 5ac94bb. Reviewed the PR's own change (main merged into the head, so the earlier #2080 commits drop out). The key file is read and validated at startup with clear errors that name the file, the existing key folder path still works, a token signed with the wrong key now gets a 401, and the targeted auth tests pass.
Follow-ups, fine to fix here if convenient, otherwise please track them as issues and link them from the description:
helm/templates/server/deployment.yaml:68-70: the init guard checks the firstserver.token-signing-private-key-fileline, but the server reads the last one (Propertieskeeps the later value, andextraPropertiesrenders afterserver.config.override). With a non-empty value in the override and a blankextraPropertiesentry, the guard appends nothing, the server reads the blank value, and each pod generates its own key. Checking the last matching line would match what the server reads. A small case table in CI would cover it: non-empty only, blank only, non-empty then blank, blank then non-empty.SecurityConfiguration.java:75: the folder path readspublic_key.der, while the key-file path derives the public key from the private key. If the two files do not match, the verifier and the signer use different keys, so internal tokens get a 401 and startup logs nothing. Deriving the public key here too (aspublicKeyOfdoes), while still writingpublic_key.derfor rollback, would remove this case.- Description wording: "Without it nothing changes for existing setups" holds for the key source only, since the
kidand RS512-only checks apply to every setup; maybe "Without it the key source does not change". And "(without authorization the key is unused)": the key still signstoken.txtat startup, so maybe "without authorization no request checks the key, but it still signstoken.txtat startup".
Nits:
UnityCatalogServer.java:755-757: the builder Javadoc says the folder holds the signing keys; with the setting it holds onlytoken.txt.docs/server/configuration.md:77-79: worth adding that the file must exist even with authorization off, that a new key takes effect at the next start, and that a relative path resolves against the working directory.SecurityConfiguration.java:117: no minimum key size. A 512-bit key loads and then fails at startup when the service token is signed, with a message that does not name the file.- A key file path that points to a directory fails with "Is a directory" and no path; the missing, empty and encrypted cases do name the file.
JwksOperations.java:82-85: the null-context branch exists only for theJwksOperationsTestconstructors.AuthDecoratorTest.java:142: "earlier versions failed the lookup with a 500" describes history; describing the behavior would age better.- No server-level test pins that a rejected internal token gets HTTP 401.
SecurityConfiguration.java:161-166(writeOwnerOnly): delete, create, then write is not atomic, so a crash in between leaves an emptyprivate_key.derand the next start fails until it is removed. It fails closed and the folder path is deprecated, so this is a follow-up at most.
The init container appends the Secret's key file unless server.properties already sets one. It checked whether any line sets a non-empty value, while the server reads the last line: extraProperties render after server.config.override, and Properties keeps the later value. A non-empty override followed by a blank extraProperties entry appended nothing, the server read the blank value, and each pod generated its own key. The guard now checks the last line that sets the key file. The render check runs it on four cases: non-empty only, blank only, non-empty then blank, blank then non-empty. On the old guard the third case fails. Also reword the configurationFolder Javadoc, which said the folder always holds the signing keys, and a test comment that described history instead of behavior. 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]>
|
Thanks Yi, this was a careful pass. Every item was checked against the code, and where possible with a local run. Changes are in f681566. Follow-ups
Nits
|
|
/review |
|
[AI Assisted] Merging this now. Thanks for the quick fixes: the Helm init guard now follows the last key-file line, and the new CI step covers all four cases. One follow-up from the earlier review is still open, so could you open an issue for it? In the folder path, |
|
Thanks Yi, and thanks for merging. I opened one small issue per follow-up and linked them from the description:
The |
…ests - `AGENTS.md`: CI also fails on ignored, edited or deleted files under any `etc/conf` - Drop `certs.json` from comments: since unitycatalog#2081 the server writes only its signing keys and `token.txt` - `test_check_etc_conf.py` - A nested file, `etc/conf/keys/private_key.der`, must fail - Untracked and ignored files outside `etc/conf` must not - `check_conf_stamps`: an `etc/conf` three levels deep must not be watched Co-authored-by: Isaac <[email protected]> Signed-off-by: Yi Li <[email protected]>
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
docsis updatedThis is part 3 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 give the server its token signing key as a file they choose, for example a read-only mount of a Kubernetes Secret. Before, the key had to be in
etc/conf: the server generated it there on first start, and the Helm chart copied its key Secret intoetc/conf(converting PEM to DER) to fit.server.token-signing-private-key-file, an unencrypted RSA private key: PKCS Add issue templates #8 in PEM or DER, or PKCS Update the supported Engines section #1 in PEM (as the chart and someopenssl genrsaversions write it). Other PEM blocks in the file, such as a certificate, are skipped. The server only reads the file and derives the public key from it once, at startup, so checking a token costs nothing extra. A missing file, an encrypted key or an unreadable key stops startup with a message naming the file.etc/confand generates it on first start. That is now deprecated: with authorization enabled the server logs a warning at each start (without authorization no request checks the key, but it still signstoken.txtat startup), and a newly generated private key is readable by its owner only (0600).etc/conf/certs.json, and it no longer uses a key ID: new tokens carry none, and checks ignore one. A token signed with another key is now rejected with 401 "Invalid access token", instead of a 500 that clients retried.private_key.pem(orprivate_key.der) in the Secret mount; it no longer copies keys intoetc/confor needs openssl. A key file you set yourself (server.config.overrideorextraProperties) is kept. The Secret no longer needskey_id.txt, and the create-users job no longer sets one. Generating the key Secret (server.jwtKeypairSecret.create: true, the default) still works for this release, but is deprecated:values.yaml, the install notes and the new "Token signing key" section in the Helm guide say how to keep the current key or bring your own.server.properties.openssl genrsa -out private_key.pem 2048 # server.properties server.token-signing-private-key-file=/etc/uc/private_key.pemFollow-ups: #2363 (derive the public key on the deprecated key-folder path), #2364 (a key file path that is a directory), #2365 (a key too small for RS512), #2366 (write the generated key atomically).
📐 Design notes & details
Why this shape. This follows Apache Polaris: the operator provides the key, and the server checks its own tokens against that one key with no key ID. Polaris's chart never generates keys, and its production-readiness check flags a generated key. Unlike Polaris, which takes both key files, UC takes only the private key: the public key is part of it, so a second setting would only add a way to configure a pair that doesn't match.
Why the key ID and
certs.jsoncould go.certs.jsonhad no readers. It was a JWKS copy of the public key that only the server read back, to reuse the JWKS code it uses for external identity providers. No endpoint served it.SigningKeyNotFoundException→INTERNAL, which the Java client used by the Spark and Hadoop connectors retries (5xx, 3 attempts).Compatibility. Users see these in the Upgrading section of
docs/server/auth.md.etc/conf/private_key.deror a copy of it; a new key makes them fail with 401.certs.jsonholds one key. I checked jwks-rsa 0.24.1UrlJwkProvider: no kid with one key returns that key, and a wrong kid throwsSigningKeyNotFoundException.key_id.txtandcerts.jsonare left in place, which a previous version needs. The docs say to keep them while a rollback is possible, and how to write the operator's key toetc/confin the formats an earlier version reads.key_id.txt, so an earlier server generates a new key (tokens must be reissued), and an earlier chart stops without one in the Secret. The docs say to add akey_id.txtwith any value first.resource-policy: keep), so its key and its oldkey_id.txtstay.values.yamlsays to use the image from the chart's release.private_key.pemandprivate_key.der: the chart now uses the PEM one (before: the DER one).server.config.overrideorextraProperties: it must point at the key in the Secret. The create-users job signs with that key and retries without a limit, so with another key the install waits until Helm's timeout.Not done (on purpose).
defaultModeon the Secret volume. The private key mount keeps today's mode.Tests.
SecurityConfigurationTest:readsTheOperatorsKeyFile, one row per format (PKCS Add issue templates #8 DER, PKCS Add issue templates #8 PEM, PKCS Update the supported Engines section #1 PEM, a certificate followed by a PEM key): reads the private key, derives the matching public key, and writes nothing to the configuration folder. The PEM headers are built at runtime so the secret scanner doesn't flag the test source;rejectsAnEncryptedPrivateKey;createsAGeneratedPrivateKeyReadableByItsOwnerOnly: a blank setting falls back toetc/conf, the generated key isrw-------, nokey_id.txtis written, and a later start reuses the key.AuthDecoratorTest.tokenSignedWithAnotherKeyIsRejected: with a key ID the server never had, which gave 500 before.UnityCatalogServerTest.startupUsesTheTokenSigningKeyFileSettings: startup uses the setting, fails on a missing file, and creates a configuration folder that does not exist yet.helm template/ chart lint: a key file set throughextraPropertiesis kept; a blank one gets the chart's key. The CI render step checks that the init container appends the setting and that the server container mounts the key Secret: the CI installs run with authorization off, where a server given no key file falls back to a generated key. The init container's check was run against each form (=,:, a space, blank, commented out) undershand BusyBoxgrep.openssl genrsaPKCS Update the supported Engines section #1 PEM key (valid token 200, broken signature 401, no token 401; an encrypted key stops startup), and a fresh install on kind with PostgreSQL 18, auth and a create-users user.This pull request and its description were written by Isaac.