N8N Postgre Authentication using Service Principal

Describe the problem/error/question

I wish to use Postgre DB instead of SQLite for n8n deployment in Azure. My org policies deny creation of standalone postgre users. I have to use EntraID (managed identity) or service principal.

For N8N deployment I have to provide DB user and DB password. Is there a way to use managed identities/spn-s and token authentication instead of static db user?
Do I have to edit source code to make the app rotate access tokens for each DB request, or maybe there is another solution?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: index.docker.io/n8nio/n8n:1.108.1
  • Database (default: SQLite): postgre
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Azure WebApp Container
  • Operating system: docker container

Thank you @Bringasher .
Is there any documentation how can I enable this? Is there any built-in ENV variable where I can provide credentials for my SPN (appid/app secret) or a system assigned managed identity?

Should I leave ‘DB_Password’ env var empty?

@Bringasher
This medium.com guide you provided describes DB authentication using standalone admin postgre user, not Managed Identity/SPN.

Microsoft documentation that you provided describes exacly how we can use managed identities with postgresql, however it’s only about setting the EntraID identity reference inside postgres.
I know how to setup this (and I have it setup already), but the point is:
How can I dynamically generate tokens for this Identity and refresh those tokens in N8N Application?
Of course I can generate access token manually and pass it to the N8N as DB_Password, but this token lives 1 hour, and after that time my n8n app cannot connect with DB anymore.

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