-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issues with insecure default password
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PGPASSWORD=$DB_PASSWORD | ||
DATABASE_URL=postgres://postgres:$DB_PASSWORD@localhost/ccd-scan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
ARG build_image=rust:1.76-bookworm | ||
ARG base_image=debian:bookworm-slim | ||
FROM ${build_image} AS build | ||
|
||
WORKDIR /usr/app/concordium-scan | ||
|
||
COPY ./Cargo.toml ./Cargo.lock ./ | ||
COPY ./src ./src | ||
RUN cargo install sqlx-cli --no-default-features --features "postgres" | ||
RUN cargo build --release --locked | ||
|
||
|
||
FROM ${base_image} | ||
|
||
WORKDIR /usr/app | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y gnupg wget lsb-release && \ | ||
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/postgres.list' && \ | ||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \ | ||
apt-get update && \ | ||
apt-get -y install \ | ||
ca-certificates \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY notification-server/resources /usr/app/resources | ||
COPY --from=build /usr/app/notification-server/target/release/notification-api /usr/app/notification-server/target/release/notification-service /usr/bin/ | ||
COPY --from=build $HOME/.cargo/bin/sqlx-cli /usr/local/bin/sqlx-cli | ||
|
||
RUN chmod +x /usr/bin/notification-api /usr/bin/notification-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.DEFAULT_GOAL := all | ||
|
||
all: docker-up wait-for-db create-tables | ||
|
||
setup: setup-db | ||
|
||
setup-db: | ||
@echo "Setting default password" | ||
@DB_PASSWORD=$$(openssl rand -base64 12) && \ | ||
export DB_PASSWORD=$$DB_PASSWORD && \ | ||
cat .env.template | envsubst > .env | ||
|
||
docker-up: | ||
@echo "Starting Docker containers..." | ||
docker compose up -d db | ||
|
||
# Target to wait for the PostgreSQL database to be ready. | ||
wait-for-db: | ||
@echo "Waiting for the database to be ready..." | ||
@max_attempts=10; \ | ||
current_attempt=1; \ | ||
until docker compose exec -T db pg_isready -U postgres; do \ | ||
sleep 5; \ | ||
current_attempt=$$((current_attempt+1)); \ | ||
if [ $$current_attempt -gt $$max_attempts ]; then \ | ||
echo "Database did not become ready in time."; \ | ||
exit 1; \ | ||
fi; \ | ||
echo "Retrying ($$current_attempt/$$max_attempts)..."; \ | ||
done | ||
|
||
create-tables: | ||
@echo "Creating tables from SQL files..." | ||
cargo sqlx prepare | ||
|
||
.PHONY: setup setup-db all docker-up wait-for-db create-tables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
version: '3.9' | ||
services: | ||
|
||
db: | ||
image: "postgres:16" | ||
image: postgres:16 | ||
restart: always | ||
ports: | ||
- 5432:5432 | ||
- "5432:5432" | ||
volumes: | ||
- ./data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: example | ||
POSTGRES_PASSWORD: ${PGPASSWORD} | ||
POSTGRES_DB: ccd-scan |