Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

ci(backend): reach the rotation databases by service name, not loopback

Calvin50311d01fa53
diff --git a/.github/workflows/run-backend-tests.yml b/.github/workflows/run-backend-tests.yml
index f53c6ec386..44f1b62cd2 100644
--- a/.github/workflows/run-backend-tests.yml
+++ b/.github/workflows/run-backend-tests.yml
@@ -97,11 +97,11 @@ jobs:
run: df -h /
- name: Wait for Secret Rotation testing databases
run: docker compose -f docker-compose.e2e-dbs.yml up -d --wait --wait-timeout 300
- # Same entry point a developer uses. The override adds host networking, which the
- # rotation specs need to reach the databases above and which only behaves this way on
- # Linux. Connection strings, mounts and the image build all live in the compose files.
+ # The same command a developer runs. The rotation databases above share the test stack's
+ # compose project, so the suite reaches them by service name and CI needs no networking of
+ # its own. Connection strings, mounts and the image build all live in the compose files.
- name: Run integration test
- run: make test-api-e2e TEST_SUITE_COMPOSE_OVERRIDE="-f docker-compose.test.ci.yml"
+ run: make test-api-e2e
env:
E2E_TEST_ORACLE_DB_19_HOST: ${{ secrets.E2E_TEST_ORACLE_DB_19_HOST }}
E2E_TEST_ORACLE_DB_19_USERNAME: ${{ secrets.E2E_TEST_ORACLE_DB_19_USERNAME }}
@@ -110,5 +110,4 @@ jobs:
- name: cleanup
if: always()
run: |
- make down-test-suite-containers TEST_SUITE_COMPOSE_OVERRIDE="-f docker-compose.test.ci.yml"
- docker compose -f "docker-compose.e2e-dbs.yml" down
+ make down-test-suite-containers
diff --git a/Makefile b/Makefile
index e1fd2cb78d..dcb9a11f9a 100644
--- a/Makefile
+++ b/Makefile
@@ -48,10 +48,11 @@ reviewable: reviewable-ui reviewable-api
# That is not a preference: the e2e harness runs `DROP SCHEMA public CASCADE` on whatever
# database it is pointed at, so aiming it at the dev database takes your data with it.
# Everything else (image, environment, mounts, service dependencies) is declared there.
-# CI adds -f docker-compose.test.ci.yml here, which is the only difference between how CI and a
-# developer run the suites. Everything else is shared.
-TEST_SUITE_COMPOSE_OVERRIDE ?=
-TEST_SUITE_COMPOSE = docker compose -f docker-compose.test.yml $(TEST_SUITE_COMPOSE_OVERRIDE) --profile runner
+TEST_SUITE_COMPOSE = docker compose -f docker-compose.test.yml --profile runner
+# The secret rotation specs reach these by service name on the shared test network, which is why
+# docker-compose.e2e-dbs.yml pins the same compose project. A full suite run needs them up; the
+# rest of the specs do not, and the Oracle image is large, so they are a separate target.
+ROTATION_DB_COMPOSE = docker compose -f docker-compose.e2e-dbs.yml
build-test-suite-image:
$(TEST_SUITE_COMPOSE) build api-tests
@@ -61,6 +62,11 @@ build-test-suite-image:
up-test-suite-containers:
$(TEST_SUITE_COMPOSE) up -d --wait db redis
+# Needed only for a full suite run, and only for the secret rotation specs.
+up-rotation-databases:
+ $(ROTATION_DB_COMPOSE) up -d --wait --wait-timeout 300
+
+# Shares a compose project with the test stack, so this removes the rotation databases too.
down-test-suite-containers:
$(TEST_SUITE_COMPOSE) down -v
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 75f48728dc..6b5fd653c5 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -25,7 +25,13 @@ Run both suites from the repo root, which is the same entry point CI uses:
- `make test-api-unit` — unit tests matching `./src/**/*.test.ts`
- `make test-api-e2e` — e2e tests matching `./e2e-test/**/*.spec.ts`
- `make test-api-e2e SPEC=<pattern>` — narrow to one spec, e.g. `SPEC=secret-sync`
-- `make down-test-suite-containers` — stop the backing services when finished
+- `make up-rotation-databases` — start the databases the secret rotation specs need, required
+ only for a full run (`docker-compose.e2e-dbs.yml`, and the Oracle image is large)
+- `make down-test-suite-containers` — stop everything when finished
+
+The secret rotation specs reach their databases by compose service name, so
+`docker-compose.e2e-dbs.yml` pins the same compose project as the test stack and shares its
+network. Without `make up-rotation-databases`, those specs fail on connection; the rest pass.
Both run inside the FIPS image (`Dockerfile.dev.fips`), which carries the native dependencies
the suites need (SoftHSM2, the Oracle client, the FIPS OpenSSL build) and pins the Node
diff --git a/backend/e2e-test/routes/v3/secret-rotations.spec.ts b/backend/e2e-test/routes/v3/secret-rotations.spec.ts
index 0b7c5f5ba3..e443a727ad 100644
--- a/backend/e2e-test/routes/v3/secret-rotations.spec.ts
+++ b/backend/e2e-test/routes/v3/secret-rotations.spec.ts
@@ -454,13 +454,16 @@ const createPostgresSecretRotation = async (
};
describe("Secret Rotations", async () => {
+ // The rotation databases are addressed by compose service name on the shared test network
+ // (docker-compose.e2e-dbs.yml), not by loopback and a published port. The suite runs inside a
+ // container, where loopback is the container itself, so the published ports are unreachable.
const testCases = [
{
type: SecretRotationType.MySQL,
name: "MySQL (8.4.6) Secret Rotation",
dbCredentials: {
database: "mysql-test",
- host: "127.0.0.1",
+ host: "mysql-8.4.6",
username: "root",
password: "mysql-test",
port: 3306
@@ -483,10 +486,10 @@ describe("Secret Rotations", async () => {
name: "MySQL (8.0.29) Secret Rotation",
dbCredentials: {
database: "mysql-test",
- host: "127.0.0.1",
+ host: "mysql-8.0.29",
username: "root",
password: "mysql-test",
- port: 3307
+ port: 3306
},
secretMapping: {
username: formatSqlUsername("MYSQL_USERNAME"),
@@ -506,10 +509,10 @@ describe("Secret Rotations", async () => {
name: "MySQL (5.7.31) Secret Rotation",
dbCredentials: {
database: "mysql-test",
- host: "127.0.0.1",
+ host: "mysql-5.7.31",
username: "root",
password: "mysql-test",
- port: 3308
+ port: 3306
},
secretMapping: {
username: formatSqlUsername("MYSQL_USERNAME"),
@@ -529,7 +532,7 @@ describe("Secret Rotations", async () => {
name: "OracleDB (23.8) Secret Rotation",
dbCredentials: {
database: "FREEPDB1",
- host: "127.0.0.1",
+ host: "oracle-db-23.8",
username: "system",
password: "pdb-password",
port: 1521
@@ -576,10 +579,10 @@ describe("Secret Rotations", async () => {
name: "Postgres (17) Secret Rotation",
dbCredentials: {
database: "postgres-test",
- host: "127.0.0.1",
+ host: "postgres-17",
username: "postgres-test",
password: "postgres-test",
- port: 5433
+ port: 5432
},
secretMapping: {
username: formatSqlUsername("POSTGRES_USERNAME"),
@@ -599,10 +602,10 @@ describe("Secret Rotations", async () => {
name: "Postgres (16) Secret Rotation",
dbCredentials: {
database: "postgres-test",
- host: "127.0.0.1",
+ host: "postgres-16",
username: "postgres-test",
password: "postgres-test",
- port: 5434
+ port: 5432
},
secretMapping: {
username: formatSqlUsername("POSTGRES_USERNAME"),
@@ -622,10 +625,10 @@ describe("Secret Rotations", async () => {
name: "Postgres (10.12) Secret Rotation",
dbCredentials: {
database: "postgres-test",
- host: "127.0.0.1",
+ host: "postgres-10.12",
username: "postgres-test",
password: "postgres-test",
- port: 5435
+ port: 5432
},
secretMapping: {
username: formatSqlUsername("POSTGRES_USERNAME"),
diff --git a/docker-compose.e2e-dbs.yml b/docker-compose.e2e-dbs.yml
index 2406cdfa3b..ed531ef387 100644
--- a/docker-compose.e2e-dbs.yml
+++ b/docker-compose.e2e-dbs.yml
@@ -1,5 +1,10 @@
version: '3.8'
+# Same project as docker-compose.test.yml, so these databases share its network and the suite
+# reaches them by service name. The alternative was host networking, which made the local and CI
+# runs behave differently and left the local one unable to reach these at all.
+name: infisical-test
+
services:
# Oracle Databases
oracle-db-23.8:
diff --git a/docker-compose.test.ci.yml b/docker-compose.test.ci.yml
deleted file mode 100644
index 321ea46911..0000000000
--- a/docker-compose.test.ci.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-# CI-only override for docker-compose.test.yml.
-#
-# The secret rotation specs address their databases as 127.0.0.1 on published ports
-# (backend/e2e-test/routes/v3/secret-rotations.spec.ts), so the suite has to share the host's
-# network namespace to reach the docker-compose.e2e-dbs.yml stack. Host networking only behaves
-# this way on Linux, so it stays out of the base file, which has to work on Docker Desktop too.
-#
-# Sharing the host namespace means Postgres and Redis are no longer reachable by service name,
-# so those two connection strings move to the ports the base file publishes.
-name: infisical-test
-
-services:
- api-tests:
- network_mode: host
- environment:
- DB_CONNECTION_URI: postgres://infisical:infisical@localhost:5436/infisical-test?sslmode=disable
- REDIS_URL: redis://localhost:6380
diff --git a/docker-compose.test.yml b/docker-compose.test.yml
index 02110410c7..ced1253bed 100644
--- a/docker-compose.test.yml
+++ b/docker-compose.test.yml
@@ -4,8 +4,8 @@
# That separation is not tidiness. The e2e harness (backend/e2e-test/vitest-environment-knex.ts)
# runs `DROP SCHEMA public CASCADE` on whatever database it is pointed at, before every run.
#
-# Started by `make test-api-services`; torn down by `make test-api-down`. There are no volumes,
-# so nothing here outlives the containers.
+# Run through `make test-api-e2e`, which starts what it needs; `make down-test-suite-containers`
+# tears it down. There are no volumes, so nothing here outlives the containers.
# Fixed so the project, and therefore the network name the test container joins, does not
# depend on the checkout directory.
@@ -14,8 +14,8 @@ name: infisical-test
services:
db:
image: postgres:14-alpine
- # A full suite run brings this stack up alongside the dev stack and the rotation databases
- # in docker-compose.e2e-dbs.yml, so host ports here must not clash with either.
+ # Published so a suite can also be run from the host. A full run brings this stack up
+ # alongside the dev stack, so the ports must not clash with it.
ports:
- "5436:5432"
environment:
@@ -75,8 +75,8 @@ services:
# setup, before a single spec runs. Booting the whole server needs more than 2GB.
NODE_OPTIONS: --force-fips --max-old-space-size=4096
TELEMETRY_ENABLED: "false"
- # The secret rotation specs need these plus `docker compose -f docker-compose.e2e-dbs.yml
- # up -d`. Left empty otherwise, which is how a run without them behaves anyway.
+ # The secret rotation specs need these plus `make up-rotation-databases`. Left empty
+ # otherwise, which is how a run without them behaves anyway.
E2E_TEST_ORACLE_DB_19_HOST: ${E2E_TEST_ORACLE_DB_19_HOST:-}
E2E_TEST_ORACLE_DB_19_USERNAME: ${E2E_TEST_ORACLE_DB_19_USERNAME:-}
E2E_TEST_ORACLE_DB_19_PASSWORD: ${E2E_TEST_ORACLE_DB_19_PASSWORD:-}