-
Notifications
You must be signed in to change notification settings - Fork 10
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 potentially sensitive config keys from log messages #62
Open
NoxHarmonium
wants to merge
6
commits into
bluesky:main
Choose a base branch
from
AustralianSynchrotron:main
base: main
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.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1152ab3
Redact anything potentially sensitive from config logging
NoxHarmonium c4962e6
Use consistent react function
NoxHarmonium 021d77c
Add some documentation to redact_config
NoxHarmonium 162ff49
docker-compose is no longer its own binary
NoxHarmonium 07c7a53
Test more python versions
NoxHarmonium 2892e89
Update test script to match CI
NoxHarmonium 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
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,129 @@ | ||
# See https://docs.confluent.io/platform/current/installation/configuration/producer-configs.html and | ||
# https://docs.confluent.io/platform/current/installation/configuration/consumer-configs.html | ||
CONFIG_KEY_WHITELIST = { | ||
## | ||
# -- Common Keys | ||
"bootstrap.servers", | ||
"client.dns.lookup", | ||
"client.id", | ||
"connections.max.idle.ms", | ||
"receive.buffer.bytes", | ||
"request.timeout.ms", | ||
# "sasl.client.callback.handler.class", | ||
# "sasl.jaas.config", | ||
# "sasl.kerberos.service.name", | ||
# "sasl.login.callback.handler.class", | ||
# "sasl.login.class", | ||
# "sasl.mechanism", | ||
# "sasl.oauthbearer.jwks.endpoint.url", | ||
# "sasl.oauthbearer.token.endpoint.url", | ||
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. I don't usually like having a heap of commented out code like this, but it is handy to see at a glance what keys are getting redacted so I left it in for now. |
||
"security.protocol", | ||
"send.buffer.bytes", | ||
"socket.connection.setup.timeout.max.ms", | ||
"socket.connection.setup.timeout.ms", | ||
# "ssl.enabled.protocols", | ||
# "ssl.keystore.type", | ||
# "ssl.protocol", | ||
# "ssl.provider", | ||
# "ssl.truststore.type", | ||
"auto.include.jmx.reporter", | ||
"enable.metrics.push", | ||
"interceptor.classes", | ||
"metadata.max.age.ms", | ||
"metric.reporters", | ||
"metrics.num.samples", | ||
"metrics.recording.level", | ||
"metrics.sample.window.ms", | ||
"reconnect.backoff.max.ms", | ||
"reconnect.backoff.ms", | ||
"retry.backoff.max.ms", | ||
"retry.backoff.ms", | ||
# "sasl.kerberos.kinit.cmd", | ||
# "sasl.kerberos.min.time.before.relogin", | ||
# "sasl.kerberos.ticket.renew.jitter", | ||
# "sasl.kerberos.ticket.renew.window.factor", | ||
# "sasl.login.connect.timeout.ms", | ||
# "sasl.login.read.timeout.ms", | ||
# "sasl.login.refresh.buffer.seconds", | ||
# "sasl.login.refresh.min.period.seconds", | ||
# "sasl.login.refresh.window.factor", | ||
# "sasl.login.refresh.window.jitter", | ||
# "sasl.login.retry.backoff.max.ms", | ||
# "sasl.login.retry.backoff.ms", | ||
# "sasl.oauthbearer.clock.skew.seconds", | ||
# "sasl.oauthbearer.expected.audience", | ||
# "sasl.oauthbearer.expected.issuer", | ||
# "sasl.oauthbearer.jwks.endpoint.refresh.ms", | ||
# "sasl.oauthbearer.jwks.endpoint.retry.backoff.max.ms", | ||
# "sasl.oauthbearer.jwks.endpoint.retry.backoff.ms", | ||
# "sasl.oauthbearer.scope.claim.name", | ||
# "sasl.oauthbearer.sub.claim.name", | ||
# "security.providers", | ||
# "ssl.cipher.suites", | ||
# "ssl.endpoint.identification.algorithm", | ||
# "ssl.engine.factory.class", | ||
# "ssl.keymanager.algorithm", | ||
# "ssl.secure.random.implementation", | ||
# "ssl.trustmanager.algorithm", | ||
## | ||
# -- Consumer Only Keys | ||
"key.deserializer", | ||
"value.deserializer", | ||
"fetch.min.bytes", | ||
"group.id", | ||
"group.protocol", | ||
"heartbeat.interval.ms", | ||
"max.partition.fetch.bytes", | ||
"session.timeout.ms", | ||
"allow.auto.create.topics", | ||
"auto.offset.reset", | ||
"default.api.timeout.ms", | ||
"enable.auto.commit", | ||
"exclude.internal.topics", | ||
"fetch.max.bytes", | ||
"group.instance.id", | ||
"group.remote.assignor", | ||
"isolation.level", | ||
"max.poll.interval.ms", | ||
"max.poll.records", | ||
"partition.assignment.strategy", | ||
"auto.commit.interval.ms", | ||
"check.crcs", | ||
"client.rack", | ||
"fetch.max.wait.ms", | ||
## | ||
# -- Producer Only Keys | ||
"key.serializer", | ||
"value.serializer", | ||
"buffer.memory", | ||
"compression.type", | ||
"retries", | ||
"batch.size", | ||
"delivery.timeout.ms", | ||
"linger.ms", | ||
"max.block.ms", | ||
"max.request.size", | ||
"partitioner.class", | ||
"partitioner.ignore.keys", | ||
"acks", | ||
"enable.idempotence", | ||
"max.in.flight.requests.per.connection", | ||
"metadata.max.idle.ms", | ||
"partitioner.adaptive.partitioning.enable", | ||
"partitioner.availability.timeout.ms", | ||
"transaction.timeout.ms", | ||
"transactional.id", | ||
} | ||
|
||
|
||
def redact_config(config): | ||
""" | ||
Takes a consumer/producer config dictionary and makes sure that anything potentially sensitive | ||
is masked out by asterisks so it can be safely logged. | ||
|
||
Parameters | ||
---------- | ||
config : dict | ||
Dictionary of configuration information used to construct a consumer or producer. | ||
""" | ||
return {k: v if k in CONFIG_KEY_WHITELIST else "****" for k, v in config.items()} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from bluesky_kafka.logging_utils import redact_config | ||
|
||
|
||
def test_redact_config(): | ||
example_config = { | ||
"bootstrap.servers": "some-kafka-server:9092", | ||
"sasl.mechanisms": "PLAIN", | ||
"sasl.username": "brokerUser", | ||
"security.protocol": "SASL_SSL", | ||
"ssl.ca.location": "/opt/kafka/config/certs/kafka-tls-ca", | ||
"sasl.password": "SECRET PASSWORD", | ||
"acks": "all", # Producer key | ||
"enable.idempotence": "false", | ||
"group.id": "some-group", # Consumer key | ||
} | ||
|
||
reacted_example_config = redact_config(example_config) | ||
|
||
assert reacted_example_config == { | ||
"bootstrap.servers": "some-kafka-server:9092", | ||
"sasl.mechanisms": "****", | ||
"sasl.username": "****", | ||
"security.protocol": "SASL_SSL", | ||
"ssl.ca.location": "****", | ||
"sasl.password": "****", | ||
"acks": "all", | ||
"enable.idempotence": "false", | ||
"group.id": "some-group", | ||
} |
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.
I wasn't sure if we wanted to remove some of the older versions, looks like Python 3.8 is EOL, but the builds run in parallel so it doesn't seem to hurt to have more versions in there.