Skip to content

Commit a25a3e8

Browse files
authored
add FALCON_CLUSTER_NAME env var for unmanages k8s clusters (#741)
1 parent 2796021 commit a25a3e8

File tree

9 files changed

+69
-0
lines changed

9 files changed

+69
-0
lines changed

api/falcon/v1alpha1/falconnodesensor_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ type FalconNodeSensorConfig struct {
127127
// For more information, please see https://github.com/CrowdStrike/falcon-operator/blob/main/docs/ADVANCED.md.
128128
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="DaemonSet Advanced Settings"
129129
Advanced FalconAdvanced `json:"advanced,omitempty"`
130+
131+
// When running on an unmanaged K8S cluster, set a cluster name. When running on managed, K8S cluster name is resolved cloud-side
132+
// +kubebuilder:validation:Pattern="^[0-9a-zA-Z]{1}[0-9a-zA-Z_-]{1,99}$"
133+
ClusterName *string `json:"clusterName,omitempty"`
130134
}
131135

132136
type PriorityClassConfig struct {

api/falcon/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,11 @@ func (in *FalconNodeSensorConfig) DeepCopyInto(out *FalconNodeSensorConfig) {
13251325
**out = **in
13261326
}
13271327
in.Advanced.DeepCopyInto(&out.Advanced)
1328+
if in.ClusterName != nil {
1329+
in, out := &in.ClusterName, &out.ClusterName
1330+
*out = new(string)
1331+
**out = **in
1332+
}
13281333
}
13291334

13301335
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FalconNodeSensorConfig.

config/crd/bases/falcon.crowdstrike.com_falcondeployments.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,12 @@ spec:
40334033
- kernel
40344034
- bpf
40354035
type: string
4036+
clusterName:
4037+
description: When running on an unmanaged K8S cluster, set
4038+
a cluster name. When running on managed, K8S cluster name
4039+
is resolved cloud-side
4040+
pattern: ^[0-9a-zA-Z]{1}[0-9a-zA-Z_-]{1,99}$
4041+
type: string
40364042
disableCleanup:
40374043
default: false
40384044
description: |-

config/crd/bases/falcon.crowdstrike.com_falconnodesensors.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ spec:
217217
- kernel
218218
- bpf
219219
type: string
220+
clusterName:
221+
description: When running on an unmanaged K8S cluster, set a cluster
222+
name. When running on managed, K8S cluster name is resolved
223+
cloud-side
224+
pattern: ^[0-9a-zA-Z]{1}[0-9a-zA-Z_-]{1,99}$
225+
type: string
220226
disableCleanup:
221227
default: false
222228
description: |-

deploy/falcon-operator.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7435,6 +7435,12 @@ spec:
74357435
- kernel
74367436
- bpf
74377437
type: string
7438+
clusterName:
7439+
description: When running on an unmanaged K8S cluster, set
7440+
a cluster name. When running on managed, K8S cluster name
7441+
is resolved cloud-side
7442+
pattern: ^[0-9a-zA-Z]{1}[0-9a-zA-Z_-]{1,99}$
7443+
type: string
74387444
disableCleanup:
74397445
default: false
74407446
description: |-
@@ -8931,6 +8937,12 @@ spec:
89318937
- kernel
89328938
- bpf
89338939
type: string
8940+
clusterName:
8941+
description: When running on an unmanaged K8S cluster, set a cluster
8942+
name. When running on managed, K8S cluster name is resolved
8943+
cloud-side
8944+
pattern: ^[0-9a-zA-Z]{1}[0-9a-zA-Z_-]{1,99}$
8945+
type: string
89348946
disableCleanup:
89358947
default: false
89368948
description: |-

docs/deployment/openshift/resources/node/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ spec:
6767
| node.serviceAccount.annotations | (optional) Annotations that should be added to the Service Account (e.g. for IAM role association) |
6868
| node.backend | (optional) Configure the backend mode for Falcon Sensor (allowed values: kernel, bpf) |
6969
| node.disableCleanup | (optional) Cleans up `/opt/CrowdStrike` on the nodes by deleting the files and directory. |
70+
| node.clusterName | (optional) When running on an unmanaged K8S cluster, set a cluster name. When running on managed K8S (e.g. EKS, GKE, AKS), cluster name is resolved cloud-side |
7071
| node.version | (optional) Enforce particular Falcon Sensor version to be installed (example: "6.35", "6.35.0-13207"). Use this field when pulling from CrowdStrike registries (when using Falcon API credentials). For non-CrowdStrike registries, use `node.image` instead. |
7172
| node.gke.autopilot | (optional) Enable GKE Autopilot support for FalconNodeSensor. |
7273
| node.gke.deployAllowListVersion | (optional) WorkloadAllowlist version for the sensor daemonset when using GKE AutoPilot. (example: "v1.0.3" for crowdstrike-falconsensor-deploy-allowlist-v1.0.3) |

docs/resources/node/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ spec:
6767
| node.serviceAccount.annotations | (optional) Annotations that should be added to the Service Account (e.g. for IAM role association) |
6868
| node.backend | (optional) Configure the backend mode for Falcon Sensor (allowed values: kernel, bpf) |
6969
| node.disableCleanup | (optional) Cleans up `/opt/CrowdStrike` on the nodes by deleting the files and directory. |
70+
| node.clusterName | (optional) When running on an unmanaged K8S cluster, set a cluster name. When running on managed K8S (e.g. EKS, GKE, AKS), cluster name is resolved cloud-side |
7071
| node.version | (optional) Enforce particular Falcon Sensor version to be installed (example: "6.35", "6.35.0-13207"). Use this field when pulling from CrowdStrike registries (when using Falcon API credentials). For non-CrowdStrike registries, use `node.image` instead. |
7172
| node.gke.autopilot | (optional) Enable GKE Autopilot support for FalconNodeSensor. |
7273
| node.gke.deployAllowListVersion | (optional) WorkloadAllowlist version for the sensor daemonset when using GKE AutoPilot. (example: "v1.0.3" for crowdstrike-falconsensor-deploy-allowlist-v1.0.3) |

docs/src/resources/node.md.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ spec:
6767
| node.serviceAccount.annotations | (optional) Annotations that should be added to the Service Account (e.g. for IAM role association) |
6868
| node.backend | (optional) Configure the backend mode for Falcon Sensor (allowed values: kernel, bpf) |
6969
| node.disableCleanup | (optional) Cleans up `/opt/CrowdStrike` on the nodes by deleting the files and directory. |
70+
| node.clusterName | (optional) When running on an unmanaged K8S cluster, set a cluster name. When running on managed K8S (e.g. EKS, GKE, AKS), cluster name is resolved cloud-side |
7071
| node.version | (optional) Enforce particular Falcon Sensor version to be installed (example: "6.35", "6.35.0-13207"). Use this field when pulling from CrowdStrike registries (when using Falcon API credentials). For non-CrowdStrike registries, use `node.image` instead. |
7172
| node.gke.autopilot | (optional) Enable GKE Autopilot support for FalconNodeSensor. |
7273
| node.gke.deployAllowListVersion | (optional) WorkloadAllowlist version for the sensor daemonset when using GKE AutoPilot. (example: "v1.0.3" for crowdstrike-falconsensor-deploy-allowlist-v1.0.3) |

pkg/node/config_cache.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"strings"
9+
"unicode"
910

1011
falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
1112
"github.com/crowdstrike/falcon-operator/internal/controller/common/sensor"
@@ -91,10 +92,42 @@ func (cc *ConfigCache) SensorEnvVars() map[string]string {
9192
if cc.nodesensor.Spec.Falcon.Cloud != "" {
9293
sensorConfig["FALCONCTL_OPT_CLOUD"] = cc.nodesensor.Spec.Falcon.Cloud
9394
}
95+
if cc.nodesensor.Spec.Node.ClusterName != nil {
96+
sensorConfig["FALCON_CLUSTER_NAME"] = sanitizeClusterName(cc.nodesensor.Spec.Node.ClusterName)
97+
}
9498

9599
return sensorConfig
96100
}
97101

102+
func sanitizeClusterName(clusterName *string) string {
103+
if clusterName == nil {
104+
return ""
105+
}
106+
107+
if !isClusterNameValid(*clusterName) {
108+
return ""
109+
}
110+
111+
return *clusterName
112+
}
113+
114+
// isClusterNameValid validates the clusterName.
115+
// Those rules had been taken from EKS (Amazon AWS).
116+
// See more at: https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html#API_CreateCluster_RequestSyntax
117+
func isClusterNameValid(clusterName string) bool {
118+
if len(clusterName) > 100 || len(clusterName) == 0 {
119+
return false
120+
}
121+
122+
if !unicode.IsLetter(rune(clusterName[0])) && !unicode.IsNumber(rune(clusterName[0])) {
123+
return false
124+
}
125+
126+
return !strings.ContainsFunc(clusterName, func(r rune) bool {
127+
return !unicode.IsLetter(r) && !unicode.IsNumber(r) && r != '-' && r != '_'
128+
})
129+
}
130+
98131
func (cc *ConfigCache) getFalconImage(ctx context.Context, nodesensor *falconv1alpha1.FalconNodeSensor) (string, error) {
99132
if nodesensor.Spec.Node.Image != "" {
100133
return nodesensor.Spec.Node.Image, nil

0 commit comments

Comments
 (0)