fix(logs): prefer username over numeric user id in log messages - #3672
Open
IshanA2007 wants to merge 1 commit into
Open
IshanA2007 wants to merge 1 commit into
IshanA2007 wants to merge 1 commit into
Conversation
Several log lines printed a user's numeric database id even though the corresponding User object (with its human-readable username) was already available in scope, making the logs harder to read/correlate for admins. Switch those log lines to the username. Log lines that only have a raw user id (e.g. lookup failures, or values that would require an extra DB query to resolve) are left unchanged. Also covers five lines in forward_auth.rs and openid_flow.rs that were missed in an earlier pass, and corrects three yubikey.rs handler lines that were switched to the wrong User (the target user resolved via user_for_admin_or_self, instead of the acting session.user) when the log line is describing who performed the action. The other half of the issue, adding a minimal SQL query to resolve a username where no User object is in scope, is intentionally not done here. Part of DefGuard#719
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 New contributors
📖 Description
Part of #719. Not using a closing keyword, see the note at the end.
Several
debug!/info!/warn!/error!lines printed a user's numeric database ideven though the corresponding
Userobject was already bound in scope. Switchedthose to
username, matching the convention already used elsewhere in the codebase(
"User {} listing ACL aliases", session.user.usernameand similar):crates/defguard_core/src/handlers/yubikey.rs: delete/rename handlerscrates/defguard_core/src/handlers/forward_auth.rs: session validationcrates/defguard_core/src/handlers/openid_flow.rs: authorize flowcrates/defguard_core/src/enterprise/allowed_ips/mod.rs: ACL-derived AllowedIPscrates/defguard_core/src/grpc/proxy/client_mfa.rs: posture check, inactive usercrates/defguard_setup/src/handlers/initial_wizard.rs: admin creation, setup guardWhere an id still carries information the username doesn't, it is kept alongside
rather than replaced, e.g. the initial-admin id (which is stored in settings) and
the
finish_setupmismatch guard, where seeing only a name and an id would make theerror impossible to interpret.
Left unchanged: log lines with only a raw id and no
Userobject, and lines thatfire precisely because the lookup failed. Also unchanged are the hot paths
(
enterprise/db/models/acl.rsrule evaluation,enterprise/firewall/mod.rsSNATbinding generation) and the external directory-sync modules, whose "user id" is
JumpCloud's/Entra's identifier rather than ours.
That leaves the other half of the issue, adding a minimal SQL query to resolve the
username where no
Userobject is in scope, undone, which is why this isn't markedas closing #719. In the ACL and firewall paths a query per log line would run
per-rule/per-binding, so I'd rather check with you on the approach before doing it.
Happy to follow up either way.
🛠️ Dev Branch Merge Checklist
Documentation
logic, log message content only.
Testing
no new functionality.
posture-check handlers, which have no existing automated coverage.
(
cargo test -p defguard_core --lib enterprise::allowed_ips: 20 passed;cargo test -p defguard_setup --test integration -- initial_setup: 17 passed).cargo +nightly fmt --all --checkandcargo clippy --all-targets --all-features -- -D warningsare clean across the workspace.Deployment
Prepared with AI assistance (Claude Code).