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

zip: Add tenant ID flag for debug zip #79067

Closed
wants to merge 3 commits into from

Conversation

rimadeodhar
Copy link
Collaborator

@rimadeodhar rimadeodhar commented Mar 30, 2022

The tenant ID flag will be used to indicate that the debug
zip command should be run for a specific tenant. This flag
should only be set while running debug zip against a non
system tenant.

Informs #77958

Release note (cli change): debug zip accepts a new tenant-id
flag which will be used to run the command against a tenant
SQL only server.

Please ignore commits 1 and 2 within this PR, they will be
reviewed separately in #79064
and #79065.

TODO(rimadeodhar): Add unit tests.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rimadeodhar rimadeodhar changed the title Add zip ten flag zip: Add tenant ID flag for debug zip Mar 30, 2022
@rimadeodhar rimadeodhar marked this pull request as ready for review March 30, 2022 17:54
@rimadeodhar rimadeodhar requested review from a team as code owners March 30, 2022 17:54
@rimadeodhar rimadeodhar requested a review from a team March 30, 2022 17:54
@rimadeodhar rimadeodhar requested a review from a team as a code owner March 30, 2022 17:54
@rimadeodhar rimadeodhar requested review from knz and a team March 30, 2022 17:54
Copy link
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.

LGTM for the last commit

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


pkg/cli/context.go, line 357 at r3 (raw file):

	// tenantID of the server being connected to. This flag should
	// be set while running debug zip against a tenant SQL server.
	tenantID int

int64? or roachpb.TenantID?

Copy link
Contributor

@abarganier abarganier left a comment

Choose a reason for hiding this comment

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

:lgtm: with tests - and a small suggestion once we switch to roachpb.TenantID

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @abarganier, @knz, and @rimadeodhar)


pkg/cli/zip.go, line 173 at r3 (raw file):

	s := zr.start("establishing RPC connection to %s", serverCfg.AdvertiseAddr)
	var tenantID roachpb.TenantID
	if zipCtx.tenantID == 0 {

nit: with @knz's change to make the zipCtx.tenantID a roachpb.TenantID, there are some fn's we can use on the tenantID that might make this code even clearer.

Code quote:

	if zipCtx.tenantID < 0 {
		return errors.Errorf("invalid tenant ID %d, tenant ID must be greater than 0", zipCtx.tenantID)
	}
	s := zr.start("establishing RPC connection to %s", serverCfg.AdvertiseAddr)
	var tenantID roachpb.TenantID
	if zipCtx.tenantID == 0 {
		tenantID = roachpb.SystemTenantID
	} else {
		tenantID = roachpb.MakeTenantID(uint64(zipCtx.tenantID))
	}

This PR adds a command to generate a new type of cert -
a tenant scoped client cert. This is similar to a client
cert but can only be used to connect to a specific tenant ID
as indicated in the certificate. This certificate will be used
to authenticate a client for a specific tenant server.
Subsequent PRs stacked on top of this one will implement the
authentication component for this certificate. The first use
case for this certificate will be the debug zip command.

Informs cockroachdb#77958

Release note (cli change): A new command to create a tenant scoped
client certificate has been added. This command will be used to
create certs that will authenticate a client for a specific tenant.

Release note (security update): This PR introduces a new type of
client certificate - tenant scoped client certificate. This
certificate can be used to authenticate a client on a specific
tenant only. It contains the username within the CN of the certificate
and the tenant ID in the URIs section of Subject Alternate Name (SAN)
values. The tenant ID is encoded in the URI section using the format
crdb://tenant/<tenant_id>.
This PR extends the TLS code to use a tenant scoped
client cert to authenticate a client for specific tenant.

Release note (security update): We introduce a new
tenant scoped client certificate to authenticate a client
on a specific tenant. A tenant scoped client certificate contains the client
name within the CN and the tenant ID, to which the
certificate is being scoped to, as the SAN. The tenant ID
is embedded within the URI section with the format
"crdb://tenant/<tenant_id>". For example, a root
client certificate scoped to a tenant with ID 123
will contain "root" in the CN field and the URI
"crdb://tenant/123" in the URI section of the
certificate. This certificate will authorize the root
client on the tenant with the ID 123. It will result
in an authorization error if used to authenticate the
root client on any other tenant.
The tenant ID flag will be used to indicate that the debug
zip command should be run for a specific tenant. This flag
should only be set while running debug zip against a non
system tenant.

Release note (cli change): debug zip accepts a new tenant-id
flag which will be used to run the command against a tenant
SQL only server.
@rimadeodhar rimadeodhar requested a review from a team as a code owner April 12, 2022 22:09
@otan otan removed the request for review from a team April 18, 2022 20:35
@rimadeodhar
Copy link
Collaborator Author

Thanks to the changes in the previous PRs off which this PR is based, we no longer need to add a tenant id flag to debug zip. Closing out this PR.

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