Repository navigation
feat: identity add --from-env-vars and --from-imds for Lambda/EC2 - #123
Merged
Merged
Conversation
Run pathrunner on Lambda, ECS, or EC2 and add credentials explicitly from the classic SDK credential sources: - identity add --from-env-vars reads AWS_* environment variables only (never the profile chain or IMDS), snapshotting them as static keys so the identity survives session reloads. Honors AWS_CREDENTIAL_EXPIRATION when present (ECS/EC2 container creds). - identity add --from-imds probes the EC2 metadata service for the attached instance role and stores a new "imds" identity type that re-resolves credentials from IMDS on every use, so instance role rotation and session restarts are handled without freezing static keys. - aws CLI passthrough now retrieves live credentials for imds identities (previously only profile identities bypassed static key fields). - identity list renders imds identities as "instance metadata" with "auto-refresh" expiry. - help text for bare 'identity add' clarified: it loads the full default credential chain, not just environment variables. Includes REPL help, tab completion, CLI flags, regenerated reference docs, unit tests (env parsing, ARN extraction, IMDS session-reload round-trip), and integration tests for both new commands.
Pre-existing working-tree dependency bump (aws-sdk-go-v2 v1.47.3 -> v1.47.7 and matching service/config/credentials module updates) carried into this branch so it isn't left dangling uncommitted.
|
|
||
| im.storeIdentity(identity) | ||
|
|
||
| fmt.Printf("Added identity '%s' from environment variables\n", identity.Name) |
|
|
||
| im.storeIdentity(identity) | ||
|
|
||
| fmt.Printf("Added identity '%s' from EC2 instance metadata (role credentials refresh automatically)\n", identity.Name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two explicit
identity addsources so pathrunner "just works" when running on Lambda, ECS, or EC2:identity add --from-env-vars [--name <name>]— readsAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKENfrom environment variables only (never the shared profile chain or IMDS). Values are snapshotted as static keys so the identity survives session reloads. Region resolves fromAWS_REGION, thenAWS_DEFAULT_REGION, thenus-east-1. HonorsAWS_CREDENTIAL_EXPIRATION(set by ECS/EC2 container credential providers) when present.identity add --from-imds [--name <name>]— probes the EC2 instance metadata service (bounded at 5s) for the attached instance role and the instance's region. Stores a newimdsidentity type that re-resolves credentials from IMDS on every use (GetConfigrebuilds a liveec2rolecredsprovider), so EC2 instance role rotation and session restarts are both handled without freezing static keys. Auto-names after the instance profile (e.g.pl-lab-ec2-role).Supporting changes
awsCLI passthrough retrieves live credentials forimdsidentities (previously onlyprofileidentities bypassed static key fields — animdsidentity would have failed with "identity has no credentials available")identity refreshsupports theimdstype viaRefreshConfigidentity listrendersimdsidentities as "instance metadata" with "auto-refresh" expiryidentity addhelp: it loads the full default credential chain (env vars, profile, IMDS), not just environment variablesdocs/referencefor both new optionsTesting
pkg/core/identity_sources_test.go(env-var snapshot parsing, region fallbacks, expiration handling, ARN extraction, missing-vars error paths),tests/unit/identity_imds_test.go(imdsidentity survives JSON round-trip and rebuilds a live provider after session reload)ExecuteCommandfor both new commands (failure paths store no identity)pkg/...,tests/unit,tests/integrationsuites pass--from-env-vars, verified restart persistence andaws sts get-caller-identitypassthrough with the reloaded session--from-im+ TAB) — follows the existing completer patternOff-platform behavior verified: both commands fail fast with actionable errors (e.g.
--from-imds requires running on an EC2 instance...).