feat: Allow configuration of private keys for TLS management (#2854)#7509
feat: Allow configuration of private keys for TLS management (#2854)#7509pauloappbr wants to merge 1 commit intocaddyserver:masterfrom
Conversation
|
The current CI failures (lint/tests) are expected. This PR depends on the changes introduced in caddyserver/certmagic#371, which adds the Once caddyserver/certmagic#371 is approved and merged, I will update the I’ve converted this PR to Draft status in the meantime to avoid confusion. |
|
I think we'd want to use storage loader modules instead of Also the |
Assistance Disclosure
I authored the code and performed the tests. I consulted Gemini (Google's AI) for implementation strategy guidance, architectural mapping within Caddy, and initial draft snippets. All code was manually reviewed, integrated, and validated locally.
Dependencies
Description
This PR adds support for the
key_filedirective in the TLS app and Caddyfile.It allows users to provide a pre-existing private key for automated certificate management (ACME or Internal), enabling key continuity across deployments, infrastructure migrations, and environments where keys are pre-provisioned.
The default behavior remains unchanged. If
key_fileis not specified, Caddy continues generating keys automatically via CertMagic.Relates to
Fixes #2854
Changes
Caddyfile:
key_filesubdirective totlskey_fileas a global optionAutomation:
AutomationPolicywith aKeyFilefieldProvisioning:
automation.goto instantiatecertmagic.FileKeyGeneratorwhen a custom key file is configuredPolicy Consolidation:
tlsapp.goto prevent merging policies that reference different custom keysParsing:
builtins.goandoptions.goto parse and validate thekey_filetokenTesting
Tested locally by:
Generating an EC P-384 private key:
Configuring a site block with:
Verifying via
curl -vthat the server presented a certificate using the specified P-384 key (confirmed public key type and size during the TLS handshake).Verifying that global options correctly propagate the
key_filesetting across automation policies.