Skip to content

feat(database): add managed SSL support for all database types#24

Open
roll-w wants to merge 9 commits into
masterfrom
feat/database-ssl
Open

feat(database): add managed SSL support for all database types#24
roll-w wants to merge 9 commits into
masterfrom
feat/database-ssl

Conversation

@roll-w

@roll-w roll-w commented May 16, 2026

Copy link
Copy Markdown
Owner

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

  • New SSL configuration model (DatabaseSslConfig, DatabaseSslMode, DatabaseSslMaterial) with four modes: disabled, required, verify-ca, verify-identity
  • Automatic trust store (PKCS12) and key store materialization from PEM/DER/base64 certificate material via DatabaseSslSupport
  • Certificate and private key parsing with Bouncy Castle in DatabaseSslParsing
  • Temporary file management with owner-only permissions and cleanup lifecycle (DatabaseSslTempFiles)
  • ManagedHikariDataSource and DatabaseUrl resource cleanup for proper SSL resource lifecycle
  • URL builder updates per database type:
    • MySQL/MariaDB: SSL mode mapping, trust store and client key store materialization
    • PostgreSQL: sslmode, sslrootcert, sslcert, sslkey parameter support
    • Oracle: TCPS protocol prefix (jdbc:oracle:thin:@tcps://), server DN matching
    • SQL Server: encrypt/trustServerCertificate properties, trust store for verify-identity mode
    • H2: SSL protocol prefix (jdbc:h2:ssl://), mode and target validation
  • SSL option conflict detection: reserved SSL keys are rejected in database.options

Frontend

None

Fixes

Backend

None

Frontend

None

Breaking Changes

None

Other Changes

  • Added Bouncy Castle (bcpkix, bcprov) dependency in lampray-web/build.gradle.kts

roll-w added 4 commits April 1, 2026 15:19
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.
@roll-w roll-w requested a review from Copilot May 16, 2026 13:07
@roll-w roll-w self-assigned this May 16, 2026
@roll-w roll-w added the enhancement New feature or request label May 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.ssl package: 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 through DataSourceConfiguration so 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 7 comments.

val resources = mutableListOf<AutoCloseable>()

when (config.ssl.mode) {
DatabaseSslMode.DISABLED -> properties["encrypt"] = "false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants