Skip to content

packages/ak-common/config: coerce file:// and env:// values to their native type - #23758

Merged
rissson merged 1 commit into
goauthentik:mainfrom
ImmanuelVonNeumann:fix/config-expand-typed-scalars
Jul 6, 2026
Merged

rissson merged 1 commit into
goauthentik:mainfrom
ImmanuelVonNeumann:fix/config-expand-typed-scalars

Conversation

@ImmanuelVonNeumann

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

Non-string config fields can now be supplied via file:// and env://
references without crashing the worker at startup.

Each non-string scalar field gets a deserializer that accepts either a native
value (YAML / direct env var) or a string (what a file:// / env:// reference
resolves to).
String-typed fields are left untouched.

Why is this change needed?

Setting e.g. postgresql.port: file:///run/secrets/pg-port crashed the worker:

Error:
   0: invalid type: string "5432", expected u16

A direct AUTHENTIK_POSTGRESQL__PORT=5432 env var works because config_rs
coerces it to a number before it reaches the config tree. file:// / env://
values are resolved later and arrive as strings, and serde_json won't coerce a
string into u16. This has been the case since the Rust config module was introduced,
which replaced the Python loader's lenient handling with strict typed deserialization.

How was this tested?

Added unit test config::tests::expand_typed: loads a config where
postgresql.port is set via file:// and postgresql.password via a file://
whose contents are the digits 12345, then asserts port == 5432 (numeric field
coerced from the resolved string) and password == "12345" (numeric-looking
string field left untouched).

Local runs, all green:

  • cargo nextest run -p authentik-common → 51/51 passed (incl. expand_typed).
  • cargo +nightly fmt --all --check (ci-lint-rustfmt) → clean.
  • cargo clippy -p authentik-common --all-targets -- -D warnings (ci-lint-clippy) → clean.
  • cargo deny --locked --workspace check (ci-lint-cargo-deny) → ok.
  • cargo machete (ci-lint-cargo-machete) → ok.

End-to-end in a built image against the dev Postgres: port via file:// boots
and runs migrations; a numeric-looking password via file:// and env://
stays a string and connects.

Linked issues

closes #22908


Checklist

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

…t type

Values resolved from file:// and env:// references are inserted into the config
tree as strings, so non-string fields (e.g. postgresql.port) failed to
deserialize with `invalid type: string "5432", expected u16`. Direct AUTHENTIK_*
environment variables avoid this because config_rs coerces them via try_parsing;
file:// / env:// expansion runs afterwards on the already-built tree and bypasses
that coercion.

Add opt-in, target-type-aware deserializers on the non-string scalar fields
(numeric and boolean), each accepting either a native value or a string. This
fixes the reported class for both file:// and env:// while leaving string-typed
fields untouched: a numeric-looking secret read from a file stays a string rather
than being coerced to a number and rejected (which a blanket coerce-on-expand
would do). The numeric helper is gated behind a sealed trait so it cannot be
attached to a String field.
@ImmanuelVonNeumann
ImmanuelVonNeumann requested a review from a team as a code owner July 6, 2026 09:06
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 492f229
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a4b6ffacb60e800081bd7fa
😎 Deploy Preview https://deploy-preview-23758--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 Jul 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 492f229
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a4b6ffa9b04b00008a111a4
😎 Deploy Preview https://deploy-preview-23758--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 Jul 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 492f229
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a4b6ffa681544000863eecd
😎 Deploy Preview https://deploy-preview-23758--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.

@codecov

codecov Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.18%. Comparing base (27f8d1e) to head (492f229).
⚠️ Report is 49 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23758      +/-   ##
==========================================
- Coverage   93.23%   93.18%   -0.05%     
==========================================
  Files        1039     1039              
  Lines       60848    60868      +20     
  Branches      424      424              
==========================================
- Hits        56729    56721       -8     
- Misses       4119     4147      +28     
Flag Coverage Δ
conformance 36.30% <ø> (-0.01%) ⬇️
e2e 41.51% <ø> (+0.02%) ⬆️
integration 32.24% <ø> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 92.30% <ø> (+<0.01%) ⬆️
unit-migrate 92.32% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Jul 6, 2026
@rissson rissson added the backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 label Jul 6, 2026
@rissson
rissson merged commit f8ed008 into goauthentik:main Jul 6, 2026
107 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Jul 6, 2026
rissson added a commit that referenced this pull request Jul 6, 2026
…native type (cherry-pick #23758 to version-2026.5) (#23759)

Co-authored-by: Immanuel von Neumann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Specifying postgres port manually via environment variable causes the worker process to crash

2 participants