The problem

I run a small AWS organization for my company: five accounts, everything defined in code, deployed from a laptop that signs in through IAM Identity Center, the thing most people still call SSO. That works on a laptop because SSO is a browser flow. The CLI prints a code, you approve it in a browser, and you get a token that lasts a workday.

Then I moved the deploy jobs to an always-on local device with no screen attached. A scheduler runs them. There is no browser, and nobody is sitting there to approve a device code at six in the morning. The SSO token also expires between runs, so the first job after it expires fails, and so does every job after that until a human logs in again.

The obvious answer is an IAM user with access keys in a file on the device. That is the answer every AWS security guide, and every incident write-up, tells you not to pick: a long-lived secret on disk, usable from anywhere by anyone who copies it, with no tie to the machine it was issued to.

The shape of the right answer is well known. A device proves who it is with something that cannot be copied off it, a trusted service hands back credentials that expire within the hour, and nothing long-lived sits on disk. Large environments build that with a secrets-manager server and a certificate authority in front of it. For two devices and five accounts, a server to patch, back up, unseal and pay for is more infrastructure than the problem deserves. I wanted the same guarantee without running anything.

What Roles Anywhere is

AWS IAM Roles Anywhere is AWS's managed version of that exact pattern. You register a certificate authority you control as a trust anchor in an account. A machine holding a certificate signed by that CA presents it to the Roles Anywhere endpoint, and AWS hands back temporary credentials for an IAM role whose trust policy says "only sessions that came through this anchor, from a certificate with this subject."

The service has no charge. The CA can be one you make with openssl in a terminal. AWS's own Private CA product works too, at about $400 a month for a general-purpose CA, which is a lot of money to protect one device.

Three AWS objects per account, two files per device, one line in a config file. Here is the build, in the order I did it.

1. Make a CA, offline, and keep it off the device

The CA private key is the thing that mints device identities. It lives on my laptop, under full-disk encryption, mode 0600, with a copy in a password manager. It is never on the deploy device and never in a repository.

mkdir -m 700 ~/.stingrayio-ca && cd ~/.stingrayio-ca

cat > ca.cnf <<'EOF'
[req]
distinguished_name = dn
x509_extensions = v3_ca
prompt = no
[dn]
C = US
ST = West Virginia
O = StingRayIO LLC
OU = stingrayio-devices
CN = StingRayIO Devices CA
[v3_ca]
basicConstraints = critical, CA:TRUE, pathlen:0
keyUsage = critical, keyCertSign, cRLSign, digitalSignature
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always
EOF

openssl ecparam -name prime256v1 -genkey -noout -out ca.key
chmod 600 ca.key
openssl req -new -x509 -key ca.key -config ca.cnf -days 3650 -sha256 -out ca.crt

Roles Anywhere requires the CA certificate to carry CA:TRUE and the certificate-signing key usage. pathlen:0 means this CA can sign device certificates but can never sign another CA, so a leaked key cannot quietly grow a tree. Ten years, P-256. The public certificate, ca.crt, is fine to commit anywhere; it is what AWS will trust.

2. A key and a certificate per device, and the key never moves

On each device, generate the key where it will live and make a signing request:

mkdir -m 700 ~/.aws/ra && cd ~/.aws/ra
openssl ecparam -name prime256v1 -genkey -noout -out device-01.key
chmod 600 device-01.key
openssl req -new -key device-01.key -sha256 \
  -subj "/C=US/ST=West Virginia/O=StingRayIO LLC/OU=stingrayio-devices/CN=device-01" \
  -out device-01.csr

Copy only the .csr to the laptop that holds the CA. Sign it for one year with the extensions a client certificate needs:

cat > device.ext <<'EOF'
basicConstraints = CA:FALSE
keyUsage = critical, digitalSignature
extendedKeyUsage = clientAuth
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
EOF

openssl x509 -req -in device-01.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -days 365 -sha256 -extfile device.ext -out device-01.crt

Copy the .crt back next to its key, along with ca.crt, and delete the request. Repeat for the laptop with its own CN. Roles Anywhere requires digitalSignature in the key usage; the rest is ordinary client-certificate hygiene.

One year is a deliberate choice. Renewal is a five-minute round trip of the same two commands, and nothing in AWS changes when you do it, because AWS trusts the CA, not the individual certificate.

3. Three objects in each AWS account

Per account: a trust anchor, a role, and a profile. I wrote these as an idempotent target in my infrastructure tool so I can re-run it to add a device or refresh a policy. The equivalent CLI calls follow; the console works too.

The trust anchor is the CA certificate, registered. The PEM goes in as one JSON string with the line breaks escaped:

aws rolesanywhere create-trust-anchor --cli-input-json file://anchor.json

# anchor.json
{
  "name": "stingrayio-devices",
  "enabled": true,
  "source": {
    "sourceType": "CERTIFICATE_BUNDLE",
    "sourceData": { "x509CertificateData": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n" }
  }
}

The role is where the security actually lives. This is the trust policy as my tool generates it, with only the device names changed:

{
  "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:us-east-1:<ACCOUNT>:trust-anchor/<ANCHOR_ID>"
      },
      "StringEquals": {
        "aws:PrincipalTag/x509Subject/CN": [ "device-01", "laptop-01" ]
      }
    }
  }]
}

Three things to notice. The principal is the Roles Anywhere service, not a user or an account. sts:TagSession is required because Roles Anywhere passes the certificate's subject fields into the session as tags, and the CN condition reads one of those tags. And there are two conditions joined by AND: the session must have come through my anchor, and the certificate's CN must be one of the two names listed. If my CA ever signs a third certificate, that device cannot touch this role until I add its name here.

