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: Enable renewing the intermediate cert in the primary DC #8784

Merged
merged 6 commits into from
Oct 9, 2020

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Sep 30, 2020

This PR enables renewing the intermediate certificate in the primary DC for providers that depend on it (currently only Vault) - previously we were renewing intermediates periodically in the secondary DCs but not the primary.

This also adds a check to make sure we aren't using an out of date cert in the primary when cross-signing.

Copy link
Member

@hanshasselberg hanshasselberg left a comment

Choose a reason for hiding this comment

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

LGTM, left a couple of notes.

agent/consul/leader_connect.go Outdated Show resolved Hide resolved
// which means it must never take that lock itself or call anything that does.
func (s *Server) getIntermediateCAPrimary(provider ca.Provider, newActiveRoot *structs.CARoot) error {
connectLogger := s.loggers.Named(logging.Connect)
intermediatePEM, err := provider.GenerateIntermediate()
Copy link
Member

Choose a reason for hiding this comment

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

This generates and signs an intermediate cert. I had to look that up which is why I am leaving a note here for others.

@kyhavlov kyhavlov self-assigned this Oct 6, 2020
@kyhavlov kyhavlov changed the title [WIP] connect: Enable renewing the intermediate cert in the primary DC connect: Enable renewing the intermediate cert in the primary DC Oct 9, 2020
Copy link
Member

@hanshasselberg hanshasselberg left a comment

Choose a reason for hiding this comment

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

LGTM

}
if rootCert.NotAfter.Before(time.Now()) {
return "", fmt.Errorf("root certificate is expired")
}
Copy link
Member

Choose a reason for hiding this comment

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

I assume that means that Vault would happily sign a cert with an expired root CA?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, it's because the sign-self-issued endpoint does minimal validation (only checks for CA cert and self-issued) so it was possible for the cert to expire and the provider would still cross-sign with it.

@kyhavlov kyhavlov merged commit e5ab1b4 into master Oct 9, 2020
@kyhavlov kyhavlov deleted the renew-intermediate-primary branch October 9, 2020 19:19
@hashicorp-ci
Copy link
Contributor

🍒❌ Cherry pick of commit e5ab1b4 onto release/1.8.x failed! Build Log

kyhavlov added a commit that referenced this pull request Oct 9, 2020
connect: Enable renewing the intermediate cert in the primary DC
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.

Nice! I don't know very much about our CA providers, so I can't review this very well, but I had some minor suggestions, nothing blocking.

Comment on lines +360 to +361
# Run leader tests that require Vault
gotestsum --format=short-verbose --junitfile "$(TEST_RESULTS_DIR)/gotestsum-report-leader.xml" -- -cover -coverprofile=coverage-leader.txt -run TestLeader_Vault_ ./agent/consul
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should try and move these tests that require vault into the agent/connect/ca or test/integration packages at some point. But I don't see any reason to block merging this PR. We can revisit once we have a better idea of how we would like to organize our integration tests.

I'm not sure if this extra coverage file will get sent to codecov, I suspect only the coverage.txt will get sent, but that's something we can fix in a follow up as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It definitely feels strange in agent/consul, although it does test internal leader logic. It couldn't go directly in agent/connect/ca but maybe creating a new subpackage in one of these would be the way to go (like agent/consul/integration or something similar, that has tests like this which involve leader functionality and something external like a CA).

Comment on lines +22 to +24
var PrimaryIntermediateProviders = map[string]struct{}{
"vault": {},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like implementing this kind of thing as a method on the type. Then calling code can use an interface to check if the type has the method:

if _, ok := provider.(interface{
    IntermediateCertInPrimaryDC()
}); ok {
   ...
}

But I think we could easily change that later, so I don't want to hold up this bug fix.

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 idea, I overlooked that pattern when thinking about this 👍

Comment on lines +90 to +102
func SkipIfVaultNotPresent(t testing.T) {
vaultBinaryName := os.Getenv("VAULT_BINARY_NAME")
if vaultBinaryName == "" {
vaultBinaryName = "vault"
}

path, err := exec.LookPath(vaultBinaryName)
if err != nil || path == "" {
t.Skipf("%q not found on $PATH - download and install to run this test", vaultBinaryName)
}
}

func NewTestVaultServer(t testing.T) *TestVaultServer {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these kind of helpers are great, but can sometimes make the package harder to use when they are in the godoc together with the production stuff. I generally try to put this type of thing into an internal/test/vaultca type package.

But not a big issue, and easy to do as a follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants