Skip to content

Configurable issuer duration and renewBefore Take 2#893

Merged
jetstack-bot merged 66 commits intocert-manager:masterfrom
Queuecumber:cert-duration
Nov 14, 2018
Merged

Configurable issuer duration and renewBefore Take 2#893
jetstack-bot merged 66 commits intocert-manager:masterfrom
Queuecumber:cert-duration

Conversation

@Queuecumber
Copy link
Copy Markdown
Contributor

@Queuecumber Queuecumber commented Sep 12, 2018

This is me commandeering #520 because it is clearly not being worked on

Plan right now is to skip 516be06 in favor of validation which disallows duration for ACME issuers.

What this PR does / why we need it:

This pull request makes possible to configure the certificate validity duration and the renewal before duration per issuer.

Which issue this PR fixes

#437

Special notes for your reviewer:

TODO

  1. Salvage code from 7230151
  2. Make the existing unit and e2e tests work
  3. Use duration config in self-signed issuer
  4. General code quality updates
  5. Validate that duration is not set for ACME certs (w/ unit test)
  6. Test everything in a real cluster
  7. Validate durations in validation and not issuer setup

Release note:

Configurable certificate duration and renewal duration using fields Certificate.spec.duration and 
Certificate.spec.renewBefore respectively.
The CA Issuer and Self-Signed Isuuer default duration is now 90 days instead of 365 days to make all issuers more consistent when configured without explicit duration.

@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Sep 12, 2018
@jetstack-bot jetstack-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 12, 2018
@Queuecumber
Copy link
Copy Markdown
Contributor Author

/hold

This is just to get the ball roling and get some early feedback, e2e tests had a lot of changes since the original commit and need to be reworked. Docs are not updated yet and validation still needs to be written.

@jetstack-bot jetstack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 12, 2018

const (
// Error reason generated when duration or renewBefore is invalid
ErrorDurationInvalid = "ErrDurationInvalid"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A lot of things to do with constants seemed to move since the original commit, so I stuck this here, Is there a better place for it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From what I can tell, this var isn't actually used? Unless GitHub is collapsing things in the diff for me! 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup you're right, this is a holdover from when we were triggering events for stuff (I think) so I'll remove it

)

// to help testing
var now = time.Now
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kind of hate this line, and I don't understand it's purpose in the original commit. I know that it is used in the test (next file down), but there must be a better way to handle it.

@munnerz
Copy link
Copy Markdown
Member

munnerz commented Sep 13, 2018

/ok-to-test

@jetstack-bot jetstack-bot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 13, 2018
@jetstack-bot jetstack-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 13, 2018
@jetstack-bot jetstack-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2018
@Queuecumber
Copy link
Copy Markdown
Contributor Author

@munnerz Can you tell me what version of dep the CI server uses? I dont think the new Bazel system prints it out like the old hack script used to and for a while now I get the following error when I run bazel run hack://update-deps

(81/93) Wrote github.com/hashicorp/errwrap@master: hash of vendored tree didn't match digest in Gopkg.lock
grouped write of manifest, lock and vendor: failed to export bitbucket.org/ww/goautoneg: 
        (1) hg is not installed: 
        (2) hg is not installed: 
        (3) hg is not installed: 
        (4) failed to list versions for https://bitbucket.org/ww/goautoneg: fatal: repository 'https://bitbucket.org/ww/goautoneg/' not found
: exit status 128
        (5) failed to list versions for ssh://git@bitbucket.org/ww/goautoneg: not a git repository.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
: exit status 128
        (6) failed to list versions for git://bitbucket.org/ww/goautoneg: fatal: unable to connect to bitbucket.org:
bitbucket.org[0: 18.205.93.2]: errno=Connection timed out
bitbucket.org[1: 18.205.93.0]: errno=Connection timed out
bitbucket.org[2: 18.205.93.1]: errno=Connection timed out

: exit status 128
        (7) failed to list versions for http://bitbucket.org/ww/goautoneg: fatal: repository 'http://bitbucket.org/ww/goautoneg/' not found
: exit status 128

@Queuecumber
Copy link
Copy Markdown
Contributor Author

OK well nvm it looks like it really did just need the hg binary to complete I dont know why thats surprising to me

@munnerz
Copy link
Copy Markdown
Member

munnerz commented Sep 13, 2018

