Secrets and Credentials in n8n: Secure Operations
Encryption is one control, not the entire trust boundary
Key custody, least privilege, effective access, redaction and rotation
Original CRED-8 architecture with failure modes and production acceptance criteria
n8n credential security, encryption keys, external secrets, access control, rotation, restore and audit evidence

$ secure n8n --contract CRED-8
> inventory: owner / environment / consumers
> protect: encryption-key / credential-store / vault
> authorize: identity / least-privilege / denied-path
> rotate: canary / overlap / revoke / verify
> audit: redaction / restore / incident-evidenceThe problem: a credential is not just a value in a node
An n8n workflow can look harmless while holding authority to send money, update a CRM, read customer documents or administer cloud infrastructure. The visual graph shows the business sequence; it does not show the complete security boundary. That boundary also includes the n8n database, the instance encryption key, runtime environment, external secret manager, user and project permissions, execution data, logs, backups and every target API.
Secure credential operations therefore starts with a stricter statement:
> A secret is confidential material. A credential is secret material plus an identity, scope, owner, target, lifecycle and revocation path.
Putting an API token in n8n's credential store is safer than pasting it into a Set or Code node, but it is not the finish line. The token may still be too powerful, shared too broadly, impossible to rotate without downtime or exposed indirectly through execution payloads. This guide uses CRED-8, an original eight-control architecture for reducing those risks without pretending that one vault or one environment variable solves everything.
The broad commercial question of who can design and operate AI automation in Armenia belongs to the AI specialist in Armenia and AI automation service pages. This article stays narrow: how to design, test and operate secrets and credentials in n8n.
Requirements before choosing a storage mechanism
Write a credential contract before creating the credential:
credential_contract:
id: crm-orders-prod-write
owner: revenue-operations
environment: production
target: crm.example
auth_method: oauth2-client
allowed_actions:
- order.read
- order.note.create
denied_actions:
- user.admin
- order.delete
consumers:
- workflow: order-triage-v3
rotation:
maximum_age_days: 90
overlap_supported: true
revocation:
owner: security-on-call
verification: target-api-readbackThe exact fields can change, but five questions cannot remain implicit:
- Which identity is used?
- What is the smallest scope needed by this workflow?
- Who can use or change it?
- How is it rotated and revoked?
- What evidence proves that the old value no longer works?
Do not reuse a founder's personal token because it already exists. Do not let development and production share the same credential. Do not grant a whole CRM or cloud account when the workflow needs one read and one bounded write. Least privilege must exist at the target system as well as inside n8n.
CRED-8: the architecture from source to audited use
C1 — Inventory authority, not only secret names
Maintain a registry that connects each credential to its owner, environment, target scopes, workflow consumers, creation date, rotation deadline and revocation procedure. A name such as Google API is not enough. billing-export-prod-readonly, owned by Finance Operations, is inspectable.
The inventory must cover more than n8n credential objects. Include N8N_ENCRYPTION_KEY, database access, Redis access in queue mode, SMTP, object storage, runner credentials, webhook authentication and backup decryption material. Mark which values are platform infrastructure and which represent business-system authority.
C2 — Separate secret sources by responsibility
Use three explicit layers:
- Instance key layer:
N8N_ENCRYPTION_KEYprotects n8n credential data. For self-hosted installations, set and custody it deliberately rather than relying on an unmanaged local file. - Credential layer: n8n credential objects hold authentication material used by nodes. Workflows reference credentials; they should not contain literal tokens.
- Infrastructure layer: a deployment secret store or external secrets provider supplies instance-level values and, where supported, centrally managed secrets.
n8n documents an external secrets feature and configuration options for a custom encryption key. Feature availability depends on the deployment and plan, so the architecture must record the actual capability rather than assume every installation includes it.
C3 — Keep the encryption key stable, protected and recoverable
Encrypted credentials are only useful if every process that needs them can decrypt them and unauthorized processes cannot. In a single instance, losing the encryption key can make stored credentials unusable. In queue mode, main and worker processes need the same key.
Treat the key as recovery-critical material:
- inject it at runtime from a protected deployment source;
- restrict access to the service identity;
- do not commit it to Compose files, repositories or workflow JSON;
- back it up separately from the database, with tested access controls;
- test restoration with a disposable instance;
- never rotate it by simply replacing the value and restarting production.
Database encryption does not protect a secret after a legitimately authorized node has decrypted and used it. Scope, permissions and runtime isolation remain necessary.
C4 — Enforce least privilege at the target
Create a dedicated service identity per environment and meaningful trust boundary. Prefer short-lived OAuth tokens or workload identity when the target supports them. If a static API key is unavoidable, restrict it by scope, resource, network and expiry where possible.
One credential per node is not the goal. One credential per bounded authority is. Several workflows may safely share the same read-only catalog identity; a workflow that issues refunds should not share an administrator token with unrelated flows.
Test the denied path. A credential contract is incomplete until an automated or controlled test proves that forbidden operations fail.
C5 — Limit who can attach and execute credentials
n8n workflow and credential permissions must match operational roles. Sharing a workflow can allow editors to use credentials referenced by that workflow even when the credential is not separately shared; n8n documents this behavior in workflow sharing. Review project membership, workflow sharing, credential sharing and instance administration together.
Separate these abilities where the edition and operating model allow:
- create or update workflows;
- attach an existing production credential;
- edit or share a credential;
- activate or publish a workflow;
- inspect execution data;
- administer the instance.
A protected production environment is stronger than a policy asking developers not to click the wrong button.
C6 — Prevent secret material from entering data and logs
Credentials should be resolved at execution time, not copied into item JSON. Never use expressions to move raw tokens into ordinary fields. Do not include secrets in node names, errors, manual test payloads, pinned data, webhook responses or support screenshots.
Redaction needs negative tests with canary values:
const forbidden = [
process.env.TEST_SECRET_CANARY,
"Authorization: Bearer",
"client_secret",
];
for (const surface of [executionJson, applicationLog, errorEvent]) {
assert(!forbidden.some((value) => value && surface.includes(value)));
}Execution retention is part of secret safety. Store only what is needed for debugging and audit, prune it on a documented schedule and restrict who can read failed executions. Binary files, request headers and third-party error bodies deserve the same review as JSON.
C7 — Rotate through overlap, validation and rollback
Rotation is a release, not an edit. Use a two-version procedure when the target supports overlapping credentials:
- Create the new credential with the same bounded scope.
- Validate it in a non-destructive health workflow.
- Update one canary consumer.
- Observe authentication errors and business receipts.
- Move remaining consumers.
- Revoke the old value at the target.
- Prove old-value rejection and new-value success.
- Update inventory and next-rotation deadline.
If overlap is impossible, schedule a controlled window, pause triggers, drain executions, switch atomically and keep a recovery path that does not restore a compromised credential. Rollback should restore service behavior, not blindly reactivate a secret that was revoked because of an incident.
C8 — Audit continuously and rehearse incidents
n8n provides a security audit through the CLI, API or n8n node. Its reports include unused credentials, risky nodes, file-system access, database-expression risks, unprotected webhooks and missing instance settings. Use it as one input, not as a certificate of safety.
Add your own evidence:
- credentials without owners or rotation dates;
- active workflows using deprecated identities;
- production credentials attached to development workflows;
- scope drift at target APIs;
- secret-like canaries found in executions or logs;
- failed rotations and expired credentials;
- access changes in projects and administrator roles;
- backup and restore exercises.
An incident drill should answer: which workflows consume the secret, how to disable them, how to revoke the identity, what data may have been exposed, how to rotate dependants and what evidence closes the incident.
Key components and their contracts
| Component | Owns | Must not own | Verification |
|---|---|---|---|
| Secret source | encrypted value delivery | workflow business logic | runtime can fetch; repository cannot |
| n8n credential store | node authentication material | target authorization policy | credential works only in intended environment |
| Encryption key custody | decryptability and recovery | per-API business scopes | restore drill on disposable instance |
| Target IAM | identity scope and expiry | workflow orchestration | allowed call succeeds; denied call fails |
| n8n project/RBAC | who can use and change assets | target-side authorization | role matrix and access review |
| Execution storage | bounded operational evidence | reusable secret material | canary absent; retention enforced |
| Rotation controller | version transition and receipts | undocumented manual edits | old version revoked after verified cutover |
| Audit pipeline | findings and ownership | false “secure” score | each finding has evidence and due date |
The important design property is independence. A database breach should not automatically grant target administration. A leaked read-only API credential should not decrypt every other credential. A workflow editor should not automatically become an instance administrator. A backup operator should not receive all recovery keys by default.
Failure modes that survive encryption
A key is generated locally and never backed up
The database backup restores, but all credentials fail to decrypt. The fix is controlled key custody and a tested restore, not another database snapshot.
Every process receives a different key
The main instance works while workers fail, or a new deployment cannot decrypt existing credentials. Distribute the same approved key to the exact n8n components that require it and verify startup before traffic cutover.
One administrator token powers every workflow
Encryption protects the token at rest, but any compromised consumer inherits broad authority. Replace it with dedicated identities and scopes, then test forbidden actions.
Secrets are pasted into workflow JSON
Source control, exports, execution data and support bundles become leakage channels. Move values into credentials or a managed secret source, purge copies through an incident process and rotate the exposed value.
Rotation changes the value but not the consumers
Some workflows silently keep old credentials until the first scheduled run. Maintain a consumer map and canary each activation path before revocation.
Logs hide the token but expose the response
A provider error may echo request headers or sensitive account data. Test real failure payloads and sanitize at both application and log-shipping boundaries.
A credential is “not shared” but a shared workflow can use it
Operational access is broader than the credential-sharing screen suggests. Review workflow sharing and project membership as part of the effective permission graph.
Testing and production gate
Use a disposable target account where possible. Never test revocation or destructive denied actions against a valuable production identity.
Configuration tests
- The repository and workflow exports contain no known secret canaries.
- Production, staging and development use distinct identities.
N8N_ENCRYPTION_KEYis explicitly supplied and consistent across required processes.- Backup storage and key custody are separated.
- Service files and container metadata do not expose plaintext values to unauthorized users.
Authorization tests
- Every allowed operation succeeds with the intended identity.
- At least one meaningful forbidden operation returns an authorization failure.
- Project roles cannot attach, share or edit credentials beyond policy.
- Removing a user or service identity removes effective access.
Runtime and leakage tests
- Success, provider rejection, timeout and malformed-response paths contain no secret canary in execution data, logs, alerts or webhook responses.
- Manual executions and pinned data do not persist authentication material.
- Error workflows receive redacted context and a stable correlation ID.
Rotation and recovery tests
- The new credential passes a non-destructive probe.
- Canary consumers move before bulk consumers.
- The old value is rejected after revocation.
- The instance restores from database plus approved key in an isolated environment.
- Queue workers decrypt and execute after restart.
Acceptance criteria
Release the credential only when:
- Owner, consumer map, environment and target scopes are documented.
- No literal secret exists in workflow code, pinned data or repository history under review.
- Allowed and denied target operations have evidence.
- Effective n8n access matches the role matrix.
- Logs and executions pass canary leakage tests.
- Rotation has a tested overlap or maintenance procedure.
- Revocation and incident ownership are explicit.
- Restore evidence proves credentials remain usable without exposing the key.
- Audit findings have owners and due dates.
- Production activation has a reversible workflow release and observable receipt.
What to do after the review
Start with the highest-authority credential, not the easiest one. Build its contract, trace every consumer, test scope and leakage, then rehearse rotation. Repeat the same process for the next trust boundary.
If the workflow also contains AI decisions, combine credential controls with a human approval gate, bounded retries and dead-letter recovery, and the broader production n8n architecture. For implementation evidence and delivery patterns, review the case studies.
A useful architecture review should return concrete artifacts: the credential registry, target-scope matrix, effective access graph, leakage-test results, rotation runbook and incident checklist. Those artifacts make secure operation repeatable; a screenshot of a vault does not.
require(contract.owner && contract.scope && contract.consumers);
require(key.recoverable && deniedPath.tested && leakageScan.clean);
release = rotateCanary() && revokeOld() && verifyTargetReceipt();