From a8888af4805cf705c12b082083f2635fe036e8f9 Mon Sep 17 00:00:00 2001 From: Peter Valdez Date: Sat, 15 Feb 2020 23:45:28 -0500 Subject: [PATCH 1/3] Set an explicit username and password for the db service --- docker-compose.yml | 5 ++++- result/server.js | 2 +- worker/src/Worker/Program.cs | 4 ++-- worker/src/main/java/worker/Worker.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5417f7c..00955d8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,6 +43,9 @@ services: db: image: postgres:9.4 container_name: db + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" volumes: - "db-data:/var/lib/postgresql/data" networks: @@ -53,4 +56,4 @@ volumes: networks: front-tier: - back-tier: \ No newline at end of file + back-tier: diff --git a/result/server.js b/result/server.js index d15a165..c4b9e90 100644 --- a/result/server.js +++ b/result/server.js @@ -24,7 +24,7 @@ io.sockets.on('connection', function (socket) { }); var pool = new pg.Pool({ - connectionString: 'postgres://postgres@db/postgres' + connectionString: 'postgres://postgres:postgres@db/postgres' }); async.retry( diff --git a/worker/src/Worker/Program.cs b/worker/src/Worker/Program.cs index e8ca4c1..e6c66d2 100644 --- a/worker/src/Worker/Program.cs +++ b/worker/src/Worker/Program.cs @@ -16,7 +16,7 @@ namespace Worker { try { - var pgsql = OpenDbConnection("Server=db;Username=postgres;"); + var pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;"); var redisConn = OpenRedisConnection("redis"); var redis = redisConn.GetDatabase(); @@ -46,7 +46,7 @@ namespace Worker if (!pgsql.State.Equals(System.Data.ConnectionState.Open)) { Console.WriteLine("Reconnecting DB"); - pgsql = OpenDbConnection("Server=db;Username=postgres;"); + pgsql = OpenDbConnection("Server=db;Username=postgres;Password=postgres;"); } else { // Normal +1 vote requested diff --git a/worker/src/main/java/worker/Worker.java b/worker/src/main/java/worker/Worker.java index 040c1a2..8121430 100644 --- a/worker/src/main/java/worker/Worker.java +++ b/worker/src/main/java/worker/Worker.java @@ -72,7 +72,7 @@ class Worker { while (conn == null) { try { - conn = DriverManager.getConnection(url, "postgres", ""); + conn = DriverManager.getConnection(url, "postgres", "postgres"); } catch (SQLException e) { System.err.println("Waiting for db"); sleep(1000); From 7d1e4a982d4dfa7de72d3907e6781f521f4c9681 Mon Sep 17 00:00:00 2001 From: Peter Valdez Date: Wed, 19 Feb 2020 14:44:32 -0500 Subject: [PATCH 2/3] Set an explicit username/password for Postgres in the other Compose files too --- docker-compose-javaworker.yml | 3 +++ docker-compose-k8s.yml | 3 +++ docker-compose-simple.yml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/docker-compose-javaworker.yml b/docker-compose-javaworker.yml index 6d20494..544865b 100644 --- a/docker-compose-javaworker.yml +++ b/docker-compose-javaworker.yml @@ -41,6 +41,9 @@ services: db: image: postgres:9.4 container_name: db + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" volumes: - "db-data:/var/lib/postgresql/data" networks: diff --git a/docker-compose-k8s.yml b/docker-compose-k8s.yml index 5a65415..4789742 100644 --- a/docker-compose-k8s.yml +++ b/docker-compose-k8s.yml @@ -7,6 +7,9 @@ services: - "6379:6379" db: image: postgres:9.4 + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" ports: - "5432:5432" vote: diff --git a/docker-compose-simple.yml b/docker-compose-simple.yml index 5834881..f8454ef 100644 --- a/docker-compose-simple.yml +++ b/docker-compose-simple.yml @@ -18,6 +18,9 @@ services: db: image: postgres:9.4 + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" result: build: ./result From e8e002bb234fac89927c62a909ce5398075e9d3b Mon Sep 17 00:00:00 2001 From: Peter Valdez Date: Wed, 19 Feb 2020 14:54:19 -0500 Subject: [PATCH 3/3] Set an explicit username/password for Postgres in the swarm and k8s files too --- docker-stack-simple.yml | 5 ++++- docker-stack.yml | 3 +++ k8s-specifications/db-deployment.yaml | 5 +++++ kube-deployment.yml | 4 ++++ result/docker-compose.test.yml | 3 +++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docker-stack-simple.yml b/docker-stack-simple.yml index 8189386..04f5dd9 100644 --- a/docker-stack-simple.yml +++ b/docker-stack-simple.yml @@ -16,6 +16,9 @@ services: condition: on-failure db: image: postgres:9.4 + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" volumes: - db-data:/var/lib/postgresql/data networks: @@ -78,4 +81,4 @@ networks: backend: volumes: - db-data: \ No newline at end of file + db-data: diff --git a/docker-stack.yml b/docker-stack.yml index c7ffa76..e80f8c2 100644 --- a/docker-stack.yml +++ b/docker-stack.yml @@ -14,6 +14,9 @@ services: condition: on-failure db: image: postgres:9.4 + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" volumes: - db-data:/var/lib/postgresql/data networks: diff --git a/k8s-specifications/db-deployment.yaml b/k8s-specifications/db-deployment.yaml index f552a75..55622bb 100644 --- a/k8s-specifications/db-deployment.yaml +++ b/k8s-specifications/db-deployment.yaml @@ -18,6 +18,11 @@ spec: containers: - image: postgres:9.4 name: postgres + env: + - name: POSTGRES_USER + value: postgres + - name: POSTGRES_PASSWORD + value: postgres ports: - containerPort: 5432 name: postgres diff --git a/kube-deployment.yml b/kube-deployment.yml index e56956c..c567e38 100644 --- a/kube-deployment.yml +++ b/kube-deployment.yml @@ -77,6 +77,10 @@ spec: env: - name: PGDATA value: /var/lib/postgresql/data/pgdata + - name: POSTGRES_USER + value: postgres + - name: POSTGRES_PASSWORD + value: postgres ports: - containerPort: 5432 name: db diff --git a/result/docker-compose.test.yml b/result/docker-compose.test.yml index 0df964e..42e15e4 100644 --- a/result/docker-compose.test.yml +++ b/result/docker-compose.test.yml @@ -47,6 +47,9 @@ services: db: image: postgres:9.4 + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" volumes: - "db-data:/var/lib/postgresql/data" networks: