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

sql,backupccl: allow owners to also control schedules #87287

Merged
merged 1 commit into from
Sep 7, 2022

Conversation

adityamaru
Copy link
Contributor

This change relaxes the admin only check that was enforced
when resuming, pasuing, dropping and altering a backup schedule
to also allow non-admin owners of the schedules to perform
these control operations.

Release note (sql change): Owners of a backup schedule can now
control their schedule using the supported pause, resume, drop
and alter queries.

Release justification: high impact change to introduce finer grained
permission control to disaster recovery operations

@adityamaru adityamaru requested review from benbardin, stevendanna and a team September 1, 2022 16:42
@adityamaru adityamaru requested a review from a team as a code owner September 1, 2022 16:42
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@adityamaru
Copy link
Contributor Author

First commit is from #87188.

pkg/ccl/backupccl/create_scheduled_backup.go Outdated Show resolved Hide resolved
pkg/ccl/backupccl/alter_backup_schedule.go Outdated Show resolved Hide resolved
datums, cols, err := params.ExecCfg().InternalExecutor.QueryRowExWithCols(
params.ctx,
"load-schedule",
params.p.Txn(), sessiondata.InternalExecutorOverride{User: username.RootUserName()},
params.p.Txn(), sessiondata.InternalExecutorOverride{User: username.NodeUserName()},
Copy link
Collaborator

Choose a reason for hiding this comment

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

happy to support this, but why? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that NodeUser is what we should be using for intra-cluster traffic -

const NodeUser = "node"
. It is the user used when a node is acting on its own behalf, rather than as an external user or an app running as root.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be running on its own behalf? Or should loadSchedule take a context and run as the user executing the query?

More concretely, I guess, can we imagine a world where we want a user to see/load some schedules but not others? (yes, I think?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should loadSchedule take a context and run as the user executing the query?

This would be tricky because only admin is allowed to select against a system table. So a non-admin owner would get an error running loadSchedule. The scan of the system table is an internal implementation detail that expects other pieces of the logic to perform the appropriate privilege checks.

can we imagine a world where we want a user to see/load some schedules but not others

Yes, I think so, but "load" is an internal implementation detail so I think the filtering needs to be in the logic that uses the loaded schedule, which is what we're doing here. We are already allowing users to only alter a limited set of schedules if they are non-admin, i.e. the schedules they own. Similarly if we want to limit what schedules a user sees we should be adding this privilege check to SHOW SCHEDULES and other user facing queries that allow for introspection.

Copy link
Collaborator

@benbardin benbardin Sep 1, 2022

Choose a reason for hiding this comment

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

expects other pieces of the logic to perform the appropriate privilege checks

Yeah, exactly this - I'd worry about a developer forgetting that. It's not obvious to me that somebody calling something called loadSchedule() will be executing node-level privileges under the hood. That said, if it's obvious to you (i.e. common practice :) ) then I'm fine with it.

isOwner := schedule.Owner() == params.p.User()
if !isAdmin && !isOwner {
return pgerror.Newf(pgcode.InsufficientPrivilege, "must be admin or owner of the "+
"schedule %d to %s it", schedule.ScheduleID(), n.command.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

is n.command.String() helpful info here?

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 makes for a more informative error message that you're not allowed to RESUME, DROP, PAUSE it, but I guess you already know that because you're running the command.

pkg/sql/opt/optbuilder/misc_statements.go Show resolved Hide resolved
@adityamaru adityamaru force-pushed the do-our-own-owner-management branch 2 times, most recently from 44774f5 to 6bb4d6d Compare September 1, 2022 18:19
@adityamaru adityamaru requested a review from benbardin September 1, 2022 18:20
@adityamaru adityamaru force-pushed the do-our-own-owner-management branch 2 times, most recently from 490f378 to 5b91f9d Compare September 6, 2022 15:34
@adityamaru adityamaru requested a review from a team as a code owner September 6, 2022 15:34
@adityamaru
Copy link
Contributor Author

The race failures are all timeouts and are being investigated here https://cockroachlabs.slack.com/archives/C023S0V4YEB/p1662488784308579. I have high confidence that they are not caused by this diff so going ahead and borsing while we investigate.

bors r=benbardin

@craig
Copy link
Contributor

craig bot commented Sep 7, 2022

Merge conflict.

@adityamaru adityamaru force-pushed the do-our-own-owner-management branch from 5b91f9d to cea5360 Compare September 7, 2022 14:56
This change relaxes the admin only check that was enforced
when resuming, pasuing, dropping and altering a backup schedule
to also allow non-admin owners of the schedules to perform
these control operations.

Release note (sql change): Owners of a backup schedule can now
control their schedule using the supported pause, resume, drop
and alter queries.

Release justification: high impact change to introduce finer grained
permission control to disaster recovery operations
@adityamaru adityamaru force-pushed the do-our-own-owner-management branch from cea5360 to 0e5371e Compare September 7, 2022 18:18
@adityamaru
Copy link
Contributor Author

@craig
Copy link
Contributor

craig bot commented Sep 7, 2022

Build succeeded:

@adityamaru
Copy link
Contributor Author

blathers backport release-22.2

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.

3 participants