Security policy now configurable via environment variables

n8n administrators can now pre-configure MFA enforcement, personal space publishing, and personal space sharing through environment variables — security policies apply automatically on instance startup rather than requiring manual UI configuration.
Instance administrators previously had to configure security policies manually through the UI or API after startup. For teams running n8n in containers or managing multiple deployments, this meant either repetitive manual work or custom tooling to apply consistent security settings across environments.
Security policy settings — MFA enforcement, personal space publishing, and personal space sharing — can now be controlled via environment variables. When N8N_SECURITY_POLICY_MANAGED_BY_ENV is set to true, these policies are applied automatically on every instance startup. The CLI loader retrieves the configuration values and updates the relevant services before the instance becomes operational.
When security settings are managed by environment variables, the API rejects any attempt to modify them through the UI or endpoints. The frontend displays a notice indicating that settings are controlled via environment variables and disables the relevant toggle controls. This prevents configuration drift between what the environment specifies and what users might set through the interface.
The implementation follows the same pattern already used for owner settings — a dedicated loader class applies configuration during the startup sequence, with a master toggle that serves as a gate for all related environment variables. In the CLI package, new environment variables were added to the configuration schema. The API controllers gained guards that prevent updates when the environment is managing settings, and the SecuritySettingsDto now exposes a managedByEnv flag so clients know the state. The frontend component uses this flag to present a read-only view when appropriate.
View Original GitHub DescriptionFact Check
Summary
Add environment variable support for security policy settings using the instance settings loader pattern. This allows MFA enforcement, personal space publishing, and personal space sharing to be pre-configured via env vars and applied on instance startup.
New env vars:
N8N_SECURITY_POLICY_MANAGED_BY_ENV(boolean, defaultfalse) — master toggle; when false, all other security policy env vars are ignoredN8N_SECURITY_POLICY_MFA_ENFORCED(boolean, defaultfalse) — enforce MFA for all usersN8N_SECURITY_POLICY_PERSONAL_SPACE_PUBLISHING(boolean, defaulttrue) — allow personal space publishingN8N_SECURITY_POLICY_PERSONAL_SPACE_SHARING(boolean, defaulttrue) — allow personal space sharing
How to test:
- Set
N8N_SECURITY_POLICY_MANAGED_BY_ENV=truealong with desired policy env vars - Start the instance
- Verify security settings in UI match the env var values
- Restart and confirm settings are re-applied on every startup
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/LIGO-436
Review / Merge checklist
- I have seen this code, I have run this code, and I take responsibility for this code.
- PR title and summary are descriptive. (conventions)
- Docs updated or follow-up ticket created.
- Tests included.
- PR Labeled with
release/backport(if the PR is an urgent fix that needs to be backported)