Skip to content

Commit 7cbd244

Browse files
Merge pull request #3133 from mansikulkarni96/WINC-1147
WINC-1147: Implement node-specific RBAC for WICD
2 parents efa1b2e + ea07d8e commit 7cbd244

35 files changed

+3476
-290
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app.kubernetes.io/name: windows-machine-config-operator
7+
app.kubernetes.io/part-of: wicd
8+
name: system-wicd-nodes
9+
rules:
10+
- apiGroups:
11+
- ""
12+
resources:
13+
- configmaps
14+
verbs:
15+
- get
16+
- list
17+
- watch
18+
- apiGroups:
19+
- ""
20+
resources:
21+
- nodes
22+
verbs:
23+
- list
24+
- apiGroups:
25+
- ""
26+
resources:
27+
- nodes
28+
- nodes/status
29+
verbs:
30+
- get
31+
- patch
32+
- update
33+
- watch
34+
- apiGroups:
35+
- certificates.k8s.io
36+
resources:
37+
- certificatesigningrequests
38+
verbs:
39+
- create
40+
- get
41+
- list
42+
- watch
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRoleBinding
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app.kubernetes.io/name: windows-machine-config-operator
7+
app.kubernetes.io/part-of: wicd
8+
name: system-wicd-nodes
9+
roleRef:
10+
apiGroup: rbac.authorization.k8s.io
11+
kind: ClusterRole
12+
name: system-wicd-nodes
13+
subjects:
14+
- apiGroup: rbac.authorization.k8s.io
15+
kind: Group
16+
name: system:wicd-nodes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: windows-instance-config-daemon

bundle/manifests/windows-instance-config-daemon_rbac.authorization.k8s.io_v1_clusterrole.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@ apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRole
33
metadata:
44
creationTimestamp: null
5+
labels:
6+
app.kubernetes.io/name: windows-machine-config-operator
7+
app.kubernetes.io/part-of: wicd
58
name: windows-instance-config-daemon
69
rules:
710
- apiGroups:
811
- ""
912
resources:
10-
- nodes
13+
- configmaps
1114
verbs:
12-
- list
13-
- watch
1415
- get
15-
- patch
16-
- update
16+
- list
1717
- apiGroups:
1818
- ""
1919
resources:
20-
- nodes/status
20+
- nodes
2121
verbs:
22+
- get
23+
- list
2224
- patch
2325
- update
26+
- apiGroups:
27+
- certificates.k8s.io
28+
resources:
29+
- certificatesigningrequests
30+
verbs:
31+
- create
32+
- get
33+
- list
34+
- watch

bundle/manifests/windows-machine-config-operator.clusterserviceversion.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ spec:
265265
resources:
266266
- certificatesigningrequests
267267
verbs:
268+
- create
268269
- get
269270
- list
270271
- watch
@@ -288,6 +289,14 @@ spec:
288289
- get
289290
- patch
290291
- update
292+
- apiGroups:
293+
- certificates.k8s.io
294+
resourceNames:
295+
- kubernetes.io/kube-apiserver-client
296+
resources:
297+
- signers
298+
verbs:
299+
- approve
291300
- apiGroups:
292301
- certificates.k8s.io
293302
resourceNames:

