Skip to content

fix(aws): stop storing credentials in Pulumi provider state#866

Open
apodhrad wants to merge 1 commit into
redhat-developer:mainfrom
apodhrad:fix/avoid-storing-aws-creds-in-pulumi-state
Open

fix(aws): stop storing credentials in Pulumi provider state#866
apodhrad wants to merge 1 commit into
redhat-developer:mainfrom
apodhrad:fix/avoid-storing-aws-creds-in-pulumi-state

Conversation

@apodhrad

Copy link
Copy Markdown
Contributor

AWS credentials (access key, secret key, session token) were being set via Pulumi config, which caused them to be persisted in the provider resource state. When destroying a cluster provisioned with an older session token, Pulumi would use the expired credentials from state instead of the fresh ones from the environment, causing destroy to fail with ExpiredToken errors.

Let the AWS SDK resolve credentials through its default credential chain (env vars, shared credentials file, IAM roles) instead of explicitly setting them in Pulumi config. Only the region is configured explicitly.

AWS credentials (access key, secret key, session token) were being set
via Pulumi config, which caused them to be persisted in the provider
resource state. When destroying a cluster provisioned with an older
session token, Pulumi would use the expired credentials from state
instead of the fresh ones from the environment, causing destroy to fail
with ExpiredToken errors.

Let the AWS SDK resolve credentials through its default credential chain
(env vars, shared credentials file, IAM roles) instead of explicitly
setting them in Pulumi config. Only the region is configured explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • AWS authentication now uses the AWS SDK’s standard credential resolution, helping avoid failures caused by outdated or expired saved credentials.
    • AWS region settings continue to be recognized from supported configuration keys.
    • Removed obsolete credential configuration options that are no longer used.

Walkthrough

The AWS provider now maps only region configuration to AWS_DEFAULT_REGION and relies on the AWS SDK default credential chain instead of Pulumi-stored access, secret, and session credentials. The corresponding credential configuration constants were removed.

Changes

AWS credential resolution

