core: use stable structured log event names and field keys - #25121
Open
CodeBhavyaG wants to merge 2 commits into
Open
core: use stable structured log event names and field keys#25121CodeBhavyaG wants to merge 2 commits into
CodeBhavyaG wants to merge 2 commits into
Conversation
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Details
What does this PR change?
Fixes the structured logging anti-pattern where runtime values were used as log event names or spread as structured field keys. Runtime data is now emitted as isolated field values under fixed, predictable keys.
Specific changes made across the codebase:
authentik/sources/kerberos/sync.py,authentik/sources/ldap/sync/users.py,authentik/sources/ldap/sync/groups.py: property-mapping-builtdefaultsdicts were spread as field keys (**defaults), meaning caller-controlled attribute names became log field keys. They are now safely nested under a single stableattributeskey.authentik/blueprints/v1/importer.py:f"Entry invalid: {exc}"andf"Entry invalid on retry: {exc}"were replaced with the stable event names"Entry invalid"and"Entry invalid on retry". The exception details are now attached to theerrorfield.authentik/providers/saml/processors/authn_request_parser.py: The ACS URL mismatch warning used interpolated URLs as the root event name. It now logs a stable event ("saml_acs_url_mismatch") while capturing the endpoints securely viarequest_acs_urlandprovider_acs_urlfields. TheCannotHandleAssertionexception message thrown to the browser remains unchanged.authentik/tasks/models.py: Exception text is no longer used as the event name in theTask.info/warning/errorentrypoints. Bare exceptions now produce the stable events"Task has encountered an error"/"Task has encountered an error and will be retried". Full exception details remain preserved in theexceptionattribute viaexception_to_dict.authentik/tasks/schedules/scheduler.py:f"Sent {count} scheduled tasks"was changed to"Sent scheduled tasks"with a distinctcountfield.authentik/outposts/controllers/docker.py:f"SSH Managed externally: {exc}"was changed to the stable event"SSH Managed externally"with anerrorfield.(Note:
events/logs.py(LogEvent.log()) was intentionally left unchanged as it simply replays previously captured log events from the task log fallback. With the_make_logfix above, the events flowing through it will inherently have stable names at their source).Why is this change needed?
Dynamic event names and arbitrary field keys cause unbounded cardinality growth in log indexes and facets (e.g., Datadog, Elasticsearch). They split one logical event across thousands of names and make structured queries, dashboards, and alerting incredibly difficult to maintain. By migrating to a static event taxonomy, the semantic information is preserved while ensuring predictable, queryable log structures.
How was this tested?
ruff check,ruff format --check, andbanditpassed successfully on the changed files viamake lintandmake lint-fix.make runto launch the backend server.tests/trigger_bug_reproducer.pyto spoof aSAMLRequestXML payload with a maliciously mismatched ACS URL against the SSO binding redirect endpoint.make run 2>&1 | grep -i warning) that the backend cleanly emits the structured JSON logsaml_acs_url_mismatchinstead of the dynamic sentence.CannotHandleAssertion(msg)exception and correctly displays the "Bad Request" page with the full descriptive string unchanged (ACS URL of https://hacker.com...).Linked issues
closes #22196
Checklist
make all)make docs)