$ ls topics/{shield,security,microsoft-365}
·5 min read
The Secret to Keeping Secrets
Rotating a credential is easy. Making it safe, automatic, and dependable takes more engineering.
Dan Wagoner
Director of Infrastructure
In October, Huntress reported that attackers had used a compromised ConnectWise application credential to access customer Microsoft 365 tenants. A few weeks later, Todyl documented a separate campaign involving valid application credentials. Neither incident required a vulnerability in Microsoft 365. The applications already had access, and the credentials were enough to use it.
Those incidents are a reminder that protecting credentials is only part of managing them; they also need a lifecycle. At Mailprotector, we follow strict infrastructure patterns intended to prevent credentials from being exposed, but we’ve also built automated rotation into Shield since day zero. The interesting part isn’t simply that the keys change. It’s making those changes safely, across several different systems, without interrupting mail flow. We often compare this kind of engineering to swapping out the airplane’s engine mid-flight.
Mo’ Credentials, Mo’ Problems#
It’s tempting to think of rotation as one operation: generate a new value, replace the old one, and call it done. But Shield manages several kinds of credentials, certificates, keys, and tokens. They serve different purposes, and each presents a different challenge when it comes time to update.
Microsoft 365 application credentials#
Shield uses an application approved by each customer’s administrator to connect to Microsoft 365. We rotate this application’s credential monthly. The process generates a replacement, deploys it across the service, and removes the old credential only after every running part of Shield has restarted using the new one. That brief overlap is deliberate: removing the old credential too soon can break authentication, but leaving it active unnecessarily extends its usefulness. As an additional safeguard, each credential expires after 90 days, even if the removal process fails.
Email signing and sealing keys#
Shield rotates its DKIM and ARC signing keys every month. Unlike application credentials, these keys are used to sign messages so receiving mail systems can verify their signatures using public keys published in DNS. The challenge is that messages signed before a rotation still need to be verifiable afterward. We can’t simply replace a key and forget about the previous one.
For DKIM, Shield maintains two selectors, each with its own DNS record. While one is actively signing messages, the other is available for the next rotation. Each month, we generate a new key pair and publish the public key under the inactive selector before switching Shield to use it. The previous public key stays published so messages signed before the change can still be verified. The selectors alternate with each rotation, and because customer domains point to DKIM records we manage, the process doesn’t require customers to update their own DNS records.
ARC follows a similar approach, but with a different strategy for managing selectors. Rather than alternating between two, each rotation creates a new selector, and previous selectors remain published so existing ARC seals can still be verified. Both processes follow the same basic principle: make the new key available before switching to it, while preserving what’s needed to verify messages signed with earlier keys.
Tenant-specific mail-flow tokens#
Every 30 days, Shield rotates the token used to recognize mail returning to each customer’s Microsoft 365 tenant. The token is unique to that tenant, and the change depends on configuration within the tenant itself, so it happens in stages. The tenant’s rules first accept both the current token and the new one. Shield switches to the new token once Microsoft confirms the update, and only then is the old token removed. If tenant configuration prevents a rotation from completing, the existing token remains in place so mail keeps flowing, and our team gets an alert.
Tenant TLS certificates#
In Shield’s Charlie mail-flow architecture, each tenant also has its own TLS certificate for mail relayed back to Microsoft 365. The certificate establishes the identity of the returning connection, and it’s separate from the tenant’s mail-flow token. Shield issues it automatically when the tenant is deployed, and a daily check renews any certificate that is within 30 days of expiring.
Set It and Don’t Forget It#
Manually rotating credentials might sound manageable until you consider how many different keys, tokens, and certificates Shield maintains across its customer base. Someone has to generate each replacement, update the systems that depend on it, and make sure the old credential is retired. These are repetitive, sensitive operations where it’s easy to make a mistake. We’d rather have engineers building and overseeing reliable automation than manually moving secrets between systems every month.
Of course, automation can fail too. A scheduled job might encounter an error, or it might stop running entirely without reporting a failure. Shield’s Microsoft 365 credential rotation automatically retries failed attempts and alerts our team if it still can’t complete. A separate daily check verifies the age of the active credential, catching cases where the rotation job never ran. Tenant token rotation has similar monitoring for stalled changes and jobs that go quiet. We monitor the outcome, not just whether the job was scheduled to run.
This Is Not a Drill#
Regular rotation has another benefit: practice. If we need to replace our Microsoft 365 application credential unexpectedly, we trigger the same process that runs every month. The deployment, verification, and retirement steps aren’t some emergency procedure we’re dusting off for the first time. They’re steps we’ve already exercised repeatedly in production.
That’s the engineering principle behind all of this: the process you rely on during an incident should be one you already know works. By making rotation a routine operation, we can find and fix problems under normal circumstances rather than discovering them when something has gone wrong.
This is also something worth considering when evaluating any vendor with access to your environment. Ask what credentials they manage, how they’re rotated, and how they know the process is working. A company’s size or reputation doesn’t guarantee that these fundamentals are in place. The ability to explain and demonstrate them is a much better indicator.
