Skip to content

Commit f2c393e

Browse files
feat: add globalproxysettings (#550)
Signed-off-by: Oliver Bähler <[email protected]>
1 parent e53fa53 commit f2c393e

File tree

95 files changed

+1333
-581
lines changed

Some content is hidden

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

95 files changed

+1333
-581
lines changed
File renamed without changes.

.github/workflows/e2e.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: e2e
2+
permissions: {}
3+
4+
on:
5+
push:
6+
branches: [ "*" ]
7+
paths:
8+
- '.github/workflows/e2e.yml'
9+
- 'api/**'
10+
- 'controllers/**'
11+
- 'internal/**'
12+
- 'e2e/*'
13+
- 'Dockerfile'
14+
- 'go.*'
15+
- 'main.go'
16+
- 'Makefile'
17+
pull_request:
18+
branches: [ "*" ]
19+
paths:
20+
- '.github/workflows/e2e.yml'
21+
- 'api/**'
22+
- 'controllers/**'
23+
- 'internal/**'
24+
- 'e2e/*'
25+
- 'Dockerfile'
26+
- 'go.*'
27+
- 'main.go'
28+
- 'Makefile'
29+
30+
concurrency:
31+
group: ${{ github.workflow }}-${{ github.ref }}
32+
cancel-in-progress: true
33+
34+
jobs:
35+
kind:
36+
name: Kubernetes
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
k8s-version: [ 'v1.24.7', 'v1.25.3', 'v1.26.3', 'v1.27.2', 'v1.28.0', 'v1.29.0', 'v1.30.0', 'v1.31.0' ]
41+
runs-on: ubuntu-20.04
42+
steps:
43+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
44+
with:
45+
fetch-depth: 0
46+
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
47+
with:
48+
go-version-file: 'go.mod'
49+
- uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v3
50+
with:
51+
version: v3.14.2
52+
- uses: engineerd/setup-kind@aa272fe2a7309878ffc2a81c56cfe3ef108ae7d0 # v0.5.0
53+
with:
54+
skipClusterCreation: true
55+
- name: e2e testing
56+
run: KIND_K8S_VERSION=${{ matrix.k8s-version }} make e2e

.golangci.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ linters-settings:
1111
min-occurrences: 2
1212
cyclop:
1313
max-complexity: 17
14+
issues:
15+
exclude-rules:
16+
- path: (.+)_test.go
17+
linters:
18+
- revive
19+
text: "^(dot-imports)"
1420
linters:
1521
enable-all: true
1622
disable:
23+
- err113
24+
- mnd
1725
- errchkjson
1826
- errname
1927
- forcetypeassert
@@ -27,14 +35,10 @@ linters:
2735
- nilerr
2836
- exhaustruct
2937
- depguard
30-
# should be enabled
3138
- revive
32-
- err113
33-
- mnd
3439
- nilnil
3540
- wsl
3641
- perfsprint
37-
38-
# deprecated
3942
- exportloopref
40-
- execinquery
43+
- execinquery
44+
- forcetypeassert

Makefile

+32-20
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ helm-docs: docker
106106
helm-lint: docker
107107
@docker run -v "$(SRC_ROOT):/workdir" --entrypoint /bin/sh quay.io/helmpack/chart-testing:v3.3.1 -c "cd /workdir; ct lint --config .github/configs/ct.yaml --lint-conf .github/configs/lintconf.yaml --all --debug"
108108

109-
helm-test: helm-controller-version kind ct ko-build-all helm-create helm-install helm-destroy
109+
helm-test: helm-controller-version ct ko-build-all helm-create helm-install helm-destroy
110110

111111
helm-install:
112112
@kubectl apply --server-side=true -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.2/cert-manager.yaml
113113
@make install-capsule
114114
@kubectl apply --server-side=true -f https://github.com/prometheus-operator/prometheus-operator/releases/download/v0.58.0/bundle.yaml
115115
@$(CT) install --config $(SRC_ROOT)/.github/configs/ct.yaml --namespace=capsule-system --all --debug
116116

117-
helm-create:
118-
@kind create cluster --wait=60s --name capsule-charts
119-
@kind load docker-image --name capsule-charts $(CAPSULE_PROXY_IMG):$(VERSION)
117+
helm-create: kind
118+
@$(KIND) create cluster --wait=60s --name capsule-charts
119+
@$(KIND) load docker-image --name capsule-charts $(CAPSULE_PROXY_IMG):$(VERSION)
120120
@kubectl create ns capsule-system
121121

122-
helm-destroy:
123-
@kind delete cluster --name capsule-charts
122+
helm-destroy: kind
123+
@$(KIND) delete cluster --name capsule-charts
124124

125125
####################
126126
# -- Testing
@@ -129,14 +129,18 @@ helm-destroy:
129129
.PHONY: e2e
130130
e2e: e2e-build e2e-install e2e-exec
131131

132-
.PHONY: e2e-exec
133-
e2e-exec:
132+
.PHONY: e2e-legacy-exec
133+
e2e-legacy-exec:
134134
@./e2e/run.bash $${CLIENT_TEST:-kubectl}-$${CAPSULE_PROXY_MODE:-https}
135135

136+
.PHONY: e2e-exec
137+
e2e-exec: ginkgo
138+
$(GINKGO) -v -tags e2e ./e2e
139+
136140
.PHONY: e2e-build
137-
e2e-build:
141+
e2e-build: kind
138142
@echo "Building kubernetes env using Kind $${KIND_K8S_VERSION:-v1.27.0}..."
139-
@kind create cluster --name capsule --image kindest/node:$${KIND_K8S_VERSION:-v1.27.0} --config ./e2e/kind.yaml --wait=120s \
143+
@$(KIND) create cluster --name capsule --image kindest/node:$${KIND_K8S_VERSION:-v1.27.0} --config ./e2e/kind.yaml --wait=120s \
140144
&& kubectl taint nodes capsule-worker2 key1=value1:NoSchedule
141145
@helm repo add bitnami https://charts.bitnami.com/bitnami
142146
@helm repo update
@@ -149,13 +153,13 @@ e2e-build:
149153
e2e-install: install-capsule install-capsule-proxy rbac-fix
150154

151155
.PHONY: e2e-load-image
152-
e2e-load-image: ko-build-all
156+
e2e-load-image: kind ko-build-all
153157
@echo "Loading Docker image..."
154-
@kind load docker-image --name capsule --nodes capsule-worker $(CAPSULE_PROXY_IMG):$(VERSION)
158+
@$(KIND) load docker-image --name capsule $(CAPSULE_PROXY_IMG):$(VERSION)
155159

156160
.PHONY: e2e-destroy
157-
e2e-destroy:
158-
kind delete cluster --name capsule
161+
e2e-destroy: kind
162+
$(KIND) delete cluster --name capsule
159163

160164
install-capsule:
161165
@echo "Installing capsule..."
@@ -185,7 +189,8 @@ ifeq ($(CAPSULE_PROXY_MODE),http)
185189
--set "kind=DaemonSet" \
186190
--set "daemonset.hostNetwork=true" \
187191
--set "serviceMonitor.enabled=false" \
188-
--set "options.generateCertificates=false"
192+
--set "options.generateCertificates=false" \
193+
--set "options.extraArgs={--feature-gates=ProxyClusterScoped=true,--feature-gates=ProxyAllNamespaced=true}"
189194
else
190195
@echo "Running in HTTPS mode"
191196
@echo "capsule proxy certificates..."
@@ -194,19 +199,19 @@ else
194199
&& kubectl --namespace capsule-system create secret generic capsule-proxy --from-file=tls.key=./127.0.0.1-key.pem --from-file=tls.crt=./127.0.0.1.pem --from-literal=ca=$$(cat $(ROOTCA) | base64 |tr -d '\n')
195200
@echo "kubeconfig configurations..."
196201
@cd hack \
197-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- alice oil capsule.clastix.io \
202+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- alice oil projectcapsule.dev,capsule.clastix.io \
198203
&& mv alice-oil.kubeconfig alice.kubeconfig \
199204
&& KUBECONFIG=alice.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
200205
&& KUBECONFIG=alice.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
201-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- bob gas capsule.clastix.io \
206+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- bob gas projectcapsule.dev,capsule.clastix.io \
202207
&& mv bob-gas.kubeconfig bob.kubeconfig \
203208
&& KUBECONFIG=bob.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
204209
&& KUBECONFIG=bob.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
205-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- joe gas capsule.clastix.io,foo.clastix.io \
210+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- joe gas projectcapsule.dev,capsule.clastix.io,foo.clastix.io \
206211
&& mv joe-gas.kubeconfig foo.clastix.io.kubeconfig \
207212
&& KUBECONFIG=foo.clastix.io.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
208213
&& KUBECONFIG=foo.clastix.io.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
209-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- dave soil capsule.clastix.io,bar.clastix.io \
214+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- dave soil projectcapsule.dev,capsule.clastix.io,bar.clastix.io \
210215
&& mv dave-soil.kubeconfig dave.kubeconfig \
211216
&& kubectl --kubeconfig=dave.kubeconfig config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
212217
&& kubectl --kubeconfig=dave.kubeconfig config set clusters.kind-capsule.server https://127.0.0.1:9001
@@ -219,8 +224,10 @@ else
219224
--set "service.nodePort=" \
220225
--set "kind=DaemonSet" \
221226
--set "daemonset.hostNetwork=true" \
222-
--set "serviceMonitor.enabled=false"
227+
--set "serviceMonitor.enabled=false" \
228+
--set "options.extraArgs={--feature-gates=ProxyClusterScoped=true,--feature-gates=ProxyAllNamespaced=true}"
223229
endif
230+
@kubectl rollout restart ds capsule-proxy -n capsule-system || true
224231

225232
rbac-fix:
226233
@echo "RBAC customization..."
@@ -258,6 +265,11 @@ CONTROLLER_GEN_VERSION = v0.8.0
258265
controller-gen: ## Download controller-gen locally if necessary.
259266
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION))
260267

