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

Adds support for revocation of VDS secrets on delete. #143

Merged
merged 18 commits into from
Apr 26, 2023

Conversation

kschoche
Copy link
Contributor

Adds support for revocation of VDS secrets on delete:

  • Adds the field Revoke to the VDS secret Spec.
  • Adds logic to revoke the VDS secret on deletion through a finalizer.
  • Updates tests to validate revocation of VDS secrets.

Note: Introducing this behaviour requires the following policy added to each VaultAuthMethod which is referenced by VDS secrets that enable revocation:

path "sys/leases/revoke" {
    capabilities = ["update"]
}

In the absence of the above policy, revocation will fail on VDS secret deletion.
This should fix #125

@kschoche kschoche self-assigned this Apr 17, 2023
@kschoche kschoche added the enhancement New feature or request label Apr 17, 2023
@kschoche kschoche marked this pull request as ready for review April 20, 2023 14:38
@kschoche kschoche requested a review from a team April 20, 2023 14:38
logger.Info("Got deletion timestamp", "obj", o)
if err := r.handleDeletion(ctx, o); err != nil {
msg := "Failed to handle deletion"
r.Recorder.Eventf(o, corev1.EventTypeWarning, consts.ReasonSecretLeaseRevoked, msg+": %s", err)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be better to use a reason that's not in the past tense here, since in this err handling the lease may not have been revoked yet. And it looks like this error could be either from removing the finalizer or revoking the lease.

It may be useful to emit an event on successful revoke too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point thanks, fixed in 451a326

controllers/vaultdynamicsecret_controller.go Outdated Show resolved Hide resolved
api/v1alpha1/vaultdynamicsecret_types.go Outdated Show resolved Hide resolved
@kschoche kschoche requested a review from tvoran April 25, 2023 16:08
…hicorp/vault-secrets-operator into VAULT-15424/add_revoke_option_to_vds
Copy link
Member

@tvoran tvoran left a comment

Choose a reason for hiding this comment

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

Seems to be working for me!

Comment on lines 313 to 317
if err := r.revokeLease(ctx, o, ""); err != nil {
// Do not return error, otherwise we may fail to remove the finalizer.
// Worst case at this point we will leave a dangling lease instead of a secret which
// cannot be deleted.
}
Copy link
Member

Choose a reason for hiding this comment

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

The comment is great, but should we log something here? Otherwise the if err := ... seems extraneous (and go-staticcheck is complaining to me about it 🙂).

Copy link
Contributor Author

@kschoche kschoche Apr 25, 2023

Choose a reason for hiding this comment

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

Good call, we're actually emitting an Event and logging inside this function in those cases, I'm going to change the function signature a bit so we're not "hiding anything" and adjust the comment accordingly.

// Check to be sure all leases have been revoked.
retry.DoWithRetry(t, "waitForAllLeasesToBeRevoked", 30, time.Second, func() (string, error) {
// ensure that all leases have been revoked.
resp, err := c.Logical().ListWithContext(ctx, fmt.Sprintf("sys/leases/lookup/%s/creds/readonly", outputs.DBRole))
Copy link
Member

Choose a reason for hiding this comment

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

Remind me how this works? I was thinking it would be more like sys/leases/lookup/<outputs.DBPath>/creds/<output.DBRole>.

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, I grabbed this from https://developer.hashicorp.com/vault/docs/commands/lease#examples
I think you're right on that path, I'll look into it.
I have validated in the controller logs though that the leases are revoked, but this does look off thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup that was it, thanks! Did confirm that I can see the # of leases getting smaller through that loop on shutdown!

test/integration/vaultdynamicsecret_integration_test.go Outdated Show resolved Hide resolved
@tvoran
Copy link
Member

tvoran commented Apr 25, 2023

Oh and don't forget a changelog entry 🙂

@kschoche kschoche merged commit b55047a into main Apr 26, 2023
@kschoche kschoche deleted the VAULT-15424/add_revoke_option_to_vds branch April 26, 2023 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop AWS IAM_USER when the VaultDynamicSecret is deleted
2 participants