Skip to content

Commit 6308082

Browse files
authored
Merge pull request #190 from docker/feat/mysecret-init
feat: new CLI to mange local secrets
2 parents 7da7c2a + fa0ffe6 commit 6308082

1,182 files changed

Lines changed: 206131 additions & 29852 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@ on:
77
pull_request:
88

99
jobs:
10+
mysecret:
11+
name: Build docker-mysecret Plugin
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
pull-requests: write
16+
contents: write
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Hub login
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ vars.DOCKERBUILDBOT_USERNAME }}
26+
password: ${{ secrets.DOCKERBUILDBOT_WRITE_PAT }}
27+
28+
- name: Set up Docker Buildx
29+
id: buildx
30+
uses: docker/setup-buildx-action@v3
31+
with:
32+
driver: cloud
33+
endpoint: "docker/secrets-engine"
34+
install: true
35+
36+
- name: Build docker-mysecret Plugin
37+
run: make BUILDER=${{ steps.buildx.outputs.name }} mysecret-cross
1038

1139
nri-plugin:
1240
name: Build NRI Plugin

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ GO_VERSION := $(shell sh -c "awk '/^go / { print \$$2 }' go.mod")
66
export BUF_VERSION := v1.54.0
77

88
export NRI_PLUGIN_BINARY := nri-secrets-engine
9+
export MYSECRET_BINARY := docker-mysecret
910

1011
ifeq ($(OS),Windows_NT)
1112
WINDOWS = $(OS)
1213
EXTENSION = .exe
1314
DOCKER_SOCKET = //var/run/docker.sock
15+
DOCKER_MYSECRET_DST = $(USERPROFILE)\.docker\cli-plugins\$(MYSECRET_BINARY)$(EXTENSION)
1416
else
1517
WINDOWS =
1618
EXTENSION =
1719
DOCKER_SOCKET = /var/run/docker.sock
20+
DOCKER_MYSECRET_DST = $(HOME)/.docker/cli-plugins/$(MYSECRET_BINARY)$(EXTENSION)
1821
endif
1922

2023

@@ -27,6 +30,7 @@ BUILDER=buildx-multiarch
2730
DOCKER_BUILD_ARGS := --build-arg GO_VERSION \
2831
--build-arg GOLANGCI_LINT_VERSION \
2932
--build-arg NRI_PLUGIN_BINARY \
33+
--build-arg MYSECRET_BINARY \
3034
--build-arg BUF_VERSION \
3135
--build-arg GIT_TAG
3236

@@ -75,6 +79,15 @@ keychain-unit-tests:
7579
engine-unit-tests:
7680
CGO_ENABLED=0 go test -v $$(go list ./engine/...)
7781

82+
mysecret:
83+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags "-s -w" -o ./dist/$(MYSECRET_BINARY)$(EXTENSION) ./cmd/mysecret
84+
rm "$(DOCKER_MYSECRET_DST)" || true
85+
cp "dist/$(MYSECRET_BINARY)$(EXTENSION)" "$(DOCKER_MYSECRET_DST)"
86+
87+
mysecret-cross: multiarch-builder
88+
docker buildx build $(DOCKER_BUILD_ARGS) --pull --builder=$(BUILDER) --target=package-mysecret --file cmd/mysecret/Dockerfile --platform=linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64,windows/arm64 -o ./dist .
89+
90+
7891
nri-plugin:
7992
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags "-s -w" -o ./dist/$(NRI_PLUGIN_BINARY)$(EXTENSION) ./cmd/nri-plugin
8093

client/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ require (
1111
)
1212

1313
require (
14-
github.com/google/go-cmp v0.6.0 // indirect
14+
github.com/google/go-cmp v0.7.0 // indirect
1515
golang.org/x/mod v0.26.0 // indirect
1616
)

client/go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ connectrpc.com/connect v1.18.1 h1:PAg7CjSAGvscaf6YZKUefjoih5Z/qYkyaTrBW8xvYPw=
22
connectrpc.com/connect v1.18.1/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
88
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
99
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1010
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1111
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
1212
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
13-
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
14-
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
15-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
16-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
13+
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
14+
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
15+
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
16+
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
1717
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
1818
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
1919
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

cmd/mysecret/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#syntax=docker/dockerfile:1
2+
3+
ARG GO_VERSION=latest
4+
5+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS gobase
6+
RUN apk add --no-cache findutils build-base git
7+
8+
FROM gobase AS build-mysecret
9+
ARG TARGETOS
10+
ARG TARGETARCH
11+
ARG MYSECRET_BINARY
12+
WORKDIR /src
13+
RUN mkdir /out
14+
RUN --mount=type=bind,target=. \
15+
--mount=type=cache,target=/root/.cache/go-build \
16+
--mount=type=cache,target=/go/pkg/mod \
17+
--mount=type=tmpfs,target=/go/src/ <<EOT
18+
set -euo pipefail
19+
EXT=""
20+
[ "$TARGETOS" = "windows" ] && EXT=".exe"
21+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "-s -w" -o "/out/${MYSECRET_BINARY}${EXT}" ./cmd/mysecret
22+
EOT
23+
24+
FROM scratch AS package-mysecret
25+
COPY --link --from=build-mysecret /out .

