Skip to content

Commit

Permalink
adding 2.1.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
djkormo committed Jun 16, 2024
1 parent ae5eb47 commit ddb6f72
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 38 deletions.
24 changes: 12 additions & 12 deletions adcs/ntlm_certsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
neturl "net/url"
"os"
Expand All @@ -19,10 +19,10 @@ import (
)

type NtlmCertsrv struct {
url string
username string
password string
ca string
url string
username string
password string
//ca string
httpClient *http.Client
}

Expand Down Expand Up @@ -142,10 +142,10 @@ func (s *NtlmCertsrv) GetExistingCertificate(id string) (AdcsResponseStatus, str
defer res.Body.Close()

if res.StatusCode == http.StatusOK {
switch ct := strings.Split(res.Header.Get(http.CanonicalHeaderKey("content-type")), ";"); ct[0] {
switch ct := strings.Split(res.Header.Get("content-type"), ";"); ct[0] {
case ct_html:
// Denied or pending
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.Error(err, "Cannot read ADCS Certserv response")
return certStatus, "", id, err
Expand Down Expand Up @@ -192,7 +192,7 @@ func (s *NtlmCertsrv) GetExistingCertificate(id string) (AdcsResponseStatus, str

case ct_pkix:
// Certificate
cert, err := ioutil.ReadAll(res.Body)
cert, err := io.ReadAll(res.Body)
if err != nil {
log.Error(err, "Cannot read ADCS Certserv response")
return certStatus, "", id, err
Expand Down Expand Up @@ -267,7 +267,7 @@ func (s *NtlmCertsrv) RequestCertificate(csr string, template string) (AdcsRespo
log.Info("Sending request", "response", res)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)

log.Info("Body", "body", body)

Expand Down Expand Up @@ -341,7 +341,7 @@ func (s *NtlmCertsrv) obtainCaCertificate(certPage string, expectedContentType s
return "", err
}
defer res1.Body.Close()
body, err := ioutil.ReadAll(res1.Body)
body, err := io.ReadAll(res1.Body)
if err != nil {
log.Error(err, "Cannot read ADCS Certserv response")
return "", err
Expand Down Expand Up @@ -373,13 +373,13 @@ func (s *NtlmCertsrv) obtainCaCertificate(certPage string, expectedContentType s
defer res2.Body.Close()

if res2.StatusCode == http.StatusOK {
ct := res2.Header.Get(http.CanonicalHeaderKey("content-type"))
ct := res2.Header.Get("content-type")
if expectedContentType != ct {
err = errors.New("Unexpected content type")
log.Error(err, err.Error(), "content type", ct)
return "", err
}
body, err := ioutil.ReadAll(res2.Body)
body, err := io.ReadAll(res2.Body)
if err != nil {
log.Error(err, "Cannot read ADCS Certserv response")
return "", err
Expand Down
4 changes: 2 additions & 2 deletions charts/adcs-issuer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.1.1
version: 2.1.2
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.1.1"
appVersion: "2.1.2"

2 changes: 1 addition & 1 deletion charts/adcs-issuer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ spec:
readOnlyRootFilesystem: true
capabilities:
drop:
- all
- ALL


volumeMounts:
Expand Down
6 changes: 3 additions & 3 deletions charts/adcs-issuer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ controllerManager:
manager:
image:
repository: djkormo/adcs-issuer
tag: 2.1.0
tag: 2.1.2
resources:
limits:
cpu: 100m
Expand Down Expand Up @@ -79,7 +79,7 @@ nodeSelector: {}
# ADCS Simulator

simulator:
enabled: true
enabled: false
clusterIssuserName: adcs-sim-adcsclusterissuer
deploymentName: adcs-sim-deployment
configMapName: adcs-sim-configmap
Expand Down Expand Up @@ -125,7 +125,7 @@ simulator:
readOnlyRootFilesystem: true
capabilities:
drop:
- all
- ALL

resources:

Expand Down
37 changes: 32 additions & 5 deletions controllers/adcsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ func (r *AdcsRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Get the original CertificateRequest to set result in
cr, err := r.CertificateRequestController.GetCertificateRequest(ctx, req.NamespacedName)
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}

switch ar.Status.State {
case api.Pending:
// Check again later
log.Info(fmt.Sprintf("Pending request will be re-tried in %v", issuer.StatusCheckInterval))
r.setStatus(ctx, ar)
err = r.setStatus(ctx, ar)
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}
return ctrl.Result{Requeue: true, RequeueAfter: issuer.StatusCheckInterval}, nil
case api.Ready:

Expand All @@ -113,18 +122,36 @@ func (r *AdcsRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// CA cert is inside the cert above
// cr.Status.CA = caCert
r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionTrue, cmapi.CertificateRequestReasonIssued, "ADCS request successful")
err = r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionTrue, cmapi.CertificateRequestReasonIssued, "ADCS request successful")
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}

case api.Rejected:
// This is a little hack for strange cert-manager behavior in case of failed request. Cert-manager automatically
// re-tries such requests (re-created CertificateRequest object) what doesn't make sense in case of rejection.
// We keep the Reason 'Pending' to prevent from re-trying while the actual status is in the Status Condition's Message field.
// TODO: change it when cert-manager handles this better.
r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonPending, "ADCS request rejected")
err = r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonPending, "ADCS request rejected")
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}

case api.Errored:
r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonFailed, "ADCS request errored")
err = r.CertificateRequestController.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonFailed, "ADCS request errored")
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}
}

err = r.setStatus(ctx, ar)
if err != nil {
log.Error(err, "Failed request will be re-tried", "retry interval", issuer.RetryInterval)
return ctrl.Result{Requeue: true, RequeueAfter: issuer.RetryInterval}, nil
}
r.setStatus(ctx, ar)

return ctrl.Result{}, nil
}
Expand Down
6 changes: 5 additions & 1 deletion controllers/certificaterequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func (r *CertificateRequestReconciler) Reconcile(ctx context.Context, req ctrl.R
if err != nil {
return ctrl.Result{}, err
}
r.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonPending, "Processing ADCS request")

err = r.SetStatus(ctx, &cr, cmmeta.ConditionFalse, cmapi.CertificateRequestReasonPending, "Processing ADCS request")
if err != nil {
return ctrl.Result{}, err
}

log.V(4).Info("setstatus", "ctx", ctx, "cr", &cr)

Expand Down
2 changes: 1 addition & 1 deletion deploy.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=adcs-issuer
DOCKER_REPO=djkormo
VERSION=2.1.1
VERSION=2.1.2



4 changes: 2 additions & 2 deletions issuers/issuer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (f *IssuerFactory) getAdcsIssuer(ctx context.Context, key client.ObjectKey)

caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(certs)
if ok == false {
if !ok {
return nil, fmt.Errorf("error loading ADCS CA bundle")
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func (f *IssuerFactory) getClusterAdcsIssuer(ctx context.Context, key client.Obj

caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(certs)
if ok == false {
if !ok {
return nil, fmt.Errorf("error loading ADCS CA bundle")
}

Expand Down
21 changes: 12 additions & 9 deletions issuers/issuer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package issuers

import (
"io/ioutil"
"testing"

"fmt"
"github.com/stretchr/testify/assert"
"os"
"testing"

ctrl "sigs.k8s.io/controller-runtime"
)
Expand All @@ -20,10 +20,10 @@ var (

func TestParsingCaCertShouldReturnX509(t *testing.T) {
// arrange
pkcs7Pem, err := ioutil.ReadFile("testdata/pkcs7.pem")
pkcs7Pem, err := os.ReadFile("testdata/pkcs7.pem")
assert.NoError(t, err)

validX509Certificate, err := ioutil.ReadFile("testdata/x509.pem")
validX509Certificate, err := os.ReadFile("testdata/x509.pem")
assert.NoError(t, err)
// act

Expand All @@ -36,7 +36,7 @@ func TestParsingCaCertShouldReturnX509(t *testing.T) {

func TestIncorrectFormatPkcs(t *testing.T) {
//arrange
incorrectPKCS7Cert, err := ioutil.ReadFile("testdata/incorrectPKCS7Cert.pem")
incorrectPKCS7Cert, err := os.ReadFile("testdata/incorrectPKCS7Cert.pem")
assert.NoError(t, err)

// act
Expand Down Expand Up @@ -78,9 +78,9 @@ func TestIncorrectCertFormat(t *testing.T) {
func TestParseCaCertCorrectPKCS7(t *testing.T) {
// arrange
// raw format pkcs7.p7b from cfss testdata (https://github.com/cloudflare/cfssl/tree/master/helpers/testdata)
rawPkcs7, err := ioutil.ReadFile("testdata/cfss_rawPKCS7.p7b")
rawPkcs7, err := os.ReadFile("testdata/cfss_rawPKCS7.p7b")
assert.NoError(t, err)
cfssOutputX509, err := ioutil.ReadFile("testdata/cfss_outputx509.pem")
cfssOutputX509, err := os.ReadFile("testdata/cfss_outputx509.pem")
assert.NoError(t, err)

// act
Expand All @@ -95,8 +95,11 @@ func TestParseCaCertCorrectPKCS7(t *testing.T) {
func TestCorrectX509Cert(t *testing.T) {
// arrange
// raw format pkcs7.p7b from cfss testdata (https://github.com/cloudflare/cfssl/tree/master/helpers/testdata)
x509, err := ioutil.ReadFile("testdata/x509.pem")
x509, err := os.ReadFile("testdata/x509.pem")

if err != nil {
fmt.Println("TestCorrectX509Cert")
}
// act

parsedCaCert, err := parseCaCert(x509, log)
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@ func main() {
os.Exit(1)
}

mgr.AddHealthzCheck("healthz", healthcheck.HealthCheck)
mgr.AddReadyzCheck("readyz", healthcheck.HealthCheck)
err = mgr.AddHealthzCheck("healthz", healthcheck.HealthCheck)
if err != nil {
setupLog.Error(err, "unable to start AddHealthzCheck")
os.Exit(1)
}

err = mgr.AddReadyzCheck("readyz", healthcheck.HealthCheck)
if err != nil {
setupLog.Error(err, "unable to start AddReadyzCheck")
os.Exit(1)
}

certificateRequestReconciler := &controllers.CertificateRequestReconciler{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("adcs-certificaterequests-controller"),
Expand Down

0 comments on commit ddb6f72

Please sign in to comment.