Bad n8n credentials decrypt when running cron

Describe the problem/error/question

I’ve added the n8n workflow template, which back ups the workflows to github. When ran manually it executes without any problems, however the 12 hour cron is giving me a decryption error.

What is the error message (if any)?

Error: error:1C800064:Provider routines::bad decrypt
    at Decipheriv.final (node:internal/crypto/cipher:199:29)
    at Cipher.decrypt (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/Cipher.js:36:67)
    at Credentials.getData (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/Credentials.js:30:43)
    at CredentialsHelper.getDecrypted (/usr/local/lib/node_modules/n8n/dist/CredentialsHelper.js:203:51)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at getCredentials (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/NodeExecuteFunctions.js:1261:33)
    at RoutingNode.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/RoutingNode.js:60:32)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:707:23)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:652:53

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.16.0
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): queue mode
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: ubuntu 20.04

Hey @Dominic_Jay,

It sounds like one of your workers might not be configured correctly, Can you share how you have n8n deployed? I suspect the worker might not be using the same encryption key as the main instance or something.

Appreciate the reply @Jon!

Here it is:

version: “3.7”

services:
caddy:
image: caddy:latest
restart: unless-stopped
ports:
- “80:80”
- “443:443”
volumes:
- caddy_data:/data
- ${DATA_FOLDER}/caddy_config:/config
- ${DATA_FOLDER}/caddy_config/Caddyfile:/etc/caddy/Caddyfile

n8n:
image: docker.n8n.io/n8nio/n8n
restart: always
ports:
- 5678:5678
environment:
- N8N_HOST=${SUBDOMAIN}.${DOMAIN}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- DB_TYPE=postgresdb
- DB_POSTGRESDB_DATABASE=n8n_db
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_USER=redacted
- DB_POSTGRESDB_PASSWORD=redacted
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- QUEUE_BULL_REDIS_PORT=6379
- N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN=true
volumes:
- n8n_data:/home/node/.n8n
- ${DATA_FOLDER}/local_files:/files

postgres:
image: postgres:latest
restart: always
environment:
- POSTGRES_DB=n8n_db
- POSTGRES_USER=redacted
- POSTGRES_PASSWORD=redacted
volumes:
- postgres_data:/var/lib/postgresql/data # This line is for data persistence

redis:
image: redis:latest
restart: always
ports:
- “6379:6379”

n8n_worker:
image: docker.n8n.io/n8nio/n8n
restart: always
command: worker
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_DATABASE=n8n_db
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_USER=redacted
- DB_POSTGRESDB_PASSWORD=redacted
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- QUEUE_BULL_REDIS_PORT=6379

volumes:
caddy_data:
external: true
n8n_data:
external: true
postgres_data:

That looks like it should work, can you try updating all of your n8n instances and see if that changes anything? Did you always have the encryption key environment variable set for your worker as well?

We are facing the exact same issue. After upgrading up to 1.20 all of our credentials cannot be decrypted with error: Error: error:1C800064:Provider routines::bad decrypt

We use docker compose. Nothing change since the update. Only one server no workers and the encryption key is still the same.

Adding the key as env variable as described here also does not change anything: Provider routines::bad decrypt after upgrading to 1.18.0

we are seeing this as well, after upgrading to 1.21 from 1.8 and seeing Error: error:1C800064:Provider routines::bad decrypt

we already have N8N_ENCRYPTION_KEY configured and didn’t change it for a long time. We do use custom docker file and have the “USER node” appended at the end as suggested, but still no luck.

And even we revert back to 1.8 we still got this Error: error:1C800064:Provider routines::bad decrypt, it seems the changes was persisted to database somehow.

Chiming in here. I found that the encryptionkey in my volume drive was not updated with the encryptionkey I created when upgrading to queue mode. I would check your config in the volume if the key matches. Found mine was using an old key. Recreated credential to be sure before testing also now no longer get decryption errors. May be worth checking for some.

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.