Skip to content

Commit b08fa0e

Browse files
Merge pull request #4780 from QiWang19/newbufferinloop
OCPBUGS-48195: use new buffer for decoding clusterOverridePolicyJSON
2 parents bd3e487 + d0db86b commit b08fa0e

File tree

2 files changed

+140
-5
lines changed

2 files changed

+140
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,11 @@ func updateNamespacedPolicyJSONs(clusterOverridePolicyJSON []byte, internalBlock
11331133
}
11341134

11351135
namespacedPolicyJSONs := make(map[string][]byte)
1136-
decoder := json.NewDecoder(bytes.NewBuffer(clusterOverridePolicyJSON))
11371136

11381137
for namespace, requirements := range namespacedPolicies {
11391138

11401139
policyObj := &signature.Policy{}
1141-
err := decoder.Decode(policyObj)
1140+
err := json.NewDecoder(bytes.NewBuffer(clusterOverridePolicyJSON)).Decode(policyObj)
11421141
if err != nil {
11431142
return nil, fmt.Errorf("error decoding policy json for namespaced policies: %w", err)
11441143
}

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

Lines changed: 139 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,23 @@ func imagePolicyTestCRs() map[string]apicfgv1alpha1.ImagePolicy {
601601
},
602602
},
603603
},
604+
"test-cr3": {
605+
ObjectMeta: metav1.ObjectMeta{
606+
Name: "test-cr3",
607+
Namespace: "test-1-namespace",
608+
},
609+
Spec: apicfgv1alpha1.ImagePolicySpec{
610+
Scopes: []apicfgv1alpha1.ImageScope{"test3.com"},
611+
Policy: apicfgv1alpha1.Policy{
612+
RootOfTrust: apicfgv1alpha1.PolicyRootOfTrust{
613+
PolicyType: apicfgv1alpha1.PublicKeyRootOfTrust,
614+
PublicKey: &apicfgv1alpha1.PublicKey{
615+
KeyData: testKeyData,
616+
},
617+
},
618+
},
619+
},
620+
},
604621
}
605622
return testImagePolicyCRs
606623
}
@@ -1726,6 +1743,7 @@ func TestUpdateNamespacedPolicyJSONs(t *testing.T) {
17261743
testImagePolicyCR0 := clusterImagePolicyTestCRs()["test-cr0"]
17271744
testImagePolicyCR1 := clusterImagePolicyTestCRs()["test-cr1"]
17281745
testImagePolicyCR2 := imagePolicyTestCRs()["test-cr0"]
1746+
testImagePolicyCR3 := imagePolicyTestCRs()["test-cr3"]
17291747

17301748
expectClusterPolicy := []byte(`
17311749
{
@@ -1825,7 +1843,7 @@ func TestUpdateNamespacedPolicyJSONs(t *testing.T) {
18251843
}
18261844
}
18271845
`)
1828-
expectnamespacedPolicy := []byte(`
1846+
expectTestnamespacedPolicy := []byte(`
18291847
{
18301848
"default": [
18311849
{
@@ -1942,11 +1960,129 @@ func TestUpdateNamespacedPolicyJSONs(t *testing.T) {
19421960
}
19431961
`)
19441962

1963+
expectTest1namespacedPolicy := []byte(`
1964+
{
1965+
"default": [
1966+
{
1967+
"type": "insecureAcceptAnything"
1968+
}
1969+
],
1970+
"transports": {
1971+
"atomic": {
1972+
"test0.com": [
1973+
{
1974+
"type": "sigstoreSigned",
1975+
"fulcio": {
1976+
"caData": "dGVzdC1jYS1kYXRhLWRhdGE=",
1977+
"oidcIssuer": "https://OIDC.example.com",
1978+
"subjectEmail": "[email protected]"
1979+
},
1980+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
1981+
"signedIdentity": {
1982+
"type": "remapIdentity",
1983+
"prefix": "test-remap-prefix",
1984+
"signedPrefix": "test-remap-signed-prefix"
1985+
}
1986+
},
1987+
{
1988+
"type": "sigstoreSigned",
1989+
"keyData": "dGVzdC1rZXktZGF0YQ==",
1990+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
1991+
"signedIdentity": {
1992+
"type": "remapIdentity",
1993+
"prefix": "test-remap-prefix",
1994+
"signedPrefix": "test-remap-signed-prefix"
1995+
}
1996+
}
1997+
],
1998+
"test1.com": [
1999+
{
2000+
"type": "sigstoreSigned",
2001+
"keyData": "dGVzdC1rZXktZGF0YQ==",
2002+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
2003+
"signedIdentity": {
2004+
"type": "remapIdentity",
2005+
"prefix": "test-remap-prefix",
2006+
"signedPrefix": "test-remap-signed-prefix"
2007+
}
2008+
}
2009+
],
2010+
"test3.com": [
2011+
{
2012+
"type": "sigstoreSigned",
2013+
"keyData": "dGVzdC1rZXktZGF0YQ==",
2014+
"signedIdentity": {
2015+
"type": "matchRepoDigestOrExact"
2016+
}
2017+
}
2018+
]
2019+
},
2020+
"docker": {
2021+
"test0.com": [
2022+
{
2023+
"type": "sigstoreSigned",
2024+
"fulcio": {
2025+
"caData": "dGVzdC1jYS1kYXRhLWRhdGE=",
2026+
"oidcIssuer": "https://OIDC.example.com",
2027+
"subjectEmail": "[email protected]"
2028+
},
2029+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
2030+
"signedIdentity": {
2031+
"type": "remapIdentity",
2032+
"prefix": "test-remap-prefix",
2033+
"signedPrefix": "test-remap-signed-prefix"
2034+
}
2035+
},
2036+
{
2037+
"type": "sigstoreSigned",
2038+
"keyData": "dGVzdC1rZXktZGF0YQ==",
2039+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
2040+
"signedIdentity": {
2041+
"type": "remapIdentity",
2042+
"prefix": "test-remap-prefix",
2043+
"signedPrefix": "test-remap-signed-prefix"
2044+
}
2045+
}
2046+
],
2047+
"test1.com": [
2048+
{
2049+
"type": "sigstoreSigned",
2050+
"keyData": "dGVzdC1rZXktZGF0YQ==",
2051+
"rekorPublicKeyData": "dGVzdC1yZWtvci1rZXktZGF0YQ==",
2052+
"signedIdentity": {
2053+
"type": "remapIdentity",
2054+
"prefix": "test-remap-prefix",
2055+
"signedPrefix": "test-remap-signed-prefix"
2056+
}
2057+
}
2058+
],
2059+
"test3.com": [
2060+
{
2061+
"type": "sigstoreSigned",
2062+
"keyData": "dGVzdC1rZXktZGF0YQ==",
2063+
"signedIdentity": {
2064+
"type": "matchRepoDigestOrExact"
2065+
}
2066+
}
2067+
]
2068+
},
2069+
"docker-daemon": {
2070+
"": [
2071+
{
2072+
"type": "insecureAcceptAnything"
2073+
}
2074+
]
2075+
}
2076+
}
2077+
}
2078+
`)
2079+
19452080
expectRet := map[string][]byte{
1946-
testImagePolicyCR2.ObjectMeta.Namespace: expectnamespacedPolicy,
2081+
testImagePolicyCR2.ObjectMeta.Namespace: expectTestnamespacedPolicy,
2082+
testImagePolicyCR3.ObjectMeta.Namespace: expectTest1namespacedPolicy,
19472083
}
19482084

1949-
clusterScopePolicies, scopeNamespacePolicies, err := getValidScopePolicies([]*apicfgv1alpha1.ClusterImagePolicy{&testImagePolicyCR0, &testImagePolicyCR1}, []*apicfgv1alpha1.ImagePolicy{&testImagePolicyCR2}, nil)
2085+
clusterScopePolicies, scopeNamespacePolicies, err := getValidScopePolicies([]*apicfgv1alpha1.ClusterImagePolicy{&testImagePolicyCR0, &testImagePolicyCR1}, []*apicfgv1alpha1.ImagePolicy{&testImagePolicyCR2, &testImagePolicyCR3}, nil)
19502086
require.NoError(t, err)
19512087

19522088
clusterOverridePolicyJSON, err := updatePolicyJSON(templatePolicyBytes, []string{}, []string{}, "release-reg.io/image/release", clusterScopePolicies)

0 commit comments

Comments
 (0)