Skip to content

Commit 11f50c0

Browse files
committed
feat: Add HTTP2 for unencrypted HTTP
Signed-off-by: erezrokah <[email protected]>
1 parent 01b4555 commit 11f50c0

22 files changed

+397
-124
lines changed

configuration/configuration.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ type Configuration struct {
157157
// HTTP2 configuration options
158158
HTTP2 struct {
159159
// Specifies whether the registry should disallow clients attempting
160-
// to connect via http2. If set to true, only http/1.1 is supported.
160+
// to connect via HTTP/2. If set to true, only HTTP/1.1 is supported.
161161
Disabled bool `yaml:"disabled,omitempty"`
162162
} `yaml:"http2,omitempty"`
163+
164+
H2C struct {
165+
// Enables H2C (HTTP/2 Cleartext). Enable to support HTTP/2 without needing to configure TLS
166+
// Useful when deploying the registry behind a load balancer (e.g. Cloud Run)
167+
Enabled bool `yaml:"enabled,omitempty"`
168+
} `yaml:"h2c,omitempty"`
163169
} `yaml:"http,omitempty"`
164170

165171
// Notifications specifies configuration about various endpoint to which

configuration/configuration_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ var configStruct = Configuration{
9797
HTTP2 struct {
9898
Disabled bool `yaml:"disabled,omitempty"`
9999
} `yaml:"http2,omitempty"`
100+
H2C struct {
101+
Enabled bool `yaml:"enabled,omitempty"`
102+
} `yaml:"h2c,omitempty"`
100103
}{
101104
TLS: struct {
102105
Certificate string `yaml:"certificate,omitempty"`
@@ -121,6 +124,11 @@ var configStruct = Configuration{
121124
}{
122125
Disabled: false,
123126
},
127+
H2C: struct {
128+
Enabled bool `yaml:"enabled,omitempty"`
129+
}{
130+
Enabled: true,
131+
},
124132
},
125133
Redis: Redis{
126134
Addr: "localhost:6379",

docs/content/about/configuration.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ http:
220220
X-Content-Type-Options: [nosniff]
221221
http2:
222222
disabled: false
223+
h2c:
224+
enabled: false
223225
notifications:
224226
events:
225227
includereferences: true
@@ -724,6 +726,8 @@ http:
724726
X-Content-Type-Options: [nosniff]
725727
http2:
726728
disabled: false
729+
h2c:
730+
enabled: false
727731
```
728732

729733
The `http` option details the configuration for the HTTP server that hosts the
@@ -870,13 +874,24 @@ registry. This header is included in the example configuration file.
870874

871875
### `http2`
872876

873-
The `http2` structure within `http` is **optional**. Use this to control http2
877+
The `http2` structure within `http` is **optional**. Use this to control HTTP/2 over TLS
874878
settings for the registry.
879+
If `tls` is not configured this option is ignored. To enable HTTP/2 over non TLS connections use `h2c` instead.
875880

876881
| Parameter | Required | Description |
877882
|-----------|----------|-------------------------------------------------------|
878883
| `disabled` | no | If `true`, then `http2` support is disabled. |
879884

885+
### `h2c`
886+
887+
The `h2c` structure within `http` is **optional**. Use this to control H2C (HTTP/2 Cleartext)
888+
settings for the registry.
889+
Useful when deploying the registry behind a load balancer (e.g. Google Cloud Run)
890+
891+
| Parameter | Required | Description |
892+
|-----------|----------|-------------------------------------------------------|
893+
| `enabled` | no | If `true`, then `h2c` support is enabled. |
894+
880895
## `notifications`
881896

882897
```yaml

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/stretchr/testify v1.8.4
3131
go.opentelemetry.io/contrib/exporters/autoexport v0.46.1
3232
go.opentelemetry.io/otel/sdk v1.21.0
33-
golang.org/x/crypto v0.17.0
33+
golang.org/x/crypto v0.18.0
3434
golang.org/x/oauth2 v0.11.0
3535
google.golang.org/api v0.126.0
3636
gopkg.in/yaml.v2 v2.4.0
@@ -87,9 +87,9 @@ require (
8787
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
8888
go.opentelemetry.io/otel/trace v1.21.0 // indirect
8989
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
90-
golang.org/x/net v0.18.0 // indirect
90+
golang.org/x/net v0.20.0
9191
golang.org/x/sync v0.3.0 // indirect
92-
golang.org/x/sys v0.15.0 // indirect
92+
golang.org/x/sys v0.16.0 // indirect
9393
golang.org/x/text v0.14.0 // indirect
9494
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
9595
google.golang.org/appengine v1.6.7 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8U
280280
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
281281
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
282282
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
283-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
284-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
283+
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
284+
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
285285
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
286286
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
287287
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -302,8 +302,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
302302
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
303303
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
304304
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
305-
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
306-
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
305+
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
306+
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
307307
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
308308
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
309309
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
@@ -332,8 +332,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
332332
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
333333
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
334334
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
335-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
336-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
335+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
336+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
337337
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
338338
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
339339
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

registry/registry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2121
"golang.org/x/crypto/acme"
2222
"golang.org/x/crypto/acme/autocert"
23+
"golang.org/x/net/http2"
24+
"golang.org/x/net/http2/h2c"
2325

2426
"github.com/distribution/distribution/v3/configuration"
2527
"github.com/distribution/distribution/v3/health"
@@ -158,6 +160,9 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
158160
if err != nil {
159161
return nil, fmt.Errorf("error during open telemetry initialization: %v", err)
160162
}
163+
if config.HTTP.H2C.Enabled {
164+
handler = h2c.NewHandler(handler, &http2.Server{})
165+
}
161166
handler = otelHandler(handler)
162167

163168
server := &http.Server{

vendor/golang.org/x/crypto/internal/poly1305/bits_compat.go

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

vendor/golang.org/x/crypto/internal/poly1305/bits_go1.13.go

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

vendor/golang.org/x/crypto/internal/poly1305/sum_generic.go

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

0 commit comments

Comments
 (0)