Skip to content

feat(aws): add support for AWS IAM Identity Center (SSO) - #622

Open
rr3khan wants to merge 15 commits into
1Password:mainfrom
rr3khan:rr3khan/feat/aws-sso-210
Open

rr3khan wants to merge 15 commits into
1Password:mainfrom
rr3khan:rr3khan/feat/aws-sso-210

Conversation

@rr3khan

@rr3khan rr3khan commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Follow-up to #598, which added AWS IAM Identity Center (SSO) support to the AWS plugin but was closed. See the #598 description for the original design.

What it adds

  • A second credential type, SSO Profile. Its 1Password item holds only configuration (SSO start URL, SSO region, account ID, role name, optional session name and default region). The login itself stays where aws sso login puts it, in ~/.aws/sso/cache.
  • A provisioner that reads that cached login and exchanges it for short-lived role credentials through sso:GetRoleCredentials. Both config forms are supported: the legacy form (sso_start_url on the profile) and the sso_session form.
  • For sso_session profiles, an expired access token is refreshed with the cached refresh token, as the AWS CLI does, so a login lasts for the whole SSO session instead of about an hour.
  • Role credentials are kept in the plugin's encrypted cache until they expire, so repeat invocations do not call the SSO endpoint.
  • An importer that finds SSO profiles in ~/.aws/config (or AWS_CONFIG_FILE).
  • Both credential usages (Access Key and SSO Profile) are optional on all five executables (aws, cdk, sam, eksctl, awslogs), so users can link only the one they use.

How the two credential types work together

Each provisioner handles the profiles of its own kind and steps aside for the rest. When a provisioner steps aside, the profile selected with --profile is passed on as AWS_PROFILE, so the tool runs against the profile the user asked for and not the default one.

Linked Access-key profile SSO profile
Access Key only Keys from 1Password The AWS CLI handles SSO itself
SSO Profile only The AWS CLI resolves the profile itself Role credentials from the plugin
Both Keys from 1Password Role credentials from the plugin

Behaviour changes for existing Access Key users

  • An SSO profile used to fail with "SSO Authentication is not yet supported by the AWS Shell Plugin". It is now handled by the AWS CLI itself (first row of the table).
  • These commands no longer ask the plugin for credentials: aws sso login, aws sso logout, aws configure sso, aws configure sso-session, aws configure list, aws configure list-profiles, aws configure get and aws configure set. As a result, aws configure list shows the local configuration instead of the keys injected from 1Password.
  • op plugin init asks once per credential type, each with a "Stop choosing credentials" option, instead of selecting the Access Key automatically.

Nothing else changes for a setup that only has an Access Key linked. I compared a build of main with a build of this branch across 25 commands (default profile, --profile in its different spellings, AWS_PROFILE, role assumption, web identity, credential process, a missing profile, and a setup file written by older CLI versions); the first two points above are the only differences in that comparison.

Other changes in this PR

  • SDK: CredentialType.AllowsExternalSecretCache lets a credential type without a secret field pass validation, a new SSO Profile credential name and five SSO … field names.
  • SDK: the "Has no more than one credential type defined" validation check is removed. feat(sdk): support plugins with more than one credential type #710 does that properly (a replacement check, the registry JSON and GetCredentialType). I intend feat(sdk): support plugins with more than one credential type #710 to merge first and to rebase this PR on it, after which this PR no longer touches sdk/schema/plugin.go.
  • AWS SDK modules: credentials, service/sso and service/ssooidc were far behind the SDK core module, which made the SSO client fail at runtime; they are brought in line with it. The core module and service/sts move up one release.
  • The file-ownership checks are split into per-platform files so that the package keeps compiling for Windows.

Testing results

Tested against a live IAM Identity Center org with 1Password CLI 2.41.1 and a local plugin build (make aws/build), and with a development build of 1Password CLI that has this plugin compiled in.

  • Access Key only, SSO Profile only, both linked, each against an access-key profile, an SSO profile in both config forms, the default profile, and a role chain: results as in the table above.
  • SSO end to end: aws sts get-caller-identity --profile <sso profile> returns the assumed-role ARN with credentials supplied by the plugin. With the login file moved away, a repeat invocation is still served from the plugin's cache.
  • Token refresh: with the cached access token expired and no cached role credentials, the plugin refreshed the login and returned the role credentials. Checked twice: once by setting the cached token's expiry to the past, and once by waiting, where the plugin refreshed a token that had expired by itself about two hours earlier (about four and a half hours after aws sso login).
  • Error paths: no login or an ended SSO session gives "AWS SSO token is missing or expired; run aws sso login --profile …"; an item that does not match the profile is reported as a mismatch.
  • Importer: handles both config forms, including a session whose name is the start URL itself (what aws configure sso writes if the URL is pasted at the session-name prompt).
  • Other executables: cdk, sam and eksctl use the credentials from the plugin and honour AWS_PROFILE when the plugin steps aside. See the limitation about awslogs below.
  • Unit tests: the token refresh tests run the real SSO and SSO OIDC clients against a local server (a refresh, no refresh for a legacy login, and a login that is missing or can no longer be refreshed), so a mismatch between the AWS SDK modules fails in CI.
  • Builds: go build ./... passes for Linux, macOS, Windows, FreeBSD and OpenBSD.
  • Not tested: the one-time-password (MFA) path of the Access Key credential with these changes.

