Skip to content

Commit c372859

Browse files
HIVE-28838: Remove sensitive jdbc properties from JdbcStorageHandler tables
1 parent d9191df commit c372859

File tree

6 files changed

+123
-2
lines changed

6 files changed

+123
-2
lines changed

jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/conf/JdbcStorageConfigManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class JdbcStorageConfigManager {
4545
public static final String CONFIG_PWD_KEYSTORE = Constants.JDBC_KEYSTORE;
4646
public static final String CONFIG_PWD_KEY = Constants.JDBC_KEY;
4747
public static final String CONFIG_PWD_URI = Constants.JDBC_PASSWORD_URI;
48+
public static final String CONFIG_JDBC_USERNAME = Constants.JDBC_USERNAME;
49+
4850
private static final EnumSet<JdbcStorageConfig> DEFAULT_REQUIRED_PROPERTIES =
4951
EnumSet.of(JdbcStorageConfig.DATABASE_TYPE,
5052
JdbcStorageConfig.JDBC_URL,
@@ -66,7 +68,9 @@ public static void copyConfigurationToJob(Properties props, Map<String, String>
6668
if (!key.equals(CONFIG_PWD) &&
6769
!key.equals(CONFIG_PWD_KEYSTORE) &&
6870
!key.equals(CONFIG_PWD_KEY) &&
69-
!key.equals(CONFIG_PWD_URI)) {
71+
!key.equals(CONFIG_PWD_URI) &&
72+
!key.equals(CONFIG_JDBC_USERNAME)
73+
) {
7074
jobProps.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
7175
}
7276
}

ql/src/java/org/apache/hadoop/hive/ql/plan/PlanUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.apache.hadoop.hive.ql.plan;
2020

2121
import static org.apache.commons.lang3.StringUtils.isNotBlank;
22+
import static org.apache.hadoop.hive.conf.Constants.JDBC_PASSWORD;
23+
import static org.apache.hadoop.hive.conf.Constants.JDBC_USERNAME;
2224
import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_LOCATION;
2325
import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_CTAS;
2426
import static org.apache.hive.common.util.HiveStringUtils.quoteComments;
@@ -1230,7 +1232,11 @@ public static Class<? extends AbstractSerDe> getDefaultSerDe() {
12301232
return LazySimpleSerDe.class;
12311233
}
12321234

1233-
private static final String[] FILTER_OUT_FROM_EXPLAIN = {TABLE_IS_CTAS};
1235+
private static final String[] FILTER_OUT_FROM_EXPLAIN = {
1236+
TABLE_IS_CTAS,
1237+
JDBC_USERNAME,
1238+
JDBC_PASSWORD
1239+
};
12341240

12351241
/**
12361242
* Get a Map of table or partition properties to be used in explain extended output.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
CREATE TABLE explain_jdbc_hive_table (id INT, bigId BIGINT);
2+
3+
CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
4+
5+
6+
FROM (select 1 as hello) src
7+
8+
SELECT
9+
10+
dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true','','',
11+
'CREATE TABLE DERBY_TABLE ("id" INTEGER, "bigId" BIGINT)' ),
12+
13+
dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true','','',
14+
'INSERT INTO DERBY_TABLE ("id","bigId") VALUES (?,?)','20','20')
15+
limit 1;
16+
17+
CREATE EXTERNAL TABLE ext_DERBY_TABLE
18+
(
19+
id int,
20+
bigId bigint
21+
)
22+
STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
23+
TBLPROPERTIES (
24+
"hive.sql.database.type" = "DERBY",
25+
"hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
26+
"hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true;collation=TERRITORY_BASED:PRIMARY",
27+
"hive.sql.dbcp.username" = "APP",
28+
"hive.sql.dbcp.password" = "mine",
29+
"hive.sql.table" = "DERBY_TABLE",
30+
"hive.sql.dbcp.maxActive" = "1"
31+
);
32+
33+
34+
SET hive.fetch.task.conversion=none;
35+
36+
select 1 from ext_DERBY_TABLE;
37+
38+
explain extended select 1 from ext_DERBY_TABLE;
39+
40+
41+
create table if not exists ctas_dbs as select * from ext_DERBY_TABLE;
42+
43+
select 1
44+
from ctas_dbs
45+
limit 1;
46+
47+
explain extended
48+
select 1
49+
from ctas_dbs
50+
limit 1;
51+
52+
create table if not exists ctlt_dbs like ext_DERBY_TABLE;
53+
54+
insert into ctlt_dbs
55+
select * from ext_DERBY_TABLE;
56+
57+
select 1
58+
from ctlt_dbs
59+
limit 1;
60+
61+
explain extended
62+
select 1
63+
from ctlt_dbs
64+
limit 1;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--! qt:sysdb
2+
3+
SET hive.fetch.task.conversion=none;
4+
5+
select 1
6+
from sys.TBLS t
7+
join sys.DBS d on t.DB_ID = d.DB_ID
8+
limit 1;
9+
10+
explain extended
11+
select 1
12+
from sys.TBLS t
13+
join sys.DBS d on t.DB_ID = d.DB_ID
14+
limit 1;
15+
16+
show create table sys.DBS;
17+
18+
describe formatted sys.DBS;
19+
20+
create table if not exists ctas_dbs as select * from sys.DBS;
21+
22+
select 1
23+
from sys.TBLS t
24+
join ctas_dbs d on t.DB_ID = d.DB_ID
25+
limit 1;
26+
27+
explain extended
28+
select 1
29+
from sys.TBLS t
30+
join ctas_dbs d on t.DB_ID = d.DB_ID
31+
limit 1;
32+
33+
create table if not exists ctlt_dbs like sys.DBS;
34+
35+
insert into ctlt_dbs
36+
select * from sys.DBS;
37+
38+
select 1
39+
from sys.TBLS t
40+
join ctlt_dbs d on t.DB_ID = d.DB_ID
41+
limit 1;
42+
43+
explain extended
44+
select 1
45+
from sys.TBLS t
46+
join ctlt_dbs d on t.DB_ID = d.DB_ID
47+
limit 1;
20.5 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)