Skip to content

Commit ddbb664

Browse files
committed
Remove "Docker Content Trust"
As an opener, I want to make it clear that this is 100% a self-motivated change; I am not making this change on behalf of Docker Inc, nor does my opinion here represent Docker Inc in any official capacity (ie, if you're writing a splashy news article about this, you're barking up the wrong tree by attributing it officially to Docker Inc; I'm "rogue" here / doing this on my own time as a personally interested party). My biggest motivation for making this proposal is frankly the state of the upstream Notary (v1) project. It has been completely unmaintained for at least a full year, and mostly unmaintained for quite a few years. No matter what value this feature might have once had, it currently is vastly overshadowed by mass bitrot, and it is my argument/opinion that we are actively doing the community a very large disservice (and even harm) by continuing to "support" the feature in the Docker CLI. Given the state of the upstream project, it is my belief that this should qualify for an exception to our regular "deprecation" process such that we remove the feature *immediately*, and IMO we could very reasonably even consider backporting this deprecation to any past supported branches. Arguably, we should have some official means of integrating *other* "trusted image" solutions into the Docker platform, but IMO those belong in the Engine (unlike DCT which is entirely implemented in the CLI), and I see that (more complex) discussion as orthogonal to removing this bitrot. There are still quite a few `TODO` items here (most notably that we probably need some period of time with no-op/warning/erroring `--disable-content-trust=xxx` flags and deprecation documentation). I'm also certain I missed a few things, as I was mostly doing a pretty serious hack job to see how difficult this would be, not focused on creating a 100% optimal change (and this touches so many parts of the codebase that it's frankly more than I'm comfortable determining by myself whether I've made the changes correctly anyways). Signed-off-by: Tianon Gravi <[email protected]>
1 parent cfaaeb0 commit ddbb664

File tree

259 files changed

+101
-34059
lines changed

Some content is hidden

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

259 files changed

+101
-34059
lines changed

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
105105
FROM docker/compose-bin:${COMPOSE_VERSION} AS compose
106106

107107
FROM e2e-base-${BASE_VARIANT} AS e2e
108-
ARG NOTARY_VERSION=v0.6.1
109-
ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
110-
COPY --link e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert
111-
RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
112108
COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
113109
COPY --link --from=build /out ./build/
114110
COPY --link --from=build-plugins /out ./build/

cli/command/cli.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type Cli interface {
5050
ServerInfo() ServerInfo
5151
DefaultVersion() string
5252
CurrentVersion() string
53-
ContentTrustEnabled() bool
5453
BuildKitEnabled() (bool, error)
5554
ContextStore() store.Store
5655
CurrentContext() string
@@ -68,7 +67,6 @@ type DockerCli struct {
6867
err *streams.Out
6968
client client.APIClient
7069
serverInfo ServerInfo
71-
contentTrust bool
7270
contextStore store.Store
7371
currentContext string
7472
init sync.Once
@@ -155,12 +153,6 @@ func (cli *DockerCli) ServerInfo() ServerInfo {
155153
return cli.serverInfo
156154
}
157155

158-
// ContentTrustEnabled returns whether content trust has been enabled by an
159-
// environment variable.
160-
func (cli *DockerCli) ContentTrustEnabled() bool {
161-
return cli.contentTrust
162-
}
163-
164156
// BuildKitEnabled returns buildkit is enabled or not.
165157
func (cli *DockerCli) BuildKitEnabled() (bool, error) {
166158
// use DOCKER_BUILDKIT env var value if set and not empty
@@ -510,11 +502,9 @@ type ServerInfo struct {
510502
}
511503

512504
// NewDockerCli returns a DockerCli instance with all operators applied on it.
513-
// It applies by default the standard streams, and the content trust from
514-
// environment.
505+
// It applies by default the standard streams.
515506
func NewDockerCli(ops ...CLIOption) (*DockerCli, error) {
516507
defaultOps := []CLIOption{
517-
WithContentTrustFromEnv(),
518508
WithDefaultContextStoreConfig(),
519509
WithStandardStreams(),
520510
}

cli/command/cli_options.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"net/http"
88
"os"
9-
"strconv"
109
"strings"
1110

1211
"github.com/docker/cli/cli/streams"
@@ -76,28 +75,6 @@ func WithErrorStream(err io.Writer) CLIOption {
7675
}
7776
}
7877

79-
// WithContentTrustFromEnv enables content trust on a cli from environment variable DOCKER_CONTENT_TRUST value.
80-
func WithContentTrustFromEnv() CLIOption {
81-
return func(cli *DockerCli) error {
82-
cli.contentTrust = false
83-
if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
84-
if t, err := strconv.ParseBool(e); t || err != nil {
85-
// treat any other value as true
86-
cli.contentTrust = true
87-
}
88-
}
89-
return nil
90-
}
91-
}
92-
93-
// WithContentTrust enables content trust on a cli.
94-
func WithContentTrust(enabled bool) CLIOption {
95-
return func(cli *DockerCli) error {
96-
cli.contentTrust = enabled
97-
return nil
98-
}
99-
}
100-
10178
// WithDefaultContextStoreConfig configures the cli to use the default context store configuration.
10279
func WithDefaultContextStoreConfig() CLIOption {
10380
return func(cli *DockerCli) error {

cli/command/cli_options_test.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

cli/command/cli_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,12 @@ func TestExperimentalCLI(t *testing.T) {
298298

299299
func TestNewDockerCliAndOperators(t *testing.T) {
300300
// Test default operations and also overriding default ones
301-
cli, err := NewDockerCli(
302-
WithContentTrust(true),
303-
)
301+
cli, err := NewDockerCli()
304302
assert.NilError(t, err)
305303
// Check streams are initialized
306304
assert.Check(t, cli.In() != nil)
307305
assert.Check(t, cli.Out() != nil)
308306
assert.Check(t, cli.Err() != nil)
309-
assert.Equal(t, cli.ContentTrustEnabled(), true)
310307

311308
// Apply can modify a dockerCli after construction
312309
inbuf := bytes.NewBuffer([]byte("input"))

cli/command/commands/commands.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/docker/cli/cli/command/stack"
2121
"github.com/docker/cli/cli/command/swarm"
2222
"github.com/docker/cli/cli/command/system"
23-
"github.com/docker/cli/cli/command/trust"
2423
"github.com/docker/cli/cli/command/volume"
2524
"github.com/spf13/cobra"
2625
)
@@ -52,7 +51,6 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
5251
network.NewNetworkCommand(dockerCli),
5352
plugin.NewPluginCommand(dockerCli),
5453
system.NewSystemCommand(dockerCli),
55-
trust.NewTrustCommand(dockerCli),
5654
volume.NewVolumeCommand(dockerCli),
5755

5856
// orchestration (swarm) commands

cli/command/container/create.go

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import (
1212
"github.com/docker/cli/cli"
1313
"github.com/docker/cli/cli/command"
1414
"github.com/docker/cli/cli/command/completion"
15-
"github.com/docker/cli/cli/command/image"
1615
"github.com/docker/cli/cli/internal/jsonstream"
1716
"github.com/docker/cli/cli/streams"
18-
"github.com/docker/cli/cli/trust"
1917
"github.com/docker/cli/opts"
2018
"github.com/docker/docker/api/types/container"
2119
imagetypes "github.com/docker/docker/api/types/image"
@@ -35,11 +33,10 @@ const (
3533
)
3634

3735
type createOptions struct {
38-
name string
39-
platform string
40-
untrusted bool
41-
pull string // always, missing, never
42-
quiet bool
36+
name string
37+
platform string
38+
pull string // always, missing, never
39+
quiet bool
4340
}
4441

4542
// NewCreateCommand creates a new cobra.Command for `docker create`
@@ -76,7 +73,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
7673
flags.Bool("help", false, "Print usage")
7774

7875
command.AddPlatformFlag(flags, &options.platform)
79-
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
76+
// TODO add a (hidden) --disable-content-trust flag that throws a deprecation/removal warning and does nothing
8077
copts = addFlags(flags)
8178

8279
addCompletions(cmd, dockerCli)
@@ -201,11 +198,6 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
201198
hostConfig := containerCfg.HostConfig
202199
networkingConfig := containerCfg.NetworkingConfig
203200

204-
var (
205-
trustedRef reference.Canonical
206-
namedRef reference.Named
207-
)
208-
209201
containerIDFile, err := newCIDFile(hostConfig.ContainerIDFile)
210202
if err != nil {
211203
return "", err
@@ -216,27 +208,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
216208
if err != nil {
217209
return "", err
218210
}
211+
var namedRef reference.Named
219212
if named, ok := ref.(reference.Named); ok {
220213
namedRef = reference.TagNameOnly(named)
221-
222-
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && !options.untrusted {
223-
var err error
224-
trustedRef, err = image.TrustedReference(ctx, dockerCli, taggedRef)
225-
if err != nil {
226-
return "", err
227-
}
228-
config.Image = reference.FamiliarString(trustedRef)
229-
}
230-
}
231-
232-
pullAndTagImage := func() error {
233-
if err := pullImage(ctx, dockerCli, config.Image, options); err != nil {
234-
return err
235-
}
236-
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
237-
return trust.TagTrusted(ctx, dockerCli.Client(), dockerCli.Err(), trustedRef, taggedRef)
238-
}
239-
return nil
240214
}
241215

242216
var platform *specs.Platform
@@ -253,7 +227,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
253227
}
254228

255229
if options.pull == PullImageAlways {
256-
if err := pullAndTagImage(); err != nil {
230+
if err := pullImage(ctx, dockerCli, config.Image, options); err != nil {
257231
return "", err
258232
}
259233
}
@@ -269,7 +243,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
269243
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
270244
}
271245

272-
if err := pullAndTagImage(); err != nil {
246+
if err := pullImage(ctx, dockerCli, config.Image, options); err != nil {
273247
return "", err
274248
}
275249

cli/command/container/create_test.go

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/docker/cli/cli"
1414
"github.com/docker/cli/cli/config/configfile"
1515
"github.com/docker/cli/internal/test"
16-
"github.com/docker/cli/internal/test/notary"
1716
"github.com/docker/docker/api/types/container"
1817
"github.com/docker/docker/api/types/image"
1918
"github.com/docker/docker/api/types/network"
@@ -142,10 +141,9 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
142141
}
143142
fakeCLI := test.NewFakeCli(client)
144143
id, err := createContainer(context.Background(), fakeCLI, config, &createOptions{
145-
name: "name",
146-
platform: runtime.GOOS,
147-
untrusted: true,
148-
pull: tc.PullPolicy,
144+
name: "name",
145+
platform: runtime.GOOS,
146+
pull: tc.PullPolicy,
149147
})
150148

151149
if tc.ExpectedErrMsg != "" {
@@ -221,53 +219,6 @@ func TestCreateContainerValidateFlags(t *testing.T) {
221219
}
222220
}
223221

224-
func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
225-
testCases := []struct {
226-
name string
227-
args []string
228-
expectedError string
229-
notaryFunc test.NotaryClientFuncType
230-
}{
231-
{
232-
name: "offline-notary-server",
233-
notaryFunc: notary.GetOfflineNotaryRepository,
234-
expectedError: "client is offline",
235-
args: []string{"image:tag"},
236-
},
237-
{
238-
name: "uninitialized-notary-server",
239-
notaryFunc: notary.GetUninitializedNotaryRepository,
240-
expectedError: "remote trust data does not exist",
241-
args: []string{"image:tag"},
242-
},
243-
{
244-
name: "empty-notary-server",
245-
notaryFunc: notary.GetEmptyTargetsNotaryRepository,
246-
expectedError: "No valid trust data for tag",
247-
args: []string{"image:tag"},
248-
},
249-
}
250-
for _, tc := range testCases {
251-
fakeCLI := test.NewFakeCli(&fakeClient{
252-
createContainerFunc: func(config *container.Config,
253-
hostConfig *container.HostConfig,
254-
networkingConfig *network.NetworkingConfig,
255-
platform *specs.Platform,
256-
containerName string,
257-
) (container.CreateResponse, error) {
258-
return container.CreateResponse{}, errors.New("shouldn't try to pull image")
259-
},
260-
}, test.EnableContentTrust)
261-
fakeCLI.SetNotaryClient(tc.notaryFunc)
262-
cmd := NewCreateCommand(fakeCLI)
263-
cmd.SetOut(io.Discard)
264-
cmd.SetErr(io.Discard)
265-
cmd.SetArgs(tc.args)
266-
err := cmd.Execute()
267-
assert.ErrorContains(t, err, tc.expectedError)
268-
}
269-
}
270-
271222
func TestNewCreateCommandWithWarnings(t *testing.T) {
272223
testCases := []struct {
273224
name string

cli/command/container/port_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestNewPortCommandOutput(t *testing.T) {
6565
}
6666
return ci, nil
6767
},
68-
}, test.EnableContentTrust)
68+
})
6969
cmd := NewPortCommand(cli)
7070
cmd.SetErr(io.Discard)
7171
cmd.SetArgs([]string{"some_container", tc.port})

cli/command/container/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
6666
flags.Bool("help", false, "Print usage")
6767

6868
command.AddPlatformFlag(flags, &options.platform)
69-
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
69+
// TODO add a (hidden) --disable-content-trust flag that throws a deprecation/removal warning and does nothing
7070
copts = addFlags(flags)
7171

7272
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)

0 commit comments

Comments
 (0)