Skip to content

fix: validate duration on certificate regenerate - #1234

Merged
peterhaochen47 merged 1 commit into
mainfrom
TNZGOV-10507-regenerate-duration-bound
Nov 16, 2026
Merged

peterhaochen47 merged 1 commit into
mainfrom
TNZGOV-10507-regenerate-duration-bound

Conversation

@peterhaochen47

Copy link
Copy Markdown
Member

Generate (POST /api/v1/data) rejects a certificate duration outside 1-3650 days, but regenerate (POST /api/v1/certificates/{id}/regenerate) did not check the duration it accepts. Add the same check to CertificateGenerateRequest.setDuration(), so regenerate now returns the existing INVALID_DURATION error too. ONE_DAY and TEN_YEARS become shared constants in CertificateGenerationRequestParameters.

Only a caller-supplied duration is checked. The check is not in the domain-level CertificateGenerationParameters.validate(): regenerate builds parameters from the existing certificate and setKeyLength() also calls validate(), so checking there would break regenerating existing certificates longer than 3650 days.

Prior context:

  • The 1-3650 range was added in 2016 (11a331e) as input validation on generate, not as a limit on stored certificate lifetimes.
  • credhub set does not check validity, so imported certificates can exceed 3650 days.
  • Regenerating set certificates is supported, and regenerate keeps the original duration (0c0d60f, 2017).

No product decision on long-lived imported certificates was found, so this change leaves them as is. Open question: on regenerate, should they keep their duration, be capped, or be rejected?

Generate (POST /api/v1/data) rejects a certificate duration outside
1-3650 days, but regenerate (POST /api/v1/certificates/{id}/regenerate)
did not check the `duration` it accepts. Add the same check to
CertificateGenerateRequest.setDuration(), so regenerate now returns the
existing INVALID_DURATION error too. ONE_DAY and TEN_YEARS become
shared constants in CertificateGenerationRequestParameters.

Only a caller-supplied duration is checked. The check is not in the
domain-level CertificateGenerationParameters.validate(): regenerate
builds parameters from the existing certificate and setKeyLength() also
calls validate(), so checking there would break regenerating existing
certificates longer than 3650 days.

Prior context:
- The 1-3650 range was added in 2016 (11a331e) as input validation on
  generate, not as a limit on stored certificate lifetimes.
- `credhub set` does not check validity, so imported certificates can
  exceed 3650 days.
- Regenerating set certificates is supported, and regenerate keeps the
  original duration (0c0d60f, 2017).

No product decision on long-lived imported certificates was found, so
this change leaves them as is. Open question: on regenerate, should they
keep their duration, be capped, or be rejected?

@dlinsley dlinsley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice use of the parameterized test!

Setting a 10 year limit for the regeneration duration seems acceptable.

Thanks for the fix!

@github-project-automation github-project-automation Bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Nov 16, 2026
@peterhaochen47
peterhaochen47 merged commit ec43e9a into main Nov 16, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Nov 16, 2026
@peterhaochen47
peterhaochen47 deleted the TNZGOV-10507-regenerate-duration-bound branch November 16, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants