Skip to content

Commit a6b830b

Browse files
feat: add ruleset api(#1844)
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <[email protected]> * chore: modernize golang Signed-off-by: Oliver Bähler <[email protected]> * chore: modernize golang Signed-off-by: Oliver Bähler <[email protected]> * chore: modernize golang Signed-off-by: Oliver Bähler <[email protected]> * fix(config): remove usergroups default Signed-off-by: Oliver Bähler <[email protected]> * fix(config): remove usergroups default Signed-off-by: Oliver Bähler <[email protected]> * sec(GHSA-2ww6-hf35-mfjm): intercept namespace subresource Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * chore: conflicts Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> * feat(api): add rulestatus api Signed-off-by: Oliver Bähler <[email protected]> --------- Signed-off-by: Oliver Bähler <[email protected]>
1 parent b9a14a9 commit a6b830b

File tree

284 files changed

+12692
-2155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+12692
-2155
lines changed

.github/workflows/e2e.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
fail-fast: false
4646
matrix:
4747
k8s-version:
48-
- 'v1.30.0'
4948
- 'v1.31.0'
5049
- 'v1.32.0'
5150
- 'v1.33.0'

.github/workflows/releaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- uses: creekorful/goreportcard-action@1f35ced8cdac2cba28c9a2f2288a16aacfd507f9 # v1.0
3333
- uses: anchore/sbom-action/download-syft@0b82b0b1a22399a1c542d4d656f70cd903571b5c
3434
- name: Install Cosign
35-
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
35+
uses: sigstore/cosign-installer@7e8b541eb2e61bf99390e1afd4be13a184e9ebc5 # v3.10.1
3636
- name: Run GoReleaser
3737
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
3838
with:

.nwa-config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
nwa:
22
cmd: "update"
33
holder: "Project Capsule Authors"
4-
year: "2020-2025"
4+
year: "2020-2026"
55
spdxids: "Apache-2.0"
66
path:
77
- "pkg/**/*.go"
88
- "cmd/**/*.go"
99
- "api/**/*.go"
10+
- "internal/**/*.go"
1011
- "controllers/**/*.go"
1112
- "main.go"
1213
mute: false

Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ helm-schema: helm-plugin-schema
9292
helm-test: HELM_KIND_CONFIG ?= ""
9393
helm-test: kind
9494
@mkdir -p /tmp/results || true
95-
@$(KIND) create cluster --wait=60s --name capsule-charts --image kindest/node:$(KUBERNETES_SUPPORTED_VERSION) --config $(HELM_KIND_CONFIG)
95+
@$(KIND) create cluster --wait=60s --name capsule-charts --image kindest/node:$(KUBERNETES_SUPPORTED_VERSION) --config ./hack/kind-cluster.yaml
9696
@make helm-test-exec
9797
@$(KIND) delete cluster --name capsule-charts
9898

@@ -104,7 +104,7 @@ helm-test-exec: ct helm-controller-version ko-build-all
104104

105105
# Setup development env
106106
dev-build: kind
107-
$(KIND) create cluster --wait=60s --name $(CLUSTER_NAME) --image kindest/node:$(KUBERNETES_SUPPORTED_VERSION)
107+
$(KIND) create cluster --wait=60s --name $(CLUSTER_NAME) --image kindest/node:$(KUBERNETES_SUPPORTED_VERSION) --config ./hack/kind-cluster.yaml
108108
$(MAKE) dev-install-deps
109109

110110
.PHONY: dev-destroy
@@ -220,12 +220,12 @@ dev-setup-capsule: dev-setup-fluxcd
220220

221221
dev-setup-capsule-example: dev-setup-fluxcd
222222
@$(KUBECTL) kustomize --load-restrictor='LoadRestrictionsNone' hack/distro/capsule/example-setup | envsubst | kubectl apply -f -
223-
@$(KUBECTL) create ns wind-test --as joe --as-group projectcapsule.dev
224-
@$(KUBECTL) create ns wind-prod --as joe --as-group projectcapsule.dev
225-
@$(KUBECTL) create ns green-test --as bob --as-group projectcapsule.dev
226-
@$(KUBECTL) create ns green-prod --as bob --as-group projectcapsule.dev
227-
@$(KUBECTL) create ns solar-test --as alice --as-group projectcapsule.dev
228-
@$(KUBECTL) create ns solar-prod --as alice --as-group projectcapsule.dev
223+
@$(KUBECTL) create ns wind-test --as joe --as-group projectcapsule.dev || true
224+
@$(KUBECTL) create ns wind-prod --as joe --as-group projectcapsule.dev || true
225+
@$(KUBECTL) create ns green-test --as bob --as-group projectcapsule.dev || true
226+
@$(KUBECTL) create ns green-prod --as bob --as-group projectcapsule.dev || true
227+
@$(KUBECTL) create ns solar-test --as alice --as-group projectcapsule.dev || true
228+
@$(KUBECTL) create ns solar-prod --as alice --as-group projectcapsule.dev || true
229229

230230
wait-for-helmreleases:
231231
@ echo "Waiting for all HelmReleases to have observedGeneration >= 0..."
@@ -316,7 +316,7 @@ e2e-build: kind
316316
$(MAKE) e2e-install
317317

318318
.PHONY: e2e-install
319-
e2e-install: ko-build-all
319+
e2e-install: helm-controller-version ko-build-all
320320
$(MAKE) e2e-load-image CLUSTER_NAME=$(CLUSTER_NAME) IMAGE=$(CAPSULE_IMG) VERSION=$(VERSION)
321321
$(HELM) upgrade \
322322
--dependency-update \
@@ -331,6 +331,7 @@ e2e-install: ko-build-all
331331
--set 'manager.livenessProbe.failureThreshold=10' \
332332
--set 'webhooks.hooks.nodes.enabled=true' \
333333
--set "webhooks.exclusive=true"\
334+
--set "manager.options.logLevel=debug"\
334335
capsule \
335336
./charts/capsule
336337

api/v1beta1/owner_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2025 Project Capsule Authors
1+
// Copyright 2020-2026 Project Capsule Authors
22
// SPDX-License-Identifier: Apache-2.0
33

44
package v1beta1

api/v1beta1/tenant_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func (in *Tenant) SetupWebhookWithManager(mgr ctrl.Manager) error {
1515
return nil
1616
}
1717

18-
return ctrl.NewWebhookManagedBy(mgr).
19-
For(in).
18+
return ctrl.NewWebhookManagedBy(mgr, in).
2019
Complete()
2120
}

