fix: handle Attr objects in config path navigation#21557
fix: handle Attr objects in config path navigation#21557alfonsodg wants to merge 1 commit intogoauthentik:mainfrom
Conversation
When environment variables with __ separators (e.g. AUTHENTIK_POSTGRESQL__HOST) are processed, they create nested config paths. If a YAML config file has already set a value at an intermediate path, that value is an Attr object. The path navigation functions (get_path_from_dict, set_path_in_dict) then try to use dict operations on the Attr object, causing: TypeError: 'Attr' object does not support item assignment This commit adds _unwrap_attr() to dict.py that extracts the .value dict from Attr objects during path traversal, and updates config.py methods (update, get, refresh, get_keys) to handle cases where path navigation returns a dict instead of an Attr. Tested with Docker Swarm using env vars: AUTHENTIK_POSTGRESQL__HOST, AUTHENTIK_POSTGRESQL__USER, AUTHENTIK_POSTGRESQL__NAME, AUTHENTIK_POSTGRESQL__PASSWORD, AUTHENTIK_REDIS__HOST, AUTHENTIK_SECRET_KEY
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
What's the scenario where this happens? |
ScenarioDocker Swarm passes all configuration via environment variables with Unlike Docker Compose or Kubernetes, Swarm does not support mounting config files into services easily — environment variables are the standard way to configure services. What happens
Reproduction# Docker Swarm (no compose file, pure env vars)
docker service create --name authentik-server \
-e AUTHENTIK_POSTGRESQL__HOST=db \
-e AUTHENTIK_POSTGRESQL__PASSWORD=secret \
-e AUTHENTIK_SECRET_KEY=key \
ghcr.io/goauthentik/server:2024.8.3The server crashes on startup with the TypeError. Why this doesn't happen in Docker ComposeIn Docker Compose, you typically mount |
|
I feel like I'm talking with an LLM so why doesn't this happen with setting |
|
Ha, fair enough on the LLM comment — I was trying to be thorough but I see how it reads that To your question: using file:/// doesn't help here because the crash happens before the You can reproduce it with just AUTHENTIK_POSTGRESQL__HOST=db — no secrets involved. The |
|
The thing is I have seen many multiple setup where configuration is done through both the default.yml file, another .yml file, and then overrides with environment variables on top, and I've never encountered this. So without a minimal reproduction, this won't go anywhere. |
- goauthentik/authentik#21557: Attr path navigation fix - cycneuramus/seaweedfs-docker-swarm#3: Swarm overlay IP entrypoints Ref #27
Problem
When environment variables with
__separators (e.g.AUTHENTIK_POSTGRESQL__HOST) are processed, they create nested config paths. If a YAML config file has already set a value at an intermediate path, that value is anAttrobject. The path navigation functions then try to use dict operations on theAttrobject, causing:This affects Docker Swarm deployments where all config is passed via environment variables.
Fix
dict.py: Add_unwrap_attr()that extracts.valuedict fromAttrobjects during path traversalconfig.py: Updateupdate(),get(),refresh(),get_keys()to handle non-Attr resultsChanges: +36 lines, -9 lines across 2 files.
Testing
Tested on Docker Swarm 3-node cluster with env vars:
AUTHENTIK_POSTGRESQL__HOST, AUTHENTIK_POSTGRESQL__USER, AUTHENTIK_POSTGRESQL__NAME, AUTHENTIK_POSTGRESQL__PASSWORD, AUTHENTIK_REDIS__HOST, AUTHENTIK_SECRET_KEY
PostgreSQL 18 + Valkey 8.