cmd/daemon/controller.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package main
2121
import (
2222
"flag"
2323
"os"
24+
"time"
2425

2526
"github.com/spf13/cobra"
2627
"k8s.io/klog/v2"
@@ -40,6 +41,9 @@ var (
4041
windowsService bool
4142
logDir string
4243
caBundle string
44+
// Certificate-based authentication options
45+
certDir string
46+
certDuration string
4347
)
4448

4549
func init() {
@@ -50,6 +54,10 @@ func init() {
5054
"Enables running as a Windows service")
5155
controllerCmd.PersistentFlags().StringVar(&caBundle, "ca-bundle", "",
5256
"the full path to CA bundle file containing certificates trusted by the cluster")
57+
controllerCmd.PersistentFlags().StringVar(&certDir, "cert-dir", "C:\\k\\wicd-certs",
58+
"Directory to store WICD client certificates")
59+
controllerCmd.PersistentFlags().StringVar(&certDuration, "cert-duration", "1h",
60+
"Duration for WICD certificates (e.g., 10m, 1h, 24h)")
5361
}
5462

5563
func runControllerCmd(cmd *cobra.Command, args []string) {
@@ -60,6 +68,12 @@ func runControllerCmd(cmd *cobra.Command, args []string) {
6068
fs.Set("logtostderr", "false")
6169
fs.Set("log_dir", logDir)
6270
}
71+
duration, err := time.ParseDuration(certDuration)
72+
if err != nil {
73+
klog.Errorf("invalid cert-duration %s: %v", certDuration, err)
74+
os.Exit(1)
75+
}
76+
6377
ctx := ctrl.SetupSignalHandler()
6478
if windowsService {
6579
if err := initService(ctx); err != nil {
@@ -68,7 +82,7 @@ func runControllerCmd(cmd *cobra.Command, args []string) {
6882
}
6983
}
7084
klog.Info("service controller running")
71-
if err := controller.RunController(ctx, namespace, kubeconfig, caBundle); err != nil {
85+
if err := controller.RunController(ctx, namespace, kubeconfig, caBundle, certDir, duration); err != nil {
7286
klog.Error(err)
7387
os.Exit(1)
7488
}

cmd/operator/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ func main() {
266266
os.Exit(1)
267267
}
268268

269+
wicdCSRController, err := controllers.NewWICDCSRController(mgr, watchNamespace)
270+
if err != nil {
271+
setupLog.Error(err, "unable to create WICD CSR controller")
272+
os.Exit(1)
273+
}
274+
if err = wicdCSRController.SetupWithManager(mgr); err != nil {
275+
setupLog.Error(err, "unable to create controller", "controller", "WICD-CSR")
276+
os.Exit(1)
277+
}
278+
269279
mcReconciler, err := controllers.NewControllerConfigReconciler(mgr, clusterConfig, watchNamespace)
270280
if err != nil {
271281
setupLog.Error(err, "unable to create ControllerConfig reconciler")

config/rbac/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ resources:
77
# subjects if changing service account names.
88
- role.yaml
99
- role_binding.yaml
10+
- wicd-certificate-group-clusterrole.yaml
11+
- wicd-certificate-group-clusterrolebinding.yaml
1012
- leader_election_role.yaml
1113
- leader_election_role_binding.yaml
1214
# Comment the following 4 lines if you want to disable

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ rules:
107107
resources:
108108
- certificatesigningrequests
109109
verbs:
110+
- create
110111
- get
111112
- list
112113
- watch
@@ -130,6 +131,14 @@ rules:
130131
- get
131132
- patch
132133
- update
134+
- apiGroups:
135+
- certificates.k8s.io
136+
resourceNames:
137+
- kubernetes.io/kube-apiserver-client
138+
resources:
139+
- signers
140+
verbs:
141+
- approve
133142
- apiGroups:
134143
- certificates.k8s.io
135144
resourceNames:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: system-wicd-nodes
5+
labels:
6+
app.kubernetes.io/name: "windows-machine-config-operator"
7+
app.kubernetes.io/part-of: "wicd"
8+
rules:
9+
# Allow reading ConfigMaps for bootstrap phase and cleanup
10+
- apiGroups: [""]
11+
resources: ["configmaps"]
12+
verbs: ["get", "list"]
13+
# Allow listing nodes for node discovery (no resourceNames restriction needed)
14+
- apiGroups: [""]
15+
resources: ["nodes"]
16+
verbs: ["list"]
17+
# WICD certificate-based approach: broader access than OVN due to Windows management needs
18+
# Current implementation (Phase 1): Certificate authentication + group RBAC
19+
# - CSR controller ensures only legitimate nodes get certificates
20+
# - Certificate provides node-specific identity (system:wicd-node:nodename)
21+
# - Group RBAC grants necessary permissions for Windows node configuration
22+
# Future enhancement (Phase 2): Add admission webhook for operation-specific validation
23+
- apiGroups: [""]
24+
resources: ["nodes", "nodes/status"]
25+
verbs: ["get", "patch", "update", "watch"]
26+
# Allow creating CSRs for certificate renewal
27+
- apiGroups: ["certificates.k8s.io"]
28+
resources: ["certificatesigningrequests"]
29+
verbs: ["create", "get", "list", "watch"]

0 commit comments

Comments
 (0)