HUB
Sign inSign up

ricariel/autodiscover

By ricariel

•Updated 3 days ago

Autodiscover, autoconfig and Apple mail profiles for a mail server, from the Python standard library

Image
0

269

ricariel/autodiscover repository overview

⁠autodiscover-docker

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.

⁠Why this exists

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.

⁠Routes

RouteMethodAnswer
/autodiscover/autodiscover.xmlPOST, GETMicrosoft 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.xmlGETMozilla client configuration, what Thunderbird reads
/.well-known/autoconfig/mail/config-v1.1.xmlGETThe same document under the well-known path newer Thunderbird versions try first
/email.mobileconfig?email=<address>GETApple configuration profile for that address, offered as a download. Without the parameter: 400
/GETHelp page with the settings and a form for the profile
/healthzGETok, 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.

⁠Settings

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.

VariableMeaning
DOMAINMail domain. Used where a request carries only a user name, and as the fallback for the answers
COMPANY_NAMEDisplay name in all four documents
SUPPORT_URLLink to the help page, in the Mozilla and Microsoft answers
IMAP_HOST, IMAP_PORT, IMAP_SOCKETIncoming server. IMAP_SOCKET is SSL, STARTTLS or plain
POP_HOST, POP_PORT, POP_SOCKETSame for POP3, left out when POP_HOST is empty
SMTP_HOST, SMTP_PORT, SMTP_SOCKETOutgoing server
LDAP_HOST, LDAP_PORT, LDAP_SOCKET, LDAP_BASE, LDAP_USER_FIELD, LDAP_USER_BASEAddress book for the Apple profile, left out when LDAP_HOST is empty
MOBILESYNC_URL, MOBILESYNC_NAMEExchange ActiveSync server, added to the Autodiscover answer when set
PROFILE_IDENTIFIERReverse-DNS identifier of the Apple profile, for example com.example.autodiscover
PROFILE_UUID, MAIL_UUID, LDAP_UUIDPin the UUIDs of the profile payloads. Unset is the normal case, see below
PORTListening port, 8000 by default
LOG_LEVELINFO by default

IMAP_SOCKET and its siblings reach the answers in three shapes, because the clients disagree about how to say the same thing:

SettingMozilla socketTypeAutodiscover SSL / EncryptionApple UseSSL
SSLSSLon / SSLtrue
STARTTLSSTARTTLSoff / TLStrue
anything elseas givenoff / as givenfalse

⁠Differences from the image it replaces

The documents are the same, with four deliberate changes:

  • The Apple profile always carries a 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.
  • The help page carries its own style. The page of the earlier image loaded Bootstrap, jQuery and popper.js from three content delivery networks: every visitor to a mail server's help page became visible to them, and the page looked broken whenever one of them was unreachable. The page here is one self-contained document and looks plainer for it.
  • The response schema is checked against a list. An Autodiscover request names the schema its answer should use, and the answer repeats it. Only the two schemas Microsoft defines are echoed; anything else falls back to the default, so a client cannot place its own text in the document.
  • A request body is capped at 64 KiB and never handed to an XML parser. The two fields that matter are read with a bounded regular expression, so there is no entity expansion to exploit.

⁠Running it

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

./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.

⁠Attribution

The documents follow the templates of Monogramm/autodiscover-email-settings⁠, MIT licensed, which this service replaces.

Tag summary

Content type

Image

Digest

sha256:ca9d6d6ac…

Size

69.2 MB

Last updated

3 days ago

docker pull ricariel/autodiscover