Master AWS Security with `saml2aws`: A Complete Guide

Updated

saml2aws

saml2aws exchanges a SAML assertion from your identity provider for temporary AWS credentials. Four settings decide whether that is safer than a long-lived access key or not:

saml2aws configure -a corp --idp-provider=Okta --mfa=PUSH \
  --url=https://example.okta.com/home/amazon_aws/abc123/272 \
  --username=jane@example.com --profile=prod --session-duration=3600

saml2aws login -a corp          # never with --skip-verify
saml2aws exec  -a corp -- aws sts get-caller-identity

Everything below was run against the real darwin_arm64 binary of v2.36.19 (published 2025-03-13, still the current release). For installation, see the companion page on installing saml2aws on Windows; this page is only about what the flags do to your security posture.

Installing on Linux: there is no apt or yum package

The commands sudo apt install saml2aws and sudo yum install saml2aws name packages that do not exist:

Debian sources API   → {"query":"saml2aws","results":{"exact":null,"other":[]}}
Ubuntu (Launchpad)   → 0 published sources
Fedora Packages      → "No results found!" across Fedora 43, 44, Rawhide, EPEL 8/9/10

On Linux, download the release tarball or use the Homebrew formula (saml2aws, stable 2.36.19), which works there too.

Where the password actually goes

Your IdP password is not written to the config file. Two accounts created here, then grepped:

$ grep -icE 'password|secret|token' ~/.saml2aws
0

It goes to the OS credential store via a keyring library — Keychain on macOS, Credential Manager on Windows, Secret Service or pass on Linux. --disable-keychain turns that off, and its own help names the collateral damage:

--[no-]disable-keychain  Do not use keychain at all. This will also
                         disable Okta sessions & remembering MFA
                         device. (env: SAML2AWS_DISABLE_KEYCHAIN)

So it is not just “type the password each time” — it also kills Okta session reuse and the remembered-MFA-device state, so you get a fresh MFA challenge on every login. That is the right trade on a shared CI box where a per-user keychain is meaningless, and the wrong one on your laptop because a prompt annoyed you once.

A wrinkle the docs do not spell out: --disable-keychain is not persisted. After configure with the flag set, the config file contains no keychain key at all — grep -ci keychain returns 0. Pass it every time, or export SAML2AWS_DISABLE_KEYCHAIN.

Check the file’s mode while you are there: it was created 0644 — world-readable, holding your IdP URL, username and profile mapping. Not credentials, but a precise map of your SSO setup. chmod 600 ~/.saml2aws.

Session duration: saml2aws will accept a number AWS will not

--session-duration takes seconds, and is validated by AWS rather than by saml2aws. Setting a day:

$ saml2aws configure -a hw-long --session-duration=86400 --skip-prompt ...
Configuration saved for IDP account: hw-long

$ grep aws_session_duration ~/.saml2aws
aws_session_duration    = 86400

Accepted, saved, no warning. AWS’s AssumeRoleWithSAML reference says this cannot work: “You can provide a DurationSeconds value from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours.” The failure appears at login, not at configure.

The same page adds the constraint most people miss: “Your role session lasts for the duration that you specify, or until the time specified in the SAML authentication response’s SessionNotOnOrAfter value, whichever is shorter.” Your IdP can return a shorter window than you or the role asked for, and it wins. If credentials keep expiring early, look there rather than at saml2aws.

--skip-verify is the one flag that turns this tool into a liability

-s / --skip-verify is documented as “Skip verification of server certificate,” and gets recommended constantly as a fix for corporate-proxy certificate errors. Here is what it changes, against a local HTTPS server with a self-signed certificate:

$ saml2aws login -a tlstest
Using IdP Account tlstest to access ADFS https://127.0.0.1:18443/
Authenticating as jane@example.com ...
Error authenticating to IdP.: ... tls: failed to verify certificate:
x509: certificate signed by unknown authority

$ saml2aws login -a tlstest -s
Using IdP Account tlstest to access ADFS https://127.0.0.1:18443/
Authenticating as jane@example.com ...
Error authenticating to IdP.: unable to locate IDP authentication form submit URL

Both exit 1, for opposite reasons. Without the flag saml2aws refused to speak to the server. With it the TLS objection vanished and it went hunting for a login form on a host whose identity it had never established — on the one connection carrying your IdP password and your SAML assertion.

The fix for a proxy certificate error is installing your organisation’s root CA into the system trust store. Use -s once, interactively, to confirm a diagnosis — never in a stored config, an alias, or SAML2AWS_SKIP_VERIFY.

Role chaining is not a saml2aws feature

Searching the whole help output for “chain” returns four occurrences, every one of them the substring inside disable-keychain. --role is not chaining — its help reads “The ARN of the role to assume”, meaning which role in your SAML assertion to pick so you are not prompted:

saml2aws login -a corp --role=arn:aws:iam::111122223333:role/Developer

Chaining into a second account is the AWS SDK’s job. Point a profile at the one saml2aws populates:

# ~/.aws/config
[profile prod]                       # saml2aws writes credentials here

[profile audit]
role_arn       = arn:aws:iam::444455556666:role/Auditor
source_profile = prod

Two AWS limits follow. In AWS’s words, “Role chaining limits your AWS CLI or AWS API role session to a maximum of one hour” — whatever the role’s MaxSessionDuration says — and the chain starts from credentials that already expire with your SAML session. On the saml2aws side, --policyarns and --policyfile attach a session policy that can only subtract permissions from the assumed role.

AWS IAM Identity Center supports third-party IdPs

saml2aws is not the only option for Okta or ADFS shops, because AWS IAM Identity Center supports third-party IdPs. In AWS’s own documentation: “you can connect an external IdP such as Okta or Microsoft Entra ID, to IAM Identity Center.”

The distinction that matters is this: Identity Center is a service you enable and administer centrally, saml2aws is a client-side tool that federates straight against an IdP with nothing deployed on the AWS side. Where Identity Center is available, aws sso login is the safer default — credential handling becomes AWS’s problem rather than a file in your home directory.

What was and was not tested

Executed on macOS 26.6 (arm64) against the darwin_arm64 build of v2.36.19: every quoted help string, the generated config file and its permissions, the non-persistence of --disable-keychain, acceptance of a 24-hour --session-duration, and both halves of the --skip-verify demonstration against a local self-signed TLS endpoint. Package absence was checked live against Debian’s sources API, Launchpad and Fedora Packages Search; the release version against the GitHub and Homebrew formula APIs. None of these checks needs a real IdP or AWS account: saml2aws-security-guide.sh repeats all but the Launchpad lookup on your platform, downloading the release build into a scratch directory, keeping its config in a scratch file with --disable-keychain so your keychain stays out of it, and running its own self-signed TLS endpoint for the --skip-verify demonstration.

Not executed: any real IdP login, any STS call, role chaining, and the Linux and Windows keyring backends. No AWS account was used, so nothing here ever reached STS. The duration limits, the one-hour chaining cap and the Identity Center quote come from AWS’s documentation, not from a run.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.