Skip to content

Commit f1da1d3

Browse files
mingzhou.swxzmberg
mingzhou.swx
authored andcommitted
restrict the access permissions of kruise-daemon to secrets
Signed-off-by: mingzhou.swx <[email protected]>
1 parent fa7a1da commit f1da1d3

File tree

14 files changed

+754
-27
lines changed

14 files changed

+754
-27
lines changed

Diff for: Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
8888
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
8989
$(KUSTOMIZE) build config/default | kubectl apply -f -
9090
echo -e "resources:\n- manager.yaml" > config/manager/kustomization.yaml
91+
$(KUSTOMIZE) build config/daemonconfig | kubectl apply -f -
9192

9293
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
9394
$(KUSTOMIZE) build config/default | kubectl delete -f -
94-
95+
$(KUSTOMIZE) build config/daemonconfig | kubectl delete -f -
9596

9697
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
9798
controller-gen: ## Download controller-gen locally if necessary.

Diff for: apis/apps/defaults/v1alpha1.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import (
2424
"k8s.io/apimachinery/pkg/util/intstr"
2525
v1 "k8s.io/kubernetes/pkg/apis/core/v1"
2626
utilpointer "k8s.io/utils/pointer"
27+
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
28+
)
29+
30+
const (
31+
// ProtectionFinalizer is designed to ensure the GC of resources.
32+
ProtectionFinalizer = "apps.kruise.io/deletion-protection"
2733
)
2834

2935
// SetDefaults_SidecarSet set default values for SidecarSet.
@@ -372,7 +378,7 @@ func SetDefaultsImageTagPullPolicy(obj *v1alpha1.ImageTagPullPolicy) {
372378
}
373379

374380
// SetDefaults_ImagePullJob set default values for ImagePullJob.
375-
func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob) {
381+
func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob, addProtection bool) {
376382
if obj.Spec.CompletionPolicy.Type == "" {
377383
obj.Spec.CompletionPolicy.Type = v1alpha1.Always
378384
}
@@ -388,6 +394,9 @@ func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob) {
388394
if obj.Spec.ImagePullPolicy == "" {
389395
obj.Spec.ImagePullPolicy = v1alpha1.PullIfNotPresent
390396
}
397+
if addProtection {
398+
controllerutil.AddFinalizer(obj, ProtectionFinalizer)
399+
}
391400
}
392401

393402
// SetDefaultsImageListPullJob set default values for ImageListPullJob.

Diff for: config/daemonconfig/config/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resources:
2+
- namespace.yaml
3+
- rbac.yaml

Diff for: config/daemonconfig/config/namespace.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: kruise-daemon-config

Diff for: config/daemonconfig/config/rbac.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
creationTimestamp: null
5+
name: kruise-daemon-secret-role
6+
namespace: kruise-daemon-config
7+
rules:
8+
- apiGroups:
9+
- ""
10+
resources:
11+
- secrets
12+
verbs:
13+
- get
14+
- list
15+
- watch
16+
---
17+
apiVersion: rbac.authorization.k8s.io/v1
18+
kind: RoleBinding
19+
metadata:
20+
name: kruise-daemon-secret-rolebinding
21+
namespace: kruise-daemon-config
22+
roleRef:
23+
apiGroup: rbac.authorization.k8s.io
24+
kind: Role
25+
name: kruise-daemon-secret-role
26+
subjects:
27+
- kind: ServiceAccount
28+
name: kruise-daemon
29+
namespace: kruise-system

Diff for: config/daemonconfig/kustomization.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace: kruise-daemon-config
2+
# Value of this field is prepended to the
3+
# names of all resources, e.g. a deployment named
4+
# "wordpress" becomes "alices-wordpress".
5+
# Note that it should also match with the prefix (text before '-') of the namespace
6+
# field above.
7+
bases:
8+
- config

Diff for: config/rbac/daemon_role.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ rules:
5353
verbs:
5454
- get
5555
- list
56-
- patch
57-
- update
5856
- watch
5957
- apiGroups:
6058
- ""
@@ -64,14 +62,6 @@ rules:
6462
- get
6563
- patch
6664
- update
67-
- apiGroups:
68-
- ""
69-
resources:
70-
- secrets
71-
verbs:
72-
- get
73-
- list
74-
- watch
7565
- apiGroups:
7666
- apps.kruise.io
7767
resources:

0 commit comments

Comments
 (0)