sririshindra commented on code in PR #4225: URL: https://github.com/apache/polaris/pull/4225#discussion_r3231032215
########## runtime/service/src/main/java/org/apache/polaris/service/events/listeners/PersistenceAttributeSecurityFilter.java: ########## @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polaris.service.events.listeners; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.TableMetadataParser; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.rest.responses.LoadTableResponse; +import org.apache.polaris.service.events.AttributeKey; +import org.apache.polaris.service.events.EventAttributeMap; +import org.apache.polaris.service.events.EventAttributes; + +final class PersistenceAttributeSecurityFilter { + + private static final Set<String> ALLOWED_TELEMETRY_CONTEXT_KEYS = + Set.of("otel.trace_id", "otel.span_id", "otel.trace_flags", "otel.sampled"); + + Map<String, String> filterAllowlistedAttributes(EventAttributeMap attributes) { + Map<String, String> safeAttributes = new LinkedHashMap<>(); + attributes.forEach((key, value) -> addIfAllowlisted(safeAttributes, key, value)); + return safeAttributes; + } + + Map<String, String> filterAllowlistedTelemetryContext(Map<String, String> telemetryContext) { + Map<String, String> safeContext = new LinkedHashMap<>(); + telemetryContext.forEach( + (key, value) -> { + if (ALLOWED_TELEMETRY_CONTEXT_KEYS.contains(key)) { + safeContext.put(key, value); + } + }); + return safeContext; + } + + @SuppressWarnings("unchecked") + private static void addIfAllowlisted( + Map<String, String> safeAttributes, AttributeKey<?> key, Object value) { + if (EventAttributes.CATALOG_NAME.equals(key) + || EventAttributes.TABLE_NAME.equals(key) + || EventAttributes.VIEW_NAME.equals(key) + || EventAttributes.NAMESPACE_FQN.equals(key) + || EventAttributes.PARENT_NAMESPACE_FQN.equals(key)) { + safeAttributes.put(key.name(), (String) value); + return; + } + + if (EventAttributes.NAMESPACE.equals(key)) { + safeAttributes.put(key.name(), ((Namespace) value).toString()); + return; + } + + if (EventAttributes.TABLE_IDENTIFIER.equals(key) + || EventAttributes.VIEW_IDENTIFIER.equals(key)) { + safeAttributes.put(key.name(), ((TableIdentifier) value).toString()); + return; + } + + // TODO: Filter sensitive events and credential-bearing table properties before serializing + // table metadata. This and other sensitive event filtering cases will be addressed separately. + if (EventAttributes.TABLE_METADATA.equals(key)) { + addTableMetadata(safeAttributes, (TableMetadata) value); + return; + } + + if (EventAttributes.LOAD_TABLE_RESPONSE.equals(key)) { + addTableMetadata(safeAttributes, ((LoadTableResponse) value).tableMetadata()); + return; + } Review Comment: Good catch. RENAME_TABLE_REQUEST is now in the allowlist and the DefaultEventPayloadPruner serializes it as two explicit keys: rename_source and rename_destination. Additionally, resourceIdentifier captures source (for BEFORE_ events) or destination (for AFTER_ events). Both values are fully captured. -- 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]
