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

Add ability to perform automatic PKI tidy operations #16900

Merged
merged 7 commits into from
Aug 30, 2022

Conversation

cipherboy
Copy link
Contributor

@cipherboy cipherboy commented Aug 26, 2022

This enables the PKI secrets engine to allow tidy to be started
periodically by the engine itself, avoiding the need for interaction.
This operation is disabled by default (to avoid load on clusters which
don't need tidy to be run) but can be enabled.

In particular, a default tidy configuration is written (via
/config/auto-tidy) which mirrors the options passed to /tidy. Two
additional parameters, enabled and interval, are accepted, allowing
auto-tidy to be enabled or disabled and controlling the interval
(between successful tidy runs) to attempt auto-tidy.

Notably, a manual execution of tidy will delay additional auto-tidy
operations. Status is reported via the existing /tidy-status endpoint.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>


  • Docs
  • Tests
  • Changelog

@cipherboy cipherboy added this to the 1.12.0-rc1 milestone Aug 26, 2022
@cipherboy cipherboy force-pushed the cipherboy-tidy-associate-revoked-certs branch from 7d50d0c to 78d9b3d Compare August 26, 2022 16:35
@cipherboy cipherboy changed the base branch from cipherboy-tidy-associate-revoked-certs to main August 29, 2022 12:56
@cipherboy cipherboy force-pushed the cipherboy-auto-tidy-take-two branch 2 times, most recently from 0ecc396 to 1a27bb6 Compare August 29, 2022 17:14
@cipherboy cipherboy marked this pull request as ready for review August 29, 2022 17:14
@cipherboy cipherboy requested a review from a team August 29, 2022 17:16
@cipherboy cipherboy mentioned this pull request Aug 29, 2022
"github.com/stretchr/testify/require"
)

func TestAutoTidy(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test takes 17s as it is fwiw.

builtin/logical/pki/path_tidy.go Outdated Show resolved Hide resolved
builtin/logical/pki/path_tidy.go Show resolved Hide resolved
@cipherboy
Copy link
Contributor Author

@stevendpclark updated and bumped the timeout on this test... We'll see if that helps? :-)

This enables the PKI secrets engine to allow tidy to be started
periodically by the engine itself, avoiding the need for interaction.
This operation is disabled by default (to avoid load on clusters which
don't need tidy to be run) but can be enabled.

In particular, a default tidy configuration is written (via
/config/auto-tidy) which mirrors the options passed to /tidy. Two
additional parameters, enabled and interval, are accepted, allowing
auto-tidy to be enabled or disabled and controlling the interval
(between successful tidy runs) to attempt auto-tidy.

Notably, a manual execution of tidy will delay additional auto-tidy
operations. Status is reported via the existing /tidy-status endpoint.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
We modified the RollbackManager's execution window to allow more
faithful testing of the periodicFunc. However, the TestAutoRebuild and
the new TestAutoTidy would then race against each other for modifying
the period and creating their clusters (before resetting to the old
value).

This changeset adds a lock around this, preventing the races.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

Looks good to me, one nit which I feel pretty ambivalent about either way on the docs.

website/content/api-docs/secret/pki.mdx Show resolved Hide resolved
This prevents a data race between the periodic func and the execution of
the running tidy.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
When reading from tidyStatus for computing gauges, since the underlying
values aren't atomics, we really should be gating these with a read lock
around the status access.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
@cipherboy
Copy link
Contributor Author

Thanks! Finally got all the data races figured out! ty!

@cipherboy cipherboy merged commit f0c318e into main Aug 30, 2022
@cipherboy cipherboy mentioned this pull request Aug 30, 2022
"interval_duration": {
Type: framework.TypeDurationSecond,
Description: `Interval at which to run an auto-tidy operation. This is the time between tidy invocations (after one finishes to the start of the next). Running a manual tidy will reset this duration.`,
Default: 43200, // 32h, but TypeDurationSecond currently requires the default to be an int.
Copy link

Choose a reason for hiding this comment

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

43200s = 12h. Is 32h default a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good eyes. Yes, a typo. Note though that auto-tidy isn't enabled by default.

@abh
Copy link

abh commented Aug 31, 2022

Very nice; I am looking forward to trying it out!

@cipherboy cipherboy changed the title Add ability to perform automatic tidy operations Add ability to perform automatic PKI tidy operations Nov 28, 2022
@cipherboy cipherboy deleted the cipherboy-auto-tidy-take-two branch December 1, 2022 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants