ayushtkn commented on code in PR #6969:
URL: https://github.com/apache/hive/pull/6969#discussion_r4638520430
##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HivePrivilegeObject.java:
##########
@@ -110,12 +113,20 @@ private int compare(Collection<String> o1,
Collection<String> o2) {
}
/**
- * Try to get thread local configuration from HMSHandler, otherwise create a
new one.
- * @return configuration
+ * @return the given catalog name if not blank, otherwise the current
catalog of the session in HS2,
+ * or the default catalog from the HMSHandler configuration (or a new
metastore configuration).
*/
- public static Configuration getConf() {
- return HMSHandlerContext.getConfiguration()
- .orElse(new Configuration());
+ private String getCatalogOrDefault(String catName) {
+ if (StringUtils.isNotBlank(catName)) {
+ return catName;
+ } else if (SessionState.get() != null) {
+ // HS2
+ return SessionState.get().getCurrentCatalog();
+ }
Review Comment:
A `null` `catName` now resolves to `SessionState.getCurrentCatalog()` in
HS2. Metastore calls
that take no catalog (`getDatabases(pattern)`, `getTables(db, pattern)`,
`getTableMeta`, ...)
still use the metastore default catalog, so authorization and the data read
can target
different catalogs. Currently, a `null` catalog resolved to the metastore
`default`.
Maybe lets drop the session branch so a `null` catalog keeps the metastore
`default`. Callers that
mean the session catalog should pass it explicitly.
`CommandAuthorizerV2` and `DefaultHiveAuthorizationTranslator` already do.
If the branch stays, maybe add a test for it;
`testBuilderDefaults` only covers the no-session case.
If I am tracing it right: This also reaches `GetTablesOperation` through
`HivePrivilegeObjectUtils.getHivePrivDbObjects`
##########
service/src/java/org/apache/hive/service/cli/operation/GetColumnsOperation.java:
##########
@@ -235,8 +235,11 @@ private List<HivePrivilegeObject> getPrivObjs(Map<String,
List<String>> db2Tabs)
List<HivePrivilegeObject> privObjs = new ArrayList<>();
for (Entry<String, List<String>> dbTabs : db2Tabs.entrySet()) {
for (String tabName : dbTabs.getValue()) {
- privObjs.add(new
HivePrivilegeObject(HivePrivilegeObjectType.TABLE_OR_VIEW, catalogName,
dbTabs.getKey(),
- tabName));
+
privObjs.add(HivePrivilegeObject.builder(HivePrivilegeObjectType.TABLE_OR_VIEW)
+ .catName(catalogName)
Review Comment:
I think we should resolve the catalog once and use it for both
`authorization` and the `metadata` fetch.
`catalogName` is used only for the privilege objects. `getDatabases`,
`getTables`, `getSchema`,
`getPrimaryKeys`, and `TableIterable` all run against the metastore
`default`.
Since the builder now maps a `null` `catalogName` to the session catalog,
`GET_COLUMNS` authorizes one catalog and returns columns from another.
Maybe:
```
String cat = catalogName != null ? catalogName : <metastore default
catalog>;
```
and pass cat to every metastore call and to the privilege object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]