Skip to content

Commit c57e378

Browse files
authored
Fix schema public permission denied for migrator (#162)
* Add TODOs for authentication errors that was missed with my last PR * Set the DATABASE_SCHEMA env var for the migrator service to use when applying migrations * Print out the database schema being used for migrations * Try setting the schema CLI flag explicitly
1 parent 3eb12c6 commit c57e378

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ services:
3838
ROLE: migrator # entrypoint knows to migrate
3939
RUST_ENV: ${RUST_ENV} # development, staging, production
4040
POSTGRES_SSL_ROOT_CERT: ${POSTGRES_SSL_ROOT_CERT}
41+
DATABASE_SCHEMA: ${POSTGRES_SCHEMA:-public}
4142
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?${POSTGRES_OPTIONS}
4243
PLATFORM: ${PLATFORM}
4344
BACKEND_IMAGE_NAME: ${BACKEND_IMAGE_NAME}
@@ -61,7 +62,7 @@ services:
6162
POSTGRES_USER: ${POSTGRES_USER}
6263
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
6364
POSTGRES_DB: ${POSTGRES_DB}
64-
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA}
65+
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA:-public}
6566
POSTGRES_HOST: ${POSTGRES_HOST}
6667
POSTGRES_PORT: ${POSTGRES_PORT}
6768
POSTGRES_SSL_ROOT_CERT: ${POSTGRES_SSL_ROOT_CERT}

entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ main() {
6363
log_info "Running in MIGRATOR mode"
6464
validate_binary "migrationctl"
6565
validate_env "DATABASE_URL"
66+
validate_env "DATABASE_SCHEMA"
6667
validate_env "RUST_ENV"
6768

6869
log_info "Running in $RUST_ENV environment"
70+
log_info "Using schema $DATABASE_SCHEMA to apply the migrations in"
6971

7072
log_success "Running SeaORM migrations..."
71-
exec /app/migrationctl up
73+
exec /app/migrationctl up -s $DATABASE_SCHEMA
7274
;;
7375

7476
app)

web/src/controller/user_session_controller.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub async fn login(
3838
mut auth_session: AuthSession,
3939
Form(creds): Form<Credentials>,
4040
) -> WebResult<impl IntoResponse> {
41-
debug!("UserSessionController::login()");
42-
4341
let user = match auth_session.authenticate(creds.clone()).await {
4442
Ok(Some(user)) => user,
4543
Ok(None) => {
4644
// No user found - this should also be treated as an authentication error
45+
warn!("Authentication failed, invalid user: {:?}", creds.email);
46+
// TODO: replace this with a more idiomatic Rust 1-liner using from/into
4747
return Err(WebError::from(domain::error::Error {
4848
source: None,
4949
error_kind: domain::error::DomainErrorKind::Internal(
@@ -54,8 +54,10 @@ pub async fn login(
5454
}));
5555
}
5656
Err(auth_error) => {
57-
// axum_login errors contain our entity_api::Error in the error field
58-
warn!("Authentication failed: {:?}", auth_error);
57+
// Convert axum_login error to WebError by creating domain error manually.
58+
// This maps EntityApiErrorKind::RecordUnauthenticated to a 401 through the web layer.
59+
error!("Authentication failed with error: {:?}", auth_error);
60+
// TODO: replace this with a more idiomatic Rust 1-liner using from/into
5961
return Err(WebError::from(domain::error::Error {
6062
source: Some(Box::new(auth_error)),
6163
error_kind: domain::error::DomainErrorKind::Internal(

0 commit comments

Comments
 (0)