My homelab AWS organization doesn't allow IAM users. A service control policy on every member account denies iam:CreateUser to every principal except a short list of pipeline and administrator roles. I wanted that rule because static access keys are the credential I trust least. They don't expire, and sooner or later one ends up in shell history or an old commit.
The rule also left me with a problem. Workloads inside AWS already have execution roles, but plenty of my automation runs at home. The AWS CLI on the gateway host, infrastructure deployments and backup jobs all need programmatic credentials, and the old answer was an access key per account in ~/.aws/credentials.
At work the usual fixes are instance profiles for workloads in AWS and OIDC federation for CI pipelines. A machine on a home network has neither an instance profile nor an identity provider vouching for it. IAM Roles Anywhere covers that case. The machine holds an X.509 certificate signed by a CA I control. It proves it has the matching private key, and AWS hands back temporary STS credentials for a role. There's no access key to store or rotate.
The organization runs on AWS Landing Zone Accelerator (LZA) with eight accounts: Management, Network, SharedServices, Dev, AI, Backup, Audit and LogArchive. My first Roles Anywhere setup put one shared trust anchor, profile and role into all eight. Later I added narrower roles in a Terraform layer, one per workload. This post covers both.
How IAM Roles Anywhere issues credentials
Three resources do the work, and each one lives in a single account and region. The trust anchor is a CA certificate registered with Roles Anywhere. Any certificate that chains to it can attempt to authenticate. The profile lists the roles a session may assume and caps how long the session lasts. The role is an ordinary IAM role whose trust policy lets rolesanywhere.amazonaws.com assume it. Trusting one CA in eight accounts therefore means eight trust anchors, eight profiles and eight roles.
On the machine, the credential helper does the exchange. Homebrew packages it as rolesanywhere-credential-helper, and the binary is aws_signing_helper. It signs a CreateSession request with the machine's private key, sends the certificate with it, and prints the temporary credentials as JSON in the shape the AWS CLI's credential_process setting expects.
Tap to enlarge, then pinch to zoom
Building a CA that Roles Anywhere accepts
My first CA was wrong. I generated it with a bare openssl req -x509, and it was missing what Roles Anywhere requires of a trust anchor. AWS's trust model requires a trust anchor certificate to have CA:TRUE in its basic constraints and Certificate Sign in its key usage. A bare req -x509 doesn't guarantee either. With OpenSSL 3 I got the basic constraint and no key usage at all. The LibreSSL build that ships as /usr/bin/openssl on macOS adds neither. I regenerated the CA with both extensions spelled out, and that fix went in about an hour after my first commit.
These are the commands, with the extensions explicit so they behave the same under either build:
Check the CA before registering it anywhere. openssl x509 -in homelab-ca.pem -noout -text should list CA:TRUE under basic constraints and Certificate Sign, CRL Sign under key usage. If the key usage section is missing, the trust anchor won't work.
The machine certificate has fewer requirements. Roles Anywhere needs Digital Signature in its key usage, a SHA-256 or stronger signature, and no CA:TRUE. Current OpenSSL signs with SHA-256 by default. clientAuth isn't required, but I set it because it says what the certificate is for. The CA signs machine certificates directly, so there's no intermediate to ship. The helper only needs the leaf certificate, and it takes an --intermediates bundle for setups that have one.
The machine's private key is a file on disk with mode 600. It isn't in an environment variable or in any file that goes into Git.
One CloudFormation template across eight accounts
I could have created the three resources by hand in each account. With eight accounts, and more likely later, I wanted LZA to own them. LZA deploys arbitrary CloudFormation stacks through customizations-config.yaml, so the whole thing is one template. With names generalized:
The aws:SourceArn condition ties the role to this account's trust anchor. A session that came in through any other trust anchor can't assume it. The stack also outputs the trust anchor, profile and role ARNs, which go into the CLI config later.
The deployment targets OUs rather than listing accounts:
The management account sits at the organization root, outside every OU, so it's the one account listed by name. The OUs cover every other account, and a new account in one of those OUs gets the stack on the next pipeline run.
Tap to enlarge, then pinch to zoom
Why the CA certificate is hardcoded in the template
The template above has the CA's PEM pasted straight into X509CertificateData. That wasn't the plan. My first version kept the certificate out of the template and fed it in through LZA's replacements-config.yaml:
The template took CACertificatePem as a parameter and passed it to the trust anchor with !Ref. LZA's replacement step broke it on the way in. A PEM certificate depends on its line breaks, and LZA corrupted the multiline value when it substituted it into a quoted YAML string.
I could have worked around it. One option was to keep the certificate in Parameter Store and add a Lambda-backed custom resource to read it at deploy time. That's a function to maintain for one value that rarely changes, so I deleted the parameter and the replacement and hardcoded the PEM. It was my second commit that night, half an hour after the first.
Hardcoding is safe here because the CA certificate is public material. It's the same file you'd add to a trust store, and anyone holding it can verify signatures but can't issue them. The CA's private key is what needs protecting, and it never goes near the template or the repo.
Configuring the AWS CLI with credential_process
Each account gets a profile in ~/.aws/config that runs the helper:
The other five accounts follow the same pattern. The certificate, key and role name are the same everywhere. Only the trust anchor and profile ARNs differ, because each account's stack creates its own. After that, the profiles work like any others:
The AWS CLI doesn't cache credentials from credential_process, so every new CLI process runs the helper and does a fresh certificate exchange. That adds a short pause to each command. The helper also has a serve mode that answers on an IMDSv2-compatible endpoint on localhost, which avoids the repeated exchange. The cost is that any local process that can reach 127.0.0.1 can fetch the credentials, so I stayed with credential_process.
Running the helper by hand is the quickest way to debug a profile:
It prints JSON with AccessKeyId, SecretAccessKey, SessionToken and Expiration. The profile allows 43,200 seconds, but the credentials last one hour. The helper asks for 3,600 seconds unless you pass --session-duration, and Roles Anywhere uses the smaller of the requested value and the profile's value. Asking for more wouldn't work either. The role keeps IAM's default one-hour maximum session duration, and CreateSession returns an error when the duration is longer than the role allows. So the 12 hours on the profile never takes effect, and every session ends after one hour. That suits CLI use, because each new command gets fresh credentials.
Tap to enlarge, then pinch to zoom
What changed for the old access keys
Before this, ~/.aws/credentials held one key pair per account. They were valid until someone deleted them, and any one of them would have given full administrative access to its account if it leaked through a commit or a log.
None of the homelab profiles read from that file now. Getting a working credential means taking both the certificate and the private key off the machine, and credentials copied out of a log or a process expire within the hour. The SCP keeps it that way, because automation can't fall back to creating an IAM user.
Human access is unchanged. Console sign-in goes through AWS IAM Identity Center, which is the right tool for a person at a browser. Roles Anywhere is only for machines that need credentials with nobody in the loop.
Pinning certificates to specific roles
The shared role is deliberately general. Its trust policy checks which trust anchor a session came through, not which certificate, So any certificate signed by that CA gets the role's AdministratorAccess. That was fine to start with, but it's far too broad for automation that only needs one job's worth of access. AWS's getting-started guide recommends adding conditions on the certificate's subject and issuer, and I did that for my automation roles.
When I moved my Terraform automation onto Roles Anywhere, I didn't reuse that role. The SharedServices account has a second trust anchor built on a separate automation CA, managed by Terraform rather than LZA. Each workload has its own role, and each role's trust policy pins the certificate's common name. One is the Atlantis runner that plans and applies Terraform from pull requests, which I wrote about in Terraforming My Homelab. The others belong to Burrito's drift-detection datastore and to the database backup jobs. With names generalized, the pattern looks like this:
Roles Anywhere turns the certificate's subject fields into session tags, so x509Subject/CN is the CN from the certificate the client presented. A certificate issued for the backup jobs can't assume the Terraform runner's role, even though the same CA signed both. Each role also gets a policy scoped to its job. The database backup role, for example, can only read and write objects under two prefixes in one S3 bucket. These profiles and roles all use one-hour sessions, so the profile's duration and the role's maximum agree.
Tap to enlarge, then pinch to zoom
Where the pattern spread, and where it didn't
The first certificate was issued for one machine. My command center now uses a copy of the same certificate and key, so both machines share one identity. That's convenient, but revoking the certificate cuts off both, and AWS sees the same certificate subject from either one. A certificate per machine is the cleaner setup, and with my own CA it costs one more signing command.
When I later set up a separate personal AWS organization, I reused the pattern. Each of its seven accounts has its own Roles Anywhere stack, with a separate CA and a read-only role next to the admin role, so routine checks don't need admin credentials. That organization isn't as strict as the homelab one. It still has IAM users outside LZA, and my NAS's offsite S3 backup job signs in with one IAM user's access key. That key is limited to one bucket and can't permanently delete object versions.
The per-workload roles have a weak spot too. The Terraform runner's policy can create IAM roles, attach policies to them, and edit Roles Anywhere profiles, because Terraform manages the backup role and its profile. My last security audit flagged that as a path to account admin, and narrowing it is still an open item.
- IAM Roles Anywhere for certificate-based machine authentication
- aws_signing_helper 1.8.x for the credential exchange: Homebrew rolesanywhere-credential-helper on the Macs, AWS's release binary on Linux hosts, and a pinned build in the Atlantis and Burrito init containers
- OpenSSL for a self-signed CA with explicit keyCertSign and CA:TRUE, and machine certificates with digitalSignature and clientAuth
- AWS Landing Zone Accelerator and CloudFormation for the shared trust anchor, profile and role in all eight accounts, and the same pattern with read-only and admin roles in a second, personal organization
- Terraform for the CN-pinned per-workload roles in SharedServices
- Service control policies to deny iam:CreateUser in member accounts
- AWS IAM Identity Center for human console access
Homelab-CA is valid until March 2036. Replacing it, at expiry or sooner if its private key were ever exposed, means updating the trust anchor in all eight accounts and re-issuing every machine certificate it signed. Because the PEM is hardcoded, the LZA side is one change to roles-anywhere.yaml and one pipeline run. The machine certificates are the manual part, since each one has to be signed again by the new CA and put back where it runs.