DEV Community

Cover image for The rollback that kept the bug: how a duplicate identity broke env0's AWS deployments
Kashif Manzer
Kashif Manzer

Posted on Edited on

The rollback that kept the bug: how a duplicate identity broke env0's AWS deployments

Tuesday 10 November 2026, just before nine in the morning, UTC. A release finished rolling out at env0, a platform that runs infrastructure deployments for other teams. Minutes later, some customers' AWS deployments started failing at the credentials step, before any of their own code had run.

The error was plain: Not authorized to perform sts:AssumeRoleWithWebIdentity.

env0 did the obvious thing. It rolled the release back. The previous version went live at 11:00 UTC, and the deployments kept failing.

That is the interesting part of this incident. A rollback is supposed to undo a bad change. Here, the rollback kept the bug, because the bug was not really in the new code. It was in a choice the old code and the new code made differently, about which of two identical-looking robot users to trust.

First, the plain words

OIDC is short for OpenID Connect. In plain terms, it is a way for one system to prove who it is to another system without sharing a long-lived password or access key.

The proof is a token. A token here is a signed statement, a small bundle of claims that says who issued it, who it is for, and who it is about. The claim that says who the token is about is called the subject, shortened to sub.

When a deployment tool wants to act in your AWS account, it presents that token to AWS STS, the Security Token Service. STS checks the token against the trust policy on an IAM role. A trust policy is the rule that says who may assume that role. Many teams pin the exact sub value in that policy, so only tokens about one specific identity are accepted. If the token arrives with a different sub, STS refuses, and you get the error above.

To mint those tokens, env0 keeps an internal system user for each customer organisation. Think of it as a robot account whose only job is to sign the proof. The customer AWS account trusts tokens about that one robot.

Now the failure in one sentence, which is also how env0 put it in its postmortem: an organisation had two identical-looking robot users, env0 had always used one of them, the new code started using the other one, and the customer's AWS only trusts the first.

Where the duplicates came from

The duplicates were not new. According to the postmortem, a create race in early 2025 left some organisations with more than one system user, created seconds apart. A create race means two requests ran at nearly the same moment, each checked whether the user existed, each saw that it did not, and each created one.

For more than a year, that did not matter. The old code looked the user up with a search in Auth0, the identity service env0 uses, and took the first result. The search returned the same user every time, so every token carried the same sub, and AWS kept accepting them. A duplicate that nobody ever picks is harmless.

The change on 10 November, in release v4.0.312, moved that lookup from the Auth0 search to a database table. The new code made a different choice when more than one row existed: it took the oldest row.

Oldest sounds like a sensible tie-break. It is also a different tie-break from the one the system had effectively been using. For 21 organisations, the oldest row was not the user their tokens had used before. Four of those organisations minted tokens during the incident window. Two of them pinned sub in their AWS trust policies, and those two failed. The other two did not pin sub, so their deployments passed, with tokens about a different robot than the day before, and nobody noticed.

That split is worth pausing on. The same change was a hard outage for two customers and a silent identity swap for two others. Pinning sub is the stricter, safer setting, and it is exactly what turned a quiet change into a visible failure. The customers who had done the careful thing were the ones who broke.

Why the rollback did not roll back

Here is the trap, and it is the reason this incident is worth your time.

The old code took the first result of an unsorted Auth0 search. Unsorted means the code did not say in what order results should come back. Auth0, in practice, returns the most recently updated user first.

From 08:57 UTC, the duplicate user minted every token. Minting a token updates that user, so for two hours the duplicate kept becoming the most recently updated one. When env0 rolled back to the previous version at 11:00, the old code ran its search, got the duplicate first, and picked it again.

The rollback restored the old code. It did not restore the old choice, because the old choice depended on state that the incident itself had changed.

This shape shows up in ordinary code all the time. Any users[0] after a search with no explicit sort order is a choice made by the database, the search index, or the last writer, not by you. It works until the day something changes which row comes first. Then it changes silently, in production, and rolling back does not help if the new state now feeds the old code the same wrong answer.

Why nobody saw it for 75 minutes