Known limitations

In the plugin:

  • One account and role per SSO Profile item. An SSO profile whose account or role differs from the linked item is an error ("your local AWS configuration has a different SSO Account ID than the one specified in 1Password"). To use several, configure the plugin per directory, each linked to its own item.
  • awslogs with both credential types linked. awslogs treats AWS_PROFILE as an explicitly selected profile and then ignores credentials in the environment. With both linked, awslogs --profile <access-key profile> therefore does not use the Access Key from 1Password. Setups with a single credential are not affected, and neither are aws, cdk, sam and eksctl.
  • Role chains with an SSO source profile are not supported when an Access Key is linked; the plugin reports that clearly. With only an SSO Profile linked, the AWS CLI handles them itself.
  • aws sso logout does not clear role credentials the plugin has already cached; they remain usable until they expire.
  • An item imported from an sso_session profile stores the session name. Using that item with a legacy-form profile makes the plugin look for the login of that session.

In 1Password CLI (these need changes there, not in the plugin):

  • The op plugin init step for the SSO Profile is labelled "Locate your AWS Access Key". Validation runs against the correct credential type; only the label is wrong.
Screenshot 2026-07-07 at 1 01 00 PM
  • op plugin credential import aws only offers the Access Key. An SSO Profile can be imported from op plugin init.
  • With a locally built plugin and both credential types linked, a command that uses --profile fails with "Unknown options", because the command line is altered between the two provisioners. Selecting the profile with AWS_PROFILE works. A plugin compiled into the CLI is not affected.
  • op plugin init accepts "Stop choosing credentials" for both types and saves a setup without credentials.

Type of change

  • Created a new plugin
  • Improved an existing plugin
  • Fixed a bug in an existing plugin
  • Improved contributor utilities or experience

Related Issue(s)

How To Test

With a local build (make aws/build) and an IAM Identity Center org:

  1. Configure an SSO profile in ~/.aws/config and run aws sso login --profile <name>. The login command passes through without provisioning, by design.
  2. Run op plugin clear aws if the plugin is already configured in this directory; otherwise init skips the credential-type questions.
  3. Run op plugin init aws. At the first "Choose a credential type" question pick Stop choosing credentials, at the second pick AWS SSO Profile, then import the SSO profile or select an existing item. The step is labelled "Locate your AWS Access Key" (see the limitations).
  4. Run aws sts get-caller-identity --profile <name>. It prints the assumed-role ARN, and the output starts with the warning that aws is not from the official registry, which confirms the local build was used.
  5. To check the Access Key side, repeat steps 2 and 3 choosing AWS Access Key.

To check that the package builds for Windows: GOOS=windows go build ./plugins/aws/.

Changelog

Authenticate the AWS CLI with AWS IAM Identity Center (SSO) profiles using cached SSO tokens.

rjwhitworth and others added 5 commits May 9, 2026 02:57
Adds an SSO Profile credential type. The plugin reads the access token
cached by `aws sso login` from ~/.aws/sso/cache/<sha1>.json and exchanges
it for short-lived role credentials via sso:GetRoleCredentials. Supports
both the legacy `sso_start_url` form and the consolidated `sso_session`
form. Role credentials get cached in the plugin's encrypted store, so
subsequent invocations within the credential TTL skip the remote call.

Access Key and SSO Profile coexist on the same `aws` executable. Each
provisioner yields silently when the active profile is configured for
the other type, so users can link both items against the same plugin
and the right one runs per invocation.

The importer scans ~/.aws/config for both forms and surfaces a candidate
per SSO-bearing profile. cdk, eksctl, awslogs, and sam also accept the
SSO Profile credential.