OK well nvm it looks like it really did just need the hg binary to complete I dont know why thats surprising to me

This is down to that one bitbucket dependency afaict. We've had this issue for a while, and it's really annoying! 😬

Glad you got it resolved. FWIW, I think you need to run:

bazel run //hack:update-bazel
bazel run //hack:update-codegen

😄

@munnerz
Copy link
Copy Markdown
Member

munnerz commented Sep 13, 2018

I also DM'd you on slack just now - feel free to reach out directly if you run into more issues. The new Bazel build system is still early on and there could be a few rough edges!

@jetstack-bot jetstack-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 14, 2018

// Default duration before certificate expiration if Issuer.spec.renewBefore is not set
DefaultRenewBefore = time.Hour * 24 * 30
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this the best place for these constants to go?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 I think so - this ultimately does become part of our public API, and given we are still alpha, it does not preclude a breaking change if needs be 😄

@Queuecumber
Copy link
Copy Markdown
Contributor Author

@munnerz Couple of things that I was thinking about that I'd like your opinion on

  1. Currently duration and renewBefore are properties of the issuers. Should there also be properties on the certificates that override these? Or do we treat the different issuers as QoS levels, so if you want a longer duration cert then ask for one from the issuer that gives longer durations?

  2. Should there be an option to not renew a certificate? For example (real example that I am working on today), I have someone who needs access to our site for a month, so I want to issue him a certificate for one month but not renew it. I could just delete the cert resource and/or not send him the renewed certificate, but maybe there should be options for this?

I think both of these are probably future work in the space of defaulting policies and certificate delivery that you had mentioned in previous discussions.

@Queuecumber
Copy link
Copy Markdown
Contributor Author

/hold cancel

This passed a few tests I ran in a real cluster this morning, issued certs correctly have expirations set, etc. and I was able to issue such a client cert to someone who needs short term access to my cluster. So I think this is at your mercy @munnerz

@jetstack-bot jetstack-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 15, 2018
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Nov 8, 2018
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
@Queuecumber
Copy link
Copy Markdown
Contributor Author

@munnerz Ok well, it seems to pass e2e tests now, but I'm not exactly happy with the solution which was to just not set the duration and renewBefore fields on ACME tests. I still have no idea why it was failing though, and only for HTTP01. DNS01 tests worked fine, and both HTTP01 and DNS01 worked on my live cluster, so its a bit of a mystery. Your call how we proceed.

…be caught as any other too-small value

Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
@Queuecumber
Copy link
Copy Markdown
Contributor Author

/hold

cleaning up some of the e2e tests

@jetstack-bot jetstack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2018
…te API calls

Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
Signed-off-by: Max Ehrlich <max.ehr@gmail.com>
@Queuecumber
Copy link
Copy Markdown
Contributor Author

/hold cancel

I think it's done now

@jetstack-bot jetstack-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 13, 2018
Signed-off-by: James Munnelly <james@munnelly.eu>
@munnerz munnerz added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 14, 2018
Signed-off-by: James Munnelly <james@munnelly.eu>
Signed-off-by: James Munnelly <james@munnelly.eu>
Signed-off-by: James Munnelly <james@munnelly.eu>
Signed-off-by: James Munnelly <james@munnelly.eu>
Signed-off-by: James Munnelly <james@munnelly.eu>
@munnerz
Copy link
Copy Markdown
Member

munnerz commented Nov 14, 2018

I added a few commits on top to clean up a few things, to save you having to go through more rounds of review and back-and-forth!

  1. I cleaned up the Certificate controller Sync function, fixing up a rebase issue
  2. Allowed ACME certificates to specify renewBefore
  3. Updated the docs examples
  4. Renamed calculateTimeBeforeExpiry

I also removed some dead/irrelevant code that I think has been brought forward from rebases.

Thanks for being so persistent with this, I know it's been a pain!

/lgtm
/approve

@jetstack-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: munnerz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Queuecumber
Copy link
Copy Markdown
Contributor Author

Truly a momentous occasion

That's pretty much all I've got for the foreseeable future, good luck with the project

Btw how long until this is available in an image?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme Indicates a PR directly modifies the ACME Issuer code area/vault Indicates a PR directly modifies the Vault Issuer code dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/documentation Categorizes issue or PR as related to documentation. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants