Autodiscover, autoconfig and Apple mail profiles for a mail server, from the Python standard library
269
Autodiscover, autoconfig and Apple configuration profiles for a mail server: the small web service that tells Outlook, Thunderbird and iOS where the mailbox is, so that a user only types an address and a password.
It answers four documents, all of them derived from the settings in its environment. It holds no state, needs no database, writes nothing and talks to nothing.
The service replaces monogramm/autodiscover-email-settings, which stopped
being maintained in February 2024. That image carries its own Node runtime
with a bundled OpenSSL a scanner does not see, and the vulnerable versions of
its dependencies are nailed down by the tilde ranges of koa 1.7.0, so they
cannot be raised without replacing the framework. It also had no tests at
all.
This image takes the opposite approach: the service is Python and uses
nothing but the standard library. There is no pip, no virtual environment
and no lock file, so the only thing that ever needs updating is the base
image, and a scanner sees the whole surface.
The four documents are the ones that image served, and the environment variables keep their names, so an existing deployment can switch without touching its configuration.
| Route | Method | Answer |
|---|---|---|
/autodiscover/autodiscover.xml | POST, GET | Microsoft Autodiscover v1. The address from the request is echoed as LoginName. The path is matched case-insensitively, because Outlook has been seen to capitalise it |
/mail/config-v1.1.xml | GET | Mozilla client configuration, what Thunderbird reads |
/.well-known/autoconfig/mail/config-v1.1.xml | GET | The same document under the well-known path newer Thunderbird versions try first |
/email.mobileconfig?email=<address> | GET | Apple configuration profile for that address, offered as a download. Without the parameter: 400 |
/ | GET | Help page with the settings and a form for the profile |
/healthz | GET | ok, for a readiness and liveness probe |
Autodiscover v2 (the JSON endpoint) is not served, the same as before.
/favicon.ico answers 204. No icon is shipped: a binary in the repository
would have to be reviewed on every change, and nothing needs one.
Every variable is optional. A protocol without a host is left out of every answer, which is how a deployment turns POP or LDAP off.
| Variable | Meaning |
|---|---|
DOMAIN | Mail domain. Used where a request carries only a user name, and as the fallback for the answers |
COMPANY_NAME | Display name in all four documents |
SUPPORT_URL | Link to the help page, in the Mozilla and Microsoft answers |
IMAP_HOST, IMAP_PORT, IMAP_SOCKET | Incoming server. IMAP_SOCKET is SSL, STARTTLS or plain |
POP_HOST, POP_PORT, POP_SOCKET | Same for POP3, left out when POP_HOST is empty |
SMTP_HOST, SMTP_PORT, SMTP_SOCKET | Outgoing server |
LDAP_HOST, LDAP_PORT, LDAP_SOCKET, LDAP_BASE, LDAP_USER_FIELD, LDAP_USER_BASE | Address book for the Apple profile, left out when LDAP_HOST is empty |
MOBILESYNC_URL, MOBILESYNC_NAME | Exchange ActiveSync server, added to the Autodiscover answer when set |
PROFILE_IDENTIFIER | Reverse-DNS identifier of the Apple profile, for example com.example.autodiscover |
PROFILE_UUID, MAIL_UUID, LDAP_UUID | Pin the UUIDs of the profile payloads. Unset is the normal case, see below |
PORT | Listening port, 8000 by default |
LOG_LEVEL | INFO by default |
IMAP_SOCKET and its siblings reach the answers in three shapes, because
the clients disagree about how to say the same thing:
| Setting | Mozilla socketType | Autodiscover SSL / Encryption | Apple UseSSL |
|---|---|---|---|
SSL | SSL | on / SSL | true |
STARTTLS | STARTTLS | off / TLS | true |
| anything else | as given | off / as given | false |
The documents are the same, with four deliberate changes:
PayloadUUID. The earlier image
wrote the value of PROFILE_UUID, MAIL_UUID and LDAP_UUID straight
into the profile, so a deployment that did not set them served a profile
with empty UUID fields, which is invalid. Where a variable is unset, the
UUID is derived from identifier, payload and address instead. The same
address always gets the same UUID, so installing the profile again
replaces the account rather than adding a second one.docker run --rm --publish 8000:8000 \
--env DOMAIN=example.com \
--env COMPANY_NAME='Example Mail' \
--env SUPPORT_URL=https://autoconfig.example.com \
--env IMAP_HOST=imap.example.com --env IMAP_PORT=143 \
--env IMAP_SOCKET=STARTTLS \
--env SMTP_HOST=smtp.example.com --env SMTP_PORT=587 \
--env SMTP_SOCKET=STARTTLS \
--env PROFILE_IDENTIFIER=com.example.autodiscover \
<registry>/autodiscover:<version>
The container needs no account of its own and no writable path: it runs
under any user id and with a read-only root filesystem. The smoke suite
starts it that way, with --user 61234:61234 --read-only.
The Kubernetes deployment of the mail stack chart does set the read-only
root file system, but no runAsUser, so there the service still runs as
root. Nothing requires that; the chart can pin a user id. The names autodiscover.<domain> and
autoconfig.<domain> both point at it, and the clients pick the route they
need.
The service speaks plain HTTP. TLS belongs to the ingress in front of it, and so does any rate limiting: there is none here.
./tests/run.sh documents # the four documents, parsed the way clients parse them
./tests/run.sh http # routes, content types, the body limit, the schema list
./tests/run.sh smoke # the image: unprivileged start, health check, no packages
documents and http start the service inside the test process and need no
container engine. smoke builds the image and needs docker or podman;
IMAGE points it at an image that was built already. Which suite a change
has to bring along is recorded in tests/suites.yaml.
No test resolves a real name or reaches a real mail server. Every address in the fixtures comes from the reserved documentation domains.
The documents follow the templates of Monogramm/autodiscover-email-settings, MIT licensed, which this service replaces.
Content type
Image
Digest
sha256:ca9d6d6ac…
Size
69.2 MB
Last updated
3 days ago
docker pull ricariel/autodiscover