Skip to content

sql: block DROP TENANT based on a session var#99607

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20230326-drop-tenant
Mar 30, 2023
Merged

sql: block DROP TENANT based on a session var#99607
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20230326-drop-tenant

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Mar 26, 2023

Fixes #97972.
Epic: CRDB-23559

In clusters where we will promote tenant management operations, we would like to ensure there is one extra step needed for administrators to drop a tenant (and thus irremedially lose data). Given that sql_safe_updates is not set automatically when users open their SQL session using their own client, we need another mechanism.

This change introduces the new (hidden) session var, disable_drop_tenant. When set, tenant deletion fails with the following error message:

demo@127.0.0.1:26257/movr> drop tenant foo;
ERROR: rejected (via sql_safe_updates or disable_drop_tenant): DROP TENANT causes irreversible data loss
SQLSTATE: 01000

(The session var sql_safe_updates is also included as a blocker in the mechanism so that folk using cockroach sql get double protection).

The default value of this session var is false in single-tenant clusters, for compatibility with CC Serverless. It will be set to true via a config profile (#98466) when suitable.

Release note: None

@knz knz requested a review from stevendanna March 26, 2023 12:24
@knz knz requested a review from a team as a code owner March 26, 2023 12:24
@knz knz requested a review from yuzefovich March 26, 2023 12:24
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz added the backport-23.1.x PAST MAINTENANCE SUPPORT: 23.1 patch releases via ER request only label Mar 26, 2023
@knz knz force-pushed the 20230326-drop-tenant branch 4 times, most recently from 885a6e9 to 6364cee Compare March 26, 2023 22:00
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

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


pkg/sql/vars.go line 1547 at r1 (raw file):

			//   default value (false) to mean that tenant deletion is enabled.
			//   This is needed for backward-compatibility with Cockroach Cloud.
			return fmt.Sprint(!enableDropTenant.Get(sv))

nit: maybe use formatBoolAsPostgresSetting?


pkg/sql/sessiondatapb/local_only_session_data.proto line 368 at r1 (raw file):

  // prepared again.
  int64 prepared_statements_cache_size = 97;
    

nit: dangling spaces. Also this proto doesn't use empty lines between members.

@knz knz added the A-multitenancy Related to multi-tenancy label Mar 27, 2023
In clusters where we will promote tenant management operations, we
would like to ensure there is one extra step needed for administrators
to drop a tenant (and thus irremedially lose data). Given that
`sql_safe_updates` is not set automatically when users open their
SQL session using their own client, we need another mechanism.

This change introduces the new (hidden) session var,
`disable_drop_tenant`. When set, tenant deletion fails with the
following error message:

```
demo@127.0.0.1:26257/movr> drop tenant foo;
ERROR: rejected (via sql_safe_updates or disable_drop_tenant): DROP TENANT causes irreversible data loss
SQLSTATE: 01000
```

(The session var `sql_safe_updates` is _also_ included as a blocker in
the mechanism so that folk using `cockroach sql` get double
protection).

The default value of this session var is `false` in single-tenant
clusters (set via a cluster setting `sql.drop_tenant.enabled`), for
compatibility with CC Serverless. The default will be set to `true`
via a config profile when suitable.

Release note: None
Copy link
Copy Markdown
Contributor Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/sql/vars.go line 1547 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: maybe use formatBoolAsPostgresSetting?

Done.


pkg/sql/sessiondatapb/local_only_session_data.proto line 368 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: dangling spaces. Also this proto doesn't use empty lines between members.

Done.

@knz knz force-pushed the 20230326-drop-tenant branch from 6364cee to bdc8d1a Compare March 28, 2023 07:16
Copy link
Copy Markdown
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me.

Reviewed 4 of 6 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 28, 2023

TFYR!

bors r=stevendanna

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 28, 2023

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 28, 2023

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 28, 2023

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 29, 2023

Build failed (retrying...):

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 29, 2023

bors r=stevendanna

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 29, 2023

Already running a review

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 29, 2023

bors r-

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 29, 2023

Canceled.

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 29, 2023

bors r=stevendanna single on

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 29, 2023

Build failed (retrying...):

Copy link
Copy Markdown
Collaborator

@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 @knz)


pkg/sql/exec_util.go line 764 at r2 (raw file):

var enableDropTenant = settings.RegisterBoolSetting(
	settings.SystemOnly,
	"sql.drop_tenant.enabled",

I'm curious - why doesn't this use the convention we use for other cluster settings that set default values for session vars? i.e., name it something like sql.defaults.disable_drop_tenant

@craig craig bot merged commit 331a672 into cockroachdb:master Mar 30, 2023
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 30, 2023

Build succeeded:

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Mar 30, 2023

@rafiss because we now have a linter that blocks the introduction of settings named sql.defaults.*.

@rafiss
Copy link
Copy Markdown
Collaborator

rafiss commented Mar 30, 2023

I see now that this is SystemOnly and non-public, so I'm no longer concerned. I just thought it would be harder to find for users, but that concern doesn't apply here.

@knz knz deleted the 20230326-drop-tenant branch March 30, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-multitenancy Related to multi-tenancy backport-23.1.x PAST MAINTENANCE SUPPORT: 23.1 patch releases via ER request only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multitenant: Protect from accidental use of DROP TENANT

5 participants