-
Notifications
You must be signed in to change notification settings - Fork 283
Sign plugin pushes and remove the lock feature gate #6438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samuv
wants to merge
19
commits into
main
Choose a base branch
from
plugins-sig/10-push-ungate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9533bb7
Sign plugin pushes and remove the lock gate
samuv 48a32f9
Document the plugins trust model
samuv d125815
Address review on plugin push signing
samuv 99ce845
Link the key-signing gap issue from the trust doc
samuv fd410f1
Drop --key from plugin push
samuv 8081332
Harden the plugin push contract
samuv 04dcae5
Withhold identity tokens from plaintext HTTP
samuv 3105908
Persist a freshly verified bundle over a stale one
samuv ac97e2d
Treat lock entries with no trust decision as drift
samuv a893677
Offer only flags the push command defines
samuv 5e79e57
Return silently from a user-scope plugin install
samuv 6b6cd1c
Cover plugin push signing in E2E tests
samuv 2d46359
Correct the plugins trust model documentation
samuv 9d0098b
Refuse redirects on token-bearing pushes
samuv 4774672
Require consent to migrate an unsigned lock entry
samuv f4fec21
Show when a lock entry records no trust decision
samuv 32a6c5b
Document consent in the lock entry migration
samuv 0d8a084
Rematerialize when an install first locks a record
samuv cba9ed4
Describe both uses of sync --allow-unsigned
samuv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package app | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/stacklok/toolhive/pkg/plugins" | ||
| ) | ||
|
|
||
| // TestAIPluginPushSigningFlags pins the signed-by-default publish surface: | ||
| // the keyless flags must exist, the opt-out must not be preset (a defaulted | ||
| // --no-sign would publish unsigned artifacts silently), and --key must NOT be | ||
| // offered — ToolHive cannot verify key-signed artifacts at install time, so | ||
| // the flag would only produce uninstallable plugins (#6442). Re-add it in the | ||
| // change that makes key verification work. | ||
| func TestAIPluginPushSigningFlags(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, name := range []string{"identity-token", "no-sign"} { | ||
| flag := aiPluginPushCmd.Flags().Lookup(name) | ||
| require.NotNil(t, flag, "thv ai-plugin push must expose --%s", name) | ||
| } | ||
| assert.Nil(t, aiPluginPushCmd.Flags().Lookup("key"), | ||
| "plugin signing is keyless-only; --key must not be advertised until install can verify it") | ||
| assert.Equal(t, "false", aiPluginPushCmd.Flags().Lookup("no-sign").DefValue, | ||
| "pushing unsigned must always be an explicit choice") | ||
| assert.Empty(t, aiPluginPushCmd.Flags().Lookup("identity-token").DefValue) | ||
| } | ||
|
|
||
| // TestPrintAIPluginInfoTextTrustStates covers each trust state the info | ||
| // command renders. RFC THV-0080 wants the pinned identity visible at read | ||
| // time, so a state that silently renders as "no trust block" is a bug. | ||
| // | ||
| //nolint:paralleltest // captures os.Stdout, which cannot be done in parallel | ||
| func TestPrintAIPluginInfoTextTrustStates(t *testing.T) { | ||
| signed := &plugins.ProvenanceInfo{ | ||
| SignerIdentity: "/.github/workflows/release.yml", | ||
| CertIssuer: "https://token.actions.githubusercontent.com", | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| info plugins.PluginInfo | ||
| wantLines []string | ||
| wantAbsent []string | ||
| }{ | ||
| { | ||
| name: "signed", | ||
| info: plugins.PluginInfo{Provenance: signed}, | ||
| wantLines: []string{ | ||
| "Signed by: /.github/workflows/release.yml", | ||
| "Cert issuer: https://token.actions.githubusercontent.com", | ||
| }, | ||
| wantAbsent: []string{"provisional", "unsigned"}, | ||
| }, | ||
| { | ||
| name: "provisional", | ||
| info: plugins.PluginInfo{Provenance: &plugins.ProvenanceInfo{ | ||
| SignerIdentity: signed.SignerIdentity, | ||
| CertIssuer: signed.CertIssuer, | ||
| Provisional: true, | ||
| }}, | ||
| wantLines: []string{"Signed by: /.github/workflows/release.yml (provisional)"}, | ||
| }, | ||
| { | ||
| name: "unsigned exception", | ||
| info: plugins.PluginInfo{Unsigned: true}, | ||
| wantLines: []string{"Signed by: (unsigned — explicit exception)"}, | ||
| wantAbsent: []string{"Cert issuer"}, | ||
| }, | ||
| { | ||
| // The state sync reports as drift. It must read differently from | ||
| // "no lock entry", which prints no trust line at all, and it has | ||
| // to name the command that repairs it. | ||
| name: "trust unrecorded", | ||
| info: plugins.PluginInfo{TrustUnrecorded: true}, | ||
| wantLines: []string{"Signed by: (trust unrecorded — run 'thv ai-plugin sync')"}, | ||
| wantAbsent: []string{"Cert issuer", "explicit exception"}, | ||
| }, | ||
| { | ||
| name: "no lock entry", | ||
| info: plugins.PluginInfo{}, | ||
| wantAbsent: []string{"Signed by", "Cert issuer"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| tt.info.Metadata = plugins.PluginMetadata{Name: "my-plugin", Version: "1.0.0"} | ||
|
|
||
| // The tabwriter pads labels to the widest one in the block, which | ||
| // differs per case; collapse runs of spaces so the assertions | ||
| // pin the content rather than the alignment. | ||
| out := strings.Join(strings.Fields( | ||
| captureStdout(t, func() { printAIPluginInfoText(&tt.info) }), | ||
| ), " ") | ||
|
|
||
| for _, want := range tt.wantLines { | ||
| assert.Contains(t, out, want) | ||
| } | ||
| for _, absent := range tt.wantAbsent { | ||
| assert.NotContains(t, out, absent) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestPrintPluginInstallTrust proves install reports the trust state it | ||
| // recorded, rather than leaving the user to discover the pinned identity | ||
| // weeks later inside a signer-mismatch error. | ||
| // | ||
| //nolint:paralleltest // captures os.Stdout, which cannot be done in parallel | ||
| func TestPrintPluginInstallTrust(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| result *plugins.InstallResult | ||
| want string | ||
| }{ | ||
| { | ||
| name: "signed", | ||
| result: &plugins.InstallResult{ | ||
| Plugin: plugins.InstalledPlugin{Metadata: plugins.PluginMetadata{Name: "my-plugin"}}, | ||
| Provenance: &plugins.ProvenanceInfo{SignerIdentity: "/.github/workflows/release.yml"}, | ||
| }, | ||
| want: "Installed my-plugin (signed by /.github/workflows/release.yml)\n", | ||
| }, | ||
| { | ||
| name: "provisional", | ||
| result: &plugins.InstallResult{ | ||
| Plugin: plugins.InstalledPlugin{Metadata: plugins.PluginMetadata{Name: "my-plugin"}}, | ||
| Provenance: &plugins.ProvenanceInfo{ | ||
| SignerIdentity: "/.github/workflows/release.yml", | ||
| Provisional: true, | ||
| }, | ||
| }, | ||
| want: "Installed my-plugin (signed by /.github/workflows/release.yml; " + | ||
| "verification provisional — see lock file)\n", | ||
| }, | ||
| { | ||
| name: "unsigned exception", | ||
| result: &plugins.InstallResult{ | ||
| Plugin: plugins.InstalledPlugin{Metadata: plugins.PluginMetadata{Name: "my-plugin"}}, | ||
| Unsigned: true, | ||
| }, | ||
| want: "Installed my-plugin (unsigned — recorded as an explicit exception in the lock file)\n", | ||
| }, | ||
| { | ||
| // A user-scope install records no lock trust decision, so there | ||
| // is nothing trust-related to report and the CLI's silent-success | ||
| // rule applies: a bare "Installed my-plugin" would turn every | ||
| // previously quiet install into output while saying nothing about | ||
| // trust. | ||
| name: "user scope, no trust state, prints nothing", | ||
| result: &plugins.InstallResult{ | ||
| Plugin: plugins.InstalledPlugin{Metadata: plugins.PluginMetadata{Name: "my-plugin"}}, | ||
| }, | ||
| want: "", | ||
| }, | ||
| {name: "nil result prints nothing", result: nil, want: ""}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Equal(t, tt.want, captureStdout(t, func() { printPluginInstallTrust(tt.result) })) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shared acquisition helper's terminal error still recommends
--key, but this command deliberately has no--keyflag. A non-interactive push without ambient OIDC is therefore sent to an impossible remediation. Give plugin push a credential error containing only valid choices (--identity-token, CIid-token: write, or--no-sign), while retaining the shared acquisition mechanics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
e5452d7ab.ErrNoCredentialno longer carries the flag list. It is now the bare sentinel, and the remediation comes from the calling command viaOptions.Remediation, so plugin push offers--identity-token, CIid-token: write, and--no-sign— and never--key. Skill push keeps its full list including--key. The shared acquisition mechanics are untouched, as you asked.ErrNoCredentialremains the wrapped sentinel soerrors.Iskeeps working.Remediationis optional rather than required: I first made it mandatory and it forced the field on the severalAcquirepaths that can never reach that error, which was noise. Omitting it yields the bare sentinel — terser, but never pointing at a flag the command does not define.Also changed the
--identity-tokenhelp text from "ambient CI OIDC token" to "GitHub Actions OIDC token", per your second point.Covered by an E2E case in
4941e8d51that runs a non-interactive push with no credential and asserts the message contains--identity-tokenand--no-signbut not--key.