Hosting n8n with Docker and a custom Postgres setup. How can one programmatically configure the primary account to secure the n8n API key? Example configuration provided below:
backend:
image: postgres:13-alpine
ports:
- "5432:5432"
environment:
POST_USER: admin
POST_PASS: admin
DATA_DIR: /data/pg
volumes:
- ./database:/var/lib/postgresql/data
- ./db-init:/docker-entrypoint-initdb.d:ro
workflow:
image: docker.n8n.io/n8nio/n8n
ports:
- "5678:5678"
environment:
- SQL_TYPE=postgres
- SQL_PREFIX=workflow_
- SQL_DATABASE=n8n
- SQL_HOST=backend
- SQL_PORT=5432
- SQL_USER=admin
- SQL_PASS=admin
volumes:
- ./workflow_data:/home/n8n/.n8n
- ./workflow_files:/files
Based on my experience managing a self-hosted n8n instance, I found that automating the assignment of the owner account requires a bit more custom scripting than simply setting environment variables in your Docker Compose file. I had to integrate a startup script to interface with the Postgres database directly, ensuring the primary account was created during initialization. One effective method was to set up an entrypoint script for the n8n container that checks for the account and creates it if absent. This may not be officially documented, but implementing such a strategy has proved invaluable in streamlining deployment and enhancing API security.
hey, i solved it by adding a post-start sql script that inspects and creates the owner accoutn if missing. its a bit of a hack but works well for my setup.
In my experience, automating the owner assignment in n8n can be streamlined by creating a dedicated initialization routine that runs at container startup. I implemented a custom script that connects directly to the Postgres database after the container starts and checks if the primary account exists. If not, the script creates the account while ensuring API key security. This approach, although added to the startup process, provides the flexibility to modify account details as needed and avoids manual intervention after deployment.