Layer / File(s) Summary
Credential chain mapping
pkg/provider/aws/constants/constants.go, pkg/provider/aws/aws.go
The provider retains region configuration mappings, removes static credential mappings, and deletes the corresponding exported credential constants.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: removing AWS credentials from Pulumi provider state.
Description check ✅ Passed The description matches the change and explains why credentials are no longer set via Pulumi config.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/provider/aws/aws.go`:
- Around line 74-80: Add a one-time migration in SetAWSCredentials that removes
persisted aws:accessKey, aws:secretKey, and aws:sessionToken entries via
stack.RemoveConfig before or alongside setting envCredentials. Apply removal
only when those legacy keys exist, while preserving the existing region
configuration and SDK default credential-chain behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 061845ae-f970-4afe-8d3a-1c3a34ac5c50

📥 Commits

Reviewing files that changed from the base of the PR and between 25cc0d1 and b48c499.

📒 Files selected for processing (2)
  • pkg/provider/aws/aws.go
  • pkg/provider/aws/constants/constants.go
💤 Files with no reviewable changes (1)
  • pkg/provider/aws/constants/constants.go

Comment thread pkg/provider/aws/aws.go
Comment on lines +74 to +80
// Only region is set via Pulumi config; credentials (access key, secret key,
// session token) are resolved by the AWS SDK's default credential chain so
// that expired tokens stored in the Pulumi provider state never shadow
// fresh environment credentials on later operations (e.g. destroy).
var envCredentials = map[string]string{
awsConstants.CONFIG_AWS_REGION: "AWS_DEFAULT_REGION",
awsConstants.CONFIG_AWS_NATIVE_REGION: "AWS_DEFAULT_REGION",
awsConstants.CONFIG_AWS_ACCESS_KEY: "AWS_ACCESS_KEY_ID",
awsConstants.CONFIG_AWS_SECRET_KEY: "AWS_SECRET_ACCESS_KEY",
awsConstants.CONFIG_AWS_SESSION_TOKEN: "AWS_SESSION_TOKEN"}
awsConstants.CONFIG_AWS_NATIVE_REGION: "AWS_DEFAULT_REGION"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repo files matching aws.go/aws provider:"
fd -a 'aws\.go$' . | sed 's#^\./##' | head -100

echo
echo "Outline for pkg/provider/aws/aws.go if present:"
if [ -f pkg/provider/aws/aws.go ]; then
  ast-grep outline pkg/provider/aws/aws.go || true
  wc -l pkg/provider/aws/aws.go
  sed -n '1,180p' pkg/provider/aws/aws.go | cat -n
fi

echo
echo "Search for SetAWSCredentials / envCredentials / credential config references:"
rg -n "SetAWSCredentials|envCredentials|CONFIG_AWS_(ACCESS|SECRET|SESSION|REGION)|accessKey|secretKey|sessionToken|RemoveConfig|SetConfig|GetConfig|StackConfiguration" . --glob '!node_modules' --glob '!dist' --glob '!build' | head -200

Repository: redhat-developer/mapt

Length of output: 34564


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p=Path('pkg/provider/aws/aws.go')
text=p.read_text() if p.exists() else ''
checks={
    'has_pkg': p.exists(),
    'line_count': len(text.splitlines()),
    'has_envCredentials': 'envCredentials' in text,
    'has_access_key_mapping': 'aws:accessKey' in text or 'CONFIG_ACCESS_KEY' in text,
    'has_secret_key_mapping': 'aws:secretKey' in text or 'CONFIG_SECRET_KEY' in text,
    'has_session_token_mapping': 'aws:sessionToken' in text or 'CONFIG_SESSION_TOKEN' in text,
    'has_SetAWSCredentials': 'SetAWSCredentials' in text,
    'has_remove_config': any(s in text for s in ['DeleteConfig', 'RemoveConfig', 'SetAWSCredentials']),
}
for k,v in checks.items():
    print(f'{k}: {v}')
if p.exists():
    idx=text.find('var envCredentials')
    if idx!=-1:
        print('--- envCredentials block ---')
        endidx=text.find('}', idx)+1
        print(text[idx:endidx])
PY

Repository: redhat-developer/mapt

Length of output: 552


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "constants:"
cat -n pkg/provider/aws/constants/constants.go | sed -n '1,40p'

echo
echo "manager stack implementation around credentials:"
rg -n "ProviderCredentials|SetAw|Config" pkg/manager pkg/manager/context -A5 -B5 --glob '!vendor' --glob '!dist' --glob '!build' | head -240

echo
echo "candidate manager stack file:"
fd -a 'stack\.go$|.*\.go$' pkg/manager | sed 's#^\./##' | while read -r f; do
  if rg -q "ProviderCredentials|SetConfig|SetAWSCredentials|DestroyStack" "$f"; then
    echo "--- $f"
    wc -l "$f"
    sed -n '1,220p' "$f" | cat -n
  fi
done

echo
echo "Pulumi SDK local_workspace config behavior (source-only):"
if [ -d vendor/github.com/pulumi/pulumi/sdk/v3/go/auto ]; then
  rg -n "func \\(l \\*LocalWorkspace\\) SetConfig|func SetConfig|RemoveConfig|Save" vendor/github.com/pulumi/pulumi/sdk/v3/go/auto/local_workspace.go -A8 -B4
else
  echo "vendor path missing"
fi

Repository: redhat-developer/mapt

Length of output: 24577


Clean up legacy AWS credential config in existing stacks.

SetAWSCredentials only writes keys in envCredentials via stack.SetConfig, so it does not remove existing persisted aws:accessKey, aws:secretKey, or aws:sessionToken values. Add a one-time migration that stack.RemoveConfigs those keys for stacks that already store them, otherwise existing stacks can still prefer stale Pulumi provider credentials over the SDK default chain.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provider/aws/aws.go` around lines 74 - 80, Add a one-time migration in
SetAWSCredentials that removes persisted aws:accessKey, aws:secretKey, and
aws:sessionToken entries via stack.RemoveConfig before or alongside setting
envCredentials. Apply removal only when those legacy keys exist, while
preserving the existing region configuration and SDK default credential-chain
behavior.

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.

1 participant