Skip to content

Commit 6fe9d7c

Browse files
Merge pull request openshift#2689 from umohnani8/wildcards
Add parsing for registries.conf wildcard entries
2 parents 06a176c + 798d71f commit 6fe9d7c

File tree

1,248 files changed

+119513
-24679
lines changed

Some content is hidden

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

1,248 files changed

+119513
-24679
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Dockerfile.rhel7: Dockerfile Makefile
109109

110110
# This was copied from https://github.com/openshift/cluster-image-registry-operator
111111
test-e2e:
112-
go test -failfast -timeout 90m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e/
112+
go test -tags=$(GOTAGS) -failfast -timeout 90m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e/
113113

114114
test-e2e-single-node:
115-
go test -failfast -timeout 90m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-single-node/
115+
go test -tags=$(GOTAGS) -failfast -timeout 90m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-single-node/

go.mod

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ require (
1212
github.com/apparentlymart/go-cidr v1.0.0
1313
github.com/ashcrow/osrelease v0.0.0-20180626175927-9b292693c55c
1414
github.com/clarketm/json v1.14.1
15-
github.com/containers/image v3.0.2+incompatible
16-
github.com/containers/image/v5 v5.5.1
17-
github.com/containers/storage v1.20.2
15+
github.com/containers/image/v5 v5.14.0
16+
github.com/containers/storage v1.32.6
1817
github.com/coreos/fcct v0.5.0
1918
github.com/coreos/go-semver v0.3.0
2019
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
@@ -28,28 +27,28 @@ require (
2827
github.com/go-bindata/go-bindata v3.1.2+incompatible
2928
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
3029
github.com/golangci/golangci-lint v1.18.0
31-
github.com/google/go-cmp v0.5.2
30+
github.com/google/go-cmp v0.5.5
3231
github.com/google/renameio v0.1.0
3332
github.com/gostaticanalysis/analysisutil v0.0.3 // indirect
3433
github.com/hashicorp/golang-lru v0.5.3 // indirect
3534
github.com/huandu/xstrings v1.2.0 // indirect
36-
github.com/imdario/mergo v0.3.9
35+
github.com/imdario/mergo v0.3.12
36+
github.com/mattn/go-isatty v0.0.12 // indirect
3737
github.com/opencontainers/go-digest v1.0.0
3838
github.com/openshift/api v0.0.0-20210629145910-15a1cae1fca8
3939
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
4040
github.com/openshift/library-go v0.0.0-20210702104503-39570b4a2ae8
41-
github.com/openshift/runtime-utils v0.0.0-20200415173359-c45d4ff3f912
41+
github.com/openshift/runtime-utils v0.0.0-20210722191527-8b8348d80d1d
4242
github.com/pkg/errors v0.9.1
4343
github.com/prometheus/client_golang v1.7.1
4444
github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d
4545
github.com/spf13/cobra v1.1.1
46-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
4746
github.com/spf13/pflag v1.0.5
48-
github.com/stretchr/testify v1.6.1
47+
github.com/stretchr/testify v1.7.0
4948
github.com/ultraware/funlen v0.0.2 // indirect
5049
github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb
5150
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
52-
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7
51+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
5352
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
5453
k8s.io/api v0.21.1
5554
k8s.io/apiextensions-apiserver v0.21.1
@@ -58,7 +57,7 @@ require (
5857
k8s.io/code-generator v0.21.1
5958
k8s.io/kubectl v0.21.0-rc.0
6059
k8s.io/kubelet v0.21.0-rc.0
61-
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
60+
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9
6261
)
6362

6463
replace (
@@ -80,6 +79,8 @@ replace (
8079
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.0-rc.0
8180
k8s.io/code-generator => k8s.io/code-generator v0.21.0-rc.0
8281
k8s.io/component-base => k8s.io/component-base v0.21.0-rc.0
82+
k8s.io/component-helpers => k8s.io/component-helpers v0.20.0-alpha.2.0.20210708095128-55a3896515e9
83+
k8s.io/controller-manager => k8s.io/controller-manager v0.20.0-alpha.1.0.20210712075914-83508d18fce2
8384
k8s.io/cri-api => k8s.io/cri-api v0.21.0-rc.0
8485
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.21.0-rc.0
8586
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.21.0-rc.0
@@ -91,5 +92,6 @@ replace (
9192
k8s.io/kubernetes => k8s.io/kubernetes v1.21.0-rc.0
9293
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.21.0-rc.0
9394
k8s.io/metrics => k8s.io/metrics v0.21.0-rc.0
95+
k8s.io/mount-utils => k8s.io/mount-utils v0.23.0-alpha.0
9496
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.0-rc.0
9597
)

go.sum

+485-56
Large diffs are not rendered by default.

pkg/controller/container-runtime-config/helpers.go

+48-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"fmt"
99
"reflect"
1010
"strconv"
11+
"strings"
1112

1213
"github.com/BurntSushi/toml"
13-
"github.com/containers/image/docker/reference"
14-
"github.com/containers/image/pkg/sysregistriesv2"
15-
signature "github.com/containers/image/signature"
14+
"github.com/containers/image/v5/docker/reference"
15+
"github.com/containers/image/v5/pkg/sysregistriesv2"
16+
signature "github.com/containers/image/v5/signature"
1617
storageconfig "github.com/containers/storage/pkg/config"
1718
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
1819
"github.com/golang/glog"
@@ -361,6 +362,10 @@ func updateRegistriesConfig(data []byte, internalInsecure, internalBlocked []str
361362
return nil, fmt.Errorf("error unmarshalling registries config: %v", err)
362363
}
363364

365+
if err := validateRegistriesConfScopes(internalInsecure, internalBlocked, []string{}, icspRules); err != nil {
366+
return nil, err
367+
}
368+
364369
if err := registries.EditRegistriesConfig(&tomlConf, internalInsecure, internalBlocked, icspRules); err != nil {
365370
return nil, err
366371
}
@@ -383,12 +388,16 @@ func updatePolicyJSON(data []byte, internalBlocked, internalAllowed []string) ([
383388
return nil, fmt.Errorf("invalid images config: only one of AllowedRegistries or BlockedRegistries may be specified")
384389
}
385390
// Return original data if neither allowed or blocked registries are configured
386-
// Note: this is just for testing, the controller does not call this functio till
391+
// Note: this is just for testing, the controller does not call this function till
387392
// either allowed or blocked registries are configured
388393
if internalAllowed == nil && internalBlocked == nil {
389394
return data, nil
390395
}
391396

397+
if err := validateRegistriesConfScopes([]string{}, internalBlocked, internalAllowed, nil); err != nil {
398+
return nil, err
399+
}
400+
392401
policyObj := &signature.Policy{}
393402
decoder := json.NewDecoder(bytes.NewBuffer(data))
394403
err := decoder.Decode(policyObj)
@@ -495,3 +504,38 @@ func getValidBlockedRegistries(releaseImage string, imgSpec *apicfgv1.ImageSpec)
495504
}
496505
return blockedRegs, nil
497506
}
507+
508+
func validateRegistriesConfScopes(insecure, blocked, allowed []string, icspRules []*apioperatorsv1alpha1.ImageContentSourcePolicy) error {
509+
for _, scope := range insecure {
510+
if !registries.IsValidRegistriesConfScope(scope) {
511+
return fmt.Errorf("invalid entry for insecure registries %q", scope)
512+
}
513+
}
514+
515+
for _, scope := range blocked {
516+
if !registries.IsValidRegistriesConfScope(scope) {
517+
return fmt.Errorf("invalid entry for blocked registries %q", scope)
518+
}
519+
}
520+
521+
for _, scope := range allowed {
522+
if !registries.IsValidRegistriesConfScope(scope) {
523+
return fmt.Errorf("invalid entry for allowed registries %q", scope)
524+
}
525+
}
526+
527+
for _, icsp := range icspRules {
528+
for _, mirrorSet := range icsp.Spec.RepositoryDigestMirrors {
529+
if strings.Contains(mirrorSet.Source, "*") {
530+
return fmt.Errorf("wildcard entries are not supported with mirror configuration %q", mirrorSet.Source)
531+
}
532+
for _, mirror := range mirrorSet.Mirrors {
533+
if strings.Contains(mirror, "*") {
534+
return fmt.Errorf("wildcard entries are not supported with mirror configuration %q", mirror)
535+
}
536+
}
537+
}
538+
539+
}
540+
return nil
541+
}

pkg/controller/container-runtime-config/helpers_test.go

+58-24
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"testing"
1010

1111
"github.com/BurntSushi/toml"
12-
"github.com/containers/image/pkg/sysregistriesv2"
13-
signature "github.com/containers/image/signature"
14-
"github.com/containers/image/types"
12+
"github.com/containers/image/v5/pkg/sysregistriesv2"
13+
signature "github.com/containers/image/v5/signature"
14+
"github.com/containers/image/v5/types"
1515
apioperatorsv1alpha1 "github.com/openshift/api/operator/v1alpha1"
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
@@ -46,49 +46,49 @@ func TestUpdateRegistriesConfig(t *testing.T) {
4646
Registries: []sysregistriesv2.Registry{
4747
{
4848
Endpoint: sysregistriesv2.Endpoint{
49-
Location: "registry.access.redhat.com",
50-
Insecure: true,
49+
Location: "blocked.com",
5150
},
51+
Blocked: true,
5252
},
5353
{
5454
Endpoint: sysregistriesv2.Endpoint{
55-
Location: "insecure.com",
55+
Location: "common.com",
5656
Insecure: true,
5757
},
58+
Blocked: true,
5859
},
5960
{
6061
Endpoint: sysregistriesv2.Endpoint{
61-
Location: "common.com",
62-
Insecure: true,
62+
Location: "docker.io",
6363
},
6464
Blocked: true,
6565
},
6666
{
6767
Endpoint: sysregistriesv2.Endpoint{
68-
Location: "blocked.com",
68+
Location: "registry.access.redhat.com",
69+
Insecure: true,
6970
},
70-
Blocked: true,
7171
},
7272
{
7373
Endpoint: sysregistriesv2.Endpoint{
74-
Location: "docker.io",
74+
Location: "insecure.com",
75+
Insecure: true,
7576
},
76-
Blocked: true,
7777
},
7878
},
7979
},
8080
},
8181
{
82-
name: "insecure+blocked prefixes",
83-
insecure: []string{"insecure.com"},
84-
blocked: []string{"blocked.com"},
82+
name: "insecure+blocked prefixes with wildcard entries",
83+
insecure: []string{"insecure.com", "*.insecure-example.com", "*.insecure.blocked-example.com"},
84+
blocked: []string{"blocked.com", "*.blocked.insecure-example.com", "*.blocked-example.com"},
8585
icspRules: []*apioperatorsv1alpha1.ImageContentSourcePolicy{
8686
{
8787
Spec: apioperatorsv1alpha1.ImageContentSourcePolicySpec{
8888
RepositoryDigestMirrors: []apioperatorsv1alpha1.RepositoryDigestMirrors{ // other.com is neither insecure nor blocked
8989
{Source: "insecure.com/ns-i1", Mirrors: []string{"blocked.com/ns-b1", "other.com/ns-o1"}},
9090
{Source: "blocked.com/ns-b/ns2-b", Mirrors: []string{"other.com/ns-o2", "insecure.com/ns-i2"}},
91-
{Source: "other.com/ns-o3", Mirrors: []string{"insecure.com/ns-i2", "blocked.com/ns-b/ns3-b"}},
91+
{Source: "other.com/ns-o3", Mirrors: []string{"insecure.com/ns-i2", "blocked.com/ns-b/ns3-b", "foo.insecure-example.com/bar"}},
9292
},
9393
},
9494
},
@@ -128,20 +128,50 @@ func TestUpdateRegistriesConfig(t *testing.T) {
128128
Mirrors: []sysregistriesv2.Endpoint{
129129
{Location: "insecure.com/ns-i2", Insecure: true},
130130
{Location: "blocked.com/ns-b/ns3-b"},
131+
{Location: "foo.insecure-example.com/bar", Insecure: true},
131132
},
132133
},
133-
134+
{
135+
Endpoint: sysregistriesv2.Endpoint{
136+
Location: "blocked.com",
137+
},
138+
Blocked: true,
139+
},
140+
{
141+
Prefix: "*.blocked.insecure-example.com",
142+
Blocked: true,
143+
Endpoint: sysregistriesv2.Endpoint{
144+
Location: "",
145+
Insecure: true,
146+
},
147+
},
148+
{
149+
Prefix: "*.blocked-example.com",
150+
Endpoint: sysregistriesv2.Endpoint{
151+
Location: "",
152+
},
153+
Blocked: true,
154+
},
134155
{
135156
Endpoint: sysregistriesv2.Endpoint{
136157
Location: "insecure.com",
137158
Insecure: true,
138159
},
139160
},
140161
{
162+
Prefix: "*.insecure-example.com",
141163
Endpoint: sysregistriesv2.Endpoint{
142-
Location: "blocked.com",
164+
Location: "",
165+
Insecure: true,
143166
},
167+
},
168+
{
169+
Prefix: "*.insecure.blocked-example.com",
144170
Blocked: true,
171+
Endpoint: sysregistriesv2.Endpoint{
172+
Location: "",
173+
Insecure: true,
174+
},
145175
},
146176
},
147177
},
@@ -203,15 +233,17 @@ func TestUpdatePolicyJSON(t *testing.T) {
203233
},
204234
{
205235
name: "allowed",
206-
allowed: []string{"allow.io"},
236+
allowed: []string{"allow.io", "*.allowed-example.com"},
207237
want: signature.Policy{
208238
Default: signature.PolicyRequirements{signature.NewPRReject()},
209239
Transports: map[string]signature.PolicyTransportScopes{
210240
"atomic": map[string]signature.PolicyRequirements{
211-
"allow.io": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
241+
"allow.io": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
242+
"*.allowed-example.com": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
212243
},
213244
"docker": map[string]signature.PolicyRequirements{
214-
"allow.io": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
245+
"allow.io": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
246+
"*.allowed-example.com": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
215247
},
216248
"docker-daemon": map[string]signature.PolicyRequirements{
217249
"": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
@@ -221,15 +253,17 @@ func TestUpdatePolicyJSON(t *testing.T) {
221253
},
222254
{
223255
name: "blocked",
224-
blocked: []string{"block.com"},
256+
blocked: []string{"block.com", "*.blocked-example.com"},
225257
want: signature.Policy{
226258
Default: signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},
227259
Transports: map[string]signature.PolicyTransportScopes{
228260
"atomic": map[string]signature.PolicyRequirements{
229-
"block.com": signature.PolicyRequirements{signature.NewPRReject()},
261+
"block.com": signature.PolicyRequirements{signature.NewPRReject()},
262+
"*.blocked-example.com": signature.PolicyRequirements{signature.NewPRReject()},
230263
},
231264
"docker": map[string]signature.PolicyRequirements{
232-
"block.com": signature.PolicyRequirements{signature.NewPRReject()},
265+
"block.com": signature.PolicyRequirements{signature.NewPRReject()},
266+
"*.blocked-example.com": signature.PolicyRequirements{signature.NewPRReject()},
233267
},
234268
"docker-daemon": map[string]signature.PolicyRequirements{
235269
"": signature.PolicyRequirements{signature.NewPRInsecureAcceptAnything()},

pkg/daemon/drain.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/BurntSushi/toml"
9-
"github.com/containers/image/pkg/sysregistriesv2"
9+
"github.com/containers/image/v5/pkg/sysregistriesv2"
1010
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
1111
"github.com/golang/glog"
1212
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
@@ -223,12 +223,20 @@ func isSafeContainerRegistryConfChanges(oldConfig, newConfig *mcfgv1.MachineConf
223223

224224
oldRegHashMap := make(map[string]sysregistriesv2.Registry)
225225
for _, reg := range tomlConfOldReg.Registries {
226-
oldRegHashMap[reg.Location] = reg
226+
scope := reg.Location
227+
if reg.Prefix != "" {
228+
scope = reg.Prefix
229+
}
230+
oldRegHashMap[scope] = reg
227231
}
228232

229233
newRegHashMap := make(map[string]sysregistriesv2.Registry)
230234
for _, reg := range tomlConfNewReg.Registries {
231-
newRegHashMap[reg.Location] = reg
235+
scope := reg.Location
236+
if reg.Prefix != "" {
237+
scope = reg.Prefix
238+
}
239+
newRegHashMap[scope] = reg
232240
}
233241

234242
// Check for removed registry
@@ -251,6 +259,11 @@ func isSafeContainerRegistryConfChanges(oldConfig, newConfig *mcfgv1.MachineConf
251259
containerRegistryConfPath, regLoc, oldReg.Prefix, newReg.Prefix)
252260
return false, nil
253261
}
262+
if oldReg.Location != newReg.Location {
263+
glog.Infof("%s: location value for registry %s has changed from %s to %s",
264+
containerRegistryConfPath, regLoc, oldReg.Location, newReg.Location)
265+
return false, nil
266+
}
254267
if oldReg.Blocked != newReg.Blocked {
255268
glog.Infof("%s: blocked value for registry %s has changed from %t to %t",
256269
containerRegistryConfPath, regLoc, oldReg.Blocked, newReg.Blocked)

vendor/github.com/Microsoft/go-winio/CODEOWNERS

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/README.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/Microsoft/go-winio/backuptar/noop.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)