Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix the valid client certificate check #378

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions pkg/registration/clientcert/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"crypto/x509/pkix"
"errors"
"fmt"
"reflect"
"time"

"github.com/openshift/library-go/pkg/operator/events"
certificates "k8s.io/api/certificates/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
certificatesinformers "k8s.io/client-go/informers/certificates"
certificatesv1informers "k8s.io/client-go/informers/certificates/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -112,17 +112,13 @@ func certMatchSubject(cert *x509.Certificate, subject *pkix.Name) bool {
return false
}

// check groups(origanization)
if !reflect.DeepEqual(cert.Subject.Organization, subject.Organization) {
// check groups (organization)
if !sets.New(cert.Subject.Organization...).Equal(sets.New(subject.Organization...)) {
return false
}

// check originzation unit
if !reflect.DeepEqual(cert.Subject.OrganizationalUnit, subject.OrganizationalUnit) {
return false
}

return true
// check organizational units
return sets.New(cert.Subject.OrganizationalUnit...).Equal(sets.New(subject.OrganizationalUnit...))
}

// getCertValidityPeriod returns the validity period of the client certificate in the secret
Expand Down
14 changes: 14 additions & 0 deletions pkg/registration/clientcert/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ func TestIsCertificateValid(t *testing.T) {
},
isValid: true,
},
{
name: "valid cert different order",
testCert: testinghelpers.NewTestCertWithSubject(pkix.Name{
CommonName: "test",
Organization: []string{"org", "org2"},
OrganizationalUnit: []string{"ou", "ou2"},
}, 60*time.Second),
subject: &pkix.Name{
CommonName: "test",
Organization: []string{"org2", "org"},
OrganizationalUnit: []string{"ou2", "ou"},
},
isValid: true,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
Expand Down
Loading