Skip to content

Able to Grant Table Engine - #56945

Closed
jsc0218 wants to merge 9 commits into
ClickHouse:masterfrom
jsc0218:TableEngineGrant
Closed

jsc0218 wants to merge 9 commits into
ClickHouse:masterfrom
jsc0218:TableEngineGrant

Conversation

@jsc0218

@jsc0218 jsc0218 commented Nov 17, 2023 •

Copy link
Copy Markdown
Contributor

related to #38316

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

table engine is grantable now, and it won't affect existing users behavior

Documentation entry for user-facing changes

It follows the GRANT syntax, for example,

GRANT STRIPELOG ON *.* to user

@jsc0218
jsc0218 marked this pull request as draft November 17, 2023 22:33
@robot-clickhouse robot-clickhouse added the pr-feature Pull request with new product feature label Nov 17, 2023
@robot-clickhouse

robot-clickhouse commented Nov 17, 2023 •

Copy link
Copy Markdown
Member

This is an automated comment for commit 3f1f507 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ success
Docs CheckBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts❌ failure

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 18, 2023
@jsc0218
jsc0218 force-pushed the TableEngineGrant branch 2 times, most recently from ae9ea98 to 9f095db Compare November 30, 2023 01:52
@jsc0218
jsc0218 force-pushed the TableEngineGrant branch 2 times, most recently from 0cd752f to 02a221a Compare December 1, 2023 02:48
@jsc0218
jsc0218 force-pushed the TableEngineGrant branch 2 times, most recently from 0d172a5 to d178b11 Compare December 4, 2023 21:05
@jsc0218
jsc0218 marked this pull request as ready for review December 5, 2023 17:44
@jsc0218 jsc0218 changed the title (WIP) Able to Grant Table Engine Able to Grant Table Engine Dec 5, 2023
@vitlibar vitlibar self-assigned this Dec 5, 2023
@bharatnc

Copy link
Copy Markdown
Contributor

Also related to #55911.

<create_generaterandom_requires_grant>false</create_generaterandom_requires_grant>
<create_executable_requires_grant>false</create_executable_requires_grant>
<create_executablepool_requires_grant>false</create_executablepool_requires_grant>
<create_fuzzjson_requires_grant>false</create_fuzzjson_requires_grant>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That seems like too many new settings. Just one new setting like table_engines_require_grant should be enough.

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.

