Skip to content

Commit 086f3ba

Browse files
committed
update naming and readme for ciliumnodes
1 parent 82ad20e commit 086f3ba

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

azure-iptables-monitor/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# azure-iptables-monitor
22

3-
`azure-iptables-monitor` is a utility for monitoring iptables rules on Kubernetes nodes and labeling nodes based on whether they contain user-defined iptables rules.
3+
`azure-iptables-monitor` is a utility for monitoring iptables rules on Kubernetes nodes and labeling a ciliumnode resource based on whether the corresponding node contains user-defined iptables rules.
44

55
## Description
66

7-
The goal of this program is to periodically scan iptables rules across all tables (nat, mangle, filter, raw, security) and determine if any rules exist that don't match expected patterns. When unexpected rules are found, the node is labeled to indicate the presence of user-defined iptables rules.
7+
The goal of this program is to periodically scan iptables rules across all tables (nat, mangle, filter, raw, security) and determine if any rules exist that don't match expected patterns. When unexpected rules are found, the ciliumnode resource is labeled to indicate the presence of user-defined iptables rules.
88

99
## Usage
1010

@@ -25,14 +25,14 @@ Follow the steps below to build and run the program:
2525

2626
4. Start the program with:
2727
```bash
28-
./azure-iptables-monitor --input=/etc/config/ --interval=600
28+
./azure-iptables-monitor --input=/etc/config/ --interval=300
2929
```
3030
- The `--input` flag specifies the directory containing allowed regex pattern files. Default: `/etc/config/`
31-
- The `--interval` flag specifies how often to check iptables rules in seconds. Default: `600`
31+
- The `--interval` flag specifies how often to check iptables rules in seconds. Default: `300`
3232
- The `--events` flag enables Kubernetes event creation for rule violations. Default: `false`
33-
- The program must be in a k8 environment and `NODE_NAME` must be a set environment variable with the current node.
33+
- The program must be in a k8s environment and `NODE_NAME` must be a set environment variable with the current node.
3434

35-
5. The program will set the `user-iptables-rules` label on the current node to `true` if unexpected rules are found, or `false` if all rules match expected patterns. Proper RBAC is required for patching the node.
35+
5. The program will set the `user-iptables-rules` label to `true` on the specified ciliumnode resource if unexpected rules are found, or `false` if all rules match expected patterns. Proper RBAC is required for patching (patch for ciliumnodes, create for events, get for nodes).
3636

3737

3838
## Pattern File Format

azure-iptables-monitor/iptables_monitor.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ var version string
2828

2929
var (
3030
configPath = flag.String("input", "/etc/config/", "Name of the directory with the allowed regex files")
31-
checkInterval = flag.Int("interval", 600, "How often to check iptables rules (in seconds)")
31+
checkInterval = flag.Int("interval", 300, "How often to check iptables rules (in seconds)")
3232
sendEvents = flag.Bool("events", false, "Whether to send node events if unexpected iptables rules are detected")
3333
)
3434

35-
const nodeLabel = "user-iptables-rules"
35+
const label = "user-iptables-rules"
3636

3737
type FileLineReader interface {
3838
Read(filename string) ([]string, error)
@@ -66,9 +66,9 @@ func (OSFileLineReader) Read(filename string) ([]string, error) {
6666
return lines, nil
6767
}
6868

69-
// patchNodeLabel sets a specified node label to a certain value by patching it
70-
// Requires proper rbac (node patch)
71-
func patchNodeLabel(clientset dynamic.Interface, labelValue bool, nodeName string) error {
69+
// patchLabel sets a specified label to a certain value on a ciliumnode resource by patching it
70+
// Requires proper rbac
71+
func patchLabel(clientset dynamic.Interface, labelValue bool, nodeName string) error {
7272
gvr := schema.GroupVersionResource{
7373
Group: "cilium.io",
7474
Version: "v2",
@@ -81,12 +81,12 @@ func patchNodeLabel(clientset dynamic.Interface, labelValue bool, nodeName strin
8181
"%s": "%v"
8282
}
8383
}
84-
}`, nodeLabel, labelValue))
84+
}`, label, labelValue))
8585

8686
_, err := clientset.Resource(gvr).
8787
Patch(context.TODO(), nodeName, types.MergePatchType, patch, metav1.PatchOptions{})
8888
if err != nil {
89-
return fmt.Errorf("failed to patch %s with label %s=%v: %w", nodeName, nodeLabel, labelValue, err)
89+
return fmt.Errorf("failed to patch %s with label %s=%v: %w", nodeName, label, labelValue, err)
9090
}
9191
return nil
9292
}
@@ -275,12 +275,12 @@ func main() {
275275
for {
276276
userIPTablesRulesFound := nodeHasUserIPTablesRules(fileReader, iptablesClient)
277277

278-
// update node label based on whether user iptables rules were found
279-
err = patchNodeLabel(dynamicClient, userIPTablesRulesFound, currentNodeName)
278+
// update label based on whether user iptables rules were found
279+
err = patchLabel(dynamicClient, userIPTablesRulesFound, currentNodeName)
280280
if err != nil {
281-
klog.Errorf("failed to patch node label: %v", err)
281+
klog.Errorf("failed to patch label: %v", err)
282282
} else {
283-
klog.V(2).Infof("Successfully updated node label for %s: %s=%v", currentNodeName, nodeLabel, userIPTablesRulesFound)
283+
klog.V(2).Infof("Successfully updated label for %s: %s=%v", currentNodeName, label, userIPTablesRulesFound)
284284
}
285285

286286
if *sendEvents && userIPTablesRulesFound {

0 commit comments

Comments
 (0)