Skip to content

Commit c3317b0

Browse files
committed
cli/trust: Server: accept registry hostname
The IndexInfo was only used to detect if the target was an official image, which we can deduct from the hostname. Adding some normalizing just in case (but we should only get "docker.io" here). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 75f3c08 commit c3317b0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

cli/trust/trust.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func certificateDirectory(server string) (string, error) {
7979
}
8080

8181
// Server returns the base URL for the trust server.
82-
func Server(index *registrytypes.IndexInfo) (string, error) {
82+
func Server(indexName string) (string, error) {
8383
if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" {
8484
urlObj, err := url.Parse(s)
8585
if err != nil || urlObj.Scheme != "https" {
@@ -88,10 +88,10 @@ func Server(index *registrytypes.IndexInfo) (string, error) {
8888

8989
return s, nil
9090
}
91-
if index.Official {
91+
if indexName == "docker.io" || indexName == "index.docker.io" {
9292
return NotaryServer, nil
9393
}
94-
return "https://" + index.Name, nil
94+
return "https://" + indexName, nil
9595
}
9696

9797
type simpleCredentialStore struct {
@@ -117,7 +117,7 @@ const dctDeprecation = `WARNING: Docker is retiring DCT for Docker Official Imag
117117
// information needed to operate on a notary repository.
118118
// It creates an HTTP transport providing authentication support.
119119
func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *RepositoryInfo, authConfig *registrytypes.AuthConfig, actions ...string) (client.Repository, error) {
120-
server, err := Server(repoInfo.Index)
120+
server, err := Server(repoInfo.Index.Name)
121121
if err != nil {
122122
return nil, err
123123
}

cli/trust/trust_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/distribution/reference"
7-
registrytypes "github.com/moby/moby/api/types/registry"
87
"github.com/opencontainers/go-digest"
98
"github.com/theupdateframework/notary/client"
109
"github.com/theupdateframework/notary/trustpinning"
@@ -56,32 +55,32 @@ func TestGetSignableRolesError(t *testing.T) {
5655

5756
func TestENVTrustServer(t *testing.T) {
5857
t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.example.com:5000")
59-
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
60-
output, err := Server(indexInfo)
58+
output, err := Server("testserver")
6159
const expected = "https://notary-test.example.com:5000"
6260
assert.NilError(t, err)
6361
assert.Equal(t, output, expected)
6462
}
6563

6664
func TestHTTPENVTrustServer(t *testing.T) {
6765
t.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.example.com:5000")
68-
indexInfo := &registrytypes.IndexInfo{Name: "testserver"}
69-
_, err := Server(indexInfo)
66+
_, err := Server("testserver")
7067
const expected = "valid https URL required for trust server"
7168
assert.ErrorContains(t, err, expected, "Expected error with invalid scheme")
7269
}
7370

7471
func TestOfficialTrustServer(t *testing.T) {
75-
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: true}
76-
output, err := Server(indexInfo)
72+
output, err := Server("docker.io")
7773
const expected = NotaryServer
7874
assert.NilError(t, err)
7975
assert.Equal(t, output, expected)
76+
77+
output, err = Server("index.docker.io")
78+
assert.NilError(t, err)
79+
assert.Equal(t, output, expected)
8080
}
8181

8282
func TestNonOfficialTrustServer(t *testing.T) {
83-
indexInfo := &registrytypes.IndexInfo{Name: "testserver", Official: false}
84-
output, err := Server(indexInfo)
83+
output, err := Server("testserver")
8584
const expected = "https://testserver"
8685
assert.NilError(t, err)
8786
assert.Equal(t, output, expected)

0 commit comments

Comments
 (0)