The first failed deployment was at 08:59 UTC. env0 learned about the incident from a customer report at 10:14 UTC, one hour and fifteen minutes later. No alert had fired.

The reason is uncomfortable and common. On env0's side, everything succeeded. The token mint worked every time. The failure happened later, in the customer's call to AWS STS, outside env0's logs. Alerts that watch your own error logs cannot see a failure that happens in somebody else's system.

There was a second blind spot. The log line for a minted token recorded the key identifier as ****, masked out. So even after the report, env0's own logs could not say which robot user had minted the tokens. The answer was in the Auth0 action logs, which showed the minting user changing at 08:57, at the same moment as the deploy. Root cause was found within about 40 minutes of the report, from those logs.

Masking identifiers in logs is a reasonable habit. Masking the one identifier you would need to tell two identical-looking identities apart is the kind of detail that only matters on the worst morning.

The fix, and the cache that kept it broken

The mitigation was small and careful. Between about 11:11 and 11:21 UTC, env0 marked the duplicate users so that only the original could be selected. Ten duplicate users across six organisations. Each organisation kept the user with the most logins, because a check across all 80 duplicate groups, 30 for the OIDC user and 50 for another deployer user, showed that exactly one user per group had any logins. That gave the fix a safe rule: keep the one that has actually been used.

And still the tokens used the duplicates. The lookup was cached. A cache is a stored copy of an earlier answer, kept so the next lookup is fast. This one held search results for 3,600 seconds, one hour. The corrected data was in place, but the cached answer still pointed at the duplicate.

env0 refreshed the six stale cache entries one by one instead of flushing the whole cache. A full flush would have dropped cached token grants for everyone and risked rate limits from Auth0. At 11:35 UTC the original users started minting again, and by 11:36 deployments recovered. Total impact, about two hours and thirty-seven minutes.

The permanent fix, as described in the postmortem, changes the rule itself: the selection always keeps the identity an organisation already uses, and it cannot change once set. Plus removing the duplicates, alerting when several organisations fail with the same error in a short window, and a check after each release that the minting user per organisation has not changed.

One honest limit. The postmortem was written on the day, and at that point the permanent fix was approved but not yet merged. The counts above, 21 organisations where the oldest row differed, four that minted in the window, two that failed, are the postmortem's own numbers from its token logs. I have not named the affected customers, because the public summary does not name them.

Two guards you can add this week

The first guard is to make the choice once, store it, and refuse to re-choose. If your system has a get-or-create step for a robot user, a service account, or any identity that other systems trust by name, the pick must be pinned. In Go, the shape looks like this.

package main

import (
    "context"
    "errors"
    "fmt"
)

type SystemUser struct {
    ID        string
    OrgID     string
    LoginCount int
}

var ErrDuplicateSystemUser = errors.New("more than one system user for org")

// pickSystemUser returns the pinned user for an org.
// If no pin exists yet, it pins the user that has actually been used,
// and fails loudly when that is ambiguous instead of guessing.
func pickSystemUser(ctx context.Context, store Store, orgID string) (SystemUser, error) {
    if pinned, ok, err := store.PinnedSystemUser(ctx, orgID); err != nil {
        return SystemUser{}, err
    } else if ok {
        return pinned, nil // once set, never re-choose
    }

    users, err := store.SystemUsers(ctx, orgID) // explicit order, never users[0] on an unsorted search
    if err != nil {
        return SystemUser{}, err
    }

    switch len(users) {
    case 0:
        user, err := store.CreateSystemUser(ctx, orgID) // unique constraint on org_id prevents the create race
        if err != nil {
            return SystemUser{}, err
        }
        if err := store.PinSystemUser(ctx, orgID, user.ID); err != nil {
            return SystemUser{}, err
        }
        return user, nil
    case 1:
        if err := store.PinSystemUser(ctx, orgID, users[0].ID); err != nil {
            return SystemUser{}, err
        }
        return users[0], nil
    default:
        // Two or more rows. Keep the one with logins, and only if exactly one has them.
        var used []SystemUser
        for _, u := range users {
            if u.LoginCount > 0 {
                used = append(used, u)
            }
        }
        if len(used) != 1 {
            return SystemUser{}, fmt.Errorf("%w: org %s has %d candidates", ErrDuplicateSystemUser, orgID, len(users))
        }
        if err := store.PinSystemUser(ctx, orgID, used[0].ID); err != nil {
            return SystemUser{}, err
        }
        return used[0], nil
    }
}
Enter fullscreen mode Exit fullscreen mode

The numbers and types here are illustrative. What matters is the shape. Zero rows creates and pins. One row pins. Two or more rows never silently picks the first, the oldest, or the most recent. It either finds the one that has been used, or it stops and asks a human. And behind all of it, a unique constraint on the organisation column in the database makes the original create race impossible, because the second insert fails instead of creating a twin.

The same idea in Python, as a small check you can run after a deploy. This is the second guard: prove that the identity did not change.

import hashlib
import json
import sys

def fingerprint(user_id: str) -> str:
    # Log and compare a hash, not the raw id. You can tell two users apart
    # in logs without printing the identifier itself.
    return hashlib.sha256(user_id.encode()).hexdigest()[:12]

def check_minting_users(before: dict[str, str], after: dict[str, str]) -> list[str]:
    """before/after map org_id -> minting user id, sampled around a deploy."""
    changed = []
    for org_id, user_id in after.items():
        old = before.get(org_id)
        if old is not None and old != user_id:
            changed.append(org_id)
    return changed

if __name__ == "__main__":
    before = json.load(open("minting-users-before.json"))
    after = json.load(open("minting-users-after.json"))
    changed = check_minting_users(before, after)
    if changed:
        print(f"FAIL: minting user changed for {len(changed)} orgs: {changed}")
        sys.exit(1)
    print(f"OK: minting user unchanged for {len(after)} orgs")
Enter fullscreen mode Exit fullscreen mode

Run that before and after any release that touches identity lookup, token minting, or account selection, and fail the deploy when the answer changes. env0's postmortem asks for exactly this check. It would have caught the 10 November change in minutes, because the minting user for four organisations changed at 08:57, while the release was still rolling out.

There is a test worth writing next to both guards, and it is a boundary test. Feed your selection code zero rows, one row, and two rows. Zero should create. One should return that one. Two should never return a silent guess. Most get-or-create code is tested with zero and one, because those are the cases the author pictured. The duplicate case is the one that pages you two years later.

The takeaway

Nothing in this incident required a big platform. A get-or-create with no unique constraint. A search with no sort order, and a users[0] at the end of it. A tie-break changed from first-result to oldest-row in a release whose own description named the duplicate-user risk, but whose guard only covered the missing-row case. A cache that held the wrong answer for an hour. A log line that masked the one field that would have told the two users apart.

Each of those is a line you can find in a code review on a quiet day. Is there a unique constraint behind this get-or-create. When this search returns two rows, which one wins, and who decided that. If the answer changes, does anything downstream trust the old answer by name. When we roll back, does the old code read state that the bad release already changed.

env0 learned those answers on a Tuesday morning, from a customer, seventy-five minutes in. You can learn yours from a test with two rows in it.

Where in your system does a users[0], a first result, or an oldest row decide which identity, account, or record everyone downstream trusts, and what happens on the day a second row appears?

Sources: env0 status postmortem, Failed AWS deployments using OIDC authentication, 10 November 2026, 08:58 to 11:36 UTC, including the detailed postmortem OIDC Tokens Switched to a Duplicate System User and AWS Rejected Them for 2.5 Hours. The postmortem does not publish the affected customers in its public summary, so they are not named here, and the permanent fix was approved but not merged when the postmortem was written. The Go and Python snippets above show the shape of the guards, not env0 source code.

Top comments (1)

Collapse
 
maxpaint profile image
Maksym Danylenko •

The rollback test I would add is: let the new version change identity-selection state, then boot the old version against that state and its cache. Check that it selects the same trusted subject as before. Testing each version on a clean fixture would miss the failure you describe.