Skip to content

Commit 80b0ef7

Browse files
Merge pull request #28432 from deads2k/419-with-recurse-fix
OCPBUGS-24290: cert metadata: generate jsons and markdown for missing metadata viola
2 parents a95e17f + 24c909c commit 80b0ef7

File tree

93 files changed

+16549
-6939
lines changed

Some content is hidden

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

93 files changed

+16549
-6939
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ require (
2424
github.com/onsi/ginkgo/v2 v2.9.2
2525
github.com/onsi/gomega v1.27.6
2626
github.com/opencontainers/go-digest v1.0.0
27-
github.com/openshift/api v0.0.0-20231101131954-24085c95a7a2
27+
github.com/openshift/api v0.0.0-20231129134630-a782d1c1541c
2828
github.com/openshift/apiserver-library-go v0.0.0-20230915134751-5c71e94d6f05
2929
github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d
3030
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1
31-
github.com/openshift/library-go v0.0.0-20231115163822-d5b04e8d5cab
31+
github.com/openshift/library-go v0.0.0-20231130204458-653f82d961a1
3232
github.com/pborman/uuid v1.2.0
3333
github.com/pkg/errors v0.9.1
3434
github.com/prometheus/client_golang v1.16.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 h1:R
655655
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
656656
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=
657657
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
658-
github.com/openshift/api v0.0.0-20231101131954-24085c95a7a2 h1:zGTMgBHP7e5Jm91zM0xfGArBOPR3zVv+m8sE7BWGAnY=
659-
github.com/openshift/api v0.0.0-20231101131954-24085c95a7a2/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
658+
github.com/openshift/api v0.0.0-20231129134630-a782d1c1541c h1:XvPqb9JIZI40qKpdIDLUyoNXvgr4Ob3XHQeQacQN3jg=
659+
github.com/openshift/api v0.0.0-20231129134630-a782d1c1541c/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
660660
github.com/openshift/apiserver-library-go v0.0.0-20230915134751-5c71e94d6f05 h1:FuFc6HV3MuhxAGcslIkLOXhOjvBjioloKbSD3cWMzeo=
661661
github.com/openshift/apiserver-library-go v0.0.0-20230915134751-5c71e94d6f05/go.mod h1:x2CP20tBy7PnNCy0N6LxwnNHwsiPBlmAqG4xemgemZ8=
662662
github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d h1:RR4ah7FfaPR1WePizm0jlrsbmPu91xQZnAsVVreQV1k=
@@ -711,8 +711,8 @@ github.com/openshift/kubernetes/staging/src/k8s.io/pod-security-admission v0.0.0
711711
github.com/openshift/kubernetes/staging/src/k8s.io/pod-security-admission v0.0.0-20230926120034-e3ba6d9fbe72/go.mod h1:oLJ4FetmCVvyDXVnFb66XAdf9DXcnR4v3EE6ENVzDQI=
712712
github.com/openshift/kubernetes/staging/src/k8s.io/sample-apiserver v0.0.0-20230926120034-e3ba6d9fbe72 h1:W8NL1MiHFYzofXMtXE7ma2zH/wAzlj87crc9l/J8QzU=
713713
github.com/openshift/kubernetes/staging/src/k8s.io/sample-apiserver v0.0.0-20230926120034-e3ba6d9fbe72/go.mod h1:WYbrwAJFfUVjC8ddXYCLss7gvvlmZULpvn9aVcaZZME=
714-
github.com/openshift/library-go v0.0.0-20231115163822-d5b04e8d5cab h1:xiHWBSTcsnpjRR/vPvvfklxuVwPrkm4d8eCo9o5nSP0=
715-
github.com/openshift/library-go v0.0.0-20231115163822-d5b04e8d5cab/go.mod h1:8UzmrBMCn7+GzouL8DVYkL9COBQTB1Ggd13/mHJQCUg=
714+
github.com/openshift/library-go v0.0.0-20231130204458-653f82d961a1 h1:Sj0Oyn6aooVg7eHQ0zBbq6e7ERxXTadFHH5TEfmiuso=
715+
github.com/openshift/library-go v0.0.0-20231130204458-653f82d961a1/go.mod h1:0q1UIvboZXfSlUaK+08wsXYw4N6OUo2b/z3a1EWNGyw=
716716
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20230811135323-13a5964cc98e h1:WgaylNSIB4uff7ieewaqIiEG3mP6jSMER8LCkoOEkys=
717717
github.com/openshift/onsi-ginkgo/v2 v2.6.1-0.20230811135323-13a5964cc98e/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM=
718718
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=

pkg/certs/utils.go

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,12 @@ package certs
22

33
import (
44
"encoding/json"
5-
"fmt"
6-
"os"
7-
"path/filepath"
8-
"reflect"
95
"sort"
106

117
"github.com/openshift/library-go/pkg/certs/cert-inspection/certgraphapi"
128
"k8s.io/apimachinery/pkg/util/sets"
139
)
1410

15-
func GetPKIInfoFromRawData(rawTLSInfoDir string) (*certgraphapi.PKIRegistryInfo, error) {
16-
certs := SecretInfoByNamespaceName{}
17-
caBundles := ConfigMapInfoByNamespaceName{}
18-
19-
err := filepath.WalkDir(rawTLSInfoDir, func(path string, d os.DirEntry, err error) error {
20-
if err != nil {
21-
return err
22-
}
23-
if d.IsDir() {
24-
return nil
25-
}
26-
27-
filename := filepath.Join(rawTLSInfoDir, d.Name())
28-
currBytes, err := os.ReadFile(filename)
29-
if err != nil {
30-
return err
31-
}
32-
currPKI := &certgraphapi.PKIList{}
33-
err = json.Unmarshal(currBytes, currPKI)
34-
if err != nil {
35-
return err
36-
}
37-
38-
for i := range currPKI.InClusterResourceData.CertKeyPairs {
39-
currCert := currPKI.InClusterResourceData.CertKeyPairs[i]
40-
existing, ok := certs[currCert.SecretLocation]
41-
if ok && !reflect.DeepEqual(existing, currCert.CertKeyInfo) {
42-
return fmt.Errorf("mismatch of certificate info")
43-
}
44-
45-
certs[currCert.SecretLocation] = currCert.CertKeyInfo
46-
}
47-
for i := range currPKI.InClusterResourceData.CertificateAuthorityBundles {
48-
currCert := currPKI.InClusterResourceData.CertificateAuthorityBundles[i]
49-
existing, ok := caBundles[currCert.ConfigMapLocation]
50-
if ok && !reflect.DeepEqual(existing, currCert.CABundleInfo) {
51-
return fmt.Errorf("mismatch of certificate info")
52-
}
53-
54-
caBundles[currCert.ConfigMapLocation] = currCert.CABundleInfo
55-
}
56-
return nil
57-
})
58-
if err != nil {
59-
return nil, err
60-
}
61-
62-
return certsToRegistryInfo(certs, caBundles), nil
63-
}
64-
6511
func GetPKIInfoFromEmbeddedOwnership(ownershipFile []byte) (*certgraphapi.PKIRegistryInfo, error) {
6612
certs := SecretInfoByNamespaceName{}
6713
caBundles := ConfigMapInfoByNamespaceName{}
@@ -78,10 +24,10 @@ func GetPKIInfoFromEmbeddedOwnership(ownershipFile []byte) (*certgraphapi.PKIReg
7824
for _, currCABundle := range currPKI.CertificateAuthorityBundles {
7925
caBundles[currCABundle.ConfigMapLocation] = currCABundle.CABundleInfo
8026
}
81-
return certsToRegistryInfo(certs, caBundles), nil
27+
return CertsToRegistryInfo(certs, caBundles), nil
8228
}
8329

84-
func certsToRegistryInfo(certs SecretInfoByNamespaceName, caBundles ConfigMapInfoByNamespaceName) *certgraphapi.PKIRegistryInfo {
30+
func CertsToRegistryInfo(certs SecretInfoByNamespaceName, caBundles ConfigMapInfoByNamespaceName) *certgraphapi.PKIRegistryInfo {
8531
result := &certgraphapi.PKIRegistryInfo{}
8632

8733
certKeys := sets.KeySet[certgraphapi.InClusterSecretLocation, certgraphapi.PKIRegistryCertKeyPairInfo](certs).UnsortedList()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package ensure_no_violation_regression
2+
3+
import (
4+
"embed"
5+
"fmt"
6+
7+
"github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatadefaults"
8+
9+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
10+
11+
"github.com/openshift/library-go/pkg/certs/cert-inspection/certgraphapi"
12+
13+
"github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatainterfaces"
14+
15+
"k8s.io/cli-runtime/pkg/genericclioptions"
16+
)
17+
18+
type EnsureNoViolationRegressionOptions struct {
19+
ViolationsFS embed.FS
20+
Requirements []tlsmetadatainterfaces.Requirement
21+
22+
genericclioptions.IOStreams
23+
}
24+
25+
func NewEnsureNoViolationRegressionOptions(allViolations embed.FS, streams genericclioptions.IOStreams) *EnsureNoViolationRegressionOptions {
26+
return &EnsureNoViolationRegressionOptions{
27+
ViolationsFS: allViolations,
28+
Requirements: tlsmetadatadefaults.GetDefaultTLSRequirements(),
29+
IOStreams: streams,
30+
}
31+
}
32+
33+
func (o *EnsureNoViolationRegressionOptions) HaveViolationsRegressed(rawData []*certgraphapi.PKIList) ([]string, bool, error) {
34+
regressions := []string{}
35+
overallNoRegressions := false
36+
errs := []error{}
37+
for _, requirement := range o.Requirements {
38+
result, err := requirement.InspectRequirement(rawData)
39+
if err != nil {
40+
errs = append(errs, fmt.Errorf("failure inspecting for %v: %w", requirement.GetName(), err))
41+
continue
42+
}
43+
44+
descriptions, ok, err := result.HaveViolationsRegressed(o.ViolationsFS)
45+
regressions = append(regressions, descriptions...)
46+
if err != nil {
47+
errs = append(errs, err)
48+
}
49+
overallNoRegressions = overallNoRegressions || ok
50+
}
51+
52+
return regressions, overallNoRegressions, utilerrors.NewAggregate(errs)
53+
}

pkg/cmd/update-tls-artifacts/generate-owners/generate_owners_flags.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package generate_owners
33
import (
44
"fmt"
55

6+
"github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatadefaults"
7+
68
"github.com/spf13/cobra"
79
"github.com/spf13/pflag"
810
"k8s.io/cli-runtime/pkg/genericclioptions"
@@ -11,10 +13,8 @@ import (
1113
// GenerateOwnersFlags gets bound to cobra commands and arguments. It is used to validate input and then produce
1214
// the Options struct. Options struct is intended to be embeddable and re-useable without cobra.
1315
type GenerateOwnersFlags struct {
14-
RawTLSInfoDir string
15-
TLSOwnershipInfoDir string
16-
ViolationDir string
17-
Verify bool
16+
TLSInfoDir string
17+
Verify bool
1818

1919
genericclioptions.IOStreams
2020
}
@@ -48,39 +48,29 @@ func NewGenerateOwnershipCommand(streams genericclioptions.IOStreams) *cobra.Com
4848

4949
func NewGenerateOwnersFlags(streams genericclioptions.IOStreams) *GenerateOwnersFlags {
5050
return &GenerateOwnersFlags{
51-
RawTLSInfoDir: "tls/raw-data",
52-
TLSOwnershipInfoDir: "tls/ownership",
53-
ViolationDir: "tls/violations/ownership",
54-
IOStreams: streams,
51+
TLSInfoDir: "tls",
52+
IOStreams: streams,
5553
}
5654
}
5755

5856
func (f *GenerateOwnersFlags) BindFlags(flags *pflag.FlagSet) {
59-
flags.StringVar(&f.RawTLSInfoDir, "raw-tls-dir", f.RawTLSInfoDir, "The directory where the raw TLS info is located.")
60-
flags.StringVar(&f.TLSOwnershipInfoDir, "ownership-dir", f.TLSOwnershipInfoDir, "The directory where the TLS ownership info is should be written.")
61-
flags.StringVar(&f.ViolationDir, "violation-dir", f.ViolationDir, "The directory where the TLS ownership info is should be written.")
57+
flags.StringVar(&f.TLSInfoDir, "ownership-dir", f.TLSInfoDir, "The directory where the TLS ownership info is should be written.")
6258
flags.BoolVar(&f.Verify, "verify", f.Verify, "Verify content, don't mutate.")
6359
}
6460

6561
func (f *GenerateOwnersFlags) Validate() error {
66-
if len(f.RawTLSInfoDir) == 0 {
67-
return fmt.Errorf("--raw-tls-dir must be specified")
68-
}
69-
if len(f.TLSOwnershipInfoDir) == 0 {
62+
if len(f.TLSInfoDir) == 0 {
7063
return fmt.Errorf("--ownership-dir must be specified")
7164
}
72-
if len(f.ViolationDir) == 0 {
73-
return fmt.Errorf("--violation-dir must be specified")
74-
}
7565
return nil
7666
}
7767

7868
func (f *GenerateOwnersFlags) ToOptions() (*GenerateOwnersOptions, error) {
7969
return &GenerateOwnersOptions{
80-
RawTLSInfoDir: f.RawTLSInfoDir,
81-
TLSOwnershipInfoDir: f.TLSOwnershipInfoDir,
82-
ViolationDir: f.ViolationDir,
83-
Verify: f.Verify,
84-
IOStreams: f.IOStreams,
70+
TLSInfoDir: f.TLSInfoDir,
71+
Verify: f.Verify,
72+
Requirements: tlsmetadatadefaults.GetDefaultTLSRequirements(),
73+
74+
IOStreams: f.IOStreams,
8575
}, nil
8676
}

0 commit comments

Comments
 (0)