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

keyring: warn if removing a key that was used for encrypting variables #24766

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

pkazmierczak
Copy link
Contributor

This PR adds an additional check in the Keyring.Delete RPC to make sure we're not trying to delete a key that's been used to encrypt a variable. It also adds a -force flag for the CLI/API to sidestep that check.

Resolves #24591
Internal ref: https://hashicorp.atlassian.net/browse/NET-11829

@pkazmierczak pkazmierczak requested review from a team as code owners December 31, 2024 15:45
@pkazmierczak pkazmierczak added the backport/1.9.x backport to 1.9.x release line label Dec 31, 2024
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @pkazmierczak!

I tested this locally and couldn't get a delete to work even when using the force flag. I believe we need to populate the RPC request force parameter from the HTTP request here in order for the HTTP->RPC translation to handle this new parameter.

It would also be good if we could address the following items:

  • The CLI help output doesn't include the new flag option.
  • It would be nice to have API and CLI tests to cover this addition as the RPC test did not catch the issue detailed above.
  • Document the API and CLI changes.

@@ -0,0 +1,3 @@
```release-note:improvement
keyring: Warn if deleting a key previously used to encrypt a variable
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth expanding on this to note the variable should still exist? It immediately reads to me that the warning applies to any key used in the past.

return wm, err
}

// KeyringDeleteOptions are parameters for the Delete API
type KeyringDeleteOptions struct {
KeyID string // UUID
Force bool
Copy link
Member

Choose a reason for hiding this comment

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

I know not many options have this, but could we add a comment to this explaining what the force boolean does? It means external tool developers have an easy time knowing and understanding.

return err
}
if rootKeyInUse && !args.Force {
return fmt.Errorf("root key in use, cannot delete")
Copy link
Member

Choose a reason for hiding this comment

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

There is no formatting, so we could use the below (the suggestion won't compile as the file also needs the new import):

Suggested change
return fmt.Errorf("root key in use, cannot delete")
return errors.New("root key in use, cannot delete")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah force of habit I guess, but errors.New is a better choice here

Copy link
Contributor

@aimeeu aimeeu left a comment

Choose a reason for hiding this comment

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

Thanks for updating the docs!

@pkazmierczak
Copy link
Contributor Author

@jrasell I addressed all your comments, thanks for the thorough review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.9.x backport to 1.9.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warn if removing a root key that was used for encrypting Variables
3 participants