Skip to content

Commit 17df150

Browse files
authored
Merge pull request #4511 from thaJeztah/manifest_token_actions
cli/registry/client: set actions when authn with token
2 parents cdabfa2 + d2047b9 commit 17df150

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

cli/registry/client/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
manifesttypes "github.com/docker/cli/cli/manifest/types"
10+
"github.com/docker/cli/cli/trust"
1011
"github.com/docker/distribution"
1112
"github.com/docker/distribution/reference"
1213
distributionclient "github.com/docker/distribution/registry/client"
@@ -77,6 +78,7 @@ func (c *client) MountBlob(ctx context.Context, sourceRef reference.Canonical, t
7778
if err != nil {
7879
return err
7980
}
81+
repoEndpoint.actions = trust.ActionsPushAndPull
8082
repo, err := c.getRepositoryForReference(ctx, targetRef, repoEndpoint)
8183
if err != nil {
8284
return err
@@ -102,6 +104,7 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest
102104
return digest.Digest(""), err
103105
}
104106

107+
repoEndpoint.actions = trust.ActionsPushAndPull
105108
repo, err := c.getRepositoryForReference(ctx, ref, repoEndpoint)
106109
if err != nil {
107110
return digest.Digest(""), err
@@ -151,7 +154,9 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi
151154
c.authConfigResolver(ctx, repoEndpoint.info.Index),
152155
repoEndpoint.endpoint,
153156
repoEndpoint.Name(),
154-
c.userAgent)
157+
c.userAgent,
158+
repoEndpoint.actions,
159+
)
155160
return httpTransport, errors.Wrap(err, "failed to configure transport")
156161
}
157162

cli/registry/client/endpoint.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"time"
88

9+
"github.com/docker/cli/cli/trust"
910
"github.com/docker/distribution/reference"
1011
"github.com/docker/distribution/registry/client/auth"
1112
"github.com/docker/distribution/registry/client/transport"
@@ -17,6 +18,7 @@ import (
1718
type repositoryEndpoint struct {
1819
info *registry.RepositoryInfo
1920
endpoint registry.APIEndpoint
21+
actions []string
2022
}
2123

2224
// Name returns the repository name
@@ -74,7 +76,7 @@ func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry
7476
}
7577

7678
// getHTTPTransport builds a transport for use in communicating with a registry
77-
func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) {
79+
func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName, userAgent string, actions []string) (http.RoundTripper, error) {
7880
// get the http transport, this will be used in a client to upload manifest
7981
base := &http.Transport{
8082
Proxy: http.ProxyFromEnvironment,
@@ -98,8 +100,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
98100
passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken}
99101
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, passThruTokenHandler))
100102
} else {
103+
if len(actions) == 0 {
104+
actions = trust.ActionsPullOnly
105+
}
101106
creds := registry.NewStaticCredentialStore(&authConfig)
102-
tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, "push", "pull")
107+
tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, actions...)
103108
basicHandler := auth.NewBasicHandler(creds)
104109
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
105110
}

0 commit comments

Comments
 (0)