PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
Backend commands run from backend/, frontend commands from frontend/, website commands from website/. Package tests use go test ./internal/<path>/... -count=1, as the root AGENTS.md recommends; the full make test (or make test-fedora on a Fedora host) runs once, in section 7.
1. Shared SMTP transport
- 1.1 Create
backend/internal/util/smtp_transportwith theSecurityenum (tls,starttls,none) inenums.go, sentinel errors inerrors.go, theConnectionandMessagetypes, andSend(ctx, Connection, Message), which opens the connection in the chosen mode and greets with the configured name in every mode. Verify with tests against in-process fake SMTP servers:tlsdelivers,starttlsupgrades before any other command,starttlsagainst a server that does not offer the upgrade fails withErrStartTLSNotOfferedand closes the socket having sent nothing past EHLO, not evenQUIT,nonenever upgrades, and an untrusted certificate fails unless verification is switched off. - 1.2 Implement PLAIN and LOGIN authentication inside the package. Choose the mechanism from the server's
AUTHoffer (PLAIN first, then LOGIN), refuse either one on an unencrypted connection unless the mode isnone, match LOGIN prompts from both current prompt sets without regard to case, and fail on any other prompt. Verify with fake-server tests: a stripped STARTTLS offer never produces anAUTHcommand, PLAIN is used when both are offered, LOGIN is used when only it is offered, an unknown prompt ends the attempt, and an authentication error carries the server's response but not the password. - 1.3 Build messages from parsed addresses:
FromandTothroughnet/mail.Address, the subject with CR, LF and NUL removed and then Q-encoded,Message-IDon the sender's domain,MIME-Version: 1.0,Content-Type: text/html; charset="UTF-8"and a quoted-printable body. Verify with tests that read the message a fake server received: a subject containing\r\nBcc: [email protected]produces noBccheader and a single recipient, a non-ASCII display name decodes back to the original, a 5,000-character body line arrives unchanged after decoding with no wire line over 998 characters, and two messages carry differentMessage-IDvalues. - 1.4 Bound the whole conversation with a 30-second deadline derived from the caller's context and applied to both the dial and the connection. Verify with a test against a server that greets and then goes silent, using a shorter caller deadline so the test runs quickly, and assert that
Sendreturns a timeout error within that deadline. - 1.5 Add
GetDefaultSecurityForPort,ParseSender(a bare address or a display name with an address, withDatabasusas the default name),ResolveSender(from, username, host)(the explicit sender, else the username only if it parses as a bare address, elsenoreply@and the host),ValidateHeloName(a host name or an address literal) andGetDefaultHeloName(databasusURL)(the host part only, then the machine host name, thenlocalhost; an IPv4 address as[192.0.2.1], an IPv6 address as[IPv6:2001:db8::1]). Verify with table tests for each function, including a URL with a port, an IPv4 and an IPv6 host, a sender such asops at example, which must be rejected, a usernameapikeyresolving tonoreply@<host>, and greeting namesmy relayand[::1], which must be rejected. - 1.6 Run
make lintandgo test ./internal/util/smtp_transport/... -count=1.
2. Instance mail server
- 2.1 Add
SMTP_SECURITYandSMTP_HELO_NAMEtobackend/internal/config/config.go. Move the SMTP startup checks into a function that returns an error, so the existing port check, the security value check, theSMTP_HELO_NAMEcheck and theSMTP_FROMcheck can be tested without exiting the process. Verify with tests for an unknownSMTP_SECURITY, an invalidSMTP_HELO_NAME, an unreadableSMTP_FROM, a display-nameSMTP_FROM, which must be accepted, and a host without a port. - 2.2 Rebuild
backend/internal/features/emailon the transport. The singleton builds aConnectionfrom the environment, resolves the sender throughResolveSender,IsConfigured()becomesSMTPHost != "",SendEmailtakes a context, and the unconfigured path keeps logging a skip. Delete the old connection, authentication and header code together with itsloginAuth, and move the existing TLS test to the transport package if the transport tests do not already cover it. Verify withgo test ./internal/features/email/... -count=1andmake lint. - 2.3 Add a context parameter to
SendEmailinusers/interfaces/interfaces.go,workspaces/interfaces/interfaces.goand both mocks. Pass the request context from the sign-in code send (two_factor_auth.go:246), the password reset send (user_services.go:590) and the invitation send (membership_service.go:110). Verify withgo test ./internal/features/users/... ./internal/features/workspaces/... -count=1. - 2.4 Change the condition in
generate_frontend_runtime_configurationindocker/start.shtoSMTP_HOSTalone. Verify by running that function in a shell withSMTP_HOSTset andDATABASUS_URLunset and readingIS_EMAIL_CONFIGURED: 'true'in the generated file. - 2.5 Add
SMTP_SECURITY=noneto.env.examplenext to the other SMTP lines, after the user confirms this edit explicitly, because.env*files change only with that confirmation. Itstest-mailpithost is provided by no compose file, so the line matters only to a developer who points the block at a local Mailpit. Verify that the backend still starts with the resulting.envand that the users and workspaces package tests from 2.3 pass.
3. Email notification channel
- 3.1 Create the migration with
make migration-create name=add_security_to_email_notifiers. Addsecuritywith a temporarystarttlsdefault, settlswheresmtp_port = 465, drop the default, add theCHECKconstraint in its own statement, and addhelo_namewith an empty default. The down step drops the constraint and both columns. Verify withmake migration-upandmake migration-downon a scratch database, and by checking that a row on port 465 comes out astlsand a row on port 587 asstarttls. - 3.2 Add
SecurityandHeloNametoEmailNotifier. InValidate, require a known security mode, a readableFrom, aTargetEmailthat parses as a single bare address and aHeloNamethat is empty or passesValidateHeloName. InUpdate, keep the storedSecuritywhen the incoming one is empty and copyHeloNameas given. Add aFillDefaultsstep onNotifierthat delegates to the email model and sets an emptySecurityfrom the port, and call it beforeValidatein the create branch ofSaveNotifierand the unsaved branch ofSendTestNotificationToNotifierinnotifiers/service.go. RewriteSendto build aConnectionfrom the row, with the sender fromResolveSenderand the default greeting name fromDATABASUS_URL, and call the transport withcontext.Background(). Delete the old SMTP code,getHelloName,sanitizeHeaderValueandauth.go. Verify with the Mailpit test inmodel_test.goswitched tonone, plus a new test that the same Mailpit server withstarttlsfails with the STARTTLS error. - 3.3 Add notifier controller tests: a channel whose sender is
ops at exampleis refused on save, a display-name sender is accepted, an unknown security mode is refused, a recipientops at exampleand a greeting namemy relayare refused, a channel created on port 587 withoutsecurityis saved withstarttls, an update withoutsecuritykeeps the stored mode, a test notification for an unsaved channel withoutsecurityis not refused by validation, andsecurityandheloNamecome back as saved. Verify withgo test ./internal/features/notifiers/... -count=1. - 3.4 Run
make swaggerandmake lint.
4. Test message endpoint
- 4.1 Turn
checkRateLimitOrRespond(user_controller.go:426-443) into a package-level function inusers/controllersthat takes the counter and the logger, and call it fromUserController. Verify that the existing sign-in and password reset rate-limit tests pass unchanged. - 4.2 Add
ErrEmailNotConfiguredandErrAdminEmailMissingandSettingsService.SendTestEmail(ctx, admin). It checks configuration, checks the address with the validator already insettings_service.goand withnet/mail.ParseAddress, sends a short test message and writes one audit entry with the outcome, whatever stage a failure happens at. AddPOST /users/settings/test-emailtoSettingsControllerbehindRequireRole(UserRoleAdmin)and thetest_emailrate limit of five per administrator per ten minutes, and give the controller the counter and a logger through positional DI. Answer 200 withrecipientEmailon success, 400 withemail_not_configuredoradmin_email_missingon a refusal, and 400 with the delivery error and no code on a failed send. In the same file, correct theGetUsersSettingsdescription, which claims the endpoint is for administrators only. Verify withmake swaggerandmake lint. - 4.3 Add controller tests for the endpoint: a successful send reaches the mock sender at the administrator's address and writes a "sent" audit entry, a member gets 403, an unconfigured sender gets
email_not_configuredand nothing is sent, an administrator with the bootstrap login getsadmin_email_missing, a sixth request within the window gets 429, and a failing sender returns its error text and writes a "failed" audit entry. Verify withgo test ./internal/features/users/... -count=1.
5. Frontend
- 5.1 In
entity/notifiers, add theEmailNotifierSecurityenum in its own file,EMAIL_NOTIFIER_SECURITY_LABEL_KEYS,securityandheloNameonEmailNotifier,getDefaultEmailNotifierSecurity(port)using the backend's port rule, andgetSecurityAfterPortChange(currentSecurity, previousPort, nextPort), which returns the next port's default only when the current mode equals the previous port's default. Export them through the slice'sindex.ts. Verify withpnpm testcases for the port rule and for the port change:starttlson 587 becomestlson 465, andnoneon 25 staysnoneon 2525. - 5.2 Add the security select and the greeting-name input to the advanced section of
EditEmailNotifierComponent.tsx. Open the section by itself when either field differs from its default, and applygetSecurityAfterPortChangeon every port change. Verify in the running application: creating a channel on port 465 savestls, editing a migrated channel shows its stored mode, and a channel stored withnonekeepsnoneafter only its port is changed and it is saved. - 5.3 Add
sendTestEmailtoentity/users/api/settingsApi.tswith its response type in its own model file. CallfetchPostJsonwith the defaultisRetryOnError = false, so a failed send is not repeated. Mapemail_not_configuredandadmin_email_missingin the API error code table used bytranslateApiError. Verify withpnpm build. - 5.4 Add
MailServerComponentinfeatures/settings/uiand render it inSettingsComponent.tsxdirectly aboveAuditLogsComponent. It shows the configured state from the settings response, the documentation link throughgetWebsitePageUrl('advancedConfigEmailSmtp', locale), and the note that notification channels have their own SMTP settings. It also has atype="primary" ghost"Send test email" button that is disabled when the mail server is not configured, confirms delivery with the recipient address and shows failures throughtranslateApiError. Verify in the running application with the mail server configured against Mailpit, with it unconfigured, and with a wrong password. - 5.5 Add the new copy to all six dictionaries in
shared/i18n/locales/, using the interface terms fromwebsite/AGENTS.mdand a plain hyphen in English. Verify withpnpm test, which runs the placeholder check indictionaries.test.ts, andpnpm build, which fails on a missing key. - 5.6 Run
pnpm format,pnpm lint,pnpm testandpnpm build.
6. Documentation
- 6.1 Rewrite the SMTP section of
website/app/(en)/advanced-config/page.tsxunder the unchangedemail-smtpanchor. It covers the rule thatSMTP_HOSTmakes the mail server configured, the sender fallback that skips a username which is not an address, a warning that an instance requiring the emailed second factor must setSMTP_SECURITYbefore upgrading if its relay offers no STARTTLS, with the console command that switches the second factor off, the variable table withSMTP_SECURITY,SMTP_HELO_NAMEand the display-name form ofSMTP_FROM, the three security modes with the default for each port and a warning thatnonesends credentials and messages unencrypted, the advice to usenonefor a relay without STARTTLS,DATABASUS_URLas optional (invitation links and the default greeting name), and the difference between the instance mail server and an email notification channel. Update the page description and metadata if they mention the old rule. Verify withnpm run buildandnpm run lint. - 6.2 Apply the same section to the five copies in
website/app/[lang]/advanced-config/content/, keeping the hierarchy, the anchor and every technical string byte-identical to English, and following the translation rules inwebsite/AGENTS.md. Verify withnpm run buildand by checking thatout/{ru,es,pt,zh,fr}/advanced-config/index.htmleach contain theemail-smtpanchor and theSMTP_SECURITYrow.
7. Verification and review
- 7.1 Run
make testinbackend/(make test-fedoraon a Fedora host) andmake lint, thenpnpm lint,pnpm testandpnpm buildinfrontend/, andnpm run lintandnpm run buildinwebsite/. - 7.2 In the running application, reproduce the reported situation. No compose file provides a Mailpit, so start one first:
docker run -d --name databasus-mailpit -p 1025:1025 -p 8025:8025 -e MP_SMTP_AUTH_ACCEPT_ANY=true -e MP_SMTP_AUTH_ALLOW_INSECURE=true axllent/mailpit:v1.20.5, the image and settings the backend tests use. With a notification channel configured and noSMTP_HOST, the settings screen shows the mail server as not configured and the button is disabled. AfterSMTP_HOST=localhost,SMTP_PORT=1025andSMTP_SECURITY=noneare set, the test message arrives, and a workspace invitation arrives withDatabasusas the sender name and aMessage-ID. - 7.3 Pass the mandatory post-implementation review that the hooks run, resolve every finding, and list refactor suggestions for the diff as the root
AGENTS.mdrequires.