When automation picks a virtual machine image by searching for a name and taking the newest match, anyone who can publish a public image with a matching name can decide what your servers boot. This class of weakness, called a cloud image name confusion attack, was described for Amazon Machine Images (AMIs) as "whoAMI" by Datadog Security Labs in February 2025, and the same lookup pattern exists wherever images are found by name, family or filter. This guide explains how the lookup goes wrong, where it hides in infrastructure as code and scripts, and the owner filters, allow-lists and detection checks that close it on each major cloud. It is written for cloud and DevOps engineers and the owners of Terraform, Pulumi, CloudFormation and build pipelines. Clouds are listed alphabetically (Amazon Web Services, Google Cloud, Microsoft Azure); order is not a ranking.
Key takeaways
- The bug is in the lookup, not the cloud. A search by image name with "most recent" selection and no owner constraint can return an image published by a stranger; the instance then runs that stranger's code with your instance role.
- Always pin the publisher. On AWS set
ownersor anowner-idfilter, on Google Cloud always name the image project, and on Azure reference images by publisher, offer and SKU or by a gallery image ID you control. - Add a platform guardrail behind the code fix. EC2 Allowed AMIs, the Google Cloud
compute.trustedImageProjectsorganisation policy and Azure Policy image rules block untrusted images even when a template is wrong. - Start in audit mode. Allowed AMIs has an
audit-modestate and an AWS Config rule that flags instances already running from images outside the criteria, so you can measure before you enforce. - A golden image pipeline removes most of the risk. When workloads launch only from images your own account built, signed off and published, public name lookups disappear from production code.
What image name confusion is
Every major cloud offers public or community image catalogues so customers can launch an operating system without building it. Images carry a human-readable name and a stable, unique identifier (an AMI ID, an image self-link, a gallery image resource ID). Names are not unique across publishers: two accounts can publish images with the same or similar names. Image name confusion happens when a tool resolves a name pattern to an identifier without restricting who published the image, and then chooses one result, usually the newest.
The weakness is closely related to dependency confusion in package registries, where a build pulls a public package that shadows an internal one. See the Malicious Package and Dependency Confusion Guide. The image form is worse: the image is the whole operating system and runs before any agent or endpoint control is added.
| Term | Meaning |
|---|---|
| Image name confusion | A lookup by name or pattern returns an image from an unintended publisher |
| whoAMI | Datadog Security Labs' name for the AWS form of the weakness, published 12 February 2025 |
| Owner filter | A lookup constraint that limits results to named publisher accounts or aliases |
| Image allow-list | A platform setting or policy that only permits launches from approved publishers or images |
| Golden image | An internally built, hardened, approved image that workloads must launch from |
How the attack works
Datadog's research describes the conditions, and this guide keeps to the concept. Three things must be true at once:
- A name-based search: code calls an image search API (for example EC2
DescribeImages) with a name filter or regular expression such as a distribution name with a wildcard. - No publisher constraint: the search does not restrict the owner, so public images from any account are candidates.
- Automatic selection: the code takes the most recent match, so an image published later with a matching name wins.
An attacker who guesses a commonly used name pattern publishes a public image that matches it. The next time the vulnerable code runs, it resolves to the attacker's image and launches it. The resulting instance runs with whatever instance role, network position and user data the template gives it, which is why the impact is closer to a supply chain compromise (MITRE ATT&CK T1195 Supply Chain Compromise) than to a misconfiguration. A related technique, T1525 Implant Internal Image, covers an insider-planted image in your own account, which owner filters do not stop.
According to the Datadog write-up, the research found the vulnerable pattern in multiple software projects in August 2024, reported it to AWS on 16 September 2024, and estimated that about 1% of organisations it monitors were affected. AWS released Allowed AMIs on 1 December 2024, and the HashiCorp AWS provider added a warning for unsafe lookups in version 5.77.
Where it shows up (IaC, scripts, marketplaces)
- Terraform: the
aws_amidata source withmost_recent = trueand name orname_regexfilters but noowners. Since AWS provider 6.0.0 (18 June 2025) this is an error unlessowners, anowner-idfilter or animage-idfilter is set, or the operator explicitly setsallow_unsafe_filter = true, which the provider documentation advises against. Modules pinned to provider 5.x still only warn. - SDK and CLI scripts: Bash, Python, Go, Java and Pulumi code calling
describe-imagesthen sorting by creation date. Datadog lists all of these, plus the AWS Labsaws-simple-ec2-clitool, fixed in v0.11.0. - Build pipelines: image builders (Packer templates, EC2 Image Builder recipes, CI jobs) that find a base image by name before hardening it. A confused base flows into every golden image built from it, so this is the highest-value place to check.
- Community catalogues: Azure community galleries let any subscription owner publish images publicly. Microsoft states that it does not verify or test community images or publisher information and that community images are not scanned for malware; the deploying customer is responsible for the image.
- Marketplace listings: commercial listings are a separate channel with publisher onboarding. They still need a publisher constraint, because a typo or a look-alike publisher name resolves to a different product. See the Cloud Marketplace Purchasing Security guide.
Safe and unsafe lookups
The difference is usually one line. This unsafe Terraform pattern searches all public AMIs by name and takes the newest:
1 Sample only, based on the public documentation cited. Assess it independently against the current official documentation, test outside production and back up first.
data "aws_ami" "base" {
most_recent = true
filter {
name = "name"
values = ["ubuntu-*-24.04-amd64-server-*"]
}
# no owners: any publisher's image can match
}The safe version names the publisher account (here, the account the distribution publishes from, which you should confirm in the distribution's own documentation) or uses an AWS-maintained parameter:
data "aws_ami" "base" {
most_recent = true
owners = ["123456789012"] # the publisher's account ID, or "self" for your own images
filter {
name = "name"
values = ["golden-ubuntu-24.04-*"]
}
}
# Or resolve an AWS-published AMI through a public SSM parameter:
# image_id = "resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64"On Google Cloud the google_compute_image data source takes family with a project; if project is omitted the provider project is used, so always set it explicitly to the image project you intend (for example a distribution's public image project, or your own image project). On Azure, reference a Marketplace image with publisher, offer and sku, and a gallery image by its full resource id, sharedGalleryImageId or communityGalleryImageId, copied from the gallery rather than built from a display name.
Preventing it with owner filters and allow-lists
Fix the code first, then add a platform control so a future template mistake fails closed. The table lists each cloud's own controls; the sections after it give the settings.
| Cloud | Lookup constraint in code | Platform guardrail | Audit before enforcing |
|---|---|---|---|
| Amazon Web Services | owners or owner-id filter; SSM public parameters for AWS images | EC2 Allowed AMIs, per Region, centrally through an AWS Organizations declarative policy | audit-mode state; Config rule ec2-instance-launched-with-allowed-ami |
| Google Cloud | Explicit project on every image or family reference | Organisation policy compute.trustedImageProjects at organisation, folder or project | Apply to a test folder or project first and review results |
| Microsoft Azure | publisher/offer/sku or a full gallery image ID | Azure Policy rules on Microsoft.Compute/imagePublisher or Microsoft.Compute/imageId, assigned at management group | Assign the policy with an Audit effect before Deny |
Amazon Web Services
- Allowed AMIs criteria: up to 10
ImageCriterionblocks (OR between blocks, AND inside each), usingImageProviders(amazon,aws-marketplace,aws-backup-vault, 12-digit account IDs ornone),ImageNames,MarketplaceProductCodes, creation and deprecation age conditions, and Amazon Inspector scan result conditions. AWS recommends pairingImageNameswithImageProvidersbecause names alone may not identify an AMI uniquely. - Scope: the setting is per Region and applies to public AMIs and AMIs shared with the account; AMIs the account owns are always usable. Include
amazonif you run managed services such as ECS or EKS that launch AWS images. - Central management: an AWS Organizations declarative policy applies the setting across accounts and Regions and stops local changes. See the AWS Organizations and SCPs Guide.
- Availability: Inspector-based scan conditions block AMIs that Inspector has not scanned, so turn those on only once Inspector coverage is in place.
Google Cloud
- Trusted image policy: the list constraint
constraints/compute.trustedImageProjectstakesallowedValuesordeniedValuesentries of the formprojects/IMAGE_PROJECT, orallValues: DENYto block all public images. It restricts which projects persistent disks, and so boot disks, can be created from. - What it does not restrict: Google documents that custom images in the local project and image files in Cloud Storage are outside the policy, so control who can create images in workload projects as well.
- Families: image families point to the latest non-deprecated image in a project; Google recommends testing the newest family image before production and promoting it into a production family in your own project. See the Google Cloud Organization Policy Guide.
Microsoft Azure
- Publisher allow-list: the Azure Policy sample "Only allow certain image publishers from the Marketplace" denies virtual machines and scale sets whose
Microsoft.Compute/imagePublisheris not in an approved list. - Approved images: the "Approved VM images" sample denies virtual machines whose
Microsoft.Compute/imageIdis not in an approved list, and a further sample permits only images from a named resource group, which suits a golden image gallery. - Community galleries: Microsoft provides a policy rule that denies galleries whose sharing profile is set to Community, which stops your own subscriptions publishing images publicly by accident. Use the portal's Report option or the MSRC abuse form for malicious community images. See the Azure Policy and Management Groups Guide.
How to implement
- Inventory lookups: search repositories for
aws_ami,describe-images,DescribeImages,google_compute_image,source_image_referenceandimageReference, and list each one with its publisher constraint or lack of one. IaC scanners can flag these; see the Checkov and IaC Scanners Guide. - Fix code: add owners or projects, or switch to IDs from your own gallery. Upgrade the Terraform AWS provider to 6.x so unsafe lookups fail at plan time, and treat any
allow_unsafe_filter = trueas a review finding. - Turn on audit: Allowed AMIs in
audit-modein every used Region, Azure Policy with Audit effect, and the Google trusted image policy on a test folder. - Review results: resolve every running instance launched from an unexpected publisher (rebuild, or approve the publisher with a recorded reason).
- Enforce in rings: sandbox accounts and projects, then non-production, then production, keeping a documented exception path.
- Roll back safely: if enforcement breaks a managed service or scaling group, return that scope to audit (Allowed AMIs
audit-mode, Azure Audit effect, or remove the folder-level Google constraint), fix the criteria, and re-enforce. Note that changes to central policies need the central owner.
Detecting untrusted images in use
- AWS: the Config rule
ec2-instance-launched-with-allowed-ami(identifierEC2_INSTANCE_LAUNCHED_WITH_ALLOWED_AMI) marks running or stopped instances NON_COMPLIANT when their AMI does not meet the criteria, and works while the setting is enabled or in audit mode.describe-instance-image-metadatareturns per-instance image details for the same check. In CloudTrail, look forRunInstanceswhoseimageIdbelongs to an account outside your approved owner list, and forDescribeImagescalls without an owner parameter followed by a launch. See the AWS CloudTrail Guide. - Google Cloud: query disks'
sourceImagethrough Cloud Asset Inventory and alert on any image project outside the trusted list; review organisation policy violation logs after enforcement. - Microsoft Azure: query
properties.storageProfile.imageReferenceacross subscriptions with Azure Resource Graph and flag publishers outside the allow-list or anycommunityGalleryImageId; Azure Policy compliance results give the same view once the audit assignment is in place.
| Metric | Target |
|---|---|
| Image lookups in code without a publisher constraint | Zero, enforced in CI |
| Regions and accounts with Allowed AMIs enabled, or projects and subscriptions under an image policy | 100% of used scopes |
| Running instances from non-approved publishers | Zero, or each with a recorded exception and expiry |
| Share of production instances launched from internal golden images | Rising towards 100% |
| Median age of golden images in use | Inside your patch policy window |
The golden image pipeline as the long-term fix
Owner filters reduce who can supply an image; a golden image pipeline reduces it to you. Build from a pinned base image (by ID or an owner-constrained lookup), harden it, scan it, record its provenance, and publish it to an image location only the pipeline can write. Workloads then launch only from that location, which an allow-list can express exactly (your account ID and an ImageNames prefix on AWS, your image project on Google Cloud, your gallery resource group on Azure). The Server Build and Golden Image Hardening Guide covers the build, hardening, secrets and lifecycle steps in depth.
- Protect the pipeline identity: the role that publishes golden images can plant a backdoor in every server (T1525), so give it a dedicated identity, short-lived credentials and change approval. See the Infrastructure as Code Security Guide.
- Do not over-share: share golden images only with the accounts that need them and never publicly; the Public AMI and Snapshot Exposure guide covers the opposite risk of leaking your own images.
- Small versus large organisations: a small team can reach most of the benefit with owner-pinned lookups plus Allowed AMIs or the equivalent policy; a large estate should centralise images in one build account or project and enforce the allow-list through organisation-level policy.
Common failure patterns
- Owner filter only in some modules: the main module is fixed but an older module, a sandbox template or a one-off script still searches without an owner.
- Allow-list by name alone: an Allowed AMIs criterion with
ImageNamesbut noImageProvidersre-creates the original problem inside the guardrail. - Escape hatch left on:
allow_unsafe_filter = trueadded to make a provider upgrade pass and never removed. - Base image confusion in the builder: production launches only golden images, but the image builder itself finds its base image by name, so a confused base is hardened and approved.
- One Region only: Allowed AMIs enabled where the team usually works, while an unused Region accepts any public image.
- Omitted project: a Google Cloud family lookup without
projectresolves in the provider project, so a family name created there is silently used.
Framework mapping
| Control area | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | ATT&CK |
|---|---|---|---|
| Approved images only | CM-7(5) Authorized Software, Allow-by-exception; CM-2 Baseline Configuration | PR.PS-01 | T1195 Supply Chain Compromise |
| Image provenance and authenticity | SR-4 Provenance, SR-11 Component Authenticity, CM-14 Signed Components | ID.AM-08, PR.PS-02 | T1195.002 Compromise Software Supply Chain |
| Image integrity in the pipeline | SI-7 Software, Firmware, and Information Integrity | PR.PS-01 | T1525 Implant Internal Image |
| Detecting launches from untrusted images | CM-7, SI-7 | DE.CM-09 | T1578 Modify Cloud Compute Infrastructure |
Practitioner checklist
- Every image lookup in IaC, scripts and builders names a publisher account, alias, project or gallery ID.
- Terraform AWS provider at 6.x or later, and no
allow_unsafe_filter = truewithout a recorded exception. - EC2 Allowed AMIs in audit mode, then enabled, in every Region you use, managed through a declarative policy.
- Google Cloud
compute.trustedImageProjectsset at organisation or folder level with an explicit project list. - Azure Policy publisher or image ID rules assigned at management group scope, plus the rule blocking Community gallery sharing.
- Config rule, Asset Inventory query or Resource Graph query reporting instances from non-approved publishers, reviewed weekly.
- Golden image pipeline with a pinned base image, a dedicated publishing identity and images shared only with named accounts.
- IaC scanning in pull requests that fails on unconstrained image lookups.
Standards and references
- AWS: Control the discovery and use of AMIs in Amazon EC2 with Allowed AMIs
- AWS: ec2-instance-launched-with-allowed-ami Config rule
- Google Cloud: Setting up trusted image policies
- Google Cloud: Image families best practices
- Microsoft Learn: Share images using a community gallery
- Microsoft: Azure Policy Compute samples (approved images and publishers)
- HashiCorp: aws_ami data source
- Datadog Security Labs: whoAMI, a cloud image name confusion attack
Related NHI Mgmt Group resources: Server Build and Golden Image Hardening Guide · Cloud Security Guide · Amazon EC2 Security Guide · Software Supply Chain Security Guide · Container Image Security Guide