Skip to content

Commit c0384d6

Browse files
zmbergmingzhou.swx
and
mingzhou.swx
committed
restrict the access permissions of kruise-daemon to secrets (#1482)
* restrict the access permissions of kruise-daemon to secrets Signed-off-by: mingzhou.swx <[email protected]> * util meta ut Signed-off-by: liheng.zms <[email protected]> --------- Signed-off-by: mingzhou.swx <[email protected]> Signed-off-by: liheng.zms <[email protected]> Co-authored-by: mingzhou.swx <[email protected]>
1 parent c5b63fa commit c0384d6

19 files changed

+598
-28
lines changed

Diff for: Makefile

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

8081
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
8182
$(KUSTOMIZE) build config/default | kubectl delete -f -
82-
83+
$(KUSTOMIZE) build config/daemonconfig | kubectl delete -f -
8384

8485
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
8586
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.
@@ -351,7 +357,7 @@ func SetDefaultsImageTagPullPolicy(obj *v1alpha1.ImageTagPullPolicy) {
351357
}
352358

353359
// SetDefaults_ImagePullJob set default values for ImagePullJob.
354-
func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob) {
360+
func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob, addProtection bool) {
355361
if obj.Spec.CompletionPolicy.Type == "" {
356362
obj.Spec.CompletionPolicy.Type = v1alpha1.Always
357363
}
@@ -364,4 +370,7 @@ func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob) {
364370
if obj.Spec.PullPolicy.BackoffLimit == nil {
365371
obj.Spec.PullPolicy.BackoffLimit = utilpointer.Int32Ptr(3)
366372
}
373+
if addProtection {
374+
controllerutil.AddFinalizer(obj, ProtectionFinalizer)
375+
}
367376
}

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/default/kruise-daemon-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: kruise-daemon-config

Diff for: config/default/kustomization.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Adds namespace to all resources.
2-
namespace: kruise-system
3-
41
# Value of this field is prepended to the
52
# names of all resources, e.g. a deployment named
63
# "wordpress" becomes "alices-wordpress".
@@ -12,16 +9,19 @@ namePrefix: kruise-
129
#commonLabels:
1310
# someName: someValue
1411

12+
resources:
13+
- kruise-daemon-config.yaml
14+
1515
bases:
1616
- ../crd
1717
- ../rbac
1818
- ../manager
19-
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
19+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2020
# crd/kustomization.yaml
2121
- ../webhook
2222
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2323
#- ../certmanager
24-
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
24+
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2525
#- ../prometheus
2626

2727
patchesStrategicMerge:
@@ -30,7 +30,7 @@ patchesStrategicMerge:
3030
# endpoint w/o any authn/z, please comment the following line.
3131
# - manager_auth_proxy_patch.yaml
3232

33-
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
33+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3434
# crd/kustomization.yaml
3535
- manager_webhook_patch.yaml
3636

Diff for: config/manager/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# Adds namespace to all resources.
2+
namespace: kruise-system
3+
14
resources:
25
- manager.yaml

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:

Diff for: config/rbac/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Adds namespace to all resources.
2+
namespace: kruise-system
3+
14
resources:
25
- role.yaml
36
- role_binding.yaml

Diff for: config/webhook/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Adds namespace to all resources.
2+
namespace: kruise-system
3+
14
resources:
25
- manifests.yaml
36
- service.yaml

0 commit comments

Comments
 (0)