Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1427c062c | ||
|
|
f1cf20f439 | ||
|
|
5f8a8607a9 | ||
|
|
c8cf5c195f | ||
|
|
3805be7b42 |
+4
-3
@@ -20,11 +20,12 @@ RUN chmod +x gradlew && ./gradlew :backend:bootJar --no-daemon -x test
|
|||||||
|
|
||||||
# 3. Runtime: not root; data in /app/data (volume)
|
# 3. Runtime: not root; data in /app/data (volume)
|
||||||
FROM eclipse-temurin:21-jre-alpine
|
FROM eclipse-temurin:21-jre-alpine
|
||||||
RUN apk add --no-cache curl && addgroup -S mail && adduser -S -G mail mail \
|
# own user: "mail" already exists in Alpine (uid 8, group 12) — addgroup mail fails
|
||||||
&& mkdir -p /app/data/attachments /app/data/dkim-keys && chown -R mail:mail /app/data
|
RUN apk add --no-cache curl && addgroup -S -g 10001 app && adduser -S -u 10001 -G app app \
|
||||||
|
&& mkdir -p /app/data/attachments /app/data/dkim-keys && chown -R app:app /app/data
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /app/backend/build/libs/*.jar app.jar
|
COPY --from=build /app/backend/build/libs/*.jar app.jar
|
||||||
USER mail
|
USER app
|
||||||
ENV MAIL_ATTACHMENTS_DIR=/app/data/attachments DKIM_KEYS_DIR=/app/data/dkim-keys
|
ENV MAIL_ATTACHMENTS_DIR=/app/data/attachments DKIM_KEYS_DIR=/app/data/dkim-keys
|
||||||
EXPOSE 8080 3025
|
EXPOSE 8080 3025
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package com.mailserver.config;
|
|||||||
|
|
||||||
import com.mailserver.security.JwtAuthenticationFilter;
|
import com.mailserver.security.JwtAuthenticationFilter;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
||||||
import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
|
import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
|
||||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||||
|
import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
||||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||||
@@ -42,6 +44,11 @@ public class SecurityConfig {
|
|||||||
public SecurityWebFilterChain filterChain(ServerHttpSecurity http) {
|
public SecurityWebFilterChain filterChain(ServerHttpSecurity http) {
|
||||||
http
|
http
|
||||||
.csrf(ServerHttpSecurity.CsrfSpec::disable)
|
.csrf(ServerHttpSecurity.CsrfSpec::disable)
|
||||||
|
// JWT only: without this an API call with no token gets 401 + "WWW-Authenticate: Basic",
|
||||||
|
// and the browser shows its own login popup where our mailbox password does not work
|
||||||
|
.httpBasic(ServerHttpSecurity.HttpBasicSpec::disable)
|
||||||
|
.formLogin(ServerHttpSecurity.FormLoginSpec::disable)
|
||||||
|
.exceptionHandling(e -> e.authenticationEntryPoint(new HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED)))
|
||||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||||
.authorizeExchange(exchange -> exchange
|
.authorizeExchange(exchange -> exchange
|
||||||
.pathMatchers("/api/login", "/api/register", "/actuator/health").permitAll()
|
.pathMatchers("/api/login", "/api/register", "/actuator/health").permitAll()
|
||||||
|
|||||||
@@ -17,13 +17,15 @@ services:
|
|||||||
for name in DB_PASSWORD JWT_SECRET; do
|
for name in DB_PASSWORD JWT_SECRET; do
|
||||||
[ -s /secrets/$$name ] || head -c 48 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' > /secrets/$$name
|
[ -s /secrets/$$name ] || head -c 48 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' > /secrets/$$name
|
||||||
done
|
done
|
||||||
# postgres reads it as uid 70, the app as "mail" — readable inside these containers only
|
# postgres reads it as uid 70, the app as uid 10001 — readable inside these containers only
|
||||||
chmod 644 /secrets/DB_PASSWORD /secrets/JWT_SECRET
|
chmod 644 /secrets/DB_PASSWORD /secrets/JWT_SECRET
|
||||||
volumes:
|
volumes:
|
||||||
- secrets:/secrets
|
- secrets:/secrets
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:17-alpine
|
# Debian, not -alpine: on Jambotron staging VMs (Alpine 3.24, kernel 6.18) the Alpine build of postgres
|
||||||
|
# dies with "Bus error" even on --version; the Debian build works (2026-11-05)
|
||||||
|
image: postgres:17
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
secrets-init:
|
secrets-init:
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
import { HttpInterceptorFn, HttpRequest, HttpHandlerFn } from '@angular/common/http';
|
import { HttpErrorResponse, HttpInterceptorFn, HttpRequest, HttpHandlerFn } from '@angular/common/http';
|
||||||
|
import { inject } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { catchError, throwError } from 'rxjs';
|
||||||
|
|
||||||
export const authInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {
|
export const authInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {
|
||||||
|
const router = inject(Router);
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
|
const request = token ? req.clone({ setHeaders: { Authorization: `Bearer ${token}` } }) : req;
|
||||||
|
|
||||||
if (token) {
|
return next(request).pipe(
|
||||||
const cloned = req.clone({
|
catchError((error: unknown) => {
|
||||||
setHeaders: {
|
// not logged in or the token expired → to the login form
|
||||||
Authorization: `Bearer ${token}`
|
if (error instanceof HttpErrorResponse && error.status === 401 && !req.url.endsWith('/login')) {
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
localStorage.removeItem('email');
|
||||||
|
router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
});
|
return throwError(() => error);
|
||||||
return next(cloned);
|
})
|
||||||
}
|
);
|
||||||
|
|
||||||
return next(req);
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user