feat(database): add managed SSL support for all database types#24
feat(database): add managed SSL support for all database types#24roll-w wants to merge 9 commits into
Conversation
Support PEM and DER SSL materials across the JDBC builders while ignoring SSL settings for unsupported database types. Split the database SSL helpers into focused files so the connection configuration stays maintainable.
There was a problem hiding this comment.
Pull request overview
Adds end-to-end managed SSL support for all supported databases. New configuration keys (database.ssl.mode|ca|cert|key) feed a typed DatabaseSslConfig/DatabaseSslMaterial model that is materialized into PKCS12 trust/key stores (via Bouncy Castle) or PEM files in owner-only temp files, then translated into driver-specific URL params by each *UrlBuilder. A ManagedHikariDataSource and DatabaseUrl.closeResources() lifecycle ensures these temp artifacts are cleaned up on pool close or failure, and conflicts with reserved keys in database.options are rejected.
Changes:
- New
system.database.sslpackage: SSL config model, PEM/DER/Base64 + Bouncy Castle parsing, trust/key store materialization, temp-file lifecycle. - Per-builder SSL property/URL emission for MySQL/MariaDB, PostgreSQL, Oracle (TCPS), SQL Server, H2, plus reserved-key conflict detection in the abstract builder.
- Resource cleanup plumbing (
DatabaseResourceCleanup,ManagedHikariDataSource,DatabaseUrl.resources) wired throughDataSourceConfigurationso SSL temp files are deleted on close/failure.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| lampray-web/build.gradle.kts | Adds Bouncy Castle bcpkix/bcprov deps for PEM/DER parsing. |
| lampray-web/.../system/database/DatabaseConfig.kt | Adds ssl: DatabaseSslConfig field to the database config model. |
| lampray-web/.../system/database/DatabaseConfigKeys.kt | Adds `database.ssl.mode |
| lampray-web/.../system/database/DataSourceConfiguration.kt | Builds DatabaseSslConfig from config, validates combinations, wires ManagedHikariDataSource. |
| lampray-web/.../system/database/DatabaseUrl.kt | Tightens properties typing and adds an AutoCloseable resource list with closeResources(). |
| lampray-web/.../system/database/DatabaseResourceCleanup.kt | Helpers to close resource lists while aggregating suppressed exceptions. |
| lampray-web/.../system/database/ManagedHikariDataSource.kt | HikariDataSource subclass that releases SSL resources on close (missing license header). |
| lampray-web/.../system/database/ssl/DatabaseSslConfig.kt | DatabaseSslConfig/DatabaseSslMode model and parsing. |
| lampray-web/.../system/database/ssl/DatabaseSslMaterial.kt | file:/value: material source parsing. |
| lampray-web/.../system/database/ssl/DatabaseSslArtifacts.kt | Result types for materialized files/keystores. |
| lampray-web/.../system/database/ssl/DatabaseSslTempFiles.kt | Owner-only temp file creation, cleanup, and password generation. |
| lampray-web/.../system/database/ssl/DatabaseSslSupport.kt | PKCS12 trust/key store materialization from PEM/DER material. |
| lampray-web/.../system/database/ssl/DatabaseSslParsing.kt | Bouncy Castle-based X.509 cert and private key parsing (PEM/DER/Base64). |
| lampray-web/.../system/database/builders/AbstractDatabaseUrlBuilder.kt | SSL artifact integration into URL building, reserved-key conflict detection. |
| lampray-web/.../system/database/builders/MySQLUrlBuilder.kt | MySQL/MariaDB sslMode mapping and trust/key store property emission. |
| lampray-web/.../system/database/builders/PostgreSQLUrlBuilder.kt | sslmode/sslrootcert/sslcert/sslkey emission. |
| lampray-web/.../system/database/builders/OracleUrlBuilder.kt | TCPS URL prefix and oracle.net.ssl_server_dn_match emission. |
| lampray-web/.../system/database/builders/SQLServerUrlBuilder.kt | encrypt/trustServerCertificate/trust-store property emission. |
| lampray-web/.../system/database/builders/H2UrlBuilder.kt | H2 ssl:// prefix and validation of supported SSL modes/targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val resources = mutableListOf<AutoCloseable>() | ||
|
|
||
| when (config.ssl.mode) { | ||
| DatabaseSslMode.DISABLED -> properties["encrypt"] = "false" |
This pull request adds managed database SSL support across all supported database types. It introduces a configuration model for SSL modes and certificate material, automatic trust store and key store materialization, resource cleanup lifecycle management, and SSL option conflict detection against
database.options.Highlights
Backend
DatabaseSslConfig,DatabaseSslMode,DatabaseSslMaterial) with four modes:disabled,required,verify-ca,verify-identityDatabaseSslSupportDatabaseSslParsingDatabaseSslTempFiles)ManagedHikariDataSourceandDatabaseUrlresource cleanup for proper SSL resource lifecyclesslmode,sslrootcert,sslcert,sslkeyparameter supportjdbc:oracle:thin:@tcps://), server DN matchingencrypt/trustServerCertificateproperties, trust store forverify-identitymodejdbc:h2:ssl://), mode and target validationdatabase.optionsFrontend
None
Fixes
Backend
None
Frontend
None
Breaking Changes
None
Other Changes
bcpkix,bcprov) dependency inlampray-web/build.gradle.kts