Skip to content

Commit 4332794

Browse files
committed
Transfer: Registry: Enable plain HTTP
Currenlty transfer service doesn't handle plain HTTP connection. This commit fixes this issue by propagating `(core/remotes/docker/config).HostOptions.DefaultScheme` from client to the transfer service. This commit also fixes ctr to use this feature for "--plain-http" flag. Signed-off-by: Kohei Tokunaga <[email protected]>
1 parent 0807efb commit 4332794

File tree

6 files changed

+91
-46
lines changed

6 files changed

+91
-46
lines changed

api/next.pb.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7468,6 +7468,13 @@ file {
74687468
type: TYPE_STRING
74697469
json_name: "hostDir"
74707470
}
7471+
field {
7472+
name: "default_scheme"
7473+
number: 4
7474+
label: LABEL_OPTIONAL
7475+
type: TYPE_STRING
7476+
json_name: "defaultScheme"
7477+
}
74717478
nested_type {
74727479
name: "HeadersEntry"
74737480
field {

api/types/transfer/registry.pb.go

Lines changed: 45 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/transfer/registry.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ message RegistryResolver {
3636
map<string, string> headers = 2;
3737

3838
string host_dir = 3;
39+
40+
string default_scheme = 4;
3941
// Force skip verify
40-
// Force HTTP
4142
// CA callback? Client TLS callback?
4243
}
4344

cmd/ctr/commands/images/pull.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ command. As part of this process, we do the following:
132132
sopts = append(sopts, image.WithAllMetadata)
133133
}
134134

135-
reg, err := registry.NewOCIRegistry(ctx, ref, registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir")))
135+
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
136+
if context.Bool("plain-http") {
137+
opts = append(opts, registry.WithDefaultScheme("http"))
138+
}
139+
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
136140
if err != nil {
137141
return err
138142
}

cmd/ctr/commands/images/push.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ var pushCommand = &cli.Command{
104104
if local == "" {
105105
local = ref
106106
}
107-
reg, err := registry.NewOCIRegistry(ctx, ref, registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir")))
107+
opts := []registry.Opt{registry.WithCredentials(ch), registry.WithHostDir(context.String("hosts-dir"))}
108+
if context.Bool("plain-http") {
109+
opts = append(opts, registry.WithDefaultScheme("http"))
110+
}
111+
reg, err := registry.NewOCIRegistry(ctx, ref, opts...)
108112
if err != nil {
109113
return err
110114
}

core/transfer/registry/registry.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func init() {
4444
}
4545

4646
type registryOpts struct {
47-
headers http.Header
48-
creds CredentialHelper
49-
hostDir string
47+
headers http.Header
48+
creds CredentialHelper
49+
hostDir string
50+
defaultScheme string
5051
}
5152

5253
// Opt sets registry-related configurations.
@@ -76,6 +77,14 @@ func WithHostDir(hostDir string) Opt {
7677
}
7778
}
7879

80+
// WithDefaultScheme specifies the default scheme for registry configuration
81+
func WithDefaultScheme(s string) Opt {
82+
return func(o *registryOpts) error {
83+
o.defaultScheme = s
84+
return nil
85+
}
86+
}
87+
7988
// NewOCIRegistry initializes with hosts, authorizer callback, and headers
8089
func NewOCIRegistry(ctx context.Context, ref string, opts ...Opt) (*OCIRegistry, error) {
8190
var ropts registryOpts
@@ -99,16 +108,20 @@ func NewOCIRegistry(ctx context.Context, ref string, opts ...Opt) (*OCIRegistry,
99108
return c.Username, c.Secret, nil
100109
}
101110
}
111+
if ropts.defaultScheme != "" {
112+
hostOptions.DefaultScheme = ropts.defaultScheme
113+
}
102114
resolver := docker.NewResolver(docker.ResolverOptions{
103115
Hosts: config.ConfigureHosts(ctx, hostOptions),
104116
Headers: ropts.headers,
105117
})
106118
return &OCIRegistry{
107-
reference: ref,
108-
headers: ropts.headers,
109-
creds: ropts.creds,
110-
resolver: resolver,
111-
hostDir: ropts.hostDir,
119+
reference: ref,
120+
headers: ropts.headers,
121+
creds: ropts.creds,
122+
resolver: resolver,
123+
hostDir: ropts.hostDir,
124+
defaultScheme: ropts.defaultScheme,
112125
}, nil
113126
}
114127

@@ -135,6 +148,8 @@ type OCIRegistry struct {
135148

136149
hostDir string
137150

151+
defaultScheme string
152+
138153
// This could be an interface which returns resolver?
139154
// Resolver could also be a plug-able interface, to call out to a program to fetch?
140155
}
@@ -234,6 +249,7 @@ func (r *OCIRegistry) MarshalAny(ctx context.Context, sm streaming.StreamCreator
234249
res.AuthStream = sid
235250
}
236251
res.HostDir = r.hostDir
252+
res.DefaultScheme = r.defaultScheme
237253
s := &transfertypes.OCIRegistry{
238254
Reference: r.reference,
239255
Resolver: res,
@@ -253,6 +269,9 @@ func (r *OCIRegistry) UnmarshalAny(ctx context.Context, sm streaming.StreamGette
253269
if s.Resolver.HostDir != "" {
254270
hostOptions.HostDir = config.HostDirFromRoot(s.Resolver.HostDir)
255271
}
272+
if s.Resolver.DefaultScheme != "" {
273+
hostOptions.DefaultScheme = s.Resolver.DefaultScheme
274+
}
256275
if sid := s.Resolver.AuthStream; sid != "" {
257276
stream, err := sm.Get(ctx, sid)
258277
if err != nil {

0 commit comments

Comments
 (0)