diff --git a/k8s/job.yaml b/k8s/job.yaml index 65b08bc..01e90b0 100755 --- a/k8s/job.yaml +++ b/k8s/job.yaml @@ -131,27 +131,110 @@ data: ] } --- +apiVersion: v1 +kind: ConfigMap +metadata: + name: fluent-config + namespace: k8tls +data: + fluent-bit.conf: | + [SERVICE] + Flush 1 + Log_Level info + Parsers_File parsers.conf + + [INPUT] + Name tail + Path /tmp/minified_report.json + Parser json + Tag json.data + DB /tmp/minified_report.db + Read_from_Head true + Exit_On_Eof true + + [OUTPUT] + Name es + Match * + Host localhost + Port 9200 + Index findings + HTTP_User elastic + HTTP_Passwd ${ES_PASSWORD} + tls On + tls.verify On + tls.ca_file /fluent-bit/http_ca.crt + Suppress_Type_Name On + Replace_Dots On +--- +apiVersion: v1 +kind: Secret +metadata: + name: es-password + namespace: k8tls +type: Opaque +data: + es_password: aXUyQzk1ZDYtVjktamtPVUdOdWM= +--- +apiVersion: v1 +kind: Secret +metadata: + name: http-ca-secret + namespace: k8tls +type: Opaque +data: + http_ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZXVENDQTBHZ0F3SUJBZ0lVQ05HamlKVkdEODEyc3FvZE9kcDFpMm5tWVNZd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1BERTZNRGdHQTFVRUF4TXhSV3hoYzNScFkzTmxZWEpqYUNCelpXTjFjbWwwZVNCaGRYUnZMV052Ym1acApaM1Z5WVhScGIyNGdTRlJVVUNCRFFUQWVGdzB5TkRBM016QXdNelUxTXpKYUZ3MHlOekEzTXpBd016VTFNekphCk1Ed3hPakE0QmdOVkJBTVRNVVZzWVhOMGFXTnpaV0Z5WTJnZ2MyVmpkWEpwZEhrZ1lYVjBieTFqYjI1bWFXZDEKY21GMGFXOXVJRWhVVkZBZ1EwRXdnZ0lpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElDRHdBd2dnSUtBb0lDQVFEawpnS214Z0ptZW8yc3orTUhGcXhJNzdreG1iUEhCUWJNc3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3600 # Retain the job (and its pods) for 1 hour after completion template: spec: serviceAccountName: k8tls-serviceact - containers: - - name: k8tls - image: kubearmor/k8tls:latest + initContainers: + - name: init-k8tls + image: kubearmor/k8tls:latest command: ["./k8s_tlsscan"] volumeMounts: - mountPath: /home/k8tls/config/ name: config readOnly: true + - mountPath: /tmp/ + name: shared-volume + containers: + - name: fluent-bit + image: fluent/fluent-bit:latest + env: + - name: ES_PASSWORD + valueFrom: + secretKeyRef: + name: es-password + key: es_password + volumeMounts: + - mountPath: /tmp/ + name: shared-volume + - mountPath: /fluent-bit/etc/fluent-bit.conf + name: fluent-config + subPath: fluent-bit.conf + - mountPath: /fluent-bit/http_ca.crt + name: http-ca-secret + subPath: http_ca.crt restartPolicy: Never volumes: - name: config configMap: name: k8tls-cm + - name: shared-volume + emptyDir: {} + - name: fluent-config + configMap: + name: fluent-config + - name: http-ca-secret + secret: + secretName: http-ca-secret + backoffLimit: 4 ---- +--- \ No newline at end of file diff --git a/src/k8s_tlsscan b/src/k8s_tlsscan index 7de3250..1a68721 100755 --- a/src/k8s_tlsscan +++ b/src/k8s_tlsscan @@ -42,4 +42,4 @@ while read -r line; do IFS=' ' done < <(kubectl get svc --no-headers -A -o=custom-columns='NS:.metadata.namespace,NAME:.metadata.name,ClusterIP:.spec.clusterIP,PORTNAME:.spec.ports[*].name,PORT:.spec.ports[*].port,PROTOCOL:.spec.ports[*].protocol,TGTPORT:.spec.ports[*].targetPort') -$BDIR/tlsscan -f $ADDRLIST +$BDIR/tlsscan --infile $ADDRLIST --minified-json diff --git a/src/tlsscan b/src/tlsscan index 7c47e51..24d118b 100755 --- a/src/tlsscan +++ b/src/tlsscan @@ -25,6 +25,7 @@ Options: -f | --infile input file containing list of addresses (mandatory) --json output json file --csv output csv file +--minified-json output minified json file -h | --help EOF exit 1 @@ -32,7 +33,7 @@ EOF parse_cmdargs() { - OPTS=`getopt -o f:h --long csv:,infile:,json:,help -n 'parse-options' -- "$@"` + OPTS=`getopt -o f:h --long csv:,infile:,json:,minified-json,help -n 'parse-options' -- "$@"` [[ $? -ne 0 ]] && usage eval set -- "$OPTS" while true; do @@ -40,6 +41,7 @@ parse_cmdargs() -f | --infile ) infile="$2"; [[ ! -f $infile ]] && echo "$infile file not found" && exit 2; shift 2;; --json ) jsonout="$2"; [[ -f $jsonout ]] && rm -f $jsonout; shift 2;; --csv ) csvout="$2"; shift 2;; + --minified-json ) minified_json_out="/tmp/minified_report.json"; shift 1;; -h | --help ) usage; shift 1;; -- ) shift; break ;; * ) break ;; @@ -192,6 +194,9 @@ main() done < $infile jsonfooter [[ -f "$csvout" ]] && tabled --in $csvout --config ${TABLED_YAML-tabled.yaml} + if [[ -n "$minified_json_out" && -f "$jsonout" ]]; then + jq -c . $jsonout > $minified_json_out + fi echo ; getsummary }