-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][broker] PIP-402: Optionally prevent role/originalPrincipal logging #23386
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
Merged
lhotari
merged 3 commits into
apache:master
from
CleverCloud:optionallyPreventRoleLogging
Sep 23, 2025
+220
−13
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
67 changes: 67 additions & 0 deletions
67
...he/pulsar/common/configuration/anonymizer/DefaultAuthenticationRoleLoggingAnonymizer.java
This file contains hidden or 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,67 @@ | ||
| /* | ||
| * 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.pulsar.common.configuration.anonymizer; | ||
|
|
||
| import static org.apache.pulsar.common.configuration.anonymizer.DefaultRoleAnonymizerType.NONE; | ||
|
|
||
| /** | ||
| * This class provides a utility to anonymize authentication roles before logging, | ||
| * based on a configured anonymization strategy. The anonymization strategy is | ||
| * determined by the provided value of the {@link DefaultRoleAnonymizerType} enum. | ||
| * | ||
| * The primary purpose of this class is to enable flexible anonymization of sensitive | ||
| * information (such as user roles) in logs, ensuring compliance with security and | ||
| * privacy requirements while allowing customization of the anonymization behavior. | ||
| * | ||
| * Usage: | ||
| * - The class constructor accepts a string that represents the desired anonymization | ||
| * strategy (e.g., "NONE", "REDACTED", "SHA256", "MD5"), and it initializes the | ||
| * anonymizer type accordingly. | ||
| * - The {@code anonymize} method applies the selected anonymization strategy to | ||
| * the provided role and returns the anonymized value. | ||
| * | ||
| * Example: | ||
| * <pre> | ||
| * DefaultAuthenticationRoleLoggingAnonymizer roleAnonymizer = | ||
| * new DefaultAuthenticationRoleLoggingAnonymizer("SHA256"); | ||
| * String anonymizedRole = roleAnonymizer.anonymize("admin"); | ||
| * </pre> | ||
| * | ||
| * Anonymization strategies: | ||
| * - NONE: No anonymization (returns the role as-is). | ||
| * - REDACTED: Replaces the role with "[REDACTED]". | ||
| * - hash:SHA256: Hashes the role using the SHA-256 algorithm and prefixes it with "SHA-256:". | ||
| * - hash:MD5: Hashes the role using the MD5 algorithm and prefixes it with "MD5:" | ||
| */ | ||
| public final class DefaultAuthenticationRoleLoggingAnonymizer { | ||
| private static DefaultRoleAnonymizerType anonymizerType = NONE; | ||
|
|
||
| public DefaultAuthenticationRoleLoggingAnonymizer(String authenticationRoleLoggingAnonymizer) { | ||
| if (authenticationRoleLoggingAnonymizer.startsWith("hash:")) { | ||
| anonymizerType = DefaultRoleAnonymizerType.valueOf(authenticationRoleLoggingAnonymizer | ||
| .substring("hash:".length()).toUpperCase()); | ||
| } else { | ||
| anonymizerType = DefaultRoleAnonymizerType.valueOf(authenticationRoleLoggingAnonymizer); | ||
| } | ||
| } | ||
|
|
||
| public String anonymize(String role) { | ||
| return anonymizerType.anonymize(role); | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...ain/java/org/apache/pulsar/common/configuration/anonymizer/DefaultRoleAnonymizerType.java
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * 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.pulsar.common.configuration.anonymizer; | ||
|
|
||
| import java.security.MessageDigest; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.util.Base64; | ||
|
|
||
| public enum DefaultRoleAnonymizerType { | ||
| NONE { | ||
| @Override | ||
| public String anonymize(String role) { | ||
| return role; | ||
| } | ||
| }, | ||
| REDACTED { | ||
| @Override | ||
| public String anonymize(String role) { | ||
| return REDACTED_VALUE; | ||
| } | ||
| }, | ||
| SHA256 { | ||
| private static final String PREFIX = "SHA-256:"; | ||
| private final MessageDigest digest; | ||
|
|
||
| { | ||
| // Initializing the MessageDigest once for SHA-256 | ||
| try { | ||
| digest = MessageDigest.getInstance("SHA-256"); | ||
| } catch (NoSuchAlgorithmException e) { | ||
| throw new RuntimeException("SHA-256 algorithm not found", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String anonymize(String role) { | ||
| byte[] hash = digest.digest(role.getBytes()); | ||
| return PREFIX + Base64.getEncoder().encodeToString(hash); | ||
| } | ||
| }, | ||
| MD5 { | ||
| private static final String PREFIX = "MD5:"; | ||
| private final MessageDigest digest; | ||
|
|
||
| { | ||
| // Initializing the MessageDigest once for MD5 | ||
| try { | ||
| // codeql[java/weak-cryptographic-algorithm] - md5 is sufficient for this use case& | ||
| digest = MessageDigest.getInstance("MD5"); | ||
KannarFr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (NoSuchAlgorithmException e) { | ||
| throw new RuntimeException("MD5 algorithm not found", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String anonymize(String role) { | ||
| byte[] hash = digest.digest(role.getBytes()); | ||
| return PREFIX + Base64.getEncoder().encodeToString(hash); | ||
| } | ||
| }; | ||
|
|
||
| private static final String REDACTED_VALUE = "[REDACTED]"; | ||
| public abstract String anonymize(String role); | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
...-common/src/main/java/org/apache/pulsar/common/configuration/anonymizer/package-info.java
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| /** | ||
| * Pulsar Client API. | ||
| */ | ||
| package org.apache.pulsar.common.configuration.anonymizer; | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.