Skip to content

feat(pass): add install and uninstall commands - #748

Open
joe0BAB wants to merge 2 commits into
mainfrom
feat/pass-install-command
Open

joe0BAB wants to merge 2 commits into
mainfrom
feat/pass-install-command

Conversation

@joe0BAB

@joe0BAB joe0BAB commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Adds docker pass install and docker pass uninstall. Both act on the engine's plugin directory, which the embedding binary supplies.

install builds a secrets engine plugin from Go source with go install and copies the binary into the plugin directory:

docker pass install github.com/docker/secrets-engine/plugins/stdinreader
docker pass install ./plugins/stdinreader

A package path defaults to @latest; a path that starts with . or / is built in that directory. The binary is installed only if its build info lists the plugin SDK module; nothing is executed. The engine takes the file name as the plugin name, hence --name. The copy is staged in a subdirectory of the plugin directory and renamed into place, so the engine never sees a partial file.

uninstall deletes plugins from the plugin directory by file name:

docker pass uninstall stdinreader
docker pass uninstall stdinreader stdin

A name must be a file name without a directory, so the command cannot reach outside the plugin directory. It checks every name before it deletes anything, and it refuses directories.

On Linux the plugin directory is root-owned. If the copy or the delete fails with a permission error, the command prints and runs sudo install -m 0755 or sudo rm --; the build always runs as the caller.

The engine scans the plugin directory only at startup, so both commands take effect when it restarts.

The new plugins/stdinreader is the plugin the examples and tests use. It reads dotenv secrets from stdin and serves them through the standalone engine.

The tests run the real go command against that plugin and against throwaway modules, with GOPROXY=off, so they need no network.

@joe0BAB
joe0BAB force-pushed the feat/pass-install-command branch from 1e09e23 to b4d74d5 Compare November 19, 2026 13:22
@joe0BAB joe0BAB changed the title feat(pass): add install command feat(pass): add install and uninstall commands Nov 19, 2026
@joe0BAB
joe0BAB marked this pull request as ready for review November 19, 2026 13:44
@joe0BAB
joe0BAB requested a review from a team as a code owner November 19, 2026 13:44

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

if len(trimmed) == 0 || trimmed[0] == '#' {
continue
}
trimmed = bytes.TrimPrefix(trimmed, []byte("export "))

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.

[medium] parseDotenv strips export with an exact single-space match — extra whitespace silently corrupts the key

The stripping at line 156 uses bytes.TrimPrefix(trimmed, []byte("export ")) which performs a byte-exact match. After bytes.TrimSpace removes leading/trailing whitespace, a line like export KEY=val (two spaces between export and the key, as can appear from certain editors or copy-paste) results in trimmed = "export KEY=val". The prefix "export " (one space) does not match, so bytes.TrimPrefix is a no-op. bytes.Cut then splits on = and produces key "export KEY" instead of "KEY". This silently creates a differently-named secret; the caller never sees an error, but the expected key will be missing at lookup time.

The fix is to strip export and then trim the leading space with a bytes.Fields-based split, or simply use bytes.TrimLeft after the prefix check:

Suggested change
trimmed = bytes.TrimPrefix(trimmed, []byte("export "))
if after, ok := bytes.CutPrefix(trimmed, []byte("export")); ok {
trimmed = bytes.TrimLeft(after, " \t")
}
Confidence Score
🟡 moderate 70/100

Comment thread plugins/pass/commands/install.go Outdated
dir := filepath.Dir(dst)
if runtime.GOOS == "windows" {
return fmt.Errorf("installing to %s: %w", dir, fs.ErrPermission)
}

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.

hmm. strange checking this here. might need a build tag instead then for this code.

Comment on lines +150 to +153
env := slices.DeleteFunc(os.Environ(), func(kv string) bool {
key, _, _ := strings.Cut(kv, "=")
return strings.EqualFold(key, "GOOS") || strings.EqualFold(key, "GOARCH")
})

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.

hmm. is it important that we read the whole os.Environ()?

Comment on lines +194 to +196
if runtime.GOOS == "windows" && !strings.EqualFold(filepath.Ext(name), ".exe") {
name += ".exe"
}

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.

doesn't go install determine this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Only for the default name, and there the code already uses what go install wrote. withExeSuffix runs for the two names go install never sees.

Comment thread plugins/pass/commands/install.go Resolved
InstallCommand builds a secrets engine plugin from Go source and copies
the binary into the engine's plugin directory, which the embedding
binary supplies:

    docker pass install github.com/docker/secrets-engine/plugins/stdinreader
    docker pass install ./plugins/stdinreader

It runs `go install` with GOBIN set to a staging directory, so the
toolchain resolves, verifies and builds the package. A package path
defaults to @latest; a path that starts with "." or "/" is built in
that directory.

The binary is installed only if its build info lists the plugin SDK
module. Nothing is executed.

The engine launches every executable file in the plugin directory and
takes the file name as the plugin name, hence --name. The copy is
staged in a subdirectory of the plugin directory and renamed into
place: the engine's scan skips directories, so it never sees a partial
file.

GOOS and GOARCH are dropped from the build environment because
`go install` refuses to cross-compile when GOBIN is set.

On Linux the plugin directory is root-owned. The build always runs as
the caller; if the copy fails with a permission error, the command
prints and runs `sudo install -m 0755`.

plugins/stdinreader is the plugin the examples and tests use. It reads
dotenv secrets from stdin and serves them through the standalone
engine. Its version comes from the build info unless -ldflags sets one,
so a copy installed at v0.1.0 reports v0.1.0.

The tests run the real go command against that plugin and against
throwaway modules, with GOPROXY=off, so they need no network.

Signed-off-by: Johannes Großmann <grossmann.johannes@t-online.de>
@joe0BAB
joe0BAB force-pushed the feat/pass-install-command branch from b373a12 to 2eb609f Compare November 27, 2026 10:49
if err != nil {
return err
}
if err := os.Lchown(gobin, int(uid), int(gid)); err != nil {
if err != nil {
return err
}
if err := os.Lchown(gobin, int(uid), int(gid)); err != nil {
UninstallCommand deletes plugins from the engine's plugin directory by
file name:

    docker pass uninstall stdinreader
    docker pass uninstall stdinreader stdin

A name must be a file name without a directory, so the command cannot
reach outside the plugin directory. It checks every name before it
deletes anything, and it refuses directories.

Install and uninstall leave sudo to the user. If the plugin directory
is not writable, the command fails and says to rerun it with sudo.
This replaces the `sudo install` call that install made: install now
creates its staging directory first, so the permission error comes
before the build.

On Windows the hint says to rerun the command from an elevated
terminal. A process that already runs as root, or elevated on Windows,
gets no hint.

Under sudo, install runs `go install` as the user who called sudo, not
as root. If sudo drops Go from PATH, the error says to rerun with
`sudo PATH="$PATH"`.

The engine scans the plugin directory only at startup, so a deleted
plugin keeps running until the engine restarts.

The shared name check also fixes install: `--name /` passed the old
check.

plugins/stdinreader requires client v1.0.0 and plugin v0.4.1, the
versions the workspace vendors.

Signed-off-by: Johannes Großmann <grossmann.johannes@t-online.de>
@joe0BAB
joe0BAB force-pushed the feat/pass-install-command branch from 2eb609f to 4a2a461 Compare December 4, 2026 08:27
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.

4 participants