Skip to content

sql: fix "no user specified" errors in statement bundles#80405

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:80396-fix-stmt-bundles
Apr 24, 2022
Merged

sql: fix "no user specified" errors in statement bundles#80405
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:80396-fix-stmt-bundles

Conversation

@mgartner
Copy link
Copy Markdown
Contributor

@mgartner mgartner commented Apr 22, 2022

A regression was introduced in #71246 that caused errors when running
internal queries to populate files in statement bundles. As a result,
critical information was missing from the env.sql, schema.sql, and
stats*.sql files. This commit fixes the issue by using the internal
executor factory to create an internal executor with the current
session's session data.

Fixes #80396

Release note: None

@mgartner mgartner requested review from RichardJCai, knz and rafiss April 22, 2022 20:09
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

// explainBundleUserSessionsDataOverride is an InternalExecutorOverride which
// overrides the users to the RootUser.
var explainBundleUserSessionDataOverride = sessiondata.InternalExecutorOverride{
User: security.MakeSQLUsernameFromPreNormalizedString(security.RootUser)}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it safe to use a root user override here? If not, what is a better alternative?

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.

Reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rafiss, and @RichardJCai)


pkg/sql/explain_bundle.go, line 438 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Is it safe to use a root user override here? If not, what is a better alternative?

This looks suspicious. Why can't this use the identity of the user requesting the bundle?

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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rafiss, and @RichardJCai)


pkg/sql/explain_bundle.go, line 438 at r1 (raw file):

Previously, knz (kena) wrote…

This looks suspicious. Why can't this use the identity of the user requesting the bundle?

As in, make stmtEnvCollector take the requester's username as argument or something like that.

@rafiss
Copy link
Copy Markdown
Collaborator

rafiss commented Apr 22, 2022

a node user is insufficient - it does not have
privileges on user-defined relations which is needed for the
SHOW CREATE queries that populate schema.sql.

was this fixed by #79098 ?

A regression was introduced in cockroachdb#71246 that caused errors when running
internal queries to populate files in statement bundles. As a result,
critical information was missing from the `env.sql`, `schema.sql`, and
`stats*.sql` files. This commit fixes the issue by using the internal
executor factory to create an internal executor with the current
session's session data.

Fixes cockroachdb#80396

Release note: None
@mgartner mgartner force-pushed the 80396-fix-stmt-bundles branch from f0413eb to aec2c44 Compare April 22, 2022 20:23
@mgartner
Copy link
Copy Markdown
Contributor Author

How about this second attempt that doesn't use an override at all?

@knz
Copy link
Copy Markdown
Contributor

knz commented Apr 22, 2022

is it already common practice to instantiate InternalExecutors on-the-fly? Is this an expensive operation?

(Asking for a friend - if we don't need to keep a predefined instance around, I would cut down on the server code)

@mgartner
Copy link
Copy Markdown
Contributor Author

mgartner commented Apr 22, 2022

is it already common practice to instantiate InternalExecutors on-the-fly? Is this an expensive operation?

I copied this pattern from:

ie := ef.planner.extendedEvalCtx.ExecCfg.InternalExecutorFactory(
ef.planner.EvalContext().Context,
ef.planner.SessionData(),
)

It seems fairly prolific given that planner.QueryRowEx, which is used in numerous places, creates a new internal executor:
ie := p.ExecCfg().InternalExecutorFactory(ctx, p.SessionData())

@knz
Copy link
Copy Markdown
Contributor

knz commented Apr 22, 2022

Amazing. TIL. Thanks for explaining.

@mgartner
Copy link
Copy Markdown
Contributor Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 24, 2022

Build succeeded:

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.

sql: statement bundles are missing schema, environment, or table statistics

4 participants