Credentials error in queue mode

I got this error after I restarted my docker containers:

ERROR: Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data 

I an running n8n version: 0.162.0
My setup:
1 n8n server
3 n8n workers
1 postges
all n8n instances have environmental variable set:

N8N_ENCRYPTION_KEY=<random-string>

Should I set this env to the n8n server instance only?
Is there a minimal complexity for the string?

It has to be set on all. But it also has to be set on the n8n server and all n8n workers to exactly the same random string. After all is that the string that got used to encrypt the credentials, and they can only be decrypted with exactly the same string again.

The error message is saying that N8N_ENCRYPTION_KEY is currently probably set to different values on n8n servers and n8n workers. For that reason is n8n unable to decrypt the credentials.

Hope that makes sense.

@jan thanks for your reply,

Yes it has been set for all, n8n server and n8n workers.
And it has never changed but after restating I got this error.

Hey @sultan,

Were the credentials made on that main instance or imported from another instance? If you make new credentials do they work?

Hi @jon

the credentials are set in the docker yaml file,
all have the same N8N_ENCRYPTION_KEY=

each time I restart the stack I got this error

Hey @sultan,

Sorry I meant the node credentials, Is the key a static value as well or do you change it?

Hi @jon

The key is static value

Hey @sultan,

That is strange, So the key is always the same and the issue only occurs when you restart the main n8n instance?

Is it on restarts or updates, My first thought is maybe the environment variable isn’t set correctly so it is using the value in the config file and the storage volume is not persistent so it is being replaced on each update.

Hi @jon

This is the docker compose file, n8n version is not changed, restating the containers which cause the issue.
The key is always the same.

version: '3.8'

networks:
  internal:

services:
  postgres:
    image: postgres:13.5
    restart: always
    network:
      - internal
    environment:
      - POSTGRES_USER=dbuser
      - POSTGRES_PASSWORD=mysecretpassword
      - POSTGRES_DB=dpname

  n8n:
    image: n8nio/n8n:0.162.0
    restart: always
    network:
      - internal
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=dpname
      - DB_POSTGRESDB_USER=dbuser
      - DB_POSTGRESDB_PASSWORD=mysecretpassword
      - N8N_ENCRYPTION_KEY=NJK8nsKJN9NJ7jh8slk8Jokn90HJ8klL
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - NODE_ENV=production
    ports:
      - 5678:5678
  
  worker:
    image: n8nio/n8n:0.162.0
    command: n8n worker
    network:
      - internal
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=dpname
      - DB_POSTGRESDB_USER=dbuser
      - DB_POSTGRESDB_PASSWORD=mysecretpassword
      - N8N_ENCRYPTION_KEY=NJK8nsKJN9NJ7jh8slk8Jokn90HJ8klL
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - NODE_ENV=production

  redis:
    image: redis
    network:
      - internal

Any advice or help on this is appreciated

Hey @sultan,

I can’t see that anyone has tested this one yet but I also can’t see any other reports of the same issue.

I will take a look this morning and see if I can reproduce it using your compose file.

Morning @sultan,

I have just given this a test using the compose file you provided and after adding a credential and restarting the main process or the worker process the error didn’t occur. I then restarted the entire stack and everything still continued to work.

When you restart the container how are you doing it and which container are you restarting to trigger the problem?

As a test you could try running a workflow that has a function node that only contains the below that would show you what encryption key is being used.

return [{json: { encryptionKey: $env["N8N_ENCRYPTION_KEY"]}}];

Is there any chance you have another n8n instance on the same database using a different key? Maybe a test environment?

return [{json: { encryptionKey: $env["N8N_ENCRYPTION_KEY"]}}];

will give me the same given key in the stack,

I have managed to solve the issue by updating to a new version :v:t2:
Thanks for your support :blush:

1 Like