Skip to content

fix(eks): honor custom AWS credential mappings - #6089

Merged
ksail-bot[bot] merged 4 commits into
mainfrom
codex/eks-custom-aws-env-6078
Jul 13, 2026
Merged

ksail-bot[bot] merged 4 commits into
mainfrom
codex/eks-custom-aws-env-6078

Conversation

@devantler

Copy link
Copy Markdown
Contributor

🤖 Generated by the Daily AI Engineer (Codex automation).

Why

KSail resolved configured AWS credential variable names but did not project them into the environment used by eksctl or the SDK-backed EKS paths. A custom profile or static credential mapping could therefore be ignored while a stale ambient AWS identity won.

What changed

  • Snapshot configured profile, access key, secret key, and session token values without mutating the parent process.
  • Build an isolated child environment for every production eksctl path: provisioning, status/info, and discovery.
  • Apply the same snapshot to lazy EKS/STS SDK clients so status and kubeconfig token generation use the selected identity.
  • Treat non-canonical configured sources as an explicit identity boundary: require a profile or complete static pair, remove competing ambient static/profile/web-identity selectors, and preserve ECS profile inputs.
  • Preserve the standard AWS chain for canonical/default configurations, including Windows case-insensitive environment handling.
  • Redact credential values from eksctl stderr longest-first and keep environment slices isolated across concurrent calls.

Scope

Standalone ksail cluster delete/start/stop --provider AWS still lacks EKS routing independently of credential propagation; #6087 tracks that separate child of #4328.

Validation

  • go test -p=4 ./...
  • go test -race ./pkg/svc/credentials ./pkg/client/eksctl
  • changed-package golangci-lint gate: 0 issues
  • go build plus CLI --help smoke test
  • two independent correctness/security reviews: no P0-P2 findings

Fixes #6078
Part of #4328
Follow-up #6087

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

✅ Linters with no issues

actionlint, bash-exec, git_diff, hadolint, jscpd, jsonlint, lychee, markdown-table-formatter, markdownlint, prettier, prettier, shellcheck, shfmt, stylelint, syft, trivy-sbom, trufflehog, v8r, v8r, yamllint

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@github-code-quality

github-code-quality Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: Go

Go / code-coverage/go

The overall coverage in the codex/eks-custom-aws... branch remains at 66%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main 3391e0d codex/eks-custom-aws... 8e93831 +/-
pkg/svc/provide...aws/provider.go 84% 78% -6%
pkg/svc/provisi.../provisioner.go 83% 82% -1%
pkg/svc/credent.../credentials.go 96% 97% +1%
pkg/cli/lifecycle/simple.go 34% 37% +3%
pkg/svc/cluster...covery/cloud.go 57% 61% +4%
pkg/svc/provisi.../factory_eks.go 85% 92% +7%
pkg/svc/provisi...ks/connector.go 84% 93% +9%
pkg/client/eks/client.go 83% 96% +13%
pkg/client/eksctl/client.go 68% 83% +15%
pkg/cli/cmd/cluster/info.go 31% 50% +19%

Updated July 13, 2026 13:58 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Daily AI Engineer

@codex review

Exact-head review requested after all CI settled green at e41b526, including the complete 27/27 Docker system-test matrix and CI Required Checks.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: e41b526ec2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Daily AI Engineer

@coderabbitai review

Fallback exact-head review requested after the Codex lane produced no comment, review, thread, or explicit failure for 10m09s. CodeRabbit’s previously stated cooldown has elapsed; all CI remains green at e41b526, including 27/27 Docker system tests.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

@devantler I'll trigger a fresh review now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@devantler
devantler marked this pull request as ready for review July 13, 2026 12:43
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AWS credential aliases defined in cluster configuration are resolved into explicit credential values and immutable snapshots capturing which environment variables were used as sources. These resolved credentials are then isolated into child process environments that contain only canonical AWS variables, with competing identity-provider variables removed when custom sources are configured. The EKS SDK client, eksctl client, AWS provider, and EKS provisioner all support explicit credential configuration with fail-closed validation: they reject incomplete static keypairs and enforce credential availability when explicitly required. Factory and discovery code resolve credentials once and build aligned option sets for all dependent clients. The cluster lifecycle now retains resolved AWS options and passes them through cluster info status lookup into eksctl and provider credential configuration. Throughout the flow, credential values are extracted from configured environment sources, validated, propagated via client options, and redacted from captured stderr without mutating the parent process environment.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: honoring custom AWS credential mappings.
Description check ✅ Passed The description is relevant to the credential-mapping changes and matches the implemented scope.
Linked Issues check ✅ Passed The changes implement the issue's AWS env-var mapping, child-environment isolation, and coverage for custom/default credentials across EKS lifecycle paths.
Out of Scope Changes check ✅ Passed The diffs appear focused on AWS credential propagation, isolation, and tests, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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: 4