api/v1beta2/capsuleconfiguration_status.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
package v1beta2
55

66
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
79
"github.com/projectcapsule/capsule/pkg/api"
810
)
911

1012
// CapsuleConfigurationStatus defines the Capsule configuration status.
1113
type CapsuleConfigurationStatus struct {
14+
// Last time all caches were invalided
15+
LastCacheInvalidation metav1.Time `json:"lastCacheInvalidation,omitempty"`
16+
1217
// Users which are considered Capsule Users and are bound to the Capsule Tenant construct.
1318
Users api.UserListSpec `json:"users,omitempty"`
1419
}

api/v1beta2/capsuleconfiguration_types.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package v1beta2
55

66
import (
7+
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89

910
"github.com/projectcapsule/capsule/pkg/api"
@@ -53,6 +54,50 @@ type CapsuleConfigurationSpec struct {
5354
// for interacting with namespaces. Because if that label is not defined, it's assumed that namespace interaction was not targeted towards a tenant and will therefor
5455
// be ignored by capsule.
5556
Administrators api.UserListSpec `json:"administrators,omitempty"`
57+
// Configuration for dynamic Validating and Mutating Admission webhooks managed by Capsule.
58+
Admission DynamicAdmission `json:"admission,omitempty"`
59+
// Define Properties for managed ClusterRoles by Capsule
60+
// +kubebuilder:default={}
61+
RBAC *RBACConfiguration `json:"rbac"`
62+
// Define the period of time upon a cache invalidation is executed for all caches.
63+
// +kubebuilder:default="24h"
64+
CacheInvalidation metav1.Duration `json:"cacheInvalidation"`
65+
}
66+
67+
type RBACConfiguration struct {
68+
// The ClusterRoles applied for Administrators
69+
// +kubebuilder:default={capsule-namespace-deleter}
70+
AdministrationClusterRoles []string `json:"administrationClusterRoles,omitempty"`
71+
// The ClusterRoles applied for ServiceAccounts which had owner Promotion
72+
// +kubebuilder:default={capsule-namespace-provisioner,capsule-namespace-deleter}
73+
PromotionClusterRoles []string `json:"promotionClusterRoles,omitempty"`
74+
// Name for the ClusterRole required to grant Namespace Deletion permissions.
75+
// +kubebuilder:default=capsule-namespace-deleter
76+
DeleterClusterRole string `json:"deleter,omitempty"`
77+
// Name for the ClusterRole required to grant Namespace Provision permissions.
78+
// +kubebuilder:default=capsule-namespace-provisioner
79+
ProvisionerClusterRole string `json:"provisioner,omitempty"`
80+
}
81+
82+
type DynamicAdmission struct {
83+
// Configure dynamic Mutating Admission for Capsule
84+
Mutating DynamicAdmissionConfig `json:"mutating,omitempty"`
85+
86+
// Configure dynamic Validating Admission for Capsule
87+
Validating DynamicAdmissionConfig `json:"validating,omitempty"`
88+
}
89+
90+
type DynamicAdmissionConfig struct {
91+
// Name the Admission Webhook
92+
Name api.Name `json:"name,omitempty"`
93+
// Labels added to the Admission Webhook
94+
// +optional
95+
Labels map[string]string `json:"labels,omitempty"`
96+
// Annotations added to the Admission Webhook
97+
// +optional
98+
Annotations map[string]string `json:"annotations,omitempty"`
99+
// From the upstram struct
100+
Client admissionregistrationv1.WebhookClientConfig `json:"client"`
56101
}
57102

58103
type NodeMetadata struct {

api/v1beta2/namespace_rule_type.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2020-2026 Project Capsule Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1beta2
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
9+
"github.com/projectcapsule/capsule/pkg/api"
10+
)
11+
12+
// +kubebuilder:object:generate=true
13+
type NamespaceRule struct {
14+
// Enforce these properties via Rules
15+
NamespaceRuleBody `json:",inline"`
16+
17+
// Select namespaces which are going to usese
18+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
19+
}
20+
21+
// +kubebuilder:object:generate=true
22+
type NamespaceRuleBody struct {
23+
// Enforcement Rules applied
24+
//+optional
25+
Enforce NamespaceRuleEnforceBody `json:"enforce,omitzero"`
26+
}
27+
28+
// +kubebuilder:object:generate=true
29+
type NamespaceRuleEnforceBody struct {
30+
// Define registries which are allowed to be used within this tenant
31+
// The rules are aggregated, since you can use Regular Expressions the match registry endpoints
32+
Registries []api.OCIRegistry `json:"registries,omitempty"`
33+
}

api/v1beta2/resourcepool_func_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2025 Project Capsule Authors
1+
// Copyright 2020-2026 Project Capsule Authors
22
// SPDX-License-Identifier: Apache-2.0
33

44
package v1beta2

0 commit comments

Comments
 (0)