Skip to content

fix(k8s): credential sync refuses a context that is no RFC 1123 name #4091

Closed
1 of 1 issue completed

Description

@dan-petty

Bug Description

devops k8s deploy-stack --stack infra ends with the exit code 1 when the kubeconfig context is a valid kubeconfig name that is no RFC 1123 name, such as an EKS ARN.

deploy-stack accepts the name (validate_k8s_context_name). After the Helm releases, sync_k8s_credentials calls fetch_secret_data, and fetch_secret_data checks the same name with validate_k8s_name(context, "context"), which accepts only RFC 1123 names. The command prints Invalid context: '<name>'. Must be a valid RFC 1123 name. and exits with 1 after it has deployed the stack.

A test hid this: test_deploy_and_teardown_stack_use_effective_context in tests/commands/k8s/test_k8s_context.py patched sync_k8s_credentials to return {}. The test now deploys the logging stack, which has no credentials to sync.

Steps to Reproduce

  1. Set k8s.context to arn:aws:eks:us-east-1:123456789012:cluster/prod.
  2. Run devops k8s deploy-stack --stack infra --no-push-secrets against a cluster of that context.
  3. See the error after the Helm releases and the exit code 1.

Expected Behavior

fetch_secret_data accepts every context name that switch-context and deploy-stack accept, and uses validate_k8s_context_name.

Existing Tool Considered

No new tool is needed. The fix calls validate_k8s_context_name, which exists in devops_cli.core.validation.

Related: #4086 (found while it removed the patch of sync_k8s_credentials).

Proposed design

Problem statement

The k8s credential sync refuses a kubeconfig context that is not an RFC 1123 name, such as an EKS ARN. deploy-stack accepts the name and deploys the stack. Then the sync exits with code 1. The sync must use the same context validator as switch-context and deploy-stack.

Acceptance criteria

Requirement: Context validator of the credential sync

fetch_secret_data SHALL validate the context name with validate_k8s_context_name.

Scenario: An EKS ARN context

  • WHEN fetch_secret_data runs with the context arn:aws:eks:us-east-1:123456789012:cluster/prod.
  • THEN It raises no validation error, and it reads the secret with kubectl --context set to that ARN.

Requirement: Deploy of the infra stack with an ARN context

devops k8s deploy-stack --stack infra SHALL finish with exit code 0 when the context is an EKS ARN.

Scenario: The infra stack deploys against an ARN context

  • WHEN The command runs with an ARN context and --no-push-secrets.
  • THEN The exit code is 0, and the output holds no Must be a valid RFC 1123 name message.

Requirement: Rejection of an unsafe context name

fetch_secret_data MUST reject a context name that holds shell injection, a space or an empty string.

Scenario: A context name with a shell metacharacter

  • WHEN fetch_secret_data runs with the context bad; rm -rf /.
  • THEN It raises a validation error, and it starts no kubectl process.

Requirement: Regression test on the infra stack

test_deploy_and_teardown_stack_use_effective_context SHALL cover the infra stack with an ARN context.

Scenario: The context test deploys the infra stack

  • WHEN The test runs with the effective context set to an EKS ARN.
  • THEN The deploy and the teardown both exit 0, and the test no longer uses the logging stack as a stand-in.

Existing Tool Considered

No alternatives check has run. No new tool or library is needed. validate_k8s_context_name in devops_cli.core.validation covers the need: it accepts every kubeconfig name that switch-context and deploy-stack accept, and it rejects shell injection. It lacks nothing for this fix.

Key questions

  • Which validator should fetch_secret_data use for the context name?: Use validate_k8s_context_name, the validator that switch-context and deploy-stack use. (best practice) [sources: src/devops_cli/core/validation.py, src/devops_cli/k8s/credentials.py:160, src/devops_cli/commands/k8s/cluster_runtime.py, src/devops_cli/commands/argo.py:516, tests/core/test_validation.py]
    • Chosen: validate_k8s_context_name. It accepts ARN, email and GKE names, and it rejects shell injection. The commands of the issue already use it.
    • Rejected: validate_k8s_name. It accepts only RFC 1123 names, so it causes the defect.
    • Rejected: A new context validator. It duplicates an existing, tested function.
  • Does sync_k8s_credentials validate the context itself?: No. Its callers pass the context to fetch_secret_data, and fetch_secret_data holds the check. [sources: src/devops_cli/k8s/credentials.py:160, src/devops_cli/k8s/credentials.py:208, src/devops_cli/k8s/credentials.py:237, src/devops_cli/commands/k8s/stack_lifecycle.py]
  • Should the end-to-end test deploy the infra stack again?: Yes. Restore the infra stack with the ARN context, so the test covers the defect end to end. (best practice) [sources: tests/commands/k8s/test_k8s_context.py:373, openspec/changes/archive/2026-11-08-4086-k8s-command-tests-on-edge-fakes/proposal.md:52]
    • Chosen: Restore the infra stack. The test then covers the credential sync with an ARN context, which is the defect.
    • Rejected: Keep the logging stack. The logging stack syncs no credential, so the test leaves the regression uncovered.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-10: none.
Tool: none found.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    source/agent
    type/bug
    scope/k8s
    status/new
    value/medium
    effort/low
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at fe1d00b (see proposed design in issue body).

  6. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The issue is an internal bug in devops_cli.k8s.credentials.fetch_secret_data, which validates a kubeconfig context with the RFC 1123-only validate_k8s_name instead of the existing validate_k8s_context_name. The searches turned up only generic input-validation pages, no library that validates kubeconfig context names (EKS ARNs, GKE, email names) or that would replace the repository's own validator, so no external tool covers the need.

    Tool: none found

    Lacks:

    • No external tool or library validates kubeconfig context names such as EKS ARNs
    • The fix is a swap of one internal validator call plus a regression test, which no dependency provides

    Searches run:

    • python validate kubernetes context name shell injection library, results: 5
    • kubeconfig context name validation library accepts EKS ARN non-RFC 1123 names, results: 5

    Sources:

    Checked on 2026-11-10. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    owner/agent
    on Nov 11, 2026
  8. added
    status/in-progress
    and removed
    status/ready
    on Nov 12, 2026
  9. removed
    status/in-progress
    owner/agent
    on Nov 12, 2026
  10. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 05:27 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions