Skip to content

cli: add mt cert create-tenant-signing command#74646

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:create-tenant-signing
Jan 12, 2022
Merged

cli: add mt cert create-tenant-signing command#74646
craig[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:create-tenant-signing

Conversation

@rafiss
Copy link
Copy Markdown
Collaborator

@rafiss rafiss commented Jan 10, 2022

refs #74643

This key/cert will be used to generate session revival tokens.

No release note since this is only intended to be used internally.

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@rafiss rafiss marked this pull request as ready for review January 10, 2022 22:21
@rafiss rafiss requested a review from a team as a code owner January 10, 2022 22:21
@rafiss rafiss requested a review from a team January 10, 2022 22:21
@rafiss rafiss force-pushed the create-tenant-signing branch from 29de99e to d6a7c03 Compare January 10, 2022 22:26
@rafiss rafiss requested review from a team and knz January 10, 2022 22:27
Copy link
Copy Markdown
Contributor

@catj-cockroach catj-cockroach left a comment

Choose a reason for hiding this comment

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

I have a few quick requests about how we're generating the certificate and verifying information output by them, but this looks good to me otherwise!

Reviewed 37 of 37 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @rafiss)


pkg/security/x509.go, line 285 at r1 (raw file):

	publicKey crypto.PublicKey, privateKey crypto.PrivateKey, lifetime time.Duration,
) ([]byte, error) {
	template, err := newTemplate(caCommonName, lifetime)

In my opinion we should use a distinct template for the tenant signing key, rather than reusing the generate template code. We need to store very little information in the certificate, something like this would be sufficient:

template := &x509.Certificate{
		Subject: pkix.Name{
			CommonName: fmt.Sprintf("Tenant %d Token Signing Certificate", tenantID),
		},
		SerialNumber:          big.NewInt(1), // The serial number does not matter because we are not using a certificate authority and replace this certificate with a new certificate.
		BasicConstraintsValid: true,
		IsCA:                  false, // This certificate CANNOT sign other certificates.
		PublicKey:             publicKey,
		NotAfter:              time.Now().Add(lifetime),
		KeyUsage:              x509.KeyUsageDigitalSignature, // This certificate can ONLY make signatures.
	}

pkg/security/certs_tenant_test.go, line 162 at r1 (raw file):

	payload := []byte{1, 2, 3}
	signature := ed25519.Sign(ed25519PrivateKey, payload)
	ed25519PubKey, isEd25519 := signingCert.ParsedCertificates[0].PublicKey.(ed25519.PublicKey)

Rather than interacting with the ParsedCertificates, could we use the CheckSignature function?

	err = certActual.CheckSignature(x509.PureEd25519, payload, signature)
	require.NoError(t, err)

Copy link
Copy Markdown
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @catj-cockroach and @knz)


pkg/security/x509.go, line 285 at r1 (raw file):

Previously, catj-cockroach (Cat J) wrote…

In my opinion we should use a distinct template for the tenant signing key, rather than reusing the generate template code. We need to store very little information in the certificate, something like this would be sufficient:

template := &x509.Certificate{
		Subject: pkix.Name{
			CommonName: fmt.Sprintf("Tenant %d Token Signing Certificate", tenantID),
		},
		SerialNumber:          big.NewInt(1), // The serial number does not matter because we are not using a certificate authority and replace this certificate with a new certificate.
		BasicConstraintsValid: true,
		IsCA:                  false, // This certificate CANNOT sign other certificates.
		PublicKey:             publicKey,
		NotAfter:              time.Now().Add(lifetime),
		KeyUsage:              x509.KeyUsageDigitalSignature, // This certificate can ONLY make signatures.
	}

oh, nice, happy to simplify this


pkg/security/certs_tenant_test.go, line 162 at r1 (raw file):

Previously, catj-cockroach (Cat J) wrote…

Rather than interacting with the ParsedCertificates, could we use the CheckSignature function?

	err = certActual.CheckSignature(x509.PureEd25519, payload, signature)
	require.NoError(t, err)

nice, this seems like a better way (i still had to access ParsedCertificates[0], but maybe i'm missing something from your suggestion

@rafiss rafiss force-pushed the create-tenant-signing branch from d6a7c03 to 3d06d94 Compare January 11, 2022 19:05
Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

I like this. Just a nit and this is good to go from my perspective (but I'll let Catherine approve).

Reviewed 7 of 37 files at r1, 3 of 27 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @catj-cockroach and @rafiss)


pkg/cli/mt_cert.go, line 126 at r2 (raw file):

If --overwrite is true, any existing files are overwritten.
`,
	Args: cobra.MinimumNArgs(1),

ExactArgs?

@rafiss rafiss force-pushed the create-tenant-signing branch from 3d06d94 to 7e16c1f Compare January 11, 2022 19:22
Copy link
Copy Markdown
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @catj-cockroach and @knz)


pkg/cli/mt_cert.go, line 126 at r2 (raw file):

Previously, knz (kena) wrote…

ExactArgs?

fixed

@rafiss rafiss requested a review from catj-cockroach January 11, 2022 19:24
This key/cert will be used to generate session revival tokens.

No release note since this is only intended to be used internally.

Release note: None
@rafiss rafiss force-pushed the create-tenant-signing branch from 7e16c1f to 124a8f4 Compare January 11, 2022 19:38
Copy link
Copy Markdown
Contributor

@catj-cockroach catj-cockroach left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 37 files at r1, 26 of 27 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @rafiss)


pkg/security/certs_tenant_test.go, line 162 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nice, this seems like a better way (i still had to access ParsedCertificates[0], but maybe i'm missing something from your suggestion

Ahhh, I thought signingCert was an x509.Certificate. In this case, i might throw a require.Len(t, signingCert.ParsedCertificates, 1) in there but other than that looks good to me!

@rafiss
Copy link
Copy Markdown
Collaborator Author

rafiss commented Jan 12, 2022

tftr!

bors r=knz,catj-cockroach

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 12, 2022

Build succeeded:

@craig craig bot merged commit 975d380 into cockroachdb:master Jan 12, 2022
@rafiss rafiss deleted the create-tenant-signing branch January 13, 2022 15:13
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.

4 participants