Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jun 20, 2024
1 parent 37b3756 commit 98370ab
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,6 @@ issues:
path: pkg/hubtest/hubtest_item.go
text: "cyclomatic: .*RunWithLogFile"

- linters:
- canonicalheader
path: pkg/apiserver/middlewares/v1/tls_auth.go

# tolerate complex functions in tests for now
- linters:
- maintidx
Expand Down
5 changes: 2 additions & 3 deletions pkg/apiserver/middlewares/v1/cache.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package v1

import (
"crypto/x509"
"sync"
"time"

"crypto/x509"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -88,7 +87,7 @@ func (rc *RevocationCache) Set(cert *x509.Certificate, err error) {
defer rc.mu.Unlock()

Check warning on line 88 in pkg/apiserver/middlewares/v1/cache.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/cache.go#L88

Added line #L88 was not covered by tests
rc.cache[key] = cacheEntry{
err: err,
err: err,
timestamp: time.Now(),
}

Check warning on line 92 in pkg/apiserver/middlewares/v1/cache.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/cache.go#L92

Added line #L92 was not covered by tests
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/apiserver/middlewares/v1/crl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewCRLChecker(crlPath string, onLoad func(), logger *log.Entry) (*CRLChecke
return cc, nil
}

func (*CRLChecker) decodeCRLs(content []byte, logger *log.Entry) ([]*x509.RevocationList, error) {
func (*CRLChecker) decodeCRLs(content []byte) ([]*x509.RevocationList, error) {
var crls []*x509.RevocationList

Check warning on line 41 in pkg/apiserver/middlewares/v1/crl.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/crl.go#L41

Added line #L41 was not covered by tests
for {
Expand Down Expand Up @@ -87,14 +87,13 @@ func (cc *CRLChecker) refresh() error {
return fmt.Errorf("could not read CRL file: %w", err)
}

Check warning on line 88 in pkg/apiserver/middlewares/v1/crl.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/crl.go#L87-L88

Added lines #L87 - L88 were not covered by tests

cc.crls, err = cc.decodeCRLs(crlContent, cc.logger)
cc.crls, err = cc.decodeCRLs(crlContent)
if err != nil {
return err
}

Check warning on line 93 in pkg/apiserver/middlewares/v1/crl.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/crl.go#L92-L93

Added lines #L92 - L93 were not covered by tests

cc.fileInfo = fileInfo
cc.lastLoad = time.Now()

cc.logger.Debugf("loaded %d CRLs", len(cc.crls))
cc.onLoad()

Check warning on line 98 in pkg/apiserver/middlewares/v1/crl.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/crl.go#L98

Added line #L98 was not covered by tests
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver/middlewares/v1/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (j *JWT) authTLS(c *gin.Context) (*authInput, error) {
if j.TlsAuth == nil {
err := errors.New("tls authentication required")
log.Warn(err)

Check warning on line 62 in pkg/apiserver/middlewares/v1/jwt.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/jwt.go#L61-L62

Added lines #L61 - L62 were not covered by tests

return nil, err

Check warning on line 64 in pkg/apiserver/middlewares/v1/jwt.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/jwt.go#L64

Added line #L64 was not covered by tests
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/middlewares/v1/ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (oc *OCSPChecker) query(server string, cert *x509.Certificate, issuer *x509

httpRequest.Header.Add("Content-Type", "application/ocsp-request")
httpRequest.Header.Add("Accept", "application/ocsp-response")
httpRequest.Header.Add("host", ocspURL.Host)
httpRequest.Header.Add("Host", ocspURL.Host)

httpClient := &http.Client{}

Expand Down
10 changes: 7 additions & 3 deletions pkg/apiserver/middlewares/v1/tls_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ func (ta *TLSAuth) checkRevocationPath(chain []*x509.Certificate) (error, bool)

revokedByOCSP, checkedByOCSP := ta.ocspChecker.isRevokedBy(cert, issuer)
couldCheck = couldCheck && checkedByOCSP

Check warning on line 51 in pkg/apiserver/middlewares/v1/tls_auth.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/tls_auth.go#L51

Added line #L51 was not covered by tests
if revokedByOCSP && checkedByOCSP {
return fmt.Errorf("certificate revoked by OCSP"), couldCheck
return errors.New("certificate revoked by OCSP"), couldCheck

Check warning on line 53 in pkg/apiserver/middlewares/v1/tls_auth.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/tls_auth.go#L53

Added line #L53 was not covered by tests
}

revokedByCRL, checkedByCRL := ta.crlChecker.isRevokedBy(cert, issuer)
couldCheck = couldCheck && checkedByCRL

if revokedByCRL && checkedByCRL {
return fmt.Errorf("certificate revoked by CRL"), couldCheck
return errors.New("certificate revoked by CRL"), couldCheck
}

Check warning on line 61 in pkg/apiserver/middlewares/v1/tls_auth.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/tls_auth.go#L61

Added line #L61 was not covered by tests
}

Expand Down Expand Up @@ -115,13 +117,14 @@ func (ta *TLSAuth) ValidateCert(c *gin.Context) (string, error) {
}

if ta.isExpired(leaf) {
return "", fmt.Errorf("client certificate is expired")
return "", errors.New("client certificate is expired")

Check warning on line 120 in pkg/apiserver/middlewares/v1/tls_auth.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/middlewares/v1/tls_auth.go#L120

Added line #L120 was not covered by tests
}

if validErr, cached := ta.revocationCache.Get(leaf); cached {
if validErr != nil {
return "", fmt.Errorf("(cache) %w", validErr)
}

return leaf.Subject.CommonName, nil
}

Expand All @@ -134,6 +137,7 @@ func (ta *TLSAuth) ValidateCert(c *gin.Context) (string, error) {
for _, chain := range c.Request.TLS.VerifiedChains {
validErr, couldCheck = ta.checkRevocationPath(chain)
okToCache = okToCache && couldCheck

if validErr != nil {
break
}
Expand Down

0 comments on commit 98370ab

Please sign in to comment.