Skip to content

Commit 39202ff

Browse files
committed
feat: add validating webhook for run-levels
Signed-off-by: SequeI <[email protected]>
1 parent b5dd67a commit 39202ff

22 files changed

+494
-11
lines changed

.github/actions/kind-cluster/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,10 @@ runs:
121121
shell: bash
122122
run: |
123123
kustomize build --enable-helm ./ci/nfs/overlay/ | kubectl apply -f -
124+
125+
- name: Install Cert-Manager
126+
shell: bash
127+
run: |
128+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.19.1/cert-manager.yaml
129+
kubectl wait --for=condition=available deployment/cert-manager-webhook -n cert-manager --timeout=5m
130+
kubectl wait --for=condition=available deployment/cert-manager -n cert-manager --timeout=5m

.tekton/rhtas-operator-bundle-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ spec:
4242
- name: image-expires-after
4343
value: 5d
4444
- name: manager-pipelinerun-selector
45-
value: appstudio.openshift.io/application=operator,appstudio.openshift.io/component=rhtas-operator,pipelinesascode.tekton.dev/sha={{revision}},pipelinesascode.tekton.dev/event-type in (pull_request,incoming)
45+
value: appstudio.openshift.io/application=operator,appstudio.openshift.io/component=rhtas-operator,pipelinesascode.tekton.dev/sha={{revision}},pipelinesascode.tekton.dev/event-type in (pull_request,incoming,retest-all-comment)
4646
- name: manager-registry-url
4747
value: registry.redhat.io/rhtas/rhtas-rhel9-operator
4848
pipelineRef:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ help: ## Display this help.
113113
##@ Development
114114

115115
.PHONY: manifests
116-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
117-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
116+
manifests: controller-gen ## Generate ClusterRole and CustomResourceDefinition objects.
117+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
118118

119119
.PHONY: generate
120120
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

api/v1alpha1/securesign_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type SecuresignTSAStatus struct {
7373
//+kubebuilder:printcolumn:name="Rekor URL",type=string,JSONPath=`.status.rekor.url`,description="The rekor url"
7474
//+kubebuilder:printcolumn:name="Fulcio URL",type=string,JSONPath=`.status.fulcio.url`,description="The fulcio url"
7575
//+kubebuilder:printcolumn:name="Tuf URL",type=string,JSONPath=`.status.tuf.url`,description="The tuf url"
76+
//+kubebuilder:webhook:path=/validate,mutating=false,failurePolicy=fail,groups=rhtas.redhat.com,resources=securesigns,verbs=create,versions=v1alpha1,name=securesign.rhtas.redhat.com,sideEffects=None,admissionReviewVersions=v1
7677

7778
// Securesign is the Schema for the securesigns API
7879
type Securesign struct {

cmd/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
"github.com/securesign/operator/internal/controller/trillian"
6363
"github.com/securesign/operator/internal/controller/tsa"
6464
"github.com/securesign/operator/internal/controller/tuf"
65+
rhtas_webhook "github.com/securesign/operator/internal/webhook"
6566
//+kubebuilder:scaffold:imports
6667
)
6768

@@ -195,6 +196,17 @@ func main() {
195196
os.Exit(1)
196197
}
197198

199+
if err := ctrl.NewWebhookManagedBy(mgr).
200+
For(&rhtasv1alpha1.Securesign{}).
201+
WithValidator(&rhtas_webhook.SecureSignValidator{
202+
Client: mgr.GetClient(),
203+
}).
204+
WithValidatorCustomPath("/validate").
205+
Complete(); err != nil {
206+
setupLog.Error(err, "unable to create SecureSign validating webhook")
207+
os.Exit(1)
208+
}
209+
198210
setupController("securesign", securesign.NewReconciler, mgr)
199211
setupController("fulcio", fulcio.NewReconciler, mgr)
200212
setupController("trillian", trillian.NewReconciler, mgr)

config/default/kustomization.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namePrefix: rhtas-
1515
#commonLabels:
1616
# someName: someValue
1717

18-
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
19-
# crd/kustomization.yaml
20-
#- ../webhook
2118
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2219
#- ../certmanager
2320
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
@@ -26,6 +23,7 @@ resources:
2623
- ../rbac
2724
- ../manager
2825
- ../prometheus
26+
- ../webhook
2927

3028
patches:
3129
- path: manager_metrics_patch.yaml
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Issuer
3+
metadata:
4+
name: selfsigned-issuer
5+
namespace: openshift-rhtas-operator
6+
spec:
7+
selfSigned: {}
8+
---
9+
apiVersion: cert-manager.io/v1
10+
kind: Certificate
11+
metadata:
12+
name: webhook-serving-cert
13+
namespace: openshift-rhtas-operator
14+
spec:
15+
secretName: webhook-server-tls
16+
issuerRef:
17+
name: selfsigned-issuer
18+
kind: Issuer
19+
dnsNames:
20+
- rhtas-controller-manager-webhook-service.openshift-rhtas-operator.svc
21+
- rhtas-controller-manager-webhook-service.openshift-rhtas-operator.svc.cluster.local
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingWebhookConfiguration
3+
metadata:
4+
name: validation.securesigns.rhtas.redhat.com
5+
annotations:
6+
cert-manager.io/inject-ca-from: openshift-rhtas-operator/webhook-serving-cert
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33

4+
namespace: openshift-rhtas-operator
5+
46
resources:
57
- ../../default
8+
- cert_resources.yaml
9+
10+
patches:
11+
- path: kubernetes_webhook_patch.yaml
12+
target:
13+
kind: ValidatingWebhookConfiguration
14+
name: validation.securesigns.rhtas.redhat.com
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingWebhookConfiguration
3+
metadata:
4+
name: validation.securesigns.rhtas.redhat.com
5+
annotations:
6+
service.beta.openshift.io/inject-cabundle: "true"

0 commit comments

Comments
 (0)