cmd/mysecret/command.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/docker/cli/cli-plugins/plugin"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/docker/secrets-engine/internal/config"
11+
)
12+
13+
// Note: We use a custom help template to make it more brief.
14+
const helpTemplate = `Docker MySecret CLI - Manage your local secrets.
15+
{{if .UseLine}}
16+
Usage: {{.UseLine}}
17+
{{end}}{{if .HasAvailableLocalFlags}}
18+
Flags:
19+
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}
20+
{{end}}{{if .HasAvailableSubCommands}}
21+
Available Commands:
22+
{{range .Commands}}{{if (or .IsAvailableCommand)}} {{rpad .Name .NamePadding }} {{.Short}}
23+
{{end}}{{end}}{{end}}{{if .HasExample}}
24+
25+
Examples:
26+
{{.Example}}{{end}}
27+
`
28+
29+
// rootCommand returns the root command for the init plugin
30+
func rootCommand(ctx context.Context) *cobra.Command {
31+
cmd := &cobra.Command{
32+
Use: "mysecret [OPTIONS]",
33+
TraverseChildren: true,
34+
CompletionOptions: cobra.CompletionOptions{
35+
DisableDefaultCmd: false,
36+
HiddenDefaultCmd: true,
37+
},
38+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
39+
cmd.SetContext(ctx)
40+
return plugin.PersistentPreRunE(cmd, args)
41+
},
42+
Version: fmt.Sprintf("%s, commit %s", config.Version, config.Commit()),
43+
}
44+
cmd.SetVersionTemplate("Docker MySecret Plugin\n{{.Version}}\n")
45+
cmd.Flags().BoolP("version", "v", false, "Print version information and quit")
46+
cmd.SetHelpTemplate(helpTemplate)
47+
48+
_ = cmd.RegisterFlagCompletionFunc("mysecret", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
49+
return []string{"--help"}, cobra.ShellCompDirectiveNoFileComp
50+
})
51+
52+
cmd.AddCommand(dummyCommand())
53+
54+
return cmd
55+
}
56+
57+
func dummyCommand() *cobra.Command {
58+
cmd := &cobra.Command{
59+
Use: "dummy",
60+
Short: "just a test",
61+
}
62+
63+
cmd.AddCommand(&cobra.Command{
64+
Use: "read",
65+
Short: "Read the configuration",
66+
Args: cobra.NoArgs,
67+
RunE: func(*cobra.Command, []string) error {
68+
fmt.Println("hello")
69+
return nil
70+
},
71+
})
72+
73+
return cmd
74+
}

cmd/mysecret/main.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/signal"
7+
8+
"github.com/docker/cli/cli-plugins/manager"
9+
"github.com/docker/cli/cli-plugins/plugin"
10+
"github.com/docker/cli/cli/command"
11+
"github.com/spf13/cobra"
12+
13+
"github.com/docker/secrets-engine/internal/config"
14+
)
15+
16+
type errCtxSignalTerminated struct {
17+
signal os.Signal
18+
}
19+
20+
func (errCtxSignalTerminated) Error() string {
21+
return ""
22+
}
23+
24+
func main() {
25+
ctx, cancel := notifyContext(context.Background())
26+
defer cancel()
27+
if plugin.RunningStandalone() {
28+
os.Args = append([]string{os.Args[0], "mysecret"}, os.Args[1:]...)
29+
}
30+
31+
plugin.Run(func(command.Cli) *cobra.Command {
32+
return rootCommand(ctx)
33+
},
34+
manager.Metadata{
35+
SchemaVersion: "0.1.0",
36+
Vendor: "Docker Inc.",
37+
Version: config.Version,
38+
ShortDescription: "Docker MySecret Plugin",
39+
},
40+
)
41+
}
42+
43+
func notifyContext(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc) {
44+
ch := make(chan os.Signal, 1)
45+
signal.Notify(ch, signals...)
46+
47+
ctxCause, cancel := context.WithCancelCause(ctx)
48+
49+
go func() {
50+
select {
51+
case <-ctx.Done():
52+
signal.Stop(ch)
53+
return
54+
case sig := <-ch:
55+
cancel(errCtxSignalTerminated{signal: sig})
56+
signal.Stop(ch)
57+
return
58+
}
59+
}()
60+
61+
return ctxCause, func() {
62+
signal.Stop(ch)
63+
cancel(nil)
64+
}
65+
}

engine/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222

2323
require (
2424
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/kr/text v0.2.0 // indirect
2526
github.com/pmezard/go-difflib v1.0.0 // indirect
2627
golang.org/x/mod v0.26.0 // indirect
2728
gopkg.in/yaml.v3 v3.0.1 // indirect

engine/go.sum

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,35 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1x
44
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
55
github.com/containerd/nri v0.9.0 h1:jribDJs/oQ95vLO4Yn19HKFYriZGWKiG6nKWjl9Y/x4=
66
github.com/containerd/nri v0.9.0/go.mod h1:sDRoMy5U4YolsWthg7TjTffAwPb6LEr//83O+D3xVU4=
7+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
78
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
89
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
10-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
11+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1112
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
1213
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
14+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
15+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1316
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1417
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
15-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
16-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
1718
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1819
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
20+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
21+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
1922
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
2023
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2124
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
2225
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
23-
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
24-
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
26+
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
27+
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
2528
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
2629
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
27-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
28-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
30+
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
31+
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
2932
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
3033
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
3134
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
32-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
33-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
35+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
36+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
3437
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3538
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)