-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Redact sensitive information in catalog queries #24563
Draft
piotrrzysko
wants to merge
11
commits into
trinodb:master
Choose a base branch
from
piotrrzysko:redact-sensitive-queries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,714
−160
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
de0da72
Add SPI for returning connectors' sensitive properties
piotrrzysko 28256ef
Update Airlift
piotrrzysko 9e22f87
Expose security-sensitive properties for PostgreSQL connector
piotrrzysko 22e0347
Expose security-sensitive properties for HDFS
piotrrzysko b486e53
Expose security-sensitive properties for Hive connector
piotrrzysko 410523a
Expose security-sensitive properties for Iceberg connector
piotrrzysko c98dc03
Expose security-sensitive properties for Delta Lake connector
piotrrzysko 47db44b
Expose security-sensitive properties for Hudi connector
piotrrzysko 4c5b5cf
Introduce redaction for sensitive statements
piotrrzysko f28846e
Ensure queries in system.runtime.queries are redacted
piotrrzysko 654d3e2
Ensure queries returned via REST API are redacted
piotrrzysko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
core/trino-main/src/main/java/io/trino/connector/CatalogPropertiesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.trino.connector; | ||
|
||
import io.trino.spi.catalog.CatalogName; | ||
import io.trino.spi.catalog.CatalogProperties; | ||
import io.trino.spi.connector.ConnectorName; | ||
|
||
import java.util.Map; | ||
|
||
public interface CatalogPropertiesProvider | ||
{ | ||
CatalogProperties getCatalogProperties(CatalogName catalogName, ConnectorName connectorName, Map<String, String> properties); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
*/ | ||
package io.trino.connector; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.errorprone.annotations.ThreadSafe; | ||
import com.google.inject.Inject; | ||
import io.airlift.configuration.secrets.SecretsResolver; | ||
|
@@ -32,6 +33,7 @@ | |
import io.trino.spi.PageIndexerFactory; | ||
import io.trino.spi.PageSorter; | ||
import io.trino.spi.VersionEmbedder; | ||
import io.trino.spi.catalog.CatalogName; | ||
import io.trino.spi.catalog.CatalogProperties; | ||
import io.trino.spi.classloader.ThreadContextClassLoader; | ||
import io.trino.spi.connector.CatalogHandle; | ||
|
@@ -45,6 +47,7 @@ | |
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
|
@@ -144,6 +147,25 @@ public CatalogConnector createCatalog(CatalogHandle catalogHandle, ConnectorName | |
return createCatalog(catalogHandle, connectorName, connector, Optional.empty()); | ||
} | ||
|
||
@Override | ||
public Set<String> getSecuritySensitivePropertyNames(CatalogProperties catalogProperties) | ||
{ | ||
ConnectorFactory connectorFactory = connectorFactories.get(catalogProperties.connectorName()); | ||
if (connectorFactory == null) { | ||
// If someone tries to use a non-existent connector, we assume they | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great catch, I didn't think of this case. |
||
// misspelled the name and, for safety, we redact all the properties. | ||
return ImmutableSet.copyOf(catalogProperties.properties().keySet()); | ||
} | ||
|
||
ConnectorContext context = createConnectorContext(catalogProperties.catalogHandle()); | ||
CatalogName catalogName = catalogProperties.catalogHandle().getCatalogName(); | ||
Map<String, String> config = secretsResolver.getResolvedConfiguration(catalogProperties.properties()); | ||
|
||
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(connectorFactory.getClass().getClassLoader())) { | ||
return connectorFactory.getSecuritySensitivePropertyNames(catalogName.toString(), config, context); | ||
} | ||
} | ||
|
||
private CatalogConnector createCatalog(CatalogHandle catalogHandle, ConnectorName connectorName, Connector connector, Optional<CatalogProperties> catalogProperties) | ||
{ | ||
Tracer tracer = createTracer(catalogHandle); | ||
|
@@ -196,7 +218,16 @@ private Connector createConnector( | |
ConnectorFactory connectorFactory, | ||
Map<String, String> properties) | ||
{ | ||
ConnectorContext context = new ConnectorContextInstance( | ||
ConnectorContext context = createConnectorContext(catalogHandle); | ||
|
||
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(connectorFactory.getClass().getClassLoader())) { | ||
return connectorFactory.create(catalogName, properties, context); | ||
} | ||
} | ||
|
||
private ConnectorContext createConnectorContext(CatalogHandle catalogHandle) | ||
{ | ||
return new ConnectorContextInstance( | ||
catalogHandle, | ||
openTelemetry, | ||
createTracer(catalogHandle), | ||
|
@@ -206,10 +237,6 @@ private Connector createConnector( | |
new InternalMetadataProvider(metadata, typeManager), | ||
pageSorter, | ||
pageIndexerFactory); | ||
|
||
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(connectorFactory.getClass().getClassLoader())) { | ||
return connectorFactory.create(catalogName, properties, context); | ||
} | ||
} | ||
|
||
private Tracer createTracer(CatalogHandle catalogHandle) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/trino-main/src/main/java/io/trino/connector/DynamicCatalogPropertiesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.trino.connector; | ||
|
||
import com.google.inject.Inject; | ||
import io.trino.spi.catalog.CatalogName; | ||
import io.trino.spi.catalog.CatalogProperties; | ||
import io.trino.spi.catalog.CatalogStore; | ||
import io.trino.spi.connector.ConnectorName; | ||
|
||
import java.util.Map; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DynamicCatalogPropertiesProvider | ||
implements CatalogPropertiesProvider | ||
{ | ||
private final CatalogStore catalogStore; | ||
|
||
@Inject | ||
public DynamicCatalogPropertiesProvider(CatalogStore catalogStore) | ||
{ | ||
this.catalogStore = requireNonNull(catalogStore, "catalogStore is null"); | ||
} | ||
|
||
@Override | ||
public CatalogProperties getCatalogProperties(CatalogName catalogName, ConnectorName connectorName, Map<String, String> properties) | ||
{ | ||
return catalogStore.createCatalogProperties(catalogName, connectorName, properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/trino-main/src/main/java/io/trino/connector/StaticCatalogPropertiesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.trino.connector; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.trino.spi.catalog.CatalogName; | ||
import io.trino.spi.catalog.CatalogProperties; | ||
import io.trino.spi.connector.CatalogHandle; | ||
import io.trino.spi.connector.ConnectorName; | ||
|
||
import java.util.Map; | ||
|
||
import static io.trino.spi.connector.CatalogHandle.createRootCatalogHandle; | ||
|
||
public class StaticCatalogPropertiesProvider | ||
implements CatalogPropertiesProvider | ||
{ | ||
@Override | ||
public CatalogProperties getCatalogProperties(CatalogName catalogName, ConnectorName connectorName, Map<String, String> properties) | ||
{ | ||
return new CatalogProperties( | ||
createRootCatalogHandle(catalogName, new CatalogHandle.CatalogVersion("default")), | ||
connectorName, | ||
ImmutableMap.copyOf(properties)); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@mosabua for suggestions about config naming. 😄
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'm not sure we want an option to disable this. Maybe as a temporary kill switch, but we should remove this as soon as we are happy with this feature
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.
Agreed, we can prefix with
experimental.
in that case like we have done in past to clarify this. Or maybedeprecated.
from the beginning.