Repository navigation
Conversation
1e09e23 to
b4d74d5
Compare
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
| if len(trimmed) == 0 || trimmed[0] == '#' { | ||
| continue | ||
| } | ||
| trimmed = bytes.TrimPrefix(trimmed, []byte("export ")) |
There was a problem hiding this comment.
[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:
| 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 |
| dir := filepath.Dir(dst) | ||
| if runtime.GOOS == "windows" { | ||
| return fmt.Errorf("installing to %s: %w", dir, fs.ErrPermission) | ||
| } |
There was a problem hiding this comment.
hmm. strange checking this here. might need a build tag instead then for this code.
| env := slices.DeleteFunc(os.Environ(), func(kv string) bool { | ||
| key, _, _ := strings.Cut(kv, "=") | ||
| return strings.EqualFold(key, "GOOS") || strings.EqualFold(key, "GOARCH") | ||
| }) |
There was a problem hiding this comment.
hmm. is it important that we read the whole os.Environ()?
| if runtime.GOOS == "windows" && !strings.EqualFold(filepath.Ext(name), ".exe") { | ||
| name += ".exe" | ||
| } |
There was a problem hiding this comment.
doesn't go install determine this?
There was a problem hiding this comment.
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.
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>
b373a12 to
2eb609f
Compare
| 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>
2eb609f to
4a2a461
Compare
Adds
docker pass installanddocker pass uninstall. Both act on the engine's plugin directory, which the embedding binary supplies.installbuilds a secrets engine plugin from Go source withgo installand copies the binary into the plugin directory: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.uninstalldeletes plugins from the plugin directory by file name: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 0755orsudo 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/stdinreaderis 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.