-
Notifications
You must be signed in to change notification settings - Fork 379
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
[#2179] Improvement: Improve security when creating and dropping schemas and tables #2335
Conversation
.../src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/SqliteDatabaseOperations.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlDatabaseOperations.java
Outdated
Show resolved
Hide resolved
...n/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
Outdated
Show resolved
Hide resolved
...trato/gravitino/integration/test/catalog/jdbc/postgresql/TestPostgreSqlSchemaOperations.java
Outdated
Show resolved
Hide resolved
@zivali |
...on/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
Outdated
Show resolved
Hide resolved
...n/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlDatabaseOperations.java
Outdated
Show resolved
Hide resolved
Absolutely! Do you mean we should apply similar checks in JdbcTableOperations (MysqlTableOperations / SqliteTableOperations / PostgreSqlTableOperations)? p.s. I modified the PR per comments. Thanks for help reviewing! |
hey @justinmclean, is this improvement done? If not, may I look into this? |
@simarjeetss IThanks for offering to help, but as this is almost complete, I woudl suggest you find another issue to work on. |
Sure, thanks for letting me know! |
@jerryshao |
I would say it is not related to #1652. Might consider merging this as it is an overall improvement to the existing code? |
@zivali Are you still interested in working on this? No issue if you can't, it would just be good to know. |
@justinmclean Hi, I am still working on it. Will update here when finished. Thank you! |
// dollar signs | ||
// \w matches [a-zA-Z0-9_] | ||
// \p{L} matches any kind of letter from any language | ||
if (!databaseName.matches("^[\\w\\p{L}$]*$")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a rule from experience? Or is it an official MySQL constraint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just saw the description in your PR, it's a limitation of MySQL official.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the most basic permitted characters in unquoted identifiers for MySQL. I think most DB users uses only these characters. But other characters can also be used with quoted identifiers. Do you think we should include those characters as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can start with stricter restrictions and gradually relax them as needed.
The name specification capability of catalog is now available, you can rebase the main branch and proceed with the PR |
635678b
to
488b8e2
Compare
@mchades @justinmclean Could you help review again when you have time? Thank you! |
// The constraints of the name spec may be more strict than underlying catalog, | ||
// and for compatibility reasons, we only apply case-sensitive capabilities here. | ||
return dispatcher.dropTable(applyCaseSensitive(ident, Capability.Scope.TABLE, dispatcher)); | ||
return dispatcher.dropTable(normalizeNameIdentifier(ident)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after these changes, can I drop a Mysql table named a&b
by Gravitino?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as the current regex pattern in this PR does not try to match the character &
.
Should we add &
to the regex pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is just my assumption.
We can gradually relax the strategy after encountering real needs, or make this rule configurable when the demand is frequent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your contributions!
…g schemas and tables (apache#2335) ### What changes were proposed in this pull request? Improve security when creating and dropping schemas and tables. This PR adds the following checks for identifier names using the capability framework - Regex check - As a best practice, it's generally advised to avoid including spaces in database names. In this PR, database names that include space will be considered illegal. - String length check, since SQL injection usually requires using longer string - Mysql: at most 64 characters - Postgresql: at most 63 characters We refer to specifications of the earliest version of DB that gravitino currently supports: - Postgresql identifier rules: https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS - Mysql identifier naming: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html - Mysql identifier length limit: https://dev.mysql.com/doc/refman/5.7/en/identifier-length.html ### Why are the changes needed? Fix: apache#2179 ### Does this PR introduce _any_ user-facing change? Add name identifier checks before attempting to create or drop schemas and tables. ### How was this patch tested? Add IT tests.
What changes were proposed in this pull request?
Improve security when creating and dropping schemas and tables.
This PR adds the following checks for identifier names using the capability framework
We refer to specifications of the earliest version of DB that gravitino currently supports:
Why are the changes needed?
Fix: #2179
Does this PR introduce any user-facing change?
Add name identifier checks before attempting to create or drop schemas and tables.
How was this patch tested?
Add IT tests.