268+
GINKGO := $(shell pwd)/bin/ginkgo
269+
GINKGO_VERSION = v2.19.0
270+
ginkgo: ## Download ginkgo locally if necessary.
271+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION))
272+
261273
MKCERT = $(shell pwd)/bin/mkcert
262274
MKCERT_VERSION = v1.4.4
263275
mkcert: ## Download mkcert locally if necessary.

PROJECT

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: clastix.io
26
layout:
37
- go.kubebuilder.io/v3
@@ -16,4 +20,11 @@ resources:
1620
kind: ProxySettings
1721
path: github.com/projectcapsule/capsule-proxy/api/v1beta1
1822
version: v1beta1
23+
- api:
24+
crdVersion: v1
25+
domain: clastix.io
26+
group: capsule
27+
kind: GlobalProxySettings
28+
path: github.com/projectcapsule/capsule-proxy/api/v1beta1
29+
version: v1beta1
1930
version: "3"

api/v1beta1/clusterresoure.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ type ClusterResource struct {
2626
Operations []ClusterResourceOperation `json:"operations"`
2727

2828
// Select all cluster scoped resources with the given label selector.
29+
// Defining a selector which does not match any resources is considered not selectable (eg. using operation NotExists).
2930
Selector *metav1.LabelSelector `json:"selector"`
3031
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2020-2023 Project Capsule Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1beta1
5+
6+
import (
7+
"github.com/projectcapsule/capsule/api/v1beta2"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
// GlobalProxySettingsSpec defines the desired state of GlobalProxySettings.
12+
type GlobalProxySettingsSpec struct {
13+
// Subjects that should receive additional permissions.
14+
// The subjects are selected based on the oncoming requests. They don't have to relate to an existing tenant.
15+
// However they must be part of the capsule-user groups.
16+
// +kubebuilder:validation:MinItems=1
17+
Rules []GlobalSubjectSpec `json:"rules"`
18+
}
19+
20+
type GlobalSubjectSpec struct {
21+
// Subjects that should receive additional permissions.
22+
// The subjects are selected based on the oncoming requests. They don't have to relate to an existing tenant.
23+
// However they must be part of the capsule-user groups.
24+
Subjects []GlobalSubject `json:"subjects"`
25+
// Cluster Resources for tenant Owner.
26+
ClusterResources []ClusterResource `json:"clusterResources,omitempty"`
27+
}
28+
29+
type GlobalSubject struct {
30+
// Kind of tenant owner. Possible values are "User", "Group", and "ServiceAccount".
31+
Kind v1beta2.OwnerKind `json:"kind"`
32+
// Name of tenant owner.
33+
Name string `json:"name"`
34+
}
35+
36+
//+kubebuilder:object:root=true
37+
//+kubebuilder:subresource:status
38+
//+kubebuilder:resource:scope=Cluster
39+
40+
// GlobalProxySettings is the Schema for the globalproxysettings API.
41+
type GlobalProxySettings struct {
42+
metav1.TypeMeta `json:",inline"`
43+
metav1.ObjectMeta `json:"metadata,omitempty"`
44+
45+
Spec GlobalProxySettingsSpec `json:"spec,omitempty"`
46+
}
47+
48+
//+kubebuilder:object:root=true
49+
50+
// GlobalProxySettingsList contains a list of GlobalProxySettings.
51+
type GlobalProxySettingsList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []GlobalProxySettings `json:"items"`
55+
}
56+
57+
//nolint:gochecknoinits
58+
func init() {
59+
SchemeBuilder.Register(&GlobalProxySettings{}, &GlobalProxySettingsList{})
60+
}

0 commit comments

Comments
 (0)