Skip to content

feat: identity add --from-env-vars and --from-imds for Lambda/EC2 - #123

Merged
sethsec merged 2 commits into
mainfrom
feat/identity-add-env-vars-imds
Nov 6, 2026
Merged

sethsec merged 2 commits into
mainfrom
feat/identity-add-env-vars-imds

Conversation

@sethsec

@sethsec sethsec commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds two explicit identity add sources so pathrunner "just works" when running on Lambda, ECS, or EC2:

  • identity add --from-env-vars [--name <name>] — reads AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN from environment variables only (never the shared profile chain or IMDS). Values are snapshotted as static keys so the identity survives session reloads. Region resolves from AWS_REGION, then AWS_DEFAULT_REGION, then us-east-1. Honors AWS_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 new imds identity type that re-resolves credentials from IMDS on every use (GetConfig rebuilds a live ec2rolecreds provider), 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

  • aws CLI passthrough retrieves live credentials for imds identities (previously only profile identities bypassed static key fields — an imds identity would have failed with "identity has no credentials available")
  • identity refresh supports the imds type via RefreshConfig
  • identity list renders imds identities as "instance metadata" with "auto-refresh" expiry
  • Clarified bare identity add help: it loads the full default credential chain (env vars, profile, IMDS), not just environment variables
  • REPL help, tab completion, CLI flags, and regenerated docs/reference for both new options

Testing

  • Unit tests: 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 (imds identity survives JSON round-trip and rebuilds a live provider after session reload)
  • Integration tests via ExecuteCommand for both new commands (failure paths store no identity)
  • Full pkg/..., tests/unit, tests/integration suites pass
  • Manual E2E: added a real identity via --from-env-vars, verified restart persistence and aws sts get-caller-identity passthrough with the reloaded session
  • Manual tab-completion spot check in the REPL (--from-im + TAB) — follows the existing completer pattern

Off-platform behavior verified: both commands fail fast with actionable errors (e.g. --from-imds requires running on an EC2 instance...).

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.
Comment thread pkg/core/identity.go

im.storeIdentity(identity)

fmt.Printf("Added identity '%s' from environment variables\n", identity.Name)
Comment thread pkg/core/identity.go

im.storeIdentity(identity)

fmt.Printf("Added identity '%s' from EC2 instance metadata (role credentials refresh automatically)\n", identity.Name)
@sethsec
sethsec merged commit efffd43 into main Nov 6, 2026
10 of 11 checks passed
@sethsec
sethsec deleted the feat/identity-add-env-vars-imds branch November 6, 2026 17:03
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.

2 participants