Skip to content

core: use stable structured log event names and field keys - #25121

Open
CodeBhavyaG wants to merge 2 commits into
goauthentik:mainfrom
CodeBhavyaG:fix/structured-logging-22196
Open

core: use stable structured log event names and field keys#25121
CodeBhavyaG wants to merge 2 commits into
goauthentik:mainfrom
CodeBhavyaG:fix/structured-logging-22196

Conversation

@CodeBhavyaG

Copy link
Copy Markdown

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-built defaults dicts were spread as field keys (**defaults), meaning caller-controlled attribute names became log field keys. They are now safely nested under a single stable attributes key.
  • authentik/blueprints/v1/importer.py: f"Entry invalid: {exc}" and f"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 the error field.
  • 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 via request_acs_url and provider_acs_url fields. The CannotHandleAssertion exception message thrown to the browser remains unchanged.
  • authentik/tasks/models.py: Exception text is no longer used as the event name in the Task.info/warning/error entrypoints. 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 the exception attribute via exception_to_dict.
  • authentik/tasks/schedules/scheduler.py: f"Sent {count} scheduled tasks" was changed to "Sent scheduled tasks" with a distinct count field.
  • authentik/outposts/controllers/docker.py: f"SSH Managed externally: {exc}" was changed to the stable event "SSH Managed externally" with an error field.

(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_log fix 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?

  1. Linters: ruff check, ruff format --check, and bandit passed successfully on the changed files via make lint and make lint-fix.
  2. Backend Emulation (SAML):
    • Ran make run to launch the backend server.
    • Executed tests/trigger_bug_reproducer.py to spoof a SAMLRequest XML payload with a maliciously mismatched ACS URL against the SSO binding redirect endpoint.
    • Logs Result: Verified in the terminal (make run 2>&1 | grep -i warning) that the backend cleanly emits the structured JSON log saml_acs_url_mismatch instead of the dynamic sentence.
  3. Frontend Verification: Verified that the frontend gracefully handles the intercepted 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

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

@CodeBhavyaG
CodeBhavyaG requested a review from a team as a code owner August 15, 2026 15:27
@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 90e47c5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a808768fd413200081f4410
😎 Deploy Preview https://deploy-preview-25121--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 90e47c5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a8087683deb990008f68e06
😎 Deploy Preview https://deploy-preview-25121--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 90e47c5
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a808768fd413200081f440c
😎 Deploy Preview https://deploy-preview-25121--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

Bug: Runtime values are used as structured log event names or field keys

1 participant