Skip to content

[DPE-10563] chore: add a logging filter to redact sensitive values - #208

Open
imanenami wants to merge 3 commits into
mainfrom
chore/improve-logging
Open

imanenami wants to merge 3 commits into
mainfrom
chore/improve-logging

Conversation

@imanenami

@imanenami imanenami commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a RedactionFilter to loggers, which may log sensitive content.

This PR is backed by an analysis of source code done using Claude Code.

Logging Analysis

Dynamic log messages in src

Log call sites whose message text varies at runtime. 36 of the 65 logger calls in src.

Group A — f-string interpolation (21)

Literal string with variables interpolated into it. Stable prefix, so greppable.

Location Interpolated value(s)
src/charm.py:305 {self.unit.name} restarting...
src/charm.py:348 {self.unit.name} initializing...
src/charm.py:382 {self.unit.name} started
src/charm.py:412 {updated_servers=}
src/charm.py:440 ...switching to {self.state.cluster.quorum} quorum
src/charm.py:470 Skipping update of {client.component.name}...
src/core/cluster.py:440 Can't retrieve network binding data: {e}
src/core/models.py:59 Fields {list(items.keys())} were attempted...
src/managers/backup.py:95 Using existing bucket {bucket_name}
src/managers/backup.py:100 Created bucket {bucket_name}
src/managers/config.py:405 server/config property set-diffs (two sets)
src/managers/config.py:415 JAAS set-diffs (two sets)
src/managers/config.py:426 {self.log_level}
src/managers/quorum.py:192 {leader_chroots=}
src/managers/quorum.py:213 {sasl_acl=}
src/managers/quorum.py:224 CREATE CHROOT - {client.database}
src/managers/quorum.py:228 UPDATE CHROOT - {client.database}
src/events/backup.py:73 {missing_required_parameters}
src/events/upgrade.py:112 {self.charm.unit.name} upgrading workload...
src/events/password_actions.py:65 {...upgrade_stack} (msg built at :61-64)
src/events/password_actions.py:72 {CHARM_USERS}, {username} (msg built at :71)

Group B — bare variable, no literal text (15)

The whole message is an exception or attribute. No static text to grep for.

Location Message
src/managers/tls.py:89 e.stdout
src/managers/tls.py:173 str(e.stdout)
src/managers/tls.py:190 str(e.stdout)
src/managers/tls.py:273 str(e.stdout)
src/managers/tls.py:284 str(e.stdout)
src/workload.py:38 str(e) (.exception)
src/workload.py:45 str(e) (.exception)
src/workload.py:52 str(e) (.exception)
src/workload.py:142 str(e)
src/managers/quorum.py:85 str(e)
src/managers/quorum.py:154 str(e)
src/events/provider.py:76 str(e)
src/events/upgrade.py:130 e.cause
src/managers/k8s.py:46 e.status.message
src/core/cluster.py:468 e (object passed directly, not stringified)

@imanenami
imanenami force-pushed the chore/improve-logging branch from 2b16808 to 763b94e Compare July 16, 2026 11:17
@imanenami
imanenami force-pushed the chore/improve-logging branch from 763b94e to 4e4407d Compare July 16, 2026 11:21
@imanenami

imanenami commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

For event handlers, I prefer to set a logger prop on charm, and use self.charm.logger instead of re-instantiating the logger on every handler. WDYT?

@zmraul zmraul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would either move all logging through charm.logger or none. Because right now we have "normal" logging in several places. So I would instead clearly migrate to a custom logging for all modules.

There is then the issue where all logs controlled by the libs are not routed through this, which includes our own libs. Not sure if there is a global override for this in python. Maybe we can wire something through JujuLogHandler in ops instead?

Comment thread src/core/cluster.py
*self.cluster.internal_user_credentials.values(),
*self.cluster.client_passwords.values(),
self.cluster.s3_credentials.get("access-key", ""),
self.cluster.s3_credentials.get("secrety-key", ""),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cluster.s3_credentials.get("secrety-key", ""),
self.cluster.s3_credentials.get("secret-key", ""),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

Comment thread src/core/cluster.py
Comment on lines +347 to +348
self.unit_server.certificate,
self.unit_server.ca,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think these two are needed, but not a big deal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither, but the last time I asked Mykola he had a different opinion, so let's keep'em

@imanenami

imanenami commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

I would either move all logging through charm.logger or none. Because right now we have "normal" logging in several places. So I would instead clearly migrate to a custom logging for all modules.

Unfortunately this is not possible, since we only pass the charm object to event handlers, and that is the correct pattern. The core, managers and workloads should have their own logging facility imo, and not be coupled with ops objects.

There is then the issue where all logs controlled by the libs are not routed through this, which includes our own libs. Not sure if there is a global override for this in python. Maybe we can wire something through JujuLogHandler in ops instead?

If a lib logs sensitive content, that's the lib's issue and it should be patched by the lib maintainer imo. In that hypothetical scenario, our mitigation would be to silence the lib's logging through standard logging methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants