Skip to content

Refuse --profile and real-AWS --endpoint-url in lstk aws - #617

Open
bartsdev wants to merge 6 commits into
mainfrom
devx-1345-lstk-aws-dont-let-endpoint-url-or-profile-send-a
Open

bartsdev wants to merge 6 commits into
mainfrom
devx-1345-lstk-aws-dont-let-endpoint-url-or-profile-send-a

Conversation

@bartsdev

@bartsdev bartsdev commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Motivation

lstk aws adds --endpoint-url for LocalStack, but a caller's own options can still send the call to real AWS, signed with real credentials:

  • lstk aws sqs list-queues --endpoint-url https://sqs.us-east-1.amazonaws.com: the caller's --endpoint-url overrides lstk's.
  • lstk aws sqs list-queues --profile prod: signs with prod's credentials and runs its credential_process, SSO refresh or STS AssumeRole against real AWS.

The AWS CLI accepts abbreviations (--endp, --e=…, --pro, --p=…). Today both are allowed on purpose (external-endpoint and aws-proxy specs). The MCP server blocks them itself; doing it in lstk covers every caller.

Solution

Before starting the AWS CLI, on every path including help, lstk aws refuses:

  • an --endpoint-url whose host is an AWS partition domain or a subdomain of one (amazonaws.com, amazonaws.com.cn, api.aws, amazonaws.eu, isolated partitions);
  • an --endpoint-url that is an IP address without a port (a bare IP could be AWS; an emulator always has a port);
  • a --profile other than localstack, the profile lstk setup aws writes. That one adds no new trust: lstk already selects it through AWS_PROFILE today.

Any -- prefix of either name counts, in both --opt value and --opt=value forms, anywhere in the arguments. That matches what AWS CLI 2.42.3 resolves: its global options win when abbreviated, so --p is --profile even in s3api list-objects-v2, which has --prefix.

Any other --endpoint-url (another hostname, an IP with a port) still passes through, because people run LocalStack under their own hostnames. The refusal needs neither Docker nor an emulator:

Error: --endpoint-url points at real AWS (sqs.us-east-1.amazonaws.com): lstk aws only targets LocalStack
  ==> Use the emulator lstk found: remove --endpoint-url
  ==> Target another emulator: lstk --endpoint-url <url> aws ...

Error: only --profile localstack is supported: lstk aws only targets LocalStack, and another profile can sign with real AWS credentials
  ==> Select a LocalStack account: lstk aws --account <12-digit id> ...
  ==> Configure the LocalStack AWS profile: lstk setup aws

This is a guardrail, not a guarantee. A local proxy that refuses non-emulator traffic was measured and left to a follow-up: the cheap variant misses URL rewrites like MRAP, the complete one has to forward all emulator traffic, and both override a corporate HTTPS_PROXY. Details are in design.md.

Tests: TestAWSCommandRefusesRealAWSEndpointAndProfile (13 cases, all failed before) and TestAWSCommandAllowsNonAWSEndpoints (8 cases, including --profile localstack), plus TestFindRealAWSOption. Values the AWS CLI rejects itself (no scheme, empty) are left to it; TestAWSCommandSchemelessEndpointIsRejectedByTheCLI runs the real CLI to prove they never reach the emulator or AWS.

Spec: openspec/changes/refuse-real-aws-options/. One wart: openspec won't drop an existing scenario, so "A user-supplied profile flag wins and disables account selection" keeps its name while its WHEN/THEN now describe the refusal.

Docs

Nothing to document: lstk aws --help states the rule.

Review

Human review advised: changes user-facing behavior that was previously specified (any --profile and an AWS-pointing --endpoint-url were allowed), which breaks anyone relying on them.

Closes DEVX-1345

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bartsdev bartsdev added semver: minor docs: skip Pull request does not require documentation changes labels Dec 2, 2026
Bart and others added 5 commits December 2, 2026 15:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@skyrpex skyrpex 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.

Although I would've done something different, the proposal looks good to me.

What I'd do though is just ignore or forbid the use of --profile and let any --endpoint-url to work, as it's an explicit parameter. Profile is really of no use for lstk aws as it's only reason to exist is to interact with LocalStack instances easily.

@bartsdev

bartsdev commented Dec 2, 2026 •

Copy link
Copy Markdown
Member Author

Although I would've done something different, the proposal looks good to me.

What I'd do though is just ignore or forbid the use of --profile and let any --endpoint-url to work, as it's an explicit parameter. Profile is really of no use for lstk aws as it's only reason to exist is to interact with LocalStack instances easily.

but we do create a profile called localstack during lstk setup, I think that's still relevant usecase? I only allow for --profile localstack (albeit without validation of the setup, that will be different ticket).

My vision for later is that we ship a proxy that prevents those calls out to the aws hostanames. That way we can apply across emulators, but for now I decided on this guardrail instead of more complex setup.

WDYT?

skyrpex commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Right, we do actually create that profile, and I didn't mean not to use it but to forbid the --profile parameter from lstk aws while passing --profile=localstack to the real aws CLI. It's all a bit tricky and delicate. Anyways, I guess some users might want to use other custom profiles so let's just ignore what I said 🙂.

The proxy could be a good solution for multi emulators… One day we should list everything we will soon support and take decisions based on that.

By the way, in my opinion we should also get rid of requiring the aws CLI to be installed in the future, and just implement a small helper using the smithy definitions. It'd be fairly easy, and the lstk maintenance would become much easier and the footprint smaller. Happy to create a small proposal doc if it sounds interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants