Repository navigation
fix(terraform): rotate Caddy service principal secret yearly - #64
Conversation
The azuread_service_principal_password for Caddy had no expiry or rotation configured, so Entra ID applied its 2-year default. The secret expired on 2026-07-26; every ACME DNS-01 renewal since 2026-09-11 failed with AADSTS7000222 and the apt/yum TLS certificates lapsed on 2026-10-11 and 2026-10-12 (server-edition#199). Tie the password to a time_rotating clock with rotation_days = 365 so terraform apply replaces it yearly, well inside the 2-year lifetime. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
FooBarWidget
left a comment
There was a problem hiding this comment.
Thanks for looking into this. I've applied Terraform and you should be unblocked from fixing now.
As for this pull request: the intention is that you (infra maintainers) should be able to change the Caddy password. But it looks like the rights for this weren't set properly. All Enterprise Applications are owned by myself, so only I or some other organization owner can update them.
It looks like the Terraform code for syncing the owners is already there. But the onboarding and offboarding instructions should add an additional checklist: re-apply terraform/ (which syncs the owners), not just terraform-hisec/. You should fix this too.
Anyway, the owners lists themselves are fixed now that I've applied Terraform. You still need to run Ansible yourself.
|
I've run Ansible now so the certificate has been renewed. |
Description
Fixes the expired TLS certificates on
apt.fullstaqruby.organdyum.fullstaqruby.org(fullstaq-ruby/server-edition#199).Root cause. The Entra ID client secret that Caddy uses for the ACME DNS-01 challenge expired on 2026-07-26.
azuread_service_principal_password.caddysets noend_date, so Entra applied its default 2-year lifetime (created 2024-07-26). Caddy's journal on the VM shows every renewal attempt since 2026-09-11 failing with:Last successful renewals were 2026-07-13 (yum) and 2026-07-14 (apt). The certs expired 2026-10-11 19:02 UTC (yum) and 2026-10-12 02:22 UTC (apt). Caddy itself is healthy and still serving redirects; only renewal is broken.
Change. Tie the service principal password to a
time_rotatingclock withrotation_days = 365viarotate_when_changed, soterraform applyreplaces the secret yearly, well inside the 2-year lifetime. Adds thehashicorp/timeprovider (~> 0.12.1) and its lock-file hashes for linux_amd64, darwin_arm64 and darwin_amd64.Caveat / who must apply. I cannot apply this.
hongli-infra-maintainer@fullstaqruby.orgis the only owner of the Caddy app and service principal, and my account holds no Entra directory role, so both the password replacement and the owner update fail with403 Authorization_RequestDenied. The plan also adds the current Infra Maintainers members as owners of the app and SP (pre-existing drift), which would let other maintainers handle this next time.terraform planoutput (verified with Terraform 1.5.7 against the prod backend):Manual steps after apply. Run the Ansible playbook so
/etc/caddy/envpicks up the new secret from Key Vault, then let Caddy restart (the playbook's handler does this). A--check --diffrun of the playbook against the VM today shows only 4 unrelated, non-destructive changes. Caddy will renew both certs on its next maintenance tick (10 minutes).Follow-up, not in this PR: there is no certificate-expiry or renewal-failure alerting, which is why this went unnoticed for a month.
Testing instructions
After
terraform applyand the Ansible run:Expect two "renewed successfully" lines,
notAfterroughly 90 days out, and a credential with a 2-year end date starting today.Checklist for the submitter
Documentation updatedInfrastructure overview diagram updated**/providers.tf,.github/workflows/code-reviews.ymlanddocs/required-devtools.md(unchanged).github/ISSUE_TEMPLATE/apply_join_team.mdanddocs/responsibilities-expectations.md(unchanged)Checklist for reviewers
Ifterraform-hisec/was updated: someone with the "Infra Owner" role has checked the output ofterraform planDefinition of done (for team members)
Ifterraform-hisec/was updated: someone with the "Infra Owner" role has runterraform apply🤖 Generated with Claude Code