`aws sso login`, `aws sso logout`, `aws configure sso`, `aws configure
sso-session`, and the read-only `aws configure list/list-profiles/get/
set` subcommands skip credential provisioning so they can run without
an active session.

SDK changes:
- Allow plugins to expose more than one credential type. The op runtime
  already accepts this; the validator was the only block.
- Downgrade "has at least 1 field that is secret" from error to warning
  so credential types whose secret lives in an external token cache
  (SSO, OAuth, gcloud) can be represented without a placeholder field.

aws-sdk-go-v2/credentials and aws-sdk-go-v2/service/sso were already on
the dependency graph via aws-vault/v7; both move from indirect to
direct.

Resolves: 1Password#210
Address findings from a pre-PR security review. Each fix is local to the
AWS SSO net-new code introduced in the previous commit; pre-existing SDK
bugs surfaced by the same review are deferred to a follow-up PR.

Importer (plugins/aws/sso_importer.go):
- Validate sso_start_url (https + non-empty host)
- Regex-check sso_account_id (12 digits) and sso_region
- Reject NUL bytes mid-value
- Refuse non-regular, symlinked, or non-owned AWS_CONFIG_FILE overrides
- Match SDK ~/ prefix convention (bare ~root no longer silently joined)
- Use ini.LoadSources directly with strict botocore-parity options:
  KeyValueDelimiters="=", IgnoreContinuation=true, Loose=true

Provisioner (plugins/aws/sso_provisioner.go):
- assertSSOTokenCacheSafe rejects symlinks, non-regular files, group/world
  readable modes, and files not owned by the current uid before passing
  the path to ssocreds.New
- translateSSORetrieveError whitelists known smithy codes (Unauthorized,
  Forbidden, ResourceNotFound, TooManyRequests); unknown codes get a
  generic plugin-controlled message so server-controlled error text
  doesn't reach user-visible output
- Wrap sso:GetRoleCredentials in context.WithTimeout(30s)

SDK validator (sdk/schema/credential_type.go):
- Replace the previous severity downgrade with an opt-in
  AllowsExternalSecretCache flag on CredentialType. The "must have at
  least one secret field" check is restored to Error severity globally;
  only the SSO Profile (whose bearer token lives in the AWS SDK's
  external cache) opts out

Tests (plugins/aws/sso_*_test.go):
- Hostile-input cases for the importer (non-HTTPS, file:// scheme, short
  account ID, malformed region, NUL byte, malformed section header,
  duplicate-section last-wins)
- Direct unit tests for assertSSOTokenCacheSafe and
  validateExternalConfigPath covering symlink, world-readable,
  directory, non-existent
- Smithy-error translation table with a token-leak guard that asserts no
  JSON-key-shaped or JWT-shaped fragment from a hostile server message
  ever appears in the translated user-visible error

Deferred to follow-up PR (pre-existing code, out of scope here):
- F-2: plugins/registry.go:50-60 GetCredentialType ignores credentialName
- F-6: sdk/schema/plugin.go:116-134 MarshalJSON truncates to Credentials[0]
- F-7: plugins/aws/cli_provisioner.go:28-53 strip-by-value mis-routing
- F-9: sdk/importer/helpers.go:41-53 SanitizeNameHint byte-truncation
- F-15: plugins/aws/sts_provisioner.go:399-405 log.SetOutput global state
Broaden sso_region validation so us-gov-* profiles import correctly, and
reuse ssoLoginCommand for UnauthorizedException so named profiles get the
right aws sso login hint.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rr3khan rr3khan changed the title Rr3khan/feat/aws sso 210 feat(aws): add support for AWS IAM Identity Center (SSO) Jul 6, 2026
rr3khan added 2 commits July 6, 2026 18:58
The importer's region validation required a two-letter prefix, rejecting
eusc-de-east-1 (AWS European Sovereign Cloud, present in botocore's
endpoint data). Botocore itself does no region validation, so this check
exists only to reject values that could not be a region at all; loosen
the prefix to two-or-more letters and keep the charset and structure
anchors as the hostile-input defense. Same failure class as the earlier
GovCloud broadening (781ba27).
The original SSO guard inside GetTemporaryCredentialsProviderForProfile
was removed when top-level SSO detection moved to STSProvisioner.Provision.
That top-level check cannot see a role chain's source profile: aws-vault
keeps the source's sso_* fields in the nested SourceProfile config, so a
profile with role_arn + source_profile pointing at an SSO-configured
profile slipped past both provisioners' yield checks and fell through to
an access-key lookup, failing later with a misleading "no long lived
access key pair found" instead of a clear message.

Restore the check inside GetTemporaryCredentialsProviderForProfile, where
it is evaluated at every level of the source_profile recursion. When the
active profile itself is SSO-configured, Provision has already yielded to
the SSO Profile provisioner before this function is reached, so the new
error only fires for the unsupported chained case.
@rr3khan
rr3khan marked this pull request as ready for review July 6, 2026 23:00
@scottisloud
scottisloud self-requested a review July 6, 2026 23:04

@scottisloud scottisloud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall things look great. Going to bring this to the team to talk about the potential changes required to op to accommodate certain use-cases and whether those changes are a pre-requisite to shipping this plugin, and for a second set of eyes on the new provisioner.

Nothing is immediately standing out to me, and I'm not inclined to worry about the use cases requiring changes to op necessarily, since this is a net-improvement overall.

Provisional approval, will have a second set of eyes on this before actual approval and merge.

@scottisloud

Copy link
Copy Markdown
Contributor

After some internal discussion we want to do a bit more work to understand the implications of some of the bigger changes this plugin introduces. No showstoppers or blockers, just want to ensure that we are deliberate about introducing some new concepts, and some understanding of the changes that would need to at least eventually be made to op.

After merging main, the AWS SDK core was at 1.47.x while service/sso and credentials were still on 2023 releases. The SSO Profile provisioner failed at runtime with "not found: Retry" when building the sso:GetRoleCredentials request, because the old service module registers middleware the newer core no longer provides. Unit tests did not catch it since they mock the SSO client.

Bump service/sso and credentials to current releases so the SSO client and the SDK core agree again.
… yields

Both CLI provisioners strip --profile from the command line before deciding whether the profile is theirs. When the provisioner yielded and no other linked credential provisioned, the executable ran without the flag and silently used the default profile: for example an Access Key only setup running against an SSO profile, or an SSO Profile only setup running against an access key profile or a role chain.

When a provisioner supplies no credentials for a profile selected with --profile, pass that profile on as AWS_PROFILE. If another linked credential provisions, its environment credentials take precedence over AWS_PROFILE; if none does, the executable resolves the requested profile itself, as it would without the plugin.
The ownership checks for the SSO token cache and for AWS_CONFIG_FILE
used syscall.Stat_t, which does not exist on Windows, so the package
failed to compile there:

    GOOS=windows go build ./plugins/aws/
    plugins/aws/sso_importer.go: undefined: syscall.Stat_t
    plugins/aws/sso_provisioner.go: undefined: syscall.Stat_t

Shell plugins do not run on Windows, but 1Password CLI compiles this
package into its Windows builds.

Move the check into ownedByCurrentUser, with a Unix implementation and
a Windows implementation that always passes.
The comment describing translateSSORetrieveError sat above
ssoLoginCommand, so it documented the wrong function and left
translateSSORetrieveError without one. Move it, and give
ssoLoginCommand its own comment.
…igured

awslogs treats AWS_PROFILE as an explicitly selected profile and then
ignores credentials in the environment. With both an Access Key and an
SSO Profile configured, `awslogs --profile <access key profile>` makes
the SSO Profile provisioner yield and keep the profile as AWS_PROFILE,
so awslogs looks for credentials in that profile instead of using the
provisioned Access Key.

Setups with a single credential are not affected, and neither are aws,
cdk, sam and eksctl, which prefer the credentials in the environment.
A login through an `sso-session` yields an access token that expires
after about an hour, together with a refresh token that is valid for
the rest of the SSO session. The provisioner only read the access
token, so once it had expired and the cached role credentials had too,
the plugin asked the user to run `aws sso login` again, roughly every
hour. The AWS CLI refreshes the access token on its own and only needs
a new login when the SSO session ends.

Give the credentials provider the SDK's SSO token provider for
profiles that use an `sso-session`. It refreshes the access token with
the cached refresh token and writes the result back to the token cache,
as the AWS CLI does. Profiles in the legacy form have no refresh token
and behave as before.

The tests run the real SSO and SSO OIDC clients against a local server,
so they also catch a mismatch between the AWS SDK modules, which a
mocked client cannot.
…e used

With the SDK's SSO token provider in place, a login that is missing
from the token cache, or that can no longer be refreshed, is returned
as a plain error instead of an invalid token error. The plugin then
showed the SDK's text ("failed to read cached SSO token file ...",
"refresh cached SSO token failed ...") instead of telling the user to
run `aws sso login`.

Check the login before asking for role credentials and report both
cases as an invalid token, as the SDK does when no token provider is
used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS - SSO authentication provider

3 participants