I think there are some tradeoffs here:

  1. If using table_engines_require_grant, for example, in order to be grantable to a specific table engine, admins haves to set other old engines as well, means losing control of granularity.
  2. the settings in the config file are actually not so necessary. By default would be false according to the code, meaning engine doesn't require grant at all. I list all the setting in the config files just for completeness and illustration purpose. Probably I should just list one, and add some comment for users to reference similar settings, so it won'd be so daunting. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, I think having a config setting for each table engine means too much granularity. And if people are happy with this PR then the feature will be enabled by default at some point in the future (like it happened for other features in #58584)

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.

I agree with you. So currently I would set it to false, and add some comment to warn admins once this feature is enabled (set to true), they have to grant every table engine, otherwise it is by default not granted, what do you think? It seems lengthy for admins. BTW, should some table engines always granted?

@vitlibar vitlibar Jan 24, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW, should some table engines always granted?

No, CREATE USER should create a user without privileges. This is difficult to change and it's kind of an invariant.

So yes, after this setting will be set to true by default (but it shouldn't happen very soon) it will require some work from admin. But it's not really difficult to grant

GRANT TABLE_ENGINE ON * TO username

And if some admin doesn't really like it they will be able to just disable the feature back.

M(demangle, "", GLOBAL, INTROSPECTION) /* allows to execute function demangle() */\
M(INTROSPECTION, "INTROSPECTION FUNCTIONS", GROUP, ALL) /* allows to execute functions addressToLine(), addressToSymbol(), demangle()*/\
\
M(MergeTree, "", GLOBAL, SOURCES) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That doesn't look completely correct. I mean URL or AZURE are sources, but for example CollapsingMergeTree is not a source, it's a table engine.

Perhaps it's better to invent another privilege group ALL_TABLE_ENGINES and make SOURCES a subset of it. Also it would be nice to group similar table engines into groups according to the engine families like MERGE_TREE_TABLE_ENGINES and LOG_TABLE_ENGINES, i.e.

M(MergeTree, "", GLOBAL, MERGE_TREE_TABLE_ENGINES) \
M(CollapsingMergeTree, "", GLOBAL, MERGE_TREE_TABLE_ENGINES) \
...
M(Log, "", GLOBAL, LOG_TABLE_ENGINES) \
M(TinyLog, "", GLOBAL, LOG_TABLE_ENGINES) \
M(StripeLog, "", GLOBAL, LOG_TABLE_ENGINES) \
...
M(Buffer, GLOBAL, SPECIAL_TABLE_ENGINES) \
...
M(S3, "", GLOBAL, INTEGRATION_TABLE_ENGINES) \
...
M(MERGE_TREE_TABLE_ENGINES, "", GROUP, ALL_TABLE_ENGINES) \
M(LOG_TABLE_ENGINES, "", GROUP, ALL_TABLE_ENGINES) \
M(SPECIAL_TABLE_ENGINES, "", GROUP, ALL_TABLE_ENGINES) \
M(INTEGRATION_TABLE_ENGINES, "SOURCES", GROUP, ALL_TABLE_ENGINES) \
M(ALL_TABLE_ENGINES, "", GROUP, ALL) \

We can turn SOURCES into an alias of INTEGRATION_TABLE_ENGINES, that seems quite right.

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.

cannot agree more, would do that.


<!-- By default, for backward compatibility create table with a specific table engine ignores grant,
however you can change this behaviour by setting this to true -->
<create_mergetree_requires_grant>false</create_mergetree_requires_grant>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please add one test where such setting is true?

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.

yes, would add one.

@alexey-milovidov

Copy link
Copy Markdown
Member

@jsc0218, it is strange to have every table engine as a separate grant.
Let's make it extensible, so we don't have to edit it when adding every new table engine.

@jsc0218

jsc0218 commented Jan 22, 2024

Copy link
Copy Markdown
Contributor Author

@jsc0218, it is strange to have every table engine as a separate grant. Let's make it extensible, so we don't have to edit it when adding every new table engine.

99% of this piece of code is just for backward compatibility, that means for users with existing CH installation, no behavior change to them. If a new table engine is later added, and requires no grant ability, nothing else to do with this code. If it requires grant ability, add the name of table engine in AccessType.h, that's it.

@vitlibar

vitlibar commented Jan 24, 2024 •

Copy link
Copy Markdown
Member

@jsc0218, it is strange to have every table engine as a separate grant. Let's make it extensible, so we don't have to edit it when adding every new table engine.

We can try implementing a syntax like the following

GRANT TABLE_ENGINE ON CollapsingMergeTree TO username;

This way we will only need one new privilege TABLE_ENGINE. For example:

GRANT TABLE_ENGINE ON * TO username;
REVOKE TABLE_ENGINE ON Log FROM username;
REVOKE TABLE_ENGINE ON TinyLog FROM username;
REVOKE TABLE_ENGINE ON StripeLog FROM username;

We could also support advanced syntax with a wildcard like this:

GRANT TABLE_ENGINE ON *MergeTree TO username;

Maybe it's a bit better than the current approach of this PR. So the idea is to make the TABLE_ENGINE privilege which will allow a single parameter - mostly like the CREATE_NAMED_COLLECTION privilege.

@jsc0218 @alexey-milovidov What do you think?

@jsc0218

jsc0218 commented Jan 24, 2024 •

Copy link
Copy Markdown
Contributor Author

@jsc0218, it is strange to have every table engine as a separate grant. Let's make it extensible, so we don't have to edit it when adding every new table engine.

We can try implementing a syntax like the following

GRANT TABLE_ENGINE ON CollapsingMergeTree TO username;

This way we will only need one new privilege TABLE_ENGINE. For example:

GRANT TABLE_ENGINE ON * TO username;
REVOKE TABLE_ENGINE ON Log FROM username;
REVOKE TABLE_ENGINE ON TinyLog FROM username;
REVOKE TABLE_ENGINE ON StripeLog FROM username;

We could also support advanced syntax with a wildcard like this:

GRANT TABLE_ENGINE ON *MergeTree TO username;

Maybe it's a bit better than the current approach of this PR. So the idea is to make the TABLE_ENGINE privilege which will allow a single parameter - mostly like the CREATE_NAMED_COLLECTION privilege.

@jsc0218 @alexey-milovidov What do you think?

wildcard would be an advantage, but I have some concerns with it:

  1. There are conflicts with the current "sources" in AccessType.h files, do users need to grant the same thing with different syntax twice (one for source, one for table engine)? while current approach extends these sources idea, so just once.
  2. How to handle the grantability in the database granularity level? for example, one database with tinylog engine, another database not allowed. The current approach definitely can because it directly borrows the grant source idea. I am not sure the ability of named collection about this.
  3. How backward compatibility works with named collection? I need to do an investigate first to tell it.
    Let me take some time to go over the code to see the possibility.

@vitlibar

Copy link
Copy Markdown
Member

How to handle the grantability in the database granularity level? for example, one database with tinylog engine, another database not allowed. The current approach definitely can because it directly borrows the grant source idea.

No, this is not allowed even in the current approach. And that seems ok, because there is also GRANT CREATE TABLE which can be granted on a specific database.

There are conflicts with the current "sources" in AccessType.h files, do users need to grant the same thing with different syntax twice (one for source, one for table engine)? while current approach extends hese sources idea, so just once.

That's a good point. Too many privileges just to give the ability to create a table is not good. For example, in order to give the ability to create a table with S3 engine we already have to grant two privileges:

GRANT CREATE TABLE ON mydb.* TO username;
GRANT S3 ON *.* TO username;

It would look strange if now we will add GRANT TABLE_ENGINE ON S3 TO username to this list.

@vitlibar

vitlibar commented Jan 24, 2024 •

Copy link
Copy Markdown
Member

Ok, probably it's better to keep the current approach. But we need a unit test checking that for each table engine there is a corresponding access type (so we're not going to forget adding an access type when we will possibly add a new table engine in the future).

@jsc0218

jsc0218 commented Jan 24, 2024

Copy link
Copy Markdown
Contributor Author

Ok, probably it's better to keep the current approach. But we need a unit test checking that for each table engine there is a corresponding access type (so we're not going to forget adding an access type when we will possibly add a new table engine in the future).

