Skip to content

Support backdating leaf certificate NotBefore via env var#348

Open
jacaetevha wants to merge 2 commits into
puma:masterfrom
jacaetevha:master
Open

Support backdating leaf certificate NotBefore via env var#348
jacaetevha wants to merge 2 commits into
puma:masterfrom
jacaetevha:master

Conversation

@jacaetevha

Copy link
Copy Markdown

Unblock testing time-dependent behavior with tools like libfaketime: when a service's clock is moved into the past, TLS handshakes against puma-dev-issued certs were failing with "certificate is not yet valid" because NotBefore was always stamped from the real clock.

  • add PUMADEV_LEAF_CERT_NOT_BEFORE env var to backdate the NotBefore timestamp on generated leaf certificates, accepting either a duration (sign-normalized negative) or a past RFC3339 timestamp — falls back to time.Now() when unset, invalid, or not in the past
  • notAfter is still computed from the real current time rather than the (possibly backdated) notBefore, so a large offset cannot push a cert's expiry into the past
  • document the new env var in the README, including how to set it for background services (launchd plist / systemd unit), since a plain shell export doesn't reach those

- Add PUMADEV_LEAF_CERT_NOT_BEFORE env var to backdate the NotBefore
  timestamp on generated leaf certificates, accepting either a
  duration (sign-normalized to negative) or a past RFC3339 timestamp.
  Falls back to time.Now() when unset, invalid, or not in the past.
- Works around TLS handshake failures ("certificate is not yet
  valid") when a client's clock has been moved into the past, e.g.
  via libfaketime for testing time-dependent behavior.
- Fix notAfter to always be computed from the real current time
  rather than the (possibly backdated) notBefore, so a large offset
  can no longer push a cert's expiry into the past.
- Add tests covering the parsing/fallback behavior and a full
  chain-verification regression test against a real CA.
- Document the new env var in the README's HTTPS section.
Add a note that setting PUMADEV_LEAF_CERT_NOT_BEFORE via a plain
shell export only works when running puma-dev in the foreground.
launchd (macOS) and systemd (Linux) run it as a background service
with their own environment, so the variable must be added to the
plist/unit file instead, with copy-pasteable commands for both.
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