🤖 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/cli/lifecycle/simple.go`:
- Around line 175-190: Refactor resolveFromConfig and its callers to return or
populate a single named result struct containing clusterName, provider,
kubeconfigPath, omniOpts, kubernetesOpts, awsOpts, and awsRegion instead of
seven positional pointer parameters. Update the call sites around the
resolveFromConfig invocation and downstream field access to use the struct
fields, preserving existing configuration resolution behavior.

In `@pkg/client/eksctl/client.go`:
- Around line 292-295: Update the environment-variable switch in the stderr
redaction logic to exclude AWS_PROFILE from uniqueValues; retain only
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN so
strings.ReplaceAll does not redact common profile names from unrelated
diagnostics.

In `@pkg/svc/credentials/credentials.go`:
- Around line 177-227: Refactor ResolveAWS so each credential’s source name is
evaluated with its corresponding canonical environment name in a single paired
structure, rather than matching sourceEnvVars and canonicalNames by shared array
index. Update hasCustomCredentialEnv detection to iterate those pairs while
preserving the existing non-empty, non-canonical check and AWSResolution values.

In `@pkg/svc/provisioner/cluster/factory_eks.go`:
- Around line 56-71: Extract the shared AWS credential setup into a helper in
pkg/svc/credentials that returns the eksctl client and provider options while
preserving all RequireCredentialValues wiring. In
pkg/svc/provisioner/cluster/factory_eks.go lines 56-71, update
resolveEKSCredentialOptions to use the helper and keep the provisioner-specific
option construction local; in pkg/svc/clusterdiscovery/cloud.go lines 88-102,
replace the duplicated auth, eksctlOptions, and providerOptions construction
with the same helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b898fba3-1544-4d76-bcf4-51ebd0366cfc

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1beea and e41b526.

📒 Files selected for processing (22)
  • pkg/cli/cmd/cluster/info.go
  • pkg/cli/cmd/cluster/info_test.go
  • pkg/cli/lifecycle/awsregion_test.go
  • pkg/cli/lifecycle/simple.go
  • pkg/client/eks/client.go
  • pkg/client/eks/client_test.go
  • pkg/client/eks/errors.go
  • pkg/client/eksctl/client.go
  • pkg/client/eksctl/client_test.go
  • pkg/client/eksctl/errors.go
  • pkg/svc/clusterdiscovery/aws_environment_test.go
  • pkg/svc/clusterdiscovery/cloud.go
  • pkg/svc/credentials/aws_environment_test.go
  • pkg/svc/credentials/credentials.go
  • pkg/svc/credentials/credentials_test.go
  • pkg/svc/credentials/environment_name_test.go
  • pkg/svc/provider/aws/provider.go
  • pkg/svc/provisioner/cluster/eks/connector.go
  • pkg/svc/provisioner/cluster/eks/connector_test.go
  • pkg/svc/provisioner/cluster/eks/provisioner.go
  • pkg/svc/provisioner/cluster/factory_eks.go
  • pkg/svc/provisioner/cluster/factory_eks_test.go
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
pkg/cli/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

pkg/cli/**/*.go: Canonicalize all user-supplied file path arguments in CLI commands with fsutil.EvalCanonicalPath before using them.
For output paths that may not already exist, create the parent directory with os.MkdirAll(filepath.Dir(outputPath), <mode>) before calling fsutil.EvalCanonicalPath.
Use fsutil.ReadFileSafe for constrained reads instead of reimplementing path-containment checks.

Files:

  • pkg/cli/lifecycle/awsregion_test.go
  • pkg/cli/cmd/cluster/info.go
  • pkg/cli/cmd/cluster/info_test.go
  • pkg/cli/lifecycle/simple.go
🧠 Learnings (1)
📚 Learning: 2026-06-27T23:31:11.055Z
Learnt from: devantler
Repo: devantler-tech/ksail PR: 5489
File: pkg/svc/provider/hetzner/factory.go:54-57
Timestamp: 2026-06-27T23:31:11.055Z
Learning: In KSail’s settings connection-test flow, `pkg/svc/credentials/manager.go` `Manager.Overlay()` resolves stored credentials (including secure-storage values) and exports them into process environment variables before provider validation runs. Therefore, when reviewing provider factory/helpers (e.g., `NewProviderFromOptions()` in `pkg/svc/provider/*/factory.go`) that read tokens via `os.Getenv(tokenEnvVar)`, ensure they rely on these manager-overlayed env vars (not only values the user manually exported in the shell) and that provider construction/validation happens after `Manager.Overlay()` has populated the environment for the connection-test path.

Applied to files:

  • pkg/svc/provider/aws/provider.go
🔇 Additional comments (22)
pkg/svc/clusterdiscovery/aws_environment_test.go (1)

1-94: LGTM!

pkg/svc/provider/aws/provider.go (1)

29-90: LGTM!

Also applies to: 290-306

pkg/cli/lifecycle/awsregion_test.go (1)

1-108: LGTM!

pkg/cli/cmd/cluster/info_test.go (1)

29-67: LGTM!

Also applies to: 222-288

pkg/svc/provisioner/cluster/factory_eks.go (1)

14-26: 🎯 Functional Correctness

No change needed DefaultFactory.Create rejects a nil cluster before this branch, so cluster.Spec.Provider.AWS is safe here.

			> Likely an incorrect or invalid review comment.
pkg/svc/provisioner/cluster/eks/provisioner.go (1)

8-8: LGTM!

Also applies to: 42-46, 62-79, 100-108

pkg/svc/provisioner/cluster/eks/connector.go (1)

119-124: LGTM!

pkg/svc/provisioner/cluster/eks/connector_test.go (1)

11-11: LGTM!

Also applies to: 177-193

pkg/svc/provisioner/cluster/factory_eks_test.go (1)

34-62: LGTM!

Also applies to: 75-75, 90-100

pkg/cli/lifecycle/simple.go (1)

122-124: LGTM!

Also applies to: 217-217

pkg/cli/cmd/cluster/info.go (1)

20-20: LGTM!

Also applies to: 82-87, 216-217, 227-227, 341-358

pkg/svc/credentials/aws_environment_test.go (1)

1-361: LGTM!

pkg/svc/credentials/credentials.go (2)

13-14: LGTM!

Also applies to: 131-176, 237-287, 399-401


288-347: 🔒 Security & Privacy

Verify container-credential exemption is safe without downstream enforcement guarantees.

strippedEnvironmentNames strips AWS_WEB_IDENTITY_TOKEN_FILE/AWS_ROLE_ARN/etc. when custom sources are detected, but intentionally leaves AWS_CONTAINER_CREDENTIALS_RELATIVE_URI/_FULL_URI/AUTHORIZATION_TOKEN(_FILE) untouched (confirmed by the sibling test at aws_environment_test.go lines 132-177). Per the AWS SDK default credential chain, static/profile credentials are checked before container credentials, but if a configured custom profile/access-key resolves to an empty value, the chain can still fall through to any ECS/Pod-Identity container credentials left in the child environment. This file has no gate against that — it relies entirely on the RequireCredentialValues() option that callers conditionally append (see pkg/cli/cmd/cluster/info.go, pkg/svc/clusterdiscovery/cloud.go, pkg/svc/provisioner/cluster/factory_eks.go) actually failing the operation before eksctl/the EKS SDK client ever runs with such an environment.

Since pkg/client/eksctl and pkg/client/eks (where RequireCredentialValues is implemented) aren't in this review batch, please confirm that path truly errors out rather than silently falling back to ambient container credentials when a custom alias is unset.

pkg/svc/credentials/environment_name_test.go (1)

1-15: LGTM!

pkg/svc/credentials/credentials_test.go (1)

68-68: LGTM!

pkg/client/eks/client.go (1)

60-65: LGTM!

Also applies to: 87-196

pkg/client/eks/errors.go (1)

9-18: LGTM!

pkg/client/eks/client_test.go (1)

180-297: LGTM!

pkg/client/eksctl/client.go (1)

28-70: LGTM!

Also applies to: 91-95, 121-155, 182-277, 315-325

pkg/client/eksctl/errors.go (1)

16-33: LGTM!

pkg/client/eksctl/client_test.go (1)

29-86: LGTM!

Also applies to: 116-279

Comment thread pkg/cli/lifecycle/simple.go Outdated
Comment thread pkg/client/eksctl/client.go
Comment thread pkg/svc/credentials/credentials.go
Comment thread pkg/svc/provisioner/cluster/factory_eks.go
@ksail-bot
ksail-bot Bot enabled auto-merge (squash) July 13, 2026 13:19
@ksail-bot
ksail-bot Bot merged commit 623c797 into main Jul 13, 2026
3 checks passed
@ksail-bot
ksail-bot Bot deleted the codex/eks-custom-aws-env-6078 branch July 13, 2026 14:54
@github-project-automation github-project-automation Bot moved this from 🫴 Ready to ✅ Done in 🌊 Project Board Jul 13, 2026
@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Sent by Codex Daily AI Engineer.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

@devantler I'll trigger a fresh review now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Sent by Codex Daily AI Engineer.

CodeRabbit acknowledged the exact-head request but produced no review artifact after more than ten minutes, so this is the documented fallback lane.

@codex review

@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Sent by Codex Daily AI Engineer.

@coderabbitai run pre-merge checks

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Actions performed

Running Pre-merge checks. Results will be posted in the summary comment once complete.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 623c797923

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Honor custom AWS credential environment mappings for EKS lifecycle

1 participant