yes, definitely need to add test. Also I think for the configuration improvement part, probably better to add comments and just list one for illustration purpose, otherwise the set is too daunting (Please see the first above discussion.)

@vitlibar

vitlibar commented Jan 24, 2024 •

Copy link
Copy Markdown
Member

I have one more idea. Can we support both ways? I mean

GRANT Log ON *.* TO username

or

GRANT Set ON *.* TO username

don't look very clear, and

GRANT Dictionary ON *.* TO username;

looks even confusing. Though for MergeTree it looks better.

So I thought maybe we could support both

GRANT TABLE ENGINE ON S3

and

GRANT S3 ON *.*

but treat them the same (i.e. check that the current user has any of those access types). This is only for sources, for simple table engines we can support only syntax GRANT TABLE ENGINE ON MergeTree.

This behavior can be implemented by modifying the addImplicitAccessRights function (I mean addImplicitAccessRights() could add implicit grant GRANT S3 ON *.* if the current user has GRANT TABLE ENGINE ON S3).

@alexey-milovidov

Copy link
Copy Markdown
Member

@vitlibar, let's make it generic, so it supports specifying any table engine by their name, and we don't have to repeat them in the code.

@vitlibar

Copy link
Copy Markdown
Member

@vitlibar, let's make it generic, so it supports specifying any table engine by their name, and we don't have to repeat them in the code.

Ok, I suggested this syntax:

GRANT TABLE ENGINE ON MergeTree TO username

This way we don't have to repeat them in the code and worry that we can forget to add the corresponding privilege for a new table engine in the future.

@jsc0218

jsc0218 commented Jan 26, 2024 •

Copy link
Copy Markdown
Contributor Author

I have one more idea. Can we support both ways? I mean

GRANT Log ON *.* TO username

or

GRANT Set ON *.* TO username

don't look very clear, and

GRANT Dictionary ON *.* TO username;

looks even confusing. Though for MergeTree it looks better.

So I thought maybe we could support both

GRANT TABLE ENGINE ON S3

and

GRANT S3 ON *.*

but treat them the same (i.e. check that the current user has any of those access types). This is only for sources, for simple table engines we can support only syntax GRANT TABLE ENGINE ON MergeTree.

This behavior can be implemented by modifying the addImplicitAccessRights function (I mean addImplicitAccessRights() could add implicit grant GRANT S3 ON *.* if the current user has GRANT TABLE ENGINE ON S3).

Yes, I think this is the best approach as long as there are not many sources, also considering extensibility and *.* is just useless in table engine grant. It's better for me to start another pr.

@jsc0218 jsc0218 closed this Mar 4, 2024
@jsc0218
jsc0218 deleted the TableEngineGrant branch April 18, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants