Skip to content

Commit d541d19

Browse files
authored
Allow populaiting only single filter rules for cli usecase (#128)
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
1 parent d773b37 commit d541d19

File tree

3 files changed

+37
-89
lines changed

3 files changed

+37
-89
lines changed

res/flow-capture.yml

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,15 @@ spec:
4545
value: "false"
4646
- name: ENABLE_FLOW_FILTER
4747
value: "false"
48-
- name: FILTER_DIRECTION
49-
value: ""
50-
- name: FILTER_IP_CIDR
51-
value: "0.0.0.0/0"
52-
- name: FILTER_PROTOCOL
53-
value: ""
54-
- name: FILTER_SOURCE_PORT
55-
value: ""
56-
- name: FILTER_DESTINATION_PORT
57-
value: ""
58-
- name: FILTER_PORT
59-
value: ""
60-
- name: FILTER_SOURCE_PORT_RANGE
61-
value: ""
62-
- name: FILTER_DESTINATION_PORT_RANGE
63-
value: ""
64-
- name: FILTER_PORT_RANGE
65-
value: ""
66-
- name: FILTER_SOURCE_PORTS
67-
value: ""
68-
- name: FILTER_DESTINATION_PORTS
69-
value: ""
70-
- name: FILTER_PORTS
71-
value: ""
72-
- name: FILTER_ICMP_TYPE
73-
value: ""
74-
- name: FILTER_ICMP_CODE
75-
value: ""
76-
- name: FILTER_PEER_IP
77-
value: ""
78-
- name: FILTER_TCP_FLAGS
79-
value: ""
80-
- name: FILTER_DROPS
81-
value: "false"
82-
- name: FILTER_ACTION
83-
value: "Accept"
48+
- name: FLOW_FILTER_RULES
49+
value: >
50+
[ { "direction": "", "ip_cidr": "0.0.0.0/0", "protocol": "", "source_port": 0,
51+
"destination_port": 0, "port": 0, "source_port_range": "",
52+
"source_ports": "", "destination_port_range": "",
53+
"destination_ports": "", "port_range": "", "ports": "",
54+
"icmp_type": 0, "icmp_code": 0, "peer_ip": "", "action": "Accept",
55+
"tcp_flags": "", "drops": false }
56+
]
8457
- name: EXPORT
8558
value: "direct-flp"
8659
- name: FLP_CONFIG

res/packet-capture.yml

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,15 @@ spec:
3131
value: "false"
3232
- name: LOG_LEVEL
3333
value: info
34-
- name: FILTER_DIRECTION
35-
value: ""
36-
- name: FILTER_IP_CIDR
37-
value: "0.0.0.0/0"
38-
- name: FILTER_PROTOCOL
39-
value: ""
40-
- name: FILTER_SOURCE_PORT
41-
value: ""
42-
- name: FILTER_DESTINATION_PORT
43-
value: ""
44-
- name: FILTER_PORT
45-
value: ""
46-
- name: FILTER_SOURCE_PORT_RANGE
47-
value: ""
48-
- name: FILTER_DESTINATION_PORT_RANGE
49-
value: ""
50-
- name: FILTER_PORT_RANGE
51-
value: ""
52-
- name: FILTER_SOURCE_PORTS
53-
value: ""
54-
- name: FILTER_DESTINATION_PORTS
55-
value: ""
56-
- name: FILTER_PORTS
57-
value: ""
58-
- name: FILTER_ICMP_TYPE
59-
value: ""
60-
- name: FILTER_ICMP_CODE
61-
value: ""
62-
- name: FILTER_PEER_IP
63-
value: ""
64-
- name: FILTER_DROPS
65-
value: "false"
66-
- name: FILTER_ACTION
67-
value: "Accept"
34+
- name: FLOW_FILTER_RULES
35+
value: >
36+
[ { "direction": "", "ip_cidr": "0.0.0.0/0", "protocol": "", "source_port": 0,
37+
"destination_port": 0, "port": 0, "source_port_range": "",
38+
"source_ports": "", "destination_port_range": "",
39+
"destination_ports": "", "port_range": "", "ports": "",
40+
"icmp_type": 0, "icmp_code": 0, "peer_ip": "", "action": "Accept",
41+
"tcp_flags": "", "drops": false }
42+
]
6843
- name: EXPORT
6944
value: "direct-flp"
7045
- name: FLP_CONFIG

scripts/functions.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -397,58 +397,58 @@ function edit_manifest() {
397397
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_FLOW_FILTER\").value|=\"$2\"" "$3"
398398
;;
399399
"filter_direction")
400-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DIRECTION\").value|=\"$2\"" "$3"
400+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.direction = \"$2\")| tostring)" "$3"
401401
;;
402402
"filter_cidr")
403-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_IP_CIDR\").value|=\"$2\"" "$3"
403+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.ip_cidr = \"$2\")| tostring)" "$3"
404404
;;
405405
"filter_protocol")
406-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_PROTOCOL\").value|=\"$2\"" "$3"
406+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.protocol = \"$2\")| tostring)" "$3"
407407
;;
408408
"filter_sport")
409-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_SOURCE_PORT\").value|=\"$2\"" "$3"
409+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.source_port = $2)| tostring)" "$3"
410410
;;
411411
"filter_dport")
412-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DESTINATION_PORT\").value|=\"$2\"" "$3"
412+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.destination_port = $2)| tostring)" "$3"
413413
;;
414414
"filter_port")
415-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_PORT\").value|=\"$2\"" "$3"
415+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.port = $2)| tostring)" "$3"
416416
;;
417417
"filter_sport_range")
418-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_SOURCE_PORT_RANGE\").value|=\"$2\"" "$3"
418+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.source_port_range = \"$2\")| tostring)" "$3"
419419
;;
420420
"filter_dport_range")
421-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DESTINATION_PORT_RANGE\").value|=\"$2\"" "$3"
421+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.destination_port_range = \"$2\")| tostring)" "$3"
422422
;;
423423
"filter_port_range")
424-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_PORT_RANGE\").value|=\"$2\"" "$3"
424+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.port_range = \"$2\")| tostring)" "$3"
425425
;;
426426
"filter_sports")
427-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_SOURCE_PORTS\").value|=\"$2\"" "$3"
427+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.source_ports = \"$2\")| tostring)" "$3"
428428
;;
429-
"filter_dportS")
430-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DESTINATION_PORTS\").value|=\"$2\"" "$3"
429+
"filter_dports")
430+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.destination_ports = \"$2\")| tostring)" "$3"
431431
;;
432432
"filter_ports")
433-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_PORTS\").value|=\"$2\"" "$3"
433+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.ports = \"$2\")| tostring)" "$3"
434434
;;
435435
"filter_icmp_type")
436-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_ICMP_TYPE\").value|=\"$2\"" "$3"
436+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.icmp_type = $2)| tostring)" "$3"
437437
;;
438438
"filter_icmp_code")
439-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_ICMP_CODE\").value|=\"$2\"" "$3"
439+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.icmp_code = $2)| tostring)" "$3"
440440
;;
441441
"filter_peer_ip")
442-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_PEER_IP\").value|=\"$2\"" "$3"
442+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.peer_ip = \"$2\")| tostring)" "$3"
443443
;;
444444
"filter_action")
445-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_ACTION\").value|=\"$2\"" "$3"
445+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.action = \"$2\")| tostring)" "$3"
446446
;;
447447
"filter_tcp_flags")
448-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_TCP_FLAGS\").value|=\"$2\"" "$3"
448+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.tcp_flags = \"$2\")| tostring)" "$3"
449449
;;
450450
"filter_pkt_drops")
451-
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"FILTER_DROPS\").value|=\"$2\"" "$3"
451+
yq e --inplace " .spec.template.spec.containers[0].env[] |= select(.name == \"FLOW_FILTER_RULES\").value |=(fromjson | map(.drops = $2)| tostring)" "$3"
452452
;;
453453
"filter_regexes")
454454
copyFLPConfig "$3"

0 commit comments

Comments
 (0)