ADR-0040: The MTA-STS policy is an object in the site bucket#
- Status: accepted. Refines ADR-0037 decision 6 (the existing distribution serves the policy) and ADR-0030 decision 1 (objects are read only under
testz/). - Date: 2026-11-29
Context#
The site's viewer-request CloudFront Function serves the mail subdomain's MTA-STS policy: the policy text is in the function's code, and the function answers on mta-sts.mail.testz.dev itself. It works, and the policy and the id it hashes to are applied together. But it puts content in edge code, which the function exists to route, not to hold. The common pattern, and the one reviewers and operators recognise, is the policy as a static object behind the CDN. The radar asked for this move before the policy goes to enforce, when a wrong policy stops deliveries.
Two things stood in the way. The plan role reads no object outside the stack's state (ADR-0030), and a plan refreshes every object OpenTofu manages. And site-deploy syncs the bucket with --delete, and types every *.txt as HTML until a later step fixes the files it names.
Decision#
- The policy is an object OpenTofu writes into the site bucket, at
.well-known/mta-sts.txt, from the mail module's policy, typedtext/plain; charset=utf-8, withCache-Control: max-age=300. The id in_mta-sts.mailis still the policy's hash, and is written after the object. - The function routes, and holds no content. On the policy host it passes
/.well-known/mta-sts.txtto the bucket unchanged and answers 404 to every other path, never redirecting. On any other host it answers 404 for that path, so the policy is served on its host only. site-deployleaves the object alone. Its syncs exclude that key, so a deploy neither deletes it nor retypes it.- The plan role reads that one object.
s3:GetObject, which authorises theHeadObjecta refresh makes, ands3:GetObjectTagging, ontestz-*-site/.well-known/mta-sts.txtand nothing else. The object is public. The test that keeps the plan role's object reads undertestz/names this key as the one exception. - The grant comes first. The bootstrap layer's change is applied by
bootstrap-accountbefore the change that writes the object, whose plan fails without it.
Alternatives considered#
Keep the function. It works, and it is atomic. It also mixes content into routing code, and few people looking for an MTA-STS policy look there.
A file in the site build, deployed by site-deploy. No new grant. But terraform-apply calls site-deploy after it applies, so the id would be published before the policy it describes. site-deploy would also have to fix the file's media type, and policy and id would come from two workflows.
A bucket and distribution of its own. The usual published pattern. It adds a bucket, a bucket policy, an OAC, a distribution and a certificate for one 90-byte file, and the plan role would still need to read the object.
Let the plan role read the whole site bucket. The site is public, so the read reveals nothing. A wildcard on a bucket pattern is how the state reads were once too wide, and the exact key costs nothing.
Consequences#
Positive: the policy is an ordinary object, visible in the bucket and in the plan as a diff of its content. The function goes back to routing.
Negative:
- The edge caches the policy for up to five minutes, so a change can be served stale under its new id for that long, on top of the function's propagation.
site-deploy's invalidation, whichterraform-applyruns after an apply, usually shortens it. - The plan role reads one object outside state. It is public, but the exception has to stay that narrow.
- A key in the site bucket that
site-deploymust never touch. - Two pull requests, with
bootstrap-accountbetween them.
Neutral: no new monthly cost. The policy host, its certificate name and its records do not change.
Revisit when#
- The policy needs a host this distribution cannot serve.
- A provider release refreshes the object with a read beyond these two.
site-deploystops syncing with--delete, or the site bucket is replaced.