Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ SENTRY_RELEASE=
CF_Token=
CF_Zone_ID=
DNS_API=dns_cf
ACME_SH_EMAIL=
ACME_SH_EMAIL=devnull@localhost
MXDOMAIN=ineedatest.email
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build stage
# Official images publish 1.26.3-alpine / 1.26.3-alpine3.22+ — not alpine3.21.
FROM golang:1.26.3-alpine AS builder
# Matches the patch in go.mod. This tag is Alpine 3.24; the runtime stage stays on 3.21.
FROM golang:1.26.10-alpine AS builder

WORKDIR /app

Expand All @@ -22,7 +22,7 @@ FROM alpine:3.21
ARG ACME_SH_VERSION=3.0.7

# Install ca-certificates, openssl, socat, git, bash; pin acme.sh via git tag (no curl|sh)
RUN apk add --no-cache ca-certificates openssl socat git bash curl \
RUN apk add --no-cache ca-certificates openssl socat git bash curl su-exec \
&& git clone --depth 1 --branch "${ACME_SH_VERSION}" https://github.com/acmesh-official/acme.sh.git /opt/acme.sh \
&& addgroup -S inboundparse \
&& adduser -S -G inboundparse -h /home/inboundparse inboundparse \
Expand All @@ -39,14 +39,15 @@ COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/inboundparse /usr/local/bin/start.sh \
&& chown inboundparse:inboundparse /usr/local/bin/inboundparse /usr/local/bin/start.sh

USER inboundparse
# Stay root for the entrypoint. start.sh writes a root-owned /cert volume,
# then drops to inboundparse before the SMTP process.
ENV HOME=/home/inboundparse

# Environment variables for acme.sh and SMTP server
ENV CF_Token=""
ENV CF_Zone_ID=""
ENV DNS_API=""
ENV ACME_SH_EMAIL=""
ENV ACME_SH_EMAIL="devnull@localhost"
ENV MXDOMAIN=""
ENV WEBHOOK_URL=""
ENV ENABLE_SPF="true"
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,15 @@ You can configure InboundParse using environment variables or command line flags

#### TLS Settings

- `CERT_FILE` Path to TLS certificate file (optional)
The image entrypoint requests a Let's Encrypt certificate on startup when DNS credentials are set, then starts SMTP. No extra script is required. If those credentials are unset, or issuance fails, SMTP still starts without STARTTLS. A volume mounted at `/cert` keeps the certificate across restarts.

- `CERT_FILE` Path to TLS certificate file (optional; the entrypoint sets this when it has a certificate)
- `KEY_FILE` Path to TLS private key file (optional)
- `MXDOMAIN` Certificate domain (default: `SERVER_NAME`, then `mx.inboundparse.com`)
- `ACME_SH_EMAIL` Let's Encrypt account email (default: `devnull@localhost`)
- `DNS_API` acme.sh DNS provider (default: `dns_cf`)
- `CF_Token` Cloudflare API token (required for `dns_cf`)
- `CF_Zone_ID` Cloudflare zone id (required for `dns_cf`)

#### Feature Flags

Expand Down
5 changes: 4 additions & 1 deletion docs/providers/fly.io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ The sample Fly config in this directory is [`fly.toml`](./fly.toml). Adjust app
# From the directory that contains fly.toml
fly deploy

# Core secrets (adjust for your webhook and DNS/API provider — see `start.sh` / `Dockerfile` for ACME)
# The image entrypoint issues the certificate. No extra start script.
# ACME_SH_EMAIL defaults to devnull@localhost. SMTP still starts without
# STARTTLS when the DNS secrets are unset or issuance fails.
fly secrets set WEBHOOK_URL=https://your-webhook-url.com/api/webhook
fly secrets set CF_Token=your-cloudflare-token
fly secrets set CF_Zone_ID=your-zone-id
fly secrets set MXDOMAIN=your-domain.com
fly secrets set ACME_SH_EMAIL=you@your-domain.com

# Optional: error tracking
fly secrets set SENTRY_DSN=https://your-dsn@sentry.io/project-id
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module inboundparse

go 1.26.3
go 1.26.10

require (
github.com/emersion/go-msgauth v0.7.0
Expand All @@ -15,7 +15,8 @@ require (
github.com/rs/zerolog v1.35.1
github.com/stretchr/testify v1.11.1
github.com/zaccone/spf v0.0.0-20170817004109-76747b8658d9
golang.org/x/sync v0.20.0
golang.org/x/net v0.60.0
golang.org/x/sync v0.23.0
)

require (
Expand All @@ -34,12 +35,11 @@ require (
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
golang.org/x/crypto v0.51.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/net v0.54.0 // indirect
golang.org/x/sys v0.44.0 // indirect
golang.org/x/text v0.37.0 // indirect
golang.org/x/tools v0.45.0 // indirect
golang.org/x/crypto v0.57.0 // indirect
golang.org/x/mod v0.41.0 // indirect
golang.org/x/sys v0.48.0 // indirect
golang.org/x/text v0.42.0 // indirect
golang.org/x/tools v0.49.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w=
golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
Expand Down
54 changes: 19 additions & 35 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"os/signal"
"syscall"
"time"

"golang.org/x/sync/errgroup"
)

// App represents the application
Expand Down Expand Up @@ -190,45 +188,31 @@ func (a *App) Start() error {
return nil
}

// Run runs the application with graceful shutdown
// Run runs the application with graceful shutdown.
// Signal handlers are installed before Start is launched. Start blocks in SMTP
// Serve for the life of the process, so waiting for it to return would leave
// SIGINT and SIGTERM unhandled while mail is accepted.
func (a *App) Run() error {
// Start the application
if err := a.Start(); err != nil {
return err
}

// Set up graceful shutdown
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create error group for managing goroutines
g, ctx := errgroup.WithContext(ctx)

// Handle shutdown signals
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sigChan)

g.Go(func() error {
select {
case sig := <-sigChan:
a.logger.Info().
Str("signal", sig.String()).
Msg("Received shutdown signal")
cancel()
return nil
case <-ctx.Done():
return ctx.Err()
}
})
// Buffered so the Start goroutine can send after Run has already returned
// on a signal. An unbuffered send would leak that goroutine.
startErr := make(chan error, 1)
go func() {
startErr <- a.Start()
}()

// Wait for context cancellation
g.Go(func() error {
<-ctx.Done()
select {
case sig := <-sigChan:
a.logger.Info().
Str("signal", sig.String()).
Msg("Received shutdown signal")
return a.Stop()
})

// Wait for all goroutines to complete
return g.Wait()
case err := <-startErr:
return err
}
}

// Stop stops the application gracefully
Expand Down
Loading
Loading