aws iam create-role --role-name iac-device-admin \
  --assume-role-policy-document file://trust.json --max-session-duration 3600
aws iam attach-role-policy --role-name iac-device-admin \
  --policy-arn arn:aws:iam::aws:policy/AdministratorAccess

Yes, AdministratorAccess. I come back to that below, because it is the decision in this post I would most want you to question.

The profile binds the role and sets the session length. It cannot exceed the role's maximum, so set both:

aws rolesanywhere create-profile --name stingrayio-devices --enabled \
  --role-arns arn:aws:iam::<ACCOUNT>:role/iac-device-admin \
  --duration-seconds 3600

4. The helper and one line of config

AWS publishes aws_signing_helper, an open-source binary that signs the request to Roles Anywhere with the device key and prints credentials in the format every AWS SDK expects from a credential_process. On a Mac, brew install rolesanywhere-credential-helper; AWS publishes Linux and Windows builds on the project's releases page. Then one stanza in ~/.aws/config, with the credential_process value on a single line:

[profile sso-prod]
region = us-east-1
output = json
credential_process = /opt/homebrew/bin/aws_signing_helper credential-process --certificate /Users/<you>/.aws/ra/device-01.crt --private-key /Users/<you>/.aws/ra/device-01.key --trust-anchor-arn arn:aws:rolesanywhere:us-east-1:<ACCOUNT>:trust-anchor/<ANCHOR_ID> --profile-arn arn:aws:rolesanywhere:us-east-1:<ACCOUNT>:profile/<PROFILE_ID> --role-arn arn:aws:iam::<ACCOUNT>:role/iac-device-admin

The profile is still called sso-prod on purpose. Every account mapping in my tooling resolves by profile name, so nothing downstream had to change when the credential source did. The AWS CLI, boto3, and every other SDK read credential_process natively. The deploy script did not change by a single character.

5. Prove it

$ aws sts get-caller-identity --profile sso-stingrayio
{
    "UserId": "AROA...:<CERT_SERIAL>",
    "Account": "<ACCOUNT>",
    "Arn": "arn:aws:sts::<ACCOUNT>:assumed-role/iac-device-admin/<CERT_SERIAL>"
}

That is this laptop, this morning, with the serial masked. The session name is the certificate's serial number, so every CloudTrail event from this session says which device made it. On the deploy device, the deploy script's dry run came back clean, then the real deploy, then a scheduled job at six in the morning that nobody had to approve. It has run every day since.

What this buys

  • No long-lived secret anywhere. The private key never leaves the device. The credentials it earns last an hour.
  • Device-bound. The role names the certificates allowed to use it. The config file is useless on another machine without that machine's key, and the key is 0600 on an encrypted disk.
  • Audit by device. Every session creation is in CloudTrail with the certificate that made it, and the session name carries the serial through to every API call after that.
  • Instant revocation. Disable the trust anchor or the profile and every device stops, in one call, from the laptop. A certificate revocation list handles one device at a time if you need that.
  • Renewal without touching AWS. A CSR round trip once a year. Adding a device is a certificate and one more name in the trust policy.

Trade-offs I accepted, and would want you to look at

The device is the only factor. SSO gives you multi-factor authentication at sign-in. Roles Anywhere gives credentials to whoever holds the device's unlocked disk. Mine run full-disk encryption with automatic login off and the key at 0600. If a device were stolen while unlocked, the thief would have an hour of that role until I disabled the anchor. Decide whether that is acceptable for the permissions you grant, and grant fewer if it is not.

AdministratorAccess. My first design gave the deploy device a deploy-only role: write to one bucket, invalidate one CloudFront distribution. Then I decided that device should run the whole infrastructure tool, which needs administrative rights in each account, and I widened the role. That was a convenience decision and I know it. A box that only deploys should get a role that only deploys. Mine is one attach-role-policy call away from being tightened, and writing this post has moved that up my list.

The CA key is a file on a laptop. A hardware token or an air-gapped machine is better. For a two-device CA under full-disk encryption with a password-manager backup, I judged the file acceptable. pathlen:0 limits what a leaked key could do, and disabling the anchor kills everything it ever signed at once.

A binary you have to trust. The signing helper is published by AWS and the source is public. The Homebrew bottle is built from the GitHub release. Pin the version and check the hash if that matters in your environment.

One-year certificates need a reminder. Mine renew by September 2027, and that date is written where I will see it. An expired device certificate fails exactly like an expired SSO token: at six in the morning, in a log nobody reads.

What I did not do

  • IAM user access keys. The thing this whole post avoids.
  • Copying the laptop's SSO token to the deploy device. Fragile, and it defeats the device binding.
  • A self-hosted secrets manager on EC2. The correct pattern, but a server to patch, back up, unseal and pay for, to protect one box.
  • A secrets-manager app role with a secret ID on the device. The secret ID is itself a long-lived credential unless wrapped and network-bound, and it still needs the server.
  • An EC2 instance role. The device sits in an office in West Virginia, not in a VPC. Roles Anywhere exists for exactly that.

What it cost

Roles Anywhere: nothing. The CA: nothing. One afternoon to build it for five accounts and two devices, most of it spent writing the setup as a re-runnable target instead of clicking through a console. Renewal: five minutes a year.

If you have a box somewhere that needs to talk to AWS on a schedule, and the current answer is a pair of access keys in a file, this is the replacement. It took less time than I had spent worrying about those keys.