n8n Credentials and Secrets Management
A practical guide to storing, rotating, and auditing n8n credentials without leaking API keys through workflow logic, exports, backups, or screenshots.
The 60-second answer
- n8n credential security is not just hiding API keys. It is a production operating model for storing, using, rotating, exporting, and revoking every secret that a workflow can touch.
- The safest pattern separates three things: the n8n encryption key at the platform layer, credential records inside n8n, and short-lived or scoped service accounts at the upstream vendor.
- The practical deliverable is a simple inventory, a rotation runbook, and a rule that workflow JSON, screenshots, tickets, and docs never become the place where secrets live.
Why n8n credential management matters
An n8n workflow often sits between the systems a business cares about most: email, CRM, billing, databases, analytics, files, chat, and AI providers. A single workflow can read customer records, send messages, update invoices, and call a model with private context. That makes credentials the control plane for the automation, not a setup detail you can forget after launch.
The common failure is not a cinematic breach. It is a copied bearer token in a test node, a workflow export pasted into a ticket, a contractor using the owner account, a backup restored onto a staging host with production credentials, or an old key still active after the workflow owner changed teams. Each one is boring, and boring is exactly why it survives audits.
A good credentials model gives builders enough freedom to ship without letting every workflow become a permanent exception. The goal is not to make n8n painful. The goal is to make the safe path the fastest path: named credentials, scoped accounts, clear ownership, rotation that does not break production, and incident steps that can be followed under pressure.
The production secret model for n8n
Think of n8n secrets in layers. The first layer is the platform secret that protects n8n itself, especially the encryption key used for stored credentials. The second layer is the credential record inside n8n that a workflow node references. The third layer is the upstream account or token at the vendor, such as a Google OAuth app, Slack bot token, OpenAI API key, Postgres user, or payment processor restricted key.
Each layer has a different owner and a different rotation method. Platform secrets belong to infrastructure. n8n credential records belong to workflow owners. Upstream service accounts belong to the system owner. When those roles are blurred, nobody knows whether a key can be rotated, which workflows will fail, or who approved the scope in the first place.
The clean model is explicit: one credential record maps to one business purpose, one owner, and one upstream identity where possible. A workflow named invoice enrichment should not quietly share the same all-powerful CRM token as newsletter tagging. Sharing feels efficient until one workflow needs to be retired, one vendor connection is compromised, or one team asks for proof that a workflow cannot touch records outside its remit.
Where each kind of n8n secret should live
The table below is the policy most teams need before they add more automations. It is deliberately plain because complicated secret diagrams tend to hide accountability instead of improving it.
| Secret type | Where it should live | Why it matters |
|---|---|---|
| n8n encryption key | Host environment or secret manager, outside workflow exports. | It protects stored credential values and must survive restarts and restores. |
| Vendor API token | n8n credential record tied to a scoped upstream service account. | It lets workflows authenticate without exposing the raw token in node parameters. |
| Database password | Dedicated credential with least-privilege database role. | Read-only and write scopes can be separated before a mistake reaches production data. |
| Webhook shared secret | Credential or environment-backed validation value, never in public examples. | It proves incoming traffic is expected before the workflow trusts the payload. |
| Workflow export | Private repo or archive with restricted access. | Even without raw secrets, exports reveal endpoints, IDs, and automation intent. |
The credential flow to aim for
A secure n8n setup makes secret movement boring: the workflow never carries the raw secret, and the encryption key that protects stored values is never bundled into exports or screenshots.
A copy-paste credential inventory starter
The inventory can live in your private operations repo, ticketing system, or password manager notes. What matters is that it names the owner, purpose, upstream account, and rotation path. Do not put real secret values in this file. One value deserves special care: if N8N_ENCRYPTION_KEY is lost or changed, every stored credential becomes undecryptable, so set it explicitly and back it up. If you never set it, n8n auto-generates one and persists it at ~/.n8n/config on the host, which is fine until a restore lands on a machine that does not have that file.
# n8n production secret checklist, adapt names before use
N8N_ENCRYPTION_KEY=replace-with-32-plus-random-characters
N8N_HOST=automation.example.com
N8N_PROTOCOL=https
N8N_SECURE_COOKIE=true
credential_inventory:
owner: [email protected]
business_purpose: invoice enrichment workflow
n8n_credential_name: crm-invoice-readonly-prod
upstream_account: crm_n8n_invoice_reader
allowed_scopes:
- contacts.read
- invoices.read
forbidden_scopes:
- contacts.delete
- billing.write
rotation_cadence: quarterly
last_rotation: 2026-06-30
rollback_contact: ops-on-callRotation without breaking production
Rotation fails when teams treat it as a single event. In production, rotation is a small migration: create a new upstream credential, add it to n8n, run the workflow in a controlled path, switch the active credential reference if needed, observe executions, then revoke the old key. The dangerous version is deleting the old key first and discovering that three workflows silently depended on it.
For OAuth credentials, the rotation event may mean reauthorizing the app, changing scopes, or creating a new app registration. For API keys, it may mean two active keys during a short overlap. For database users, it may mean creating a new role and password, then proving the query set still works. The runbook should name the vendor-specific method rather than saying rotate key as if all systems behave the same.
A practical cadence is risk-based. Customer data, payment data, production databases, and AI provider keys with high spend limits deserve tighter review. Low-risk internal tools can rotate less often, but they still need an owner and an exit path. The cadence matters less than whether the first rotation has actually been practiced.
A six-step credential rotation runbook
This runbook is intentionally small enough to execute during maintenance without inventing process on the spot. The important part is the order: prove the replacement works before you remove the old path.
- Inventory every credential. Export the list of credential names from n8n, then map each one to owner, workflow, upstream service, data class, and last rotation date.
- Classify risk before editing. Separate low-risk read-only tools from credentials that can move money, expose regulated data, send external messages, or write to production databases.
- Create the replacement upstream key first. Add a new vendor token or service account with the intended scope while the old key still works, so testing does not begin with an outage.
- Update the n8n credential record. Change the credential value or create a new named record, then run a controlled test execution that covers the highest-risk branch.
- Observe real executions. Watch the next scheduled runs, execution logs and monitoring, and vendor audit logs before revoking the old credential.
- Revoke the old key and write the note. Disable the old upstream secret, record the date, owner, reason, and any workflow changes discovered during the rotation.
Worked example: one CRM token, three workflows
Assume a small company has one CRM API token used by three n8n workflows: lead enrichment, renewal reminders, and invoice lookup. The token belongs to an admin user and can read, write, and delete records. Nothing is broken yet, but the risk is already concentrated. If the token leaks, the blast radius is the whole CRM. If the admin leaves, nobody knows what will stop working.
The fix is not to rename the token. Create three upstream service accounts or three scoped API keys if the CRM supports them. Lead enrichment gets contact read and enrichment write. Renewal reminders get account read and message draft permission. Invoice lookup gets invoice read only. Then create three n8n credential records with names that describe the purpose, not the person who created them.
The migration can happen one workflow at a time. Start with the read-only invoice lookup because it has the lowest rollback cost. After a clean run, move renewal reminders, then lead enrichment. Once all three run cleanly, revoke the original admin token. The final state is easier to audit and easier to change because each credential tells you what it is allowed to do.
Common mistakes that create secret sprawl
Putting tokens in Set nodes. It is convenient during debugging, but it turns a workflow export into a secret dump and makes screenshots unsafe.
Sharing one owner credential everywhere. Shared credentials hide blast radius. A workflow that only needs read access inherits write access because the old key already existed.
Treating backups as harmless. A database backup can carry encrypted credential values and enough metadata to map business systems. Restrict and expire backup access.
Skipping vendor-side scopes. If the upstream token is all-powerful, n8n cannot compensate. Least privilege starts at the vendor account.
Rotating without a test branch. A rotation that has never been rehearsed becomes a production outage when the old key must be revoked quickly.
Access control around credentials
Credential storage is only one side of the risk. The other side is who can use the credential through a workflow. A user may never see the raw API key and still be able to trigger a workflow that spends money, exports customer data, or updates production systems. That is why n8n access should be reviewed by action, not just by whether a person can view secret values. Record those access decisions in your automation governance policy so each review starts from a known baseline.
Start with named users and named owners. Avoid shared admin accounts, especially for contractors and temporary build partners. If a person only needs to edit a sandbox workflow, do not give them production credentials by convenience. If they need production access for a short migration, record the reason and the removal date before the work starts.
The review should include executions, not only settings. Look at who can manually run workflows, who can edit credentials, who can duplicate workflows into another project, and who can export JSON. Those permissions shape the real blast radius. A credential that is encrypted at rest can still be misused if too many people can route work through it.
Backups, exports, and staging restores
The quietest credential leak is often a backup or a staging restore. A team may handle production API keys carefully inside the app, then copy the database to a less protected environment for debugging. Even when credential values are encrypted, the backup can carry credential names, workflow intent, endpoint URLs, account IDs, and enough operational context to make an attacker or careless insider dangerous.
Production backups should have their own access policy and expiry. They should not be downloadable by every developer who can edit a workflow. If a staging restore is needed, decide whether production credentials should be removed, replaced with sandbox credentials, or blocked by network policy before anyone opens the instance. A restored n8n instance that can still call production vendors is not a harmless test environment.
Workflow exports deserve similar treatment. They are useful for version control and review, but they should go to a private repo under version control with the same discipline as infrastructure code. Review diffs for credential references, webhook URLs, internal hostnames, and comments that reveal how the business process works. Secrets management is strongest when the surrounding artifacts are treated as part of the same system.
The simplest acceptance test is whether a new operator can answer three questions in five minutes: what systems can this credential touch, who approved that scope, and how do we revoke it without guessing? If the answer depends on memory, the credential model is not production-ready yet.
What other experts say
Reference card · OWASP Secrets Management
OWASP guidance is that secrets must never sit in source code, configuration files, or version control. Centralize them in a dedicated secret store, enforce least privilege, and rotate them on a defined lifecycle.
Netholics comment: this is exactly why an n8n workflow export, a Set node, or a copied JSON file is the wrong home for a credential. Keep the raw value in the platform layer, reference it from the node, and make rotation a rehearsed step rather than an emergency.
Ship a safer n8n credential setup this week
- Set the encryption key explicitly. Define
N8N_ENCRYPTION_KEYfrom the host or secret manager and store a backup copy off the instance so a restore can decrypt existing credentials. - Export the credential list and assign owners. Map every credential name to one owner, one workflow, one upstream account, and a data class before adding anything new.
- Replace shared admin tokens with scoped accounts. Create one upstream service account per business purpose so a leak or offboarding does not affect every workflow at once.
- Purge secrets from Set nodes and node parameters. Search workflows for inline tokens, move each to a named credential record, and re-test the workflow.
- Lock down exports and backups. Move workflow JSON to a private repo with restricted access, and give production backups their own access policy and expiry.
- Rehearse one rotation end to end. Create a new key, switch the reference, watch real executions, then revoke the old key, and write down the date and owner.
- Review access by action, not just visibility. Confirm who can run, edit, duplicate, or export each workflow, and remove contractor and temporary access on a fixed removal date.
Credential hardening readiness card
| Impact | High. Credentials are the control plane for every system a workflow can read or change. |
| Risk | High if shared admin tokens, inline secrets, or open backups exist; manageable once scoped and inventoried. |
| Effort | Moderate. Inventory and key handling are quick; replacing shared tokens with scoped accounts takes a few sessions. |
| Best first workflow | A read-only workflow such as invoice or record lookup, where rollback cost is lowest. |
| Do not rotate blind | Never revoke an old key before the replacement has passed a controlled test execution. |
Frequently Asked Questions
Q: Where should n8n credentials live in production?
Production n8n credentials should live in n8n credential records backed by encrypted storage, with the encryption key supplied from the host or secret manager. Do not place long-lived API keys in workflow node parameters, notes, spreadsheets, or copied JSON exports.
Q: Is n8n credential encryption enough by itself?
It is necessary, but it is not the whole control. Encryption protects stored values, while access control, backup handling, rotation, environment isolation, and audit trails decide who can use or recover those secrets.
Q: Should I use environment variables or n8n credentials?
Use environment variables for platform-level settings and shared runtime secrets such as the n8n encryption key. Use n8n credentials for service accounts consumed by workflow nodes. Mixing those roles makes rotation and incident review harder.
Q: How often should n8n API keys be rotated?
Rotate keys on a scheduled cadence for high-risk systems, after staff or vendor changes, after any suspected exposure, and whenever a workflow changes ownership. The exact interval depends on the vendor, but the rotation path should be tested before it is needed.
Q: Can workflow exports contain secrets?
They should not contain plaintext credentials, but exports can still reveal endpoints, account names, IDs, business logic, and sometimes credential references. Treat exports as sensitive operational records, not harmless documentation.
Q: What is the safest way to share n8n access with a contractor?
Give the contractor a named user with the smallest role that can do the job, avoid sharing owner accounts, provide separate sandbox credentials where possible, and remove both app access and external vendor keys when the work ends.
Q: What should I do if an n8n credential may have leaked?
Disable or rotate the upstream credential first, then inspect executions that could have used it, replace the credential record, review logs for abnormal calls, and write a short incident note so the same exposure path is closed.
Verified Sources
Secure your n8n automations with Netholics
If your n8n instance already connects to customer systems, start with a credentials inventory and a rotation rehearsal. Netholics can audit the current setup, reduce secret sprawl, and turn the safe pattern into the default for new workflows.