Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove certificates from store if tidying revoked certificates #5231

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions builtin/logical/pki/path_tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ func pathTidy(b *backend) *framework.Path {
the certificate store`,
},

"tidy_revocation_list": &framework.FieldSchema{
Type: framework.TypeBool,
Description: `Set to true to enable tidying up
the revocation list`,
},

"tidy_revoked_certs": &framework.FieldSchema{
Type: framework.TypeBool,
Description: `Set to true to expire all revoked
certificates, even if their duration has not yet passed. This will cause these
certificates to be removed from the CRL the next time the CRL is generated.`,
certificates, even if their duration has not yet passed, removing
them both from the CRL and from storage. The CRL will be rotated
if this causes any values to be removed.`,
},

"safety_buffer": &framework.FieldSchema{
Expand All @@ -58,7 +53,6 @@ Defaults to 72 hours.`,
func (b *backend) pathTidyWrite(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
safetyBuffer := d.Get("safety_buffer").(int)
tidyCertStore := d.Get("tidy_cert_store").(bool)
tidyRevocationList := d.Get("tidy_revocation_list").(bool)
tidyRevokedCerts := d.Get("tidy_revoked_certs").(bool)

if safetyBuffer < 1 {
Expand Down Expand Up @@ -127,7 +121,7 @@ func (b *backend) pathTidyWrite(ctx context.Context, req *logical.Request, d *fr
}
}

if tidyRevocationList {
if tidyRevokedCerts {
b.revokeStorageLock.Lock()
defer b.revokeStorageLock.Unlock()

Expand Down Expand Up @@ -169,10 +163,13 @@ func (b *backend) pathTidyWrite(ctx context.Context, req *logical.Request, d *fr
return errwrap.Wrapf(fmt.Sprintf("unable to parse stored revoked certificate with serial %q: {{err}}", serial), err)
}

if tidyRevokedCerts || time.Now().After(revokedCert.NotAfter.Add(bufferDuration)) {
if time.Now().After(revokedCert.NotAfter.Add(bufferDuration)) {
if err := req.Storage.Delete(ctx, "revoked/"+serial); err != nil {
return errwrap.Wrapf(fmt.Sprintf("error deleting serial %q from revoked list: {{err}}", serial), err)
}
if err := req.Storage.Delete(ctx, "certs/"+serial); err != nil {
return errwrap.Wrapf(fmt.Sprintf("error deleting serial %q from store when tidying revoked: {{err}}", serial), err)
}
tidiedRevoked = true
}
}
Expand Down
8 changes: 3 additions & 5 deletions website/source/api/secret/pki/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,12 +1539,10 @@ expiration time.
- `tidy_cert_store` `(bool: false)` Specifies whether to tidy up the certificate
store.

- `tidy_revocation_list` `(bool: false)` Specifies whether to tidy up the
revocation list (CRL).

- `tidy_revoked_certs` `(bool: false)` Set to true to expire all revoked
certificates, even if their duration has not yet passed. This will cause these
certificates to be removed from the CRL the next time the CRL is generated.
certificates, even if their duration has not yet passed, removing them both
from the CRL and from storage. The CRL will be rotated if this causes any
values to be removed.

- `safety_buffer` `(string: "")` Specifies A duration (given as an integer
number of seconds or a string; defaults to `72h`) used as a safety buffer to
Expand Down