Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: windows-machine-config-operator
app.kubernetes.io/part-of: wicd
name: system-wicd-nodes
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- apiGroups:
- ""
resources:
- nodes
- nodes/status
verbs:
- get
- patch
- update
- watch
- apiGroups:
- certificates.k8s.io
resources:
- certificatesigningrequests
verbs:
- create
- get
- list
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: windows-machine-config-operator
app.kubernetes.io/part-of: wicd
name: system-wicd-nodes
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system-wicd-nodes
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:wicd-nodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: windows-instance-config-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: windows-machine-config-operator
app.kubernetes.io/part-of: wicd
name: windows-instance-config-daemon
rules:
- apiGroups:
- ""
resources:
- nodes
- configmaps
verbs:
- list
- watch
- get
- patch
- update
- list
- apiGroups:
- ""
resources:
- nodes/status
- nodes
verbs:
- get
- list
- patch
- update
Comment on lines 24 to 25
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added back for upgrade scenario, since during upgrade previous version of WICD binary will not have the capability and permissions to remove annotations from node using the certificate method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

- apiGroups:
- certificates.k8s.io
resources:
- certificatesigningrequests
verbs:
- create
- get
- list
- watch
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ spec:
resources:
- certificatesigningrequests
verbs:
- create
- get
- list
- watch
Expand All @@ -288,6 +289,14 @@ spec:
- get
- patch
- update
- apiGroups:
- certificates.k8s.io
resourceNames:
- kubernetes.io/kube-apiserver-client
resources:
- signers
verbs:
- approve
- apiGroups:
- certificates.k8s.io
resourceNames:
Expand Down
16 changes: 15 additions & 1 deletion cmd/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package main
import (
"flag"
"os"
"time"

"github.com/spf13/cobra"
"k8s.io/klog/v2"
Expand All @@ -40,6 +41,9 @@ var (
windowsService bool
logDir string
caBundle string
// Certificate-based authentication options
certDir string
certDuration string
)

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

func runControllerCmd(cmd *cobra.Command, args []string) {
Expand All @@ -60,6 +68,12 @@ func runControllerCmd(cmd *cobra.Command, args []string) {
fs.Set("logtostderr", "false")
fs.Set("log_dir", logDir)
}
duration, err := time.ParseDuration(certDuration)
if err != nil {
klog.Errorf("invalid cert-duration %s: %v", certDuration, err)
os.Exit(1)
}

ctx := ctrl.SetupSignalHandler()
if windowsService {
if err := initService(ctx); err != nil {
Expand All @@ -68,7 +82,7 @@ func runControllerCmd(cmd *cobra.Command, args []string) {
}
}
klog.Info("service controller running")
if err := controller.RunController(ctx, namespace, kubeconfig, caBundle); err != nil {
if err := controller.RunController(ctx, namespace, kubeconfig, caBundle, certDir, duration); err != nil {
klog.Error(err)
os.Exit(1)
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ func main() {
os.Exit(1)
}

wicdCSRController, err := controllers.NewWICDCSRController(mgr, watchNamespace)
if err != nil {
setupLog.Error(err, "unable to create WICD CSR controller")
os.Exit(1)
}
if err = wicdCSRController.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "WICD-CSR")
os.Exit(1)
}

mcReconciler, err := controllers.NewControllerConfigReconciler(mgr, clusterConfig, watchNamespace)
if err != nil {
setupLog.Error(err, "unable to create ControllerConfig reconciler")
Expand Down
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ resources:
# subjects if changing service account names.
- role.yaml
- role_binding.yaml
- wicd-certificate-group-clusterrole.yaml
- wicd-certificate-group-clusterrolebinding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
Expand Down
9 changes: 9 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ rules:
resources:
- certificatesigningrequests
verbs:
- create
- get
- list
- watch
Expand All @@ -130,6 +131,14 @@ rules:
- get
- patch
- update
- apiGroups:
- certificates.k8s.io
resourceNames:
- kubernetes.io/kube-apiserver-client
resources:
- signers
verbs:
- approve
- apiGroups:
- certificates.k8s.io
resourceNames:
Expand Down
29 changes: 29 additions & 0 deletions config/rbac/wicd-certificate-group-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system-wicd-nodes
labels:
app.kubernetes.io/name: "windows-machine-config-operator"
app.kubernetes.io/part-of: "wicd"
rules:
# Allow reading ConfigMaps for bootstrap phase and cleanup
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"]
# Allow listing nodes for node discovery (no resourceNames restriction needed)
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list"]
# WICD certificate-based approach: broader access than OVN due to Windows management needs
# Current implementation (Phase 1): Certificate authentication + group RBAC
# - CSR controller ensures only legitimate nodes get certificates
# - Certificate provides node-specific identity (system:wicd-node:nodename)
# - Group RBAC grants necessary permissions for Windows node configuration
# Future enhancement (Phase 2): Add admission webhook for operation-specific validation
- apiGroups: [""]
resources: ["nodes", "nodes/status"]
verbs: ["get", "patch", "update", "watch"]
# Allow creating CSRs for certificate renewal
- apiGroups: ["certificates.k8s.io"]
resources: ["certificatesigningrequests"]
verbs: ["create", "get", "list", "watch"]
15 changes: 15 additions & 0 deletions config/rbac/wicd-certificate-group-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system-wicd-nodes
labels:
app.kubernetes.io/name: "windows-machine-config-operator"
app.kubernetes.io/part-of: "wicd"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system-wicd-nodes
subjects:
- kind: Group
name: system:wicd-nodes
apiGroup: rbac.authorization.k8s.io
24 changes: 18 additions & 6 deletions config/wicd/windows-instance-config-daemon-cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: windows-instance-config-daemon
labels:
app.kubernetes.io/name: "windows-machine-config-operator"
app.kubernetes.io/part-of: "wicd"
rules:
# Bootstrap permissions - minimal access for initial setup ONLY
- apiGroups:
- ""
resources:
- nodes
- configmaps
verbs:
- list
- watch
- get
- patch
- update
- list
- apiGroups:
- ""
resources:
- nodes/status
- nodes
verbs:
- get
- list
- patch
- update
- apiGroups:
- certificates.k8s.io
resources:
- certificatesigningrequests
verbs:
- create
- get
- list
- watch
Loading