Skip to content

fix(cli): avoid blocking on non-interactive key passwords - #1891

Merged
tkircsi merged 4 commits into
agntcy:mainfrom
Baltsat:fix/1883-dirctl-sign-noninteractive-dco
Jul 29, 2026
Merged

tkircsi merged 4 commits into
agntcy:mainfrom
Baltsat:fix/1883-dirctl-sign-noninteractive-dco

Conversation

@Baltsat

@Baltsat Baltsat commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • stop dirctl sign from implicitly reading an unrelated or permanently open stdin stream in non-interactive environments
  • add explicit --password-stdin support for intentional piped passwords
  • preserve COSIGN_PASSWORD precedence, including an explicitly empty value
  • retain interactive terminal prompting
  • add actionable guidance for unsupported Cosign/Sigstore key formats and decryption failures
  • document the non-interactive behavior and compatible key generation in command help
  • add focused regression tests for source precedence, fail-fast behavior, and error wrapping

Root cause

When COSIGN_PASSWORD was unset and no terminal was available, the password reader unconditionally called io.ReadAll(os.Stdin). A headless parent may keep stdin open without providing data, so signing could block indefinitely instead of advancing or returning an error.

The new precedence is:

  1. COSIGN_PASSWORD, including an explicitly empty value
  2. --password-stdin
  3. interactive terminal prompt
  4. immediate empty-password attempt without reading stdin

Fixes #1883

Compatibility

Scripts that intentionally pipe a private-key password must now opt in with --password-stdin, for example:

printf %s "$KEY_PASSWORD" | dirctl sign <record-cid> --key cosign.key --password-stdin

This distinguishes intentional password input from an unrelated open stdin stream.

Validation

Passed in the worker’s clean-applied source harness:

  • focused pre-fix regression: failed after 250 ms because the reader remained blocked
  • go test ./cli/cmd/sign -count=1 -v — 7 tests passed
  • go test ./cli/cmd/sign -count=100
  • go test -race ./cli/cmd/sign -count=1
  • go vet ./cli/cmd/sign
  • gofmt and git diff --check

The current binary separately reproduced the open-stdin hang and the unsupported pem type: PRIVATE KEY error before the change.

The worker VM did not provide Go 1.26.5, Taskfile, GolangCI-Lint, or Docker, so repository-wide unit, lint, build, and E2E checks remain for upstream CI. An inline PEM that fails the initial parser may still be reinterpreted as a key reference before the final error is wrapped; the exact issue reproduction uses a key file and is covered.

Copilot AI review requested due to automatic review settings July 25, 2026 06:54
@Baltsat
Baltsat requested a review from a team as a code owner July 25, 2026 06:54

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Jul 25, 2026
@github-actions
github-actions Bot force-pushed the fix/1883-dirctl-sign-noninteractive-dco branch from 13851ec to d32aebd Compare July 25, 2026 12:17
@ramizpolic
ramizpolic requested review from paralta and tkircsi July 27, 2026 16:51
@tkircsi

tkircsi commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@Baltsat Thanks for your contribution! Could you also update the related documents in docs/content/dir? Thanks!

@Baltsat

Baltsat commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — I added the related non-interactive signing documentation in b122423:

  • documented COSIGN_PASSWORD, explicit --password-stdin, terminal prompting, and the no-implicit-stdin behavior
  • documented the required Cosign/Sigstore encrypted private-key format
  • added a complete --password-stdin CLI example in both the reference and usage guide

Local documentation validation passed: MkDocs build, codespell, pymarkdown, and git diff --check.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/cmd/sign/sign.go 92.9% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

LGTM! Thanks!

@paralta paralta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for contributing! please fix the pending conflict so we can merge 🚀

Resolve the signing-reference overlap by retaining both the non-interactive password contract and the newly merged KMS documentation. Add direct coverage for the production password-reader wiring.

AI-Assisted: Codex

User-Request: finish existing OSS pull requests through final proof | codex:oss-maintainer-campaign
Signed-off-by: Konstantin Baltsat <[email protected]>
@Baltsat

Baltsat commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the conflict in aafca73 by merging current main and retaining both the non-interactive password documentation and the newly merged KMS section.

I also added direct coverage for the production password-reader wiring. Final-tree proof passed: full CLI tests, focused coverage, vet, golangci-lint, CLI build, MkDocs build, codespell, pymarkdown, and git diff --check. GitHub now reports the PR mergeable; CI is running on the exact head.

@paralta paralta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Baltsat, I think there was an issue with the merge and the last commit is removing documentation that was added recently (--project flag for install command), please check

@Baltsat

Baltsat commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching that — fixed in d4ce330.

I restored the current dirctl install --project documentation: the install flag row, global-versus-project scope behavior, example, and uninstall shared-flag reference. The password and KMS documentation remains unchanged.

Final-tree documentation proof passed with the repository's locked uv environment: MkDocs build, codespell, pymarkdown, and git diff --check. The PR diff no longer deletes any --project documentation; DCO is green and hosted CI has restarted on the exact head.

@tkircsi
tkircsi merged commit 2c4659d into agntcy:main Jul 29, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: dirctl sign blocks in non-interactive/headless environments (password prompt; key-format + COSIGN_PASSWORD undocumented)

4 participants