Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 104dc4f

Browse files
committed
Add CascadingRule CRD
1 parent e22e85c commit 104dc4f

13 files changed

+405
-0
lines changed

operator/PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ resources:
2020
- group: targets
2121
kind: Host
2222
version: v1
23+
- group: cascading
24+
kind: CascadingRule
25+
version: v1
2326
version: "2"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2020 iteratec GmbH.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
executionv1 "github.com/secureCodeBox/secureCodeBox-v2-alpha/operator/apis/execution/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/util/intstr"
23+
)
24+
25+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
26+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
27+
28+
// CascadingRuleSpec defines the desired state of CascadingRule
29+
type CascadingRuleSpec struct {
30+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
31+
// Important: Run "make" to regenerate code after modifying this file
32+
33+
// Foo is an example field of CascadingRule. Edit CascadingRule_types.go to remove/update
34+
Matches []MatchesRule `json:"matches"`
35+
ScanSpec executionv1.ScanSpec `json:"scanSpec"`
36+
}
37+
38+
// MatchesRule is a generic map which is used to model the structure of a finding for which the CascadingRule should take effect
39+
type MatchesRule struct {
40+
Name string `json:"name,omitempty"`
41+
Category string `json:"category,omitempty"`
42+
Description string `json:"description,omitempty"`
43+
Location string `json:"location,omitempty"`
44+
Severity string `json:"severity,omitempty"`
45+
OsiLayer string `json:"osi_layer,omitempty"`
46+
Attributes map[string]intstr.IntOrString `json:"attributes,omitempty"`
47+
}
48+
49+
// CascadingRuleStatus defines the observed state of CascadingRule
50+
type CascadingRuleStatus struct {
51+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
52+
// Important: Run "make" to regenerate code after modifying this file
53+
}
54+
55+
// +kubebuilder:object:root=true
56+
57+
// CascadingRule is the Schema for the cascadingrules API
58+
type CascadingRule struct {
59+
metav1.TypeMeta `json:",inline"`
60+
metav1.ObjectMeta `json:"metadata,omitempty"`
61+
62+
Spec CascadingRuleSpec `json:"spec,omitempty"`
63+
Status CascadingRuleStatus `json:"status,omitempty"`
64+
}
65+
66+
// +kubebuilder:object:root=true
67+
68+
// CascadingRuleList contains a list of CascadingRule
69+
type CascadingRuleList struct {
70+
metav1.TypeMeta `json:",inline"`
71+
metav1.ListMeta `json:"metadata,omitempty"`
72+
Items []CascadingRule `json:"items"`
73+
}
74+
75+
func init() {
76+
SchemeBuilder.Register(&CascadingRule{}, &CascadingRuleList{})
77+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2020 iteratec GmbH.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1 contains API Schema definitions for the cascading v1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=cascading.experimental.securecodebox.io
20+
package v1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "cascading.experimental.securecodebox.io", Version: "v1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

operator/apis/cascading/v1/zz_generated.deepcopy.go

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.4
8+
creationTimestamp: null
9+
name: cascadingrules.cascading.experimental.securecodebox.io
10+
spec:
11+
group: cascading.experimental.securecodebox.io
12+
names:
13+
kind: CascadingRule
14+
listKind: CascadingRuleList
15+
plural: cascadingrules
16+
singular: cascadingrule
17+
scope: Namespaced
18+
validation:
19+
openAPIV3Schema:
20+
description: CascadingRule is the Schema for the cascadingrules API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: CascadingRuleSpec defines the desired state of CascadingRule
36+
properties:
37+
matches:
38+
description: Foo is an example field of CascadingRule. Edit CascadingRule_types.go
39+
to remove/update
40+
items:
41+
description: MatchesRule is a generic map which is used to model the
42+
structure of a finding for which the CascadingRule should take effect
43+
properties:
44+
attributes:
45+
additionalProperties:
46+
anyOf:
47+
- type: integer
48+
- type: string
49+
x-kubernetes-int-or-string: true
50+
type: object
51+
category:
52+
type: string
53+
description:
54+
type: string
55+
location:
56+
type: string
57+
name:
58+
type: string
59+
osi_layer:
60+
type: string
61+
severity:
62+
type: string
63+
type: object
64+
type: array
65+
scanSpec:
66+
description: ScanSpec defines the desired state of Scan
67+
properties:
68+
parameters:
69+
items:
70+
type: string
71+
type: array
72+
scanType:
73+
type: string
74+
type: object
75+
required:
76+
- matches
77+
- scanSpec
78+
type: object
79+
status:
80+
description: CascadingRuleStatus defines the observed state of CascadingRule
81+
type: object
82+
type: object
83+
version: v1
84+
versions:
85+
- name: v1
86+
served: true
87+
storage: true
88+
status:
89+
acceptedNames:
90+
kind: ""
91+
plural: ""
92+
conditions: []
93+
storedVersions: []

operator/config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ resources:
88
- bases/execution.experimental.securecodebox.io_parsedefinitions.yaml
99
- bases/execution.experimental.securecodebox.io_scheduledscans.yaml
1010
- bases/targets.experimental.securecodebox.io_hosts.yaml
11+
- bases/cascading.experimental.securecodebox.io_cascadingrules.yaml
1112
# +kubebuilder:scaffold:crdkustomizeresource
1213

1314
patchesStrategicMerge:
@@ -19,6 +20,7 @@ patchesStrategicMerge:
1920
#- patches/webhook_in_parsedefinitions.yaml
2021
#- patches/webhook_in_scheduledscans.yaml
2122
#- patches/webhook_in_hosts.yaml
23+
#- patches/webhook_in_cascadingrules.yaml
2224
# +kubebuilder:scaffold:crdkustomizewebhookpatch
2325

2426
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
@@ -29,6 +31,7 @@ patchesStrategicMerge:
2931
#- patches/cainjection_in_parsedefinitions.yaml
3032
#- patches/cainjection_in_scheduledscans.yaml
3133
#- patches/cainjection_in_hosts.yaml
34+
#- patches/cainjection_in_cascadingrules.yaml
3235
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
3336

3437
# the following config is for teaching kustomize how to do kustomization for CRDs.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: cascadingrules.cascading.experimental.securecodebox.io
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: cascadingrules.cascading.experimental.securecodebox.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
namespace: system
16+
name: webhook-service
17+
path: /convert

0 commit comments

Comments
 (0)