Skip to content

Commit b706c92

Browse files
authoredApr 5, 2022
Merge branch 'dev' into discover
2 parents 08d0bd1 + c4747a4 commit b706c92

35 files changed

+722
-474
lines changed
 
File renamed without changes.
File renamed without changes.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.configmapAutoPolicyDiscovery.enabled -}}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ .Values.labels.app }}-config
6+
data:
7+
conf.yaml: {{ tpl (.Files.Get .Values.configmapAutoPolicyDiscovery.conf) . | quote }}
8+
{{- end }}
9+
10+
---
11+
{{- if not .Values.configmapAutoPolicyDiscovery.enabled -}}
12+
apiVersion: v1
13+
kind: ConfigMap
14+
metadata:
15+
name: {{ .Values.labels.app }}-config
16+
data:
17+
conf.yaml: |-
18+
{{ toYaml .Values.config | indent 4 }}
19+
{{- end }}
File renamed without changes.
File renamed without changes.

‎knox-auto-policy-chart/values-prod.yaml ‎deployments/helm/values-prod.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This is a YAML-formatted file.
33
# Declare variables to be passed into your templates.
44

5-
replicaCount: 2
5+
replicaCount: 1
66

77
image:
88
repository: gcr.io/mimetic-kit-294408/production/knoxautopolicy
File renamed without changes.
File renamed without changes.

‎knox-auto-policy-chart/templates/dev-config.yaml

-9
This file was deleted.

‎scripts/convert_sys_policy.sh

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
#!/bin/bash
22

3-
DATA='{"policytype": "system"}'
3+
## Run script command in below format"
4+
## ./scripts/convery_sys_policy.sh --clustername default --namespace wordpress-mysql --labels app=mysql
5+
6+
usage()
7+
{
8+
cat << EOF
9+
Usage: $0 <options>
10+
11+
Options could be:
12+
--clustername <clustername>
13+
--namespace <namespace>
14+
--labels <set-of-labels> ... for e.g. --labels "xyz=123,abc=456"
15+
EOF
16+
exit 1
17+
}
18+
19+
OPTS=`getopt -o s: --long clustername: --long namespace: --long labels: -n 'parse-options' -- "$@"`
20+
eval set -- "$OPTS"
21+
while true; do
22+
case "$1" in
23+
--clustername ) CLUSTER_NAME="$2"; shift 2;;
24+
--namespace ) NAMESPACE="$2"; shift 2;;
25+
--labels ) LABELS="$2"; shift 2;;
26+
-- ) shift; break ;;
27+
* ) break ;;
28+
esac
29+
done
30+
##[[ "$REQUEST" == "" ]] && echo "request type [observe|dbclear] not found." && usage
31+
32+
DATA='{"policytype": "system", "clustername": "'$CLUSTER_NAME'", "namespace":"'$NAMESPACE'", "labels":"'$LABELS'"}'
433

534
grpcurl -plaintext -d "$DATA" localhost:9089 v1.worker.Worker.Convert

‎src/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Builder
22

3-
FROM artifactory.accuknox.com/accuknox/golang:1.15.3-buster as builder
3+
FROM artifactory.accuknox.com/accuknox/golang:1.18.0-bullseye as builder
44

55
WORKDIR /usr/src/knox
66

‎src/build/Dockerfile.autopol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Builder
22

3-
FROM golang:1.15.3-buster as builder
3+
FROM golang:1.18.0-bullseye as builder
44

55
WORKDIR /usr/src/knox
66

‎src/cluster/k8sClientHandler.go

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ func GetServicesFromK8sClient() []types.Service {
294294
k8sService.Labels = append(k8sService.Labels, k+"="+v)
295295
}
296296

297+
for _, ip := range svc.Spec.ExternalIPs {
298+
k8sService.ExternalIPs = append(k8sService.ExternalIPs, ip)
299+
}
300+
297301
for _, port := range svc.Spec.Ports {
298302
k8sService.ClusterIP = string(svc.Spec.ClusterIP)
299303
k8sService.Protocol = string(port.Protocol)

‎src/config/configManager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func LoadConfigFromFile() {
130130
NetworkPolicyDir: viper.GetString("application.network.network-policy-dir"),
131131

132132
NetPolicyTypes: 3,
133-
NetPolicyRuleTypes: 511,
133+
NetPolicyRuleTypes: 1023,
134134
NetPolicyCIDRBits: 32,
135135

136136
NetLogFilters: []types.NetworkLogFilter{},

‎src/libs/common.go

+37-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ var GitBranch string
3232
var BuildDate string
3333
var Version string
3434

35+
const (
36+
IPProtoUnknown = -1
37+
IPProtocolICMP = 1
38+
IPProtocolTCP = 6
39+
IPProtocolUDP = 17
40+
IPProtocolICMPv6 = 58
41+
IPProtocolSCTP = 132
42+
)
43+
44+
var protocolMap = map[int]string{
45+
IPProtoUnknown: "Unknown",
46+
IPProtocolICMP: "ICMP",
47+
IPProtocolTCP: "TCP",
48+
IPProtocolUDP: "UDP",
49+
IPProtocolICMPv6: "ICMPv6",
50+
IPProtocolSCTP: "SCTP",
51+
}
52+
53+
// Array for ICMP type which can be considered as ICMP reply packets.
54+
// TODO: Identity all the ICMP reply types
55+
var ICMPReplyType = []int{
56+
0, // EchoReply
57+
}
58+
3559
func printBuildDetails() {
3660
if GitCommit == "" {
3761
return
@@ -210,14 +234,21 @@ func GetExternalIPAddr() string {
210234
}
211235

212236
func GetProtocol(protocol int) string {
213-
protocolMap := map[int]string{
214-
1: "ICMP",
215-
6: "TCP",
216-
17: "UDP",
217-
132: "STCP",
237+
return protocolMap[protocol]
238+
}
239+
240+
func IsICMP(protocol int) bool {
241+
if protocol == IPProtocolICMP || protocol == IPProtocolICMPv6 {
242+
return true
218243
}
244+
return false
245+
}
219246

220-
return protocolMap[protocol]
247+
func IsReplyICMP(icmpType int) bool {
248+
if ContainsElement(ICMPReplyType, icmpType) {
249+
return true
250+
}
251+
return false
221252
}
222253

223254
// ============ //

0 commit comments

Comments
 (0)
Please sign in to comment.