Skip to content

Commit e402fbc

Browse files
authored
[lake] Remove sensetive lake catalog properties in getTable (apache#1860)
1 parent f9b0072 commit e402fbc

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

fluss-client/src/test/java/org/apache/fluss/client/admin/ClientToServerITCaseBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ private static Configuration initConfig() {
117117
// set default datalake format for the cluster and enable datalake tables
118118
conf.set(ConfigOptions.DATALAKE_FORMAT, DataLakeFormat.PAIMON);
119119

120+
conf.setString("datalake.paimon.jdbc.user", "admin");
121+
conf.setString("datalake.paimon.jdbc.password", "pass");
122+
120123
conf.set(ConfigOptions.CLIENT_WRITER_BUFFER_MEMORY_SIZE, MemorySize.parse("1mb"));
121124
conf.set(ConfigOptions.CLIENT_WRITER_BATCH_SIZE, MemorySize.parse("1kb"));
122125
conf.set(ConfigOptions.MAX_PARTITION_NUM, 10);

fluss-client/src/test/java/org/apache/fluss/client/admin/FlussAdminITCase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ void testGetTableInfoAndSchema() throws Exception {
208208
// assert created time
209209
assertThat(tableInfo.getCreatedTime())
210210
.isBetween(timestampBeforeCreate, timestampAfterCreate);
211+
212+
// test sensitive lake catalog properties have been removed
213+
tablePath = TablePath.of("test_db", "lake_table");
214+
admin.createTable(
215+
tablePath,
216+
DEFAULT_TABLE_DESCRIPTOR.withProperties(
217+
new HashMap<String, String>() {
218+
{
219+
put("table.datalake.enabled", "true");
220+
}
221+
}),
222+
false)
223+
.get();
224+
Map<String, String> properties =
225+
admin.getTableInfo(tablePath).get().getProperties().toMap();
226+
assertThat(properties.containsKey("table.datalake.paimon.jdbc.user")).isTrue();
227+
assertThat(properties.containsKey("table.datalake.paimon.jdbc.password")).isFalse();
211228
}
212229

213230
@Test

fluss-server/src/main/java/org/apache/fluss/server/coordinator/MetadataManager.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
import java.util.Collection;
6464
import java.util.HashMap;
65+
import java.util.HashSet;
66+
import java.util.Iterator;
6567
import java.util.List;
6668
import java.util.Map;
6769
import java.util.Optional;
@@ -81,6 +83,14 @@ public class MetadataManager {
8183
private final int maxBucketNum;
8284
private final LakeCatalogDynamicLoader lakeCatalogDynamicLoader;
8385

86+
public static final Set<String> SENSITIVE_TABLE_OPTIOINS = new HashSet<>();
87+
88+
static {
89+
SENSITIVE_TABLE_OPTIOINS.add("password");
90+
SENSITIVE_TABLE_OPTIOINS.add("secret");
91+
SENSITIVE_TABLE_OPTIOINS.add("key");
92+
}
93+
8494
/**
8595
* Creates a new metadata manager.
8696
*
@@ -507,6 +517,20 @@ private boolean isDataLakeEnabled(Map<String, String> properties) {
507517
return Boolean.parseBoolean(dataLakeEnabledValue);
508518
}
509519

520+
public void removeSensitiveTableOptions(Map<String, String> tableLakeOptions) {
521+
if (tableLakeOptions == null || tableLakeOptions.isEmpty()) {
522+
return;
523+
}
524+
525+
Iterator<Map.Entry<String, String>> iterator = tableLakeOptions.entrySet().iterator();
526+
while (iterator.hasNext()) {
527+
String key = iterator.next().getKey().toLowerCase();
528+
if (SENSITIVE_TABLE_OPTIOINS.stream().anyMatch(key::contains)) {
529+
iterator.remove();
530+
}
531+
}
532+
}
533+
510534
public TableInfo getTable(TablePath tablePath) throws TableNotExistException {
511535
Optional<TableRegistration> optionalTable;
512536
try {
@@ -520,10 +544,10 @@ public TableInfo getTable(TablePath tablePath) throws TableNotExistException {
520544
}
521545
TableRegistration tableReg = optionalTable.get();
522546
SchemaInfo schemaInfo = getLatestSchema(tablePath);
523-
return tableReg.toTableInfo(
524-
tablePath,
525-
schemaInfo,
526-
lakeCatalogDynamicLoader.getLakeCatalogContainer().getDefaultTableLakeOptions());
547+
Map<String, String> tableLakeOptions =
548+
lakeCatalogDynamicLoader.getLakeCatalogContainer().getDefaultTableLakeOptions();
549+
removeSensitiveTableOptions(tableLakeOptions);
550+
return tableReg.toTableInfo(tablePath, schemaInfo, tableLakeOptions);
527551
}
528552

529553
public Map<TablePath, TableInfo> getTables(Collection<TablePath> tablePaths)

0 commit comments

Comments
 (0)