Repository navigation
Feature: straightmail v0.5.0 - #4
Open
codeministry wants to merge 48 commits into
Open
codeministry wants to merge 48 commits into
codeministry wants to merge 48 commits into
Conversation
…Spring Boot 3.5.7 / Java 21)
- **feat(backend): expose additional ports 50003, 50004 in Dockerfile** 🐳
codeministry
marked this pull request as draft
May 29, 2026 10:13
codeministry
marked this pull request as ready for review
May 29, 2026 10:14
…ead of `client/package.json`
…encies and adapt imports
…ASSPATH references
…nfiguration in README.md
- Add tenant configuration instructions (`TENANTS_CONFIG`) for non-database profiles. - Document breaking changes for template directory structure and tenant subdirectories. - Update Docker Compose examples with new environment variables and volume mappings.
# Conflicts: # backend/src/test/java/com/encircle360/oss/straightmail/AbstractTemplateLoaderTest.java # src/main/java/com/encircle360/oss/straightmail/service/EmailService.java # src/main/java/com/encircle360/oss/straightmail/service/template/AbstractTemplateLoader.java
…rove error logging functionality - Added AbstractTemplateLoaderTest to validate template loading scenarios, covering missing and partial templates. - Enhanced error logging in `AbstractTemplateLoader` to differentiate required vs optional template file handling. - Improved `EmailService` logging to provide better operator visibility for email requests and SMTP dispatch events.
…grate error messages
…a toolchain to version 25 - Bump dependencies: updated `sqlite-jdbc`, `hibernate-community-dialects`, `jsoup`, `lombok`, and others to latest versions. - Update base Docker image to Temurin 25 and optimize layering for image build process. - Adjust Gradle wrapper scripts for compatibility with the new Gradle version.
…o 25 across workflows and dependencies - Update workflows to use Node.js 22 and Java 25. - Upgrade Angular framework and related dependencies to 22.1.x. - Add `.nvmrc` for Node.js version management. - Minor template formatting adjustments in frontend components.
… of ngModel
The five shared field components received the real form control as an input but
mirrored its value by hand: an internal signal, a valueChanges subscription and a
ControlDirtyDirective that re-implemented the dirty marking reactive forms already
provide. They now bind [formControl] directly, which also removes the NG01354
warning by removing its cause rather than opting out of it.
Call sites use the typed form.controls.x instead of form.get('x'), and the
redundant [disabled] bindings on text and select fields are gone where the control
itself is already disabled. ControlDirtyDirective is deleted along with its spec.
CodeEditorComponent now buffers writeValue and setDisabledState until its view
exists. Reactive forms call both during directive init, before ngAfterViewInit
creates the editor, so without buffering the editor stayed empty and editable.
Tenants author their own templates, so template source and template ids are untrusted input. Two holes followed from that. FreeMarker was left at its default TemplateClassResolver.UNRESTRICTED_RESOLVER, so the ?new built-in could instantiate any class on the classpath — including freemarker.template.utility.Execute, which runs OS commands. Any caller holding a per-tenant API key (ROLE_USER, no admin) could reach it through POST /v1/email/inline or a stored template, read the process environment and with it ENCRYPTION_KEY, which decrypts every tenant's SMTP password and git token. FreemarkerSecurityConfig now sets ALLOWS_NOTHING_RESOLVER and disables the ?api built-in once at startup. The object wrapper moves there too: Configuration is a shared singleton, so setting it per request was both a race and repeated startup work. FileTemplateSourceProvider resolved template names against the tenant directory without normalising or confining them, so "../other-tenant/welcome" read another tenant's template — over the URL with the ::-encoding and, bypassing any URL filtering entirely, over the templateId in the JSON body of /v1/render and /v1/email. Paths are now normalised and checked to stay under the tenant directory. AbstractTemplateLoader had the same flaw on both its classpath and filesystem paths and gets the same guard; ClassPathResource normalises ".." away rather than refusing it, so the check has to happen before the lookup. Both were reproduced by tests that fail without the fixes.
TenantReadController.list() and get(slug) had no authorization at all, while every write in TenantAdminController requires ROLE_ADMIN and the sibling /me filters by identity. A customer holding only their own per-tenant API key could therefore enumerate every tenant on a shared installation and read each one's smtpHost, smtpPort, smtpUser, smtpSender, gitRepoUrl and hasApiKey — mail relay infrastructure plus half a credential pair. Passwords and tokens were correctly withheld. Both endpoints are admin-only now. That matches their only consumer: the admin UI reads them, while the login and startup flows use /v1/tenants/me, which stays open.
No filter chain configured any headers, so responses carried only Spring Security's defaults and no Content-Security-Policy. That matters here because SpaController serves the admin UI from the same origin as the API and the access token lives in browser storage: a script injected into that origin reads it. All three chains now send a CSP, a Referrer-Policy and HSTS, and forward-headers-strategy is set so HSTS is actually emitted behind a TLS terminator. The policy is derived from the deployment (the configured OIDC issuer is added to connect-src, frame-src and form-action) and can be replaced wholesale via security.content-security-policy. A strict script-src broke the app on first try: NGXS compiles selector property getters with new Function(), so the bundle needs 'unsafe-eval' unless NGXS is told otherwise. Rather than weaken the policy for exactly the attack it exists to stop, the store now runs with compatibility.strictContentSecurityPolicy. Alongside that: actuator exposure is set explicitly instead of relying on the framework default, mavenCentral comes before mavenLocal so a stale local artifact cannot win, the compose stacks bind their ports to 127.0.0.1 instead of 0.0.0.0, and docker/README.md states what a real deployment has to change — these stacks ship dev credentials and run without the production profile, so Swagger is reachable by design.
…by origin The production build configuration had no fileReplacements, so environment.prod.ts was dead code and every production bundle carried the development environment: an http://localhost:50003/api fallback, http://localhost:8090 as the OIDC issuer fallback and logLevel 1, which makes angular-auth-oidc-client log its flow to the browser console. production being false also revealed the API base URL on the dashboard. Fixing that alone would have broken the app at load: the interceptors computed their base path with new URL(environment.apiUrl) and no base argument, which throws for the relative "/api" the backend returns by default. It only worked because the dev environment's absolute fallback was shipping. Both changes therefore belong together. While in those files, credentials are now scoped by origin as well as path. A request to a foreign host whose path happens to start with the API base no longer receives the bearer token or the API key. auth.interceptor.ts had no spec at all; it has one now.
…in-repo The repository's default branch is master, but backend.yml, frontend.yml and monorepo.yml triggered on main only and therefore never ran — including the docker gate in backend.yml. The one workflow that did trigger, release.yml, could not succeed: it called ./gradlew and ./Dockerfile from the repo root although both live under backend/, never made gradlew executable and had no SKIP_FRONTEND_BUILD despite having no Node setup. The practical result was that SBOM and provenance, which only that workflow produced, reached nothing: whatever images exist were pushed unscanned and unattested. All workflows now trigger on [master, main], so this works today and survives a rename. release.yml is fixed, and its docker context is scoped to ./backend so the dev compose stacks and their placeholder credentials stay out of the build context. backend.yml and monorepo.yml — the workflows that actually push — now produce an SBOM and provenance and run a Trivy scan, which is what the job name "Build, scan & push image" already claimed. Permissions move from workflow level to job level, so build and test jobs no longer carry packages: write they never use. New: dependabot.yml for gradle, npm and github-actions, and codeql.yml for Java and TypeScript. The Gradle distribution is pinned by checksum. cleanup.yml no longer calls a reusable workflow from another repository. It runs with packages: write against this registry, so it belongs where it is reviewed. The preview sweep is dropped with it — this repo has no preview workflows — while the invariants that protect the build cache and latest are kept.
The audit listed what the suite already guarantees and what it does not. These close the gaps that mattered. AuthModeNoneTest pins auth.mode=none: an anonymous caller reaches the API and holds ROLE_ADMIN, X-Tenant-ID selects any existing tenant, an unknown slug is 404 and a malformed one 400. That configuration is intentional and network-protected, but it is the widest the application has and nothing described it. Tenant isolation is asserted against a tenant-scoped resource rather than /v1/tenants/me, which is deliberately excluded from tenant resolution for the login flow. JwtTenantResolutionFilterTest pins the tenant boundary in OIDC mode: a tenant outside the JWT claims is refused, a single claim is auto-selected, multiple claims require an explicit header rather than being resolved silently, and a token without claims is refused. A regression here would let any authenticated user act as any tenant. TenantSenderFallbackTest covers the branch TenantSenderEnforcementTest does not: with no smtpSender configured, the request sender is authoritative. That is documented behaviour, but only the enforcing half was pinned, so it could have drifted in either direction.
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
| locale = DEFAULT_LOCALE; | ||
| } | ||
|
|
||
| Template template = new Template("email", new StringReader(templateContent), freemarkerConfiguration); |
Member
Author
There was a problem hiding this comment.
By design: tenants author their own FreeMarker templates. Sandboxed: ?new resolves nothing, ?api off, DefaultMemberAccessPolicy, Spring context hidden behind TemplateRequestContext. Escape attempts are pinned in FreemarkerSandboxTest.
=> Won't fix ✅
The README described five workflows and had drifted from the YAML: codeql.yml and cleanup.yml were missing entirely, triggers listed only main instead of master and main, the image names still pointed at encircle360-oss, and the release job was named after the workflow rather than build-and-push. Add the two missing workflows, correct triggers, image repositories and tag schemes against the metadata-action config, document the Trivy scans, SBOM and provenance attestations, and extend the permissions table with security-events: write. Drop the claim that the docker/ Compose stacks consume the published image — they build from ../backend — and note that backend.yml and monorepo.yml push the same image and latest tag, so the later run wins.
…en key Three of the four Compose stacks could not start at all, which the four-stack verification of the 0.5.0 migration guide surfaced. minimal.yml, apikey-sqlite.yml and oidc-postgres.yml shipped ENCRYPTION_KEY: "CHANGE_ME_GENERATE_RANDOM_KEY". That is not valid Base64, so EncryptionService aborted the context and the container crash-looped on first start, while docker/README.md claimed every stack comes up without manual configuration. Each stack now carries a generated key with a comment saying it is for local development only. With a valid key the PostgreSQL stack still failed one step later: changeset 0002 created tenants.active, smtp_tls and smtp_ssl as integer, which SQLite accepts because it stores booleans as integers, but PostgreSQL rejects when Hibernate binds a boolean. The first insert from TenantReconciliationService aborted startup, so the stack the migration guide points at for production had never run. Changeset 0009 converts the three columns; editing 0002 instead would have broken the checksums of existing installations. The precondition marks it as ran on SQLite, which leaves those installations untouched. Verified against all four stacks: PostgreSQL applies 0009, reconciles its three tenants and delivers an inline mail to Mailpit; an existing SQLite database logs the precondition failure and keeps its schema.
…lly ships The "Migrating from 0.4.0" guide was written on 2026-06-01 and has not moved since, while twenty-three commits landed on top of it — four of them security fixes that change how a working 0.4.0 setup behaves. None of that was written down, and all three changelogs still ended at 0.5.0 with a May or April date. Four changes can break an upgrade and now have their own place in the guide. FreeMarker runs sandboxed, so templates using ?new or ?api fail at render time rather than at startup, which is why that one gets its own section with the log line it produces and a command to find affected templates. Template IDs are confined to their tenant directory. Tenant reads require ROLE_ADMIN, which also decides whether the Admin UI's tenant pages have anything to show. Actuator is down to health. A new section covers the security defaults that a deployment configures rather than trips over: the header set, replacing the generated CSP wholesale, and forward-headers-strategy behind a TLS terminator. Reference sections gained the matching rows — role requirements under Authentication, ENCRYPTION_KEY, MANAGEMENT_ENDPOINTS and SECURITY_CONTENT_SECURITY_POLICY as deployment settings, the unauthenticated management port under Ports, JDK 25 and Node 22 under Local Development. Deployment hardening stays in docker/README.md and is linked in both directions instead of duplicated. Every statement here was checked against a running stack rather than read off a commit message, including that both environment variable names bind the way the guide says they do.
Regression against master - EmailService returned an empty array on a render failure, so reading rendered[0] threw and a broken template answered 500 instead of the 400 "Error while rendering template" that master produced. Security - SecurityConfig's custom JwtDecoder bypassed Boot's resource-server autoconfiguration, so the configured jwt.audiences was never applied and any token from the same realm was accepted. - SmtpSenderBuilder fell back field by field, so a tenant declaring only an SMTP host inherited the global relay's username and password. The tenant config now wins as a whole, and SMTP AUTH is only announced when a username exists. - The oidc-sqlite stack no longer activates the local profile, which would pull a developer's application-local.yml into the image. PostgreSQL and Linux - Changesets 0010/0011 convert templates.id and template_tags.template_id to uuid and git_sync_status.last_sync_at to bigint, matching the entity mappings. Both are postgresql-only and written as raw SQL, because Liquibase validates typed change tags against SQLite too. - The image creates /data, /git and /resources/templates owned by a fixed UID, and the stacks keep writable paths in named volumes so the non-root container can write to them. - apikey-sqlite and oidc-postgres set TEMPLATES_FILE_BASE_PATH, which they were missing, so file templates were silently never found. Wrong behaviour - ApiPaths matches the API prefix on segment boundaries, so /api-key-login is no longer treated as an API path. - SpaErrorViewResolver replaces SpaController: the SPA fallback now runs on the 404 path, knows the configured api.prefix and has no nesting limit, so unknown API endpoints answer 404 instead of a page of HTML. - PageContainer builds through the builder; the all-args constructor takes (content, size, page) and every caller passed (page, size). - StatusController no longer gates on auth.enabled, a property that exists nowhere. - JacksonConfig makes Jackson prefer the no-args constructor, so an absent property means "use the default" again. Without it, POST /v1/tenants rejected every payload that left smtpTls, smtpSsl or active out. Frontend - authInterceptor reads the token from the OIDC library instead of a stale store copy, keeps X-Tenant-ID on the retry, and shares one refresh across concurrent 401s so refresh-token rotation cannot strand a caller. - The access token and the never-dispatched LoginComplete action are gone from AuthState. - Git sync releases its spinner through finalize and reports failures. - ApiService uses the configured api base throughout, and dev and e2e serve it relative like production, so calls stay same-origin and keep their credentials. - Recipients are required, and chips carry the email validator. CI and dev stacks - backend.yml is a build-and-test gate; monorepo.yml is the only publisher of ghcr.io/<repo>/backend and takes a concurrency group. - The mailpit and Keycloak health checks work (no curl in either image, and Keycloak serves /health/ready on port 9000), and the backends wait for their dependencies. - The Keycloak realm admin password matches the documented admin/admin.
SpaRoutingTest and ApiKeyLoginRouteTest assert that an unresolved browser route answers with the admin console. The console is a build artifact and src/main/resources/static is gitignored, so the backend test job, which runs with SKIP_FRONTEND_BUILD=true, had nothing to forward to and both assertions saw a 404. A stub index.html in the test resources carries <app-root>, and test resources precede main resources on the test classpath, so the tests now resolve it in every lane. They pin the SPA fallback, not the Angular bundle; the real artifact stays covered by the full build in monorepo.yml.
- Templates get a narrow TemplateRequestContext instead of Spring's RequestContext; through webApplicationContext any template could read encryption.key and call any bean. JsonNodeObjectWrapper pins DefaultMemberAccessPolicy so getClass() reflection is blocked as well. - CSRF stays enabled on all filter chains and exempts only the API prefix, which authenticates by bearer token or X-API-KEY header. - Request-controlled values pass through LogSanitizer before logging. - EncryptionService concatenates IV and ciphertext without length arithmetic.
- Spring Boot 4.1.2, Gradle 9.8.2; hibernate-community-dialects, sqlite-jdbc and Testcontainers versions come from the Boot BOM again - Angular 22.2, Vitest 5, Playwright 1.64, npm 12 and all other frontend dependencies on their latest releases; vite overridden to 8.3.5 to close the advisories in the 8.3.0 that @angular/build pins - Runtime image applies pending Ubuntu security updates and drops the unused pebble Go binary carrying critical stdlib CVEs - Keycloak 26.8.1 in the OIDC Compose stacks - Ignore .worktrees/
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: straightmail v0.5.0 — multi-tenancy, SQLite, API-key auth, Git-sync, four Docker stacks
Summary
This PR introduces multi-tenancy, three authentication modes, Git-sync for templates, SQLite as the default database,
and a restructured Docker Compose setup. Changes span backend, frontend, infrastructure, and CI/CD.
What's new
Multi-tenancy
TenantReconciliationService: tenants declared inapplication.ymlundertenants.config.*are automaticallycreated or updated at startup — zero-touch provisioning, no manual API calls required
GET/POST/PUT/DELETE /api/v1/tenants(admin-only, requiresdatabaseprofile)TenantContextresolves the active tenant from the request on every call; service and business logic layers neverread
HttpServletRequestdirectlyAuthentication modes (
AUTH_MODE)The boolean
auth.enabledflag has been replaced by a three-valueauth.modeproperty:AUTH_MODEoidc(default)api-keyX-API-KEYheader; per-tenant or global SHA-256 hash lookupnoneGit-Sync for templates
GitTemplateSourceProviderloads.ftlfiles from the working tree into a local cache tableTemplate source architecture
Templates are now resolved from up to three independent sources; the first match wins:
databaseprofile).ftlfiles from a mounted host directoryEvery template carries an implicit
source:database,source:file, orsource:gittag — filterable via the API.Encryption at rest
EncryptionService(AES-256-GCM) encrypts all secrets before persistence (SMTP password, Git token, API key hash).Secrets are never returned in plain text by the API. Double-encryption is prevented by checking the stored value before
each write.
SQLite as default database
SQLite (WAL mode, single-file) replaces PostgreSQL as the default. PostgreSQL remains fully supported via environment
variables:
Frontend changes
settings
AUTH_MODE=api-keydeploymentsTenantState,ApiKeyStateadminGuard(tenant admin area),canDeactivateFormGuard(unsaved changes protection)ApiKeyInterceptoraddsX-API-KEYandX-Tenant-IDheaders in API-Key modeInfrastructure changes
Docker Compose
The single root-level
docker-compose.ymlhas been replaced by four mode-specific stacks indocker/:minimal.ymlapikey-sqlite.ymloidc-sqlite.ymloidc-postgres.ymlBuild the JAR first, then start a stack:
See docker/README.md for details.
Helm chart
The Helm chart has been removed from this repository and will be maintained in a dedicated
helm-chartsrepository.Developer experience
application-local.ymlis now gitignored — real credentials can never be accidentally committedapplication-local.yml.exampleadded with placeholder values (ACME tenant,smtp.example.com)application-dev.ymlremoved; useapplication-local.yml(copied from the example) insteadSKIP_FRONTEND_BUILD=trueskips the Angular build for backend-only developmentBreaking changes
auth.enabled: true/falseAUTH_MODE: oidc / api-key / noneclient/frontend/docker-compose.ymlat rootdocker/service/template/TemplateService(monolithic)service/template/provider/(composite providers)controller/MailController(flat)controller/mail/MailController(nested)ENCRYPTION_KEYdatabaseprofile0001typeuuid(PostgreSQL native)varchar(36)— requires manual migration on v0.4.0 PostgreSQL instancesLiquibase note
Changeset
0001changes theidcolumn type fromuuidtovarchar(36)for SQLite compatibility.Existing PostgreSQL deployments (v0.4.0) are affected. If the old
0001changeset has already been applied (which it has on any v0.4.0 installation), Liquibase will detect a checksum mismatch and refuse to start. Before applying this PR to a v0.4.0 PostgreSQL instance, either:idcolumn type fromuuidtovarchar(36), or0001in thedatabasechangelogtable and ensure the column type is compatible.Test coverage
TenantIntegrationTest,TenantSenderEnforcementTest,TemplatesControllerTest,StatusControllerTest,EncryptionServiceTest,TenantServiceTest,TenantReconciliationServiceTest,GitSyncSchedulerTest, and moreChangelog
Backend — [0.5.0]
Added
TenantService,TenantRepository,/v1/tenantsCRUD admin APIApiKeyTenantResolutionFilter) with SHA-256 hashing viaEncryptionServiceAbstractTenantResolutionFilterbase class; JWT and API-key resolution share common logicTenantProperties+TenantReconciliationService(YAML-declared tenantsreconciled at startup)
StartupConfigLogger: logs all resolved configuration at startup with masked secretsauth.modeproperty (oidc|api-key|none) replacing the booleanauth.enabledflagNoAuthTenantResolutionFilterresolves tenant fromX-Tenant-IDheader or falls back todefault
GitSyncStatusRepository) and template cachingGitSyncSchedulerwith initial sync on application startup; ShedLock uses JVM system time for SQLite compatibilityTemplateView.editable) distinguishing DATABASE vs FILE/GIT templatessource:database,source:file,source:git) auto-applied byTemplateServiceeffectiveTagsunifying explicit and source tags for consistent tag-based filteringlogo_url,brand_color) inTenantDTOChanged
jdbc:sqlite:); Liquibase changesets updatedObjectProvider<T>used for all beans conditional on thedatabaseprofilecontroller/mail/,controller/template/,controller/tenant/,service/template/loader/,service/template/provider/@Autowiredfield injection replaced by constructor injection throughoutRemoved
auth.enabledboolean property (superseded byauth.mode)Frontend — [0.5.0]
Added
/api-key-loginpage,ApiKeyState,ApiKeyInterceptorTenantState.isDatabaseModeselector; DB-mode-only actions (New Template, New Tenant) conditionally renderedTemplatesStatewith source-tab filtering (DATABASE/FILE/GIT/ALL) and tag filteringTemplateGridComponentand grid/list view toggle (persisted inUiState)TemplateViewComponentfor GIT/FILE templatessource:gittemplatesDashboardStatetracking Git sync status per tenantFileSyncCard/GitSyncCardcomponents for sync status displayUserAvatar,TenantAvatar,NavIconComponentreusable UI componentsHelpPanelComponent: context-sensitive off-canvas help panel (right panel / bottom sheet on mobile)LocalStorageviaRenderState)templates.spec.ts,tenants.spec.tsautoAuthPlaywright fixture: pre-seeds sessionStorage/localStorage before each testChanged
TranslateModuleimports replaced by standaloneTranslatePipeacross all componentscanDeactivateacross form pagesremunits across all component stylesheetsFixed
mockTenantsE2E helper now mocks/v1/tenants/me(the actualLoadTenantsendpoint) instead of/v1/tenantsautoAuthfixture seeds tenant witheditable: trueso "New Template" / "New Tenant" buttons rendercorrectly
Checklist
application-local.ymlgitignoreddocker compose config)./gradlew compileJava -PskipFrontendBuild=true)NgModulecreated; all Angular components standalonedetectChanges()calls in production Angular code