Repository navigation
Conversation
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>
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.
scottisloud
left a comment
There was a problem hiding this comment.
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.
|
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 |
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.
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
aws sso loginputs it, in~/.aws/sso/cache.sso:GetRoleCredentials. Both config forms are supported: the legacy form (sso_start_urlon the profile) and thesso_sessionform.sso_sessionprofiles, 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.~/.aws/config(orAWS_CONFIG_FILE).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
--profileis passed on asAWS_PROFILE, so the tool runs against the profile the user asked for and not the default one.Behaviour changes for existing Access Key users
aws sso login,aws sso logout,aws configure sso,aws configure sso-session,aws configure list,aws configure list-profiles,aws configure getandaws configure set. As a result,aws configure listshows the local configuration instead of the keys injected from 1Password.op plugin initasks 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
mainwith a build of this branch across 25 commands (default profile,--profilein 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
CredentialType.AllowsExternalSecretCachelets a credential type without a secret field pass validation, a newSSO Profilecredential name and fiveSSO …field names.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 touchessdk/schema/plugin.go.credentials,service/ssoandservice/ssooidcwere far behind the SDK core module, which made the SSO client fail at runtime; they are brought in line with it. The core module andservice/stsmove up one release.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.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.aws sso login).aws sso login --profile …"; an item that does not match the profile is reported as a mismatch.aws configure ssowrites if the URL is pasted at the session-name prompt).cdk,samandeksctluse the credentials from the plugin and honourAWS_PROFILEwhen the plugin steps aside. See the limitation aboutawslogsbelow.go build ./...passes for Linux, macOS, Windows, FreeBSD and OpenBSD.Known limitations
In the plugin:
awslogswith both credential types linked.awslogstreatsAWS_PROFILEas 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 areaws,cdk,samandeksctl.aws sso logoutdoes not clear role credentials the plugin has already cached; they remain usable until they expire.sso_sessionprofile 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):
op plugin initstep for the SSO Profile is labelled "Locate your AWS Access Key". Validation runs against the correct credential type; only the label is wrong.op plugin credential import awsonly offers the Access Key. An SSO Profile can be imported fromop plugin init.--profilefails with "Unknown options", because the command line is altered between the two provisioners. Selecting the profile withAWS_PROFILEworks. A plugin compiled into the CLI is not affected.op plugin initaccepts "Stop choosing credentials" for both types and saves a setup without credentials.Type of change
Related Issue(s)
How To Test
With a local build (
make aws/build) and an IAM Identity Center org:~/.aws/configand runaws sso login --profile <name>. The login command passes through without provisioning, by design.op plugin clear awsif the plugin is already configured in this directory; otherwiseinitskips the credential-type questions.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).aws sts get-caller-identity --profile <name>. It prints the assumed-role ARN, and the output starts with the warning thatawsis not from the official registry, which confirms the local build was used.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.