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

connect/ca: ensure edits to the key type/bits for the connect builtin CA will regenerate the roots #10330

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

rboyer
Copy link
Member

@rboyer rboyer commented Jun 1, 2021

progress on #9572

@rboyer rboyer added the theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies label Jun 1, 2021
@rboyer rboyer requested a review from a team June 1, 2021 15:45
@rboyer rboyer self-assigned this Jun 1, 2021
@@ -63,8 +69,7 @@ func (c *ConsulProvider) Configure(cfg ProviderConfig) error {
return err
}
c.config = config
hash := sha256.Sum256([]byte(fmt.Sprintf("%s,%s,%v", config.PrivateKey, config.RootCert, cfg.IsPrimary)))
c.id = connect.HexString(hash[:])
c.id = hexStringHash(fmt.Sprintf("%s,%s,%s,%d,%v", config.PrivateKey, config.RootCert, config.PrivateKeyType, config.PrivateKeyBits, cfg.IsPrimary))
Copy link
Member Author

Choose a reason for hiding this comment

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

This id is used to key the builtin proxy configuration in the state store (much like a cache-key). Adding the key type/bits here allows it to have two builtin proxy roots defined simultaneously during the rotation.

Copy link
Contributor

Choose a reason for hiding this comment

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

At first I thought RootCert should have already been unique here, but after reading the tests I realize now that this input struct is a ConsulCAProviderConfig , not the CARoots, which means in most cases when PrivateKey{Type,Bits} are set, RootCert would be the zero value.

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 1, 2021 16:31 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 1, 2021 16:31 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 1, 2021 16:58 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 1, 2021 16:58 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 20:45 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 20:45 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 21:03 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 21:03 Inactive
@rboyer rboyer marked this pull request as ready for review June 30, 2021 21:03
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 21:06 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 21:06 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM! This seems like it should fix the bug with the Consul CA provider.

I also wonder how we could prevent bugs like this in the future. We could write a test, similar to #9556, which verifies that all the important fields are considered in the hash. We can ignore any existing fields that we don't need in the hash.

@@ -63,8 +69,7 @@ func (c *ConsulProvider) Configure(cfg ProviderConfig) error {
return err
}
c.config = config
hash := sha256.Sum256([]byte(fmt.Sprintf("%s,%s,%v", config.PrivateKey, config.RootCert, cfg.IsPrimary)))
c.id = connect.HexString(hash[:])
c.id = hexStringHash(fmt.Sprintf("%s,%s,%s,%d,%v", config.PrivateKey, config.RootCert, config.PrivateKeyType, config.PrivateKeyBits, cfg.IsPrimary))
Copy link
Contributor

Choose a reason for hiding this comment

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

At first I thought RootCert should have already been unique here, but after reading the tests I realize now that this input struct is a ConsulCAProviderConfig , not the CARoots, which means in most cases when PrivateKey{Type,Bits} are set, RootCert would be the zero value.

Comment on lines +36 to +44
}{
{connect.DefaultPrivateKeyType, connect.DefaultPrivateKeyBits},
{"ec", 256},
{"ec", 384},
{"rsa", 2048},
{"rsa", 4096},
}

for _, src := range types {
for _, dst := range types {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we could test these permutations without having to spin up a full server. Hopefully after a few changes like #10445 we'll be able to test this with a full persistence backend, but without serf and all the other parts that aren't used here.

@vercel vercel bot temporarily deployed to Preview – consul July 13, 2021 15:40 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 13, 2021 15:40 Inactive
@rboyer rboyer merged commit 6c47efd into main Jul 13, 2021
@rboyer rboyer deleted the ca-keyconfig-builtin branch July 13, 2021 16:12
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/408197.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants