Skip to content

Commit

Permalink
Merge pull request #1380 from swisstopo/feature/viewer-1345-enforce-ssl
Browse files Browse the repository at this point in the history
Feature 1345: Enforce SSL
  • Loading branch information
daniel-va authored Nov 27, 2024
2 parents 48d6733 + 90d816d commit 88a5c94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Added
- Add `PG_SSL_MODE` environment variable to allow SSL connections between the API and database.

### Changed
- Values for "Height", "Angle", "Pitch", and coordinates are now input fields. Users can adjust values using arrow keys.
Expand Down
4 changes: 3 additions & 1 deletion api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ PGPASSWORD=www-data
PGHOST=db
PGPORT=5432
PGDATABASE=swissgeol-local
PG_SSL_MODE=disable
# PG_SSL_MODE=require

# SQLx
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}?ssl_mode=${PG_SSL_MODE}

# S3
S3_AWS_REGION=eu-west-1
Expand Down
5 changes: 3 additions & 2 deletions api/DockerfileDev
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ FROM rust:1.82

WORKDIR /app

RUN cargo install cargo-watch

RUN cargo install cargo-watch && \
rustup component add rustfmt && \
rustup component add clippy
COPY . .

RUN chmod +x start.sh
Expand Down
8 changes: 6 additions & 2 deletions api/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
postgres::{PgConnectOptions, PgPoolOptions, PgSslMode},
Connection, Executor, PgConnection, PgPool,
};

Expand All @@ -20,6 +20,9 @@ pub struct Database {
/// The database name
#[clap(long, env)]
pub pgdatabase: String,
/// The database ssl mode
#[clap(env)]
pub pg_ssl_mode: PgSslMode,
}

impl Database {
Expand All @@ -34,7 +37,8 @@ impl Database {
.host(&self.pghost)
.port(self.pgport)
.username(&self.pguser)
.password(&self.pgpassword);
.password(&self.pgpassword)
.ssl_mode(self.pg_ssl_mode);

if create {
// Create database
Expand Down

0 comments on commit 88a5c94

Please sign in to comment.