mirror of
https://github.com/devitq/homelab.git
synced 2026-11-20 23:07:39 +00:00
init(): initial commit
This commit is contained in:
216 files changed
+36511
No files matched your search
@@ -0,0 +1,23 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-indexer
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: wazuh-indexer
|
||||
resources:
|
||||
requests:
|
||||
cpu: 500m
|
||||
memory: 1.3G
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 1.3G
|
||||
env:
|
||||
- name: OPENSEARCH_JAVA_OPTS
|
||||
value: "-Xms384m -Xmx384m"
|
||||
- name: discovery.seed_hosts
|
||||
value: "wazuh-indexer-0.wazuh-indexer"
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- ../wazuh
|
||||
- ../wazuh/wazuh_agents
|
||||
- storage-class.yaml
|
||||
|
||||
patches:
|
||||
- path: indexer-resources.yaml
|
||||
- path: wazuh-master-resources.yaml
|
||||
- path: wazuh-resources.yaml
|
||||
|
||||
replacements:
|
||||
- source:
|
||||
kind: ConfigMap
|
||||
name: wazuh-storage-settings
|
||||
fieldPath: data.storageClassName
|
||||
targets:
|
||||
- select:
|
||||
kind: PersistentVolumeClaim
|
||||
fieldPaths:
|
||||
- spec.storageClassName
|
||||
options:
|
||||
create: true
|
||||
- select:
|
||||
kind: StatefulSet
|
||||
fieldPaths:
|
||||
- spec.volumeClaimTemplates.*.spec.storageClassName
|
||||
options:
|
||||
create: true
|
||||
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: wazuh-storage-settings
|
||||
data:
|
||||
storageClassName: proxmox-hdd
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-manager-master
|
||||
namespace: wazuh
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: wazuh-manager
|
||||
env:
|
||||
- name: WAZUH_INDEXER_HOSTS
|
||||
value: "wazuh-indexer-0.wazuh-indexer:9200"
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-manager-worker
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: wazuh-manager
|
||||
env:
|
||||
- name: WAZUH_INDEXER_HOSTS
|
||||
value: 'wazuh-indexer-0.wazuh-indexer:9200'
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-dns
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: kube-system
|
||||
podSelector:
|
||||
matchLabels:
|
||||
k8s-app: kube-dns
|
||||
ports:
|
||||
- protocol: UDP
|
||||
port: 53
|
||||
- protocol: TCP
|
||||
port: 53
|
||||
@@ -0,0 +1,10 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: default-deny-all
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
- Egress
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh namespace
|
||||
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: wazuh
|
||||
@@ -0,0 +1,23 @@
|
||||
nodes:
|
||||
indexer:
|
||||
- name: indexer
|
||||
dns:
|
||||
- "wazuh-indexer"
|
||||
- "wazuh-indexer.wazuh.svc.cluster.local"
|
||||
- "wazuh-indexer-0.wazuh-indexer"
|
||||
- "wazuh-indexer-0.wazuh-indexer.wazuh.svc.cluster.local"
|
||||
|
||||
manager:
|
||||
- name: manager
|
||||
dns:
|
||||
- "wazuh-api"
|
||||
- "wazuh-api.wazuh.svc.cluster.local"
|
||||
- "wazuh-agents"
|
||||
- "wazuh-agents.wazuh.svc.cluster.local"
|
||||
|
||||
dashboard:
|
||||
- name: dashboard
|
||||
dns:
|
||||
- "dashboard"
|
||||
- "dashboard.wazuh.svc.cluster.local"
|
||||
- "wazuh.internal.itqdev.xyz"
|
||||
@@ -0,0 +1,155 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Dashboard Deployment
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: wazuh-dashboard
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wazuh-dashboard
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wazuh-dashboard
|
||||
name: wazuh-dashboard
|
||||
spec:
|
||||
# No workload talks to the Kubernetes API.
|
||||
automountServiceAccountToken: false
|
||||
volumes:
|
||||
# The Secret gets the pod's fsGroup and group read, so the service user
|
||||
# could read it: an init container copies it to a root-only file.
|
||||
- name: wazuh-credentials
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
sizeLimit: 1Mi
|
||||
- name: wazuh-credentials-secret
|
||||
secret:
|
||||
secretName: dashboard-credentials
|
||||
defaultMode: 0400
|
||||
- name: dashboard-config
|
||||
persistentVolumeClaim:
|
||||
claimName: wazuh-dashboard-config
|
||||
- name: dashboard-certs
|
||||
secret:
|
||||
secretName: dashboard-certs
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
initContainers:
|
||||
- name: install-credentials
|
||||
image: 'wazuh/wazuh-dashboard:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'umask 077 && cp /credentials-secret/wazuh-credentials /run/secrets/wazuh-credentials && chmod 0400 /run/secrets/wazuh-credentials'
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials-secret
|
||||
mountPath: /credentials-secret
|
||||
readOnly: true
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
- name: init-dashboard-config
|
||||
image: 'wazuh/wazuh-dashboard:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
if [ ! -f /pvc-config/opensearch_dashboards.yml ]; then
|
||||
cp -a /usr/share/wazuh-dashboard/config/. /pvc-config/
|
||||
fi
|
||||
volumeMounts:
|
||||
- name: dashboard-config
|
||||
mountPath: /pvc-config
|
||||
subPath: config
|
||||
containers:
|
||||
- name: wazuh-dashboard
|
||||
image: 'wazuh/wazuh-dashboard:5.0.0-rc1'
|
||||
resources:
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 1Gi
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
readOnly: true
|
||||
- name: dashboard-config
|
||||
mountPath: /usr/share/wazuh-dashboard/config
|
||||
subPath: config
|
||||
- name: dashboard-certs
|
||||
mountPath: /usr/share/wazuh-dashboard/config/certs/dashboard.pem
|
||||
readOnly: true
|
||||
subPath: dashboard.pem
|
||||
- name: dashboard-certs
|
||||
mountPath: /usr/share/wazuh-dashboard/config/certs/dashboard-key.pem
|
||||
readOnly: true
|
||||
subPath: dashboard-key.pem
|
||||
- name: dashboard-certs
|
||||
mountPath: /usr/share/wazuh-dashboard/config/certs/root-ca.pem
|
||||
subPath: root-ca.pem
|
||||
readOnly: true
|
||||
ports:
|
||||
- containerPort: 443
|
||||
name: dashboard
|
||||
startupProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -k -s -o /dev/null https://localhost:443/app/login
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 12
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -kfsS -o /dev/null https://localhost:443/app/login
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 3
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -k -s -o /dev/null https://localhost:443/app/login
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 3
|
||||
env:
|
||||
- name: OPENSEARCH_HOSTS
|
||||
value: 'https://wazuh-indexer:9200'
|
||||
- name: SERVER_SSL_ENABLED
|
||||
value: "true"
|
||||
- name: SERVER_SSL_CERTIFICATE
|
||||
value: /usr/share/wazuh-dashboard/config/certs/dashboard.pem
|
||||
- name: SERVER_SSL_KEY
|
||||
value: /usr/share/wazuh-dashboard/config/certs/dashboard-key.pem
|
||||
- name: OPENSEARCH_SSL_CERTIFICATE_AUTHORITIES
|
||||
value: /usr/share/wazuh-dashboard/config/certs/root-ca.pem
|
||||
- name: WAZUH_API_URL
|
||||
value: https://wazuh-api
|
||||
@@ -0,0 +1,27 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: dashboard-egress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-dashboard
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9200
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 55000
|
||||
@@ -0,0 +1,20 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh dashboard configuration claim
|
||||
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: wazuh-dashboard-config
|
||||
namespace: wazuh
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Dashboard service
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: dashboard
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-dashboard
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-dashboard
|
||||
ports:
|
||||
- name: dashboard
|
||||
port: 443
|
||||
targetPort: 443
|
||||
@@ -0,0 +1,214 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Indexer StatefulSet: 3 master nodes.
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-indexer
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
serviceName: wazuh-indexer
|
||||
# The indexer nodes form a quorum and have to be recreated together.
|
||||
podManagementPolicy: Parallel
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wazuh-indexer
|
||||
name: wazuh-indexer
|
||||
spec:
|
||||
# No workload talks to the Kubernetes API.
|
||||
automountServiceAccountToken: false
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
# Set the wazuh-indexer volume permissions so the wazuh-indexer user can use it
|
||||
volumes:
|
||||
# The Secret gets the pod's fsGroup and group read, so the service user
|
||||
# could read it: an init container copies it to a root-only file.
|
||||
- name: wazuh-credentials
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
sizeLimit: 1Mi
|
||||
- name: wazuh-credentials-secret
|
||||
secret:
|
||||
secretName: indexer-credentials
|
||||
defaultMode: 0400
|
||||
- name: indexer-certs
|
||||
secret:
|
||||
secretName: indexer-certs
|
||||
defaultMode: 0600
|
||||
initContainers:
|
||||
- name: install-credentials
|
||||
image: 'wazuh/wazuh-indexer:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'umask 077 && cp /credentials-secret/wazuh-credentials /run/secrets/wazuh-credentials && chmod 0400 /run/secrets/wazuh-credentials'
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials-secret
|
||||
mountPath: /credentials-secret
|
||||
readOnly: true
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
- name: volume-mount-hack
|
||||
image: busybox
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 128Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
command:
|
||||
- sh
|
||||
- '-c'
|
||||
- 'chown -R 101:101 /var/lib/wazuh-indexer'
|
||||
volumeMounts:
|
||||
- name: wazuh-indexer
|
||||
mountPath: /var/lib/wazuh-indexer
|
||||
# - name: increase-the-vm-max-map-count
|
||||
# image: busybox
|
||||
# command:
|
||||
# - sysctl
|
||||
# - -w
|
||||
# - vm.max_map_count=262144
|
||||
# securityContext:
|
||||
# privileged: true
|
||||
containers:
|
||||
- name: wazuh-indexer
|
||||
image: 'wazuh/wazuh-indexer:5.0.0-rc1'
|
||||
resources:
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 1564Mi
|
||||
env:
|
||||
- name: bootstrap.memory_lock
|
||||
value: "false"
|
||||
- name: network.host
|
||||
value: "0.0.0.0"
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
# Keep below POD_NAME and POD_NAMESPACE: $(VAR) expands backwards only.
|
||||
- name: network.publish_host
|
||||
value: "$(POD_NAME).wazuh-indexer.$(POD_NAMESPACE).svc.cluster.local"
|
||||
- name: node.name
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: cluster.initial_cluster_manager_nodes
|
||||
value: wazuh-indexer-0
|
||||
# For a 3-node cluster, all nodes should be listed here, if another node is added, it should be included as well
|
||||
- name: discovery.seed_hosts
|
||||
value: "wazuh-indexer-0.wazuh-indexer,wazuh-indexer-1.wazuh-indexer,wazuh-indexer-2.wazuh-indexer"
|
||||
- name: node.max_local_storage_nodes
|
||||
value: "3"
|
||||
- name: plugins.security.allow_default_init_securityindex
|
||||
value: "true"
|
||||
- name: NODES_DN
|
||||
value: CN=indexer,OU=Wazuh,O=Wazuh,L=California,C=US
|
||||
- name: OPENSEARCH_JAVA_OPTS
|
||||
value: '-Xms1g -Xmx1g -Dlog4j2.formatMsgNoLookups=true'
|
||||
- name: DISCOVERY_SERVICE
|
||||
value: wazuh-indexer
|
||||
- name: KUBERNETES_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
securityContext:
|
||||
capabilities:
|
||||
add: ["SYS_CHROOT"]
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
readOnly: true
|
||||
- name: wazuh-indexer
|
||||
mountPath: /var/lib/wazuh-indexer
|
||||
- name: indexer-certs
|
||||
mountPath: /usr/share/wazuh-indexer/config/certs/indexer-key.pem
|
||||
subPath: indexer-key.pem
|
||||
readOnly: true
|
||||
- name: indexer-certs
|
||||
mountPath: /usr/share/wazuh-indexer/config/certs/indexer.pem
|
||||
subPath: indexer.pem
|
||||
readOnly: true
|
||||
- name: indexer-certs
|
||||
mountPath: /usr/share/wazuh-indexer/config/certs/root-ca.pem
|
||||
subPath: root-ca.pem
|
||||
readOnly: true
|
||||
- name: indexer-certs
|
||||
mountPath: /usr/share/wazuh-indexer/config/certs/admin.pem
|
||||
subPath: admin.pem
|
||||
readOnly: true
|
||||
- name: indexer-certs
|
||||
mountPath: /usr/share/wazuh-indexer/config/certs/admin-key.pem
|
||||
subPath: admin-key.pem
|
||||
readOnly: true
|
||||
ports:
|
||||
- containerPort: 9200
|
||||
name: indexer-rest
|
||||
- containerPort: 9300
|
||||
name: indexer-nodes
|
||||
startupProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -fks https://localhost:9200/_plugins/_security/health | grep -q '"status":"UP"'
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 30
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -fks https://localhost:9200/_plugins/_security/health | grep -q '"status":"UP"'
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 5
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- curl -fks https://localhost:9200/_plugins/_security/health | grep -q '"status":"UP"'
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 5
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: wazuh-indexer
|
||||
namespace: indexer-cluster
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
@@ -0,0 +1,26 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: indexer-egress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9300
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9200
|
||||
@@ -0,0 +1,33 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: indexer-ingress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-dashboard
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9200
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9200
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9300
|
||||
@@ -0,0 +1,29 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Indexer service: Communications
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-indexer
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-indexer
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- name: indexer-nodes
|
||||
port: 9300
|
||||
targetPort: 9300
|
||||
- name: indexer-rest
|
||||
port: 9200
|
||||
targetPort: 9200
|
||||
clusterIP: None
|
||||
# The indexer nodes resolve each other before any of them is ready.
|
||||
publishNotReadyAddresses: true
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
# Adds wazuh namespace to all resources.
|
||||
namespace: wazuh
|
||||
|
||||
resources:
|
||||
- base/wazuh-ns.yaml
|
||||
- base/Allow-DNS-np.yaml
|
||||
- base/default-deny-all.yaml
|
||||
|
||||
- wazuh_managers/wazuh-cluster-svc.yaml
|
||||
- wazuh_managers/wazuh-agents-svc.yaml
|
||||
- wazuh_managers/wazuh-events-svc.yaml
|
||||
- wazuh_managers/wazuh-registration-svc.yaml
|
||||
- wazuh_managers/wazuh-api-svc.yaml
|
||||
- wazuh_managers/wazuh-master-sts.yaml
|
||||
- wazuh_managers/wazuh-worker-sts.yaml
|
||||
- wazuh_managers/network-policies/manager-egress.yaml
|
||||
- wazuh_managers/network-policies/manager-egress-external.yaml
|
||||
- wazuh_managers/network-policies/wazuh-master-ingress.yaml
|
||||
- wazuh_managers/network-policies/wazuh-worker-egress.yaml
|
||||
- wazuh_managers/network-policies/falco-agent-ingress.yaml
|
||||
|
||||
- indexer_stack/wazuh-indexer/indexer-svc.yaml
|
||||
- indexer_stack/wazuh-indexer/indexer-egress.yaml
|
||||
- indexer_stack/wazuh-indexer/indexer-ingress.yaml
|
||||
- indexer_stack/wazuh-indexer/cluster/indexer-sts.yaml
|
||||
|
||||
- indexer_stack/wazuh-dashboard/dashboard-pvc.yaml
|
||||
- indexer_stack/wazuh-dashboard/dashboard-deploy.yaml
|
||||
- indexer_stack/wazuh-dashboard/dashboard-svc.yaml
|
||||
- indexer_stack/wazuh-dashboard/dashboard-egress.yaml
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
# Certificate tool - Main functions
|
||||
# Copyright (C) 2015, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
function getHelp() {
|
||||
|
||||
echo -e ""
|
||||
echo -e "NAME"
|
||||
echo -e " wazuh-certs-tool.sh - Manages the creation of certificates of the Wazuh components."
|
||||
echo -e ""
|
||||
echo -e "SYNOPSIS"
|
||||
echo -e " wazuh-certs-tool.sh [OPTIONS]"
|
||||
echo -e ""
|
||||
echo -e "DESCRIPTION"
|
||||
echo -e " -a, --admin-certificates"
|
||||
echo -e " Creates the admin certificates."
|
||||
echo -e ""
|
||||
echo -e " -as, --agent-san <ip|dns>"
|
||||
echo -e " Adds an extra address to the subject alternative name of every"
|
||||
echo -e " agent listener certificate, on top of the ip and dns entries of"
|
||||
echo -e " each manager node in config.yml. Repeat it for more than one."
|
||||
echo -e " It is how to name an address agents dial that no single node"
|
||||
echo -e " owns, such as a load balancer shared by every node of a cluster."
|
||||
echo -e " Must be used along with one of these options: -A, -wm"
|
||||
echo -e ""
|
||||
echo -e " -ap, --api-san <ip|dns>"
|
||||
echo -e " Adds an extra address to the subject alternative name of every"
|
||||
echo -e " Server API certificate, on top of the ip and dns entries of each"
|
||||
echo -e " manager node in config.yml and loopback. Repeat it for more than"
|
||||
echo -e " one. Use it for the address API clients dial, such as a published"
|
||||
echo -e " name or a load balancer in front of the Server API."
|
||||
echo -e " Must be used along with one of these options: -A, -wm"
|
||||
echo -e ""
|
||||
echo -e " -A, --all"
|
||||
echo -e " Creates certificates specified in config.yml and admin certificates."
|
||||
echo -e " If there is no root CA in the CA directory, a new one is created there."
|
||||
echo -e ""
|
||||
echo -e " -ca, --root-ca-certificates"
|
||||
echo -e " Creates the root CA in the CA directory, if it does not exist yet."
|
||||
echo -e ""
|
||||
echo -e " -lb, --load-balancer-certificates"
|
||||
echo -e " Creates the certificates of the load_balancer entries of config.yml."
|
||||
echo -e " Only needed by a proxy that terminates"
|
||||
echo -e " TLS: it is then the certificate agents validate, signed by the same"
|
||||
echo -e " root-ca they pin. A layer 4 passthrough load balancer terminates"
|
||||
echo -e " nothing and needs -as|--agent-san instead."
|
||||
echo -e ""
|
||||
echo -e " -v, --verbose"
|
||||
echo -e " Enables verbose mode."
|
||||
echo -e ""
|
||||
echo -e " -wd, --wazuh-dashboard-certificates"
|
||||
echo -e " Creates the Wazuh dashboard certificates."
|
||||
echo -e ""
|
||||
echo -e " -wi, --wazuh-indexer-certificates"
|
||||
echo -e " Creates the Wazuh indexer certificates."
|
||||
echo -e ""
|
||||
echo -e " -wm, --wazuh-manager-certificates"
|
||||
echo -e " Creates the Wazuh manager certificates."
|
||||
echo -e " Each manager node also gets <name>-remoted.pem and <name>-remoted-key.pem,"
|
||||
echo -e " the certificate of the agent listener (remoted and authd), and"
|
||||
echo -e " <name>-apid.pem and <name>-apid-key.pem, the certificate of the Server API."
|
||||
echo -e ""
|
||||
echo -e " -tmp, --cert_tmp_path </path/to/tmp_dir>"
|
||||
echo -e " Uses this directory to create the certificates, instead of a new one in /tmp."
|
||||
echo -e " The directory must not exist, or must be an empty directory owned by root."
|
||||
echo -e " Must be used along with one of these options: -a, -A, -ca, -wi, -wd, -wm, -lb"
|
||||
echo -e ""
|
||||
echo -e "ROOT CA"
|
||||
echo -e " The root CA is read from $(wazuh_ca_get_dir 2>/dev/null), or from the directory set in WAZUH_CA_DIR."
|
||||
echo -e " Its private key, root-ca.key, stays there and is never copied to the wazuh-certificates directory."
|
||||
echo -e " The tool must be run as root."
|
||||
echo -e ""
|
||||
|
||||
exit 1
|
||||
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
# Set a restrictive umask so new regular files default to 600 and directories to 700,
|
||||
# limiting access to the current user.
|
||||
umask 0077
|
||||
|
||||
# The shared credentials library only creates and reads the root CA as root.
|
||||
common_checkRoot
|
||||
cert_checkOpenSSL
|
||||
|
||||
declare -a agent_san=()
|
||||
declare -a api_san=()
|
||||
|
||||
if [ -n "${1}" ]; then
|
||||
while [ -n "${1}" ]
|
||||
do
|
||||
case "${1}" in
|
||||
"-a"|"--admin-certificates")
|
||||
cert_rejectCAPaths "-a|--admin-certificates" "${2}"
|
||||
cadmin=1
|
||||
shift 1
|
||||
;;
|
||||
"-A"|"--all")
|
||||
cert_rejectCAPaths "-A|--all" "${2}"
|
||||
all=1
|
||||
shift 1
|
||||
;;
|
||||
"-as"|"--agent-san")
|
||||
if [[ -z "${2}" || "${2}" == -* ]]; then
|
||||
common_logger -e "Error on arguments. Probably missing <ip|dns> after -as|--agent-san"
|
||||
getHelp
|
||||
exit 1
|
||||
else
|
||||
agent_san+=("${2}")
|
||||
shift 2
|
||||
fi
|
||||
;;
|
||||
"-ap"|"--api-san")
|
||||
if [[ -z "${2}" || "${2}" == -* ]]; then
|
||||
common_logger -e "Error on arguments. Probably missing <ip|dns> after -ap|--api-san"
|
||||
getHelp
|
||||
exit 1
|
||||
else
|
||||
api_san+=("${2}")
|
||||
shift 2
|
||||
fi
|
||||
;;
|
||||
"-ca"|"--root-ca-certificates"|"--root-ca-certificate")
|
||||
ca=1
|
||||
shift 1
|
||||
;;
|
||||
"-lb"|"--load-balancer-certificates")
|
||||
cert_rejectCAPaths "-lb|--load-balancer-certificates" "${2}"
|
||||
clb=1
|
||||
shift 1
|
||||
;;
|
||||
"-h"|"--help")
|
||||
getHelp
|
||||
;;
|
||||
"-v"|"--verbose")
|
||||
debugEnabled=1
|
||||
shift 1
|
||||
;;
|
||||
"-wd"|"--wazuh-dashboard-certificates")
|
||||
cert_rejectCAPaths "-wd|--wazuh-dashboard-certificates" "${2}"
|
||||
cdashboard=1
|
||||
shift 1
|
||||
;;
|
||||
"-wi"|"--wazuh-indexer-certificates")
|
||||
cert_rejectCAPaths "-wi|--wazuh-indexer-certificates" "${2}"
|
||||
cindexer=1
|
||||
shift 1
|
||||
;;
|
||||
"-wm"|"--wazuh-manager-certificates")
|
||||
cert_rejectCAPaths "-wm|--wazuh-manager-certificates" "${2}"
|
||||
cmanager=1
|
||||
shift 1
|
||||
;;
|
||||
"-tmp"|"--cert_tmp_path")
|
||||
if [[ -n "${3}" || ( "${cadmin}" == 1 || "${all}" == 1 || "${ca}" == 1 || "${cdashboard}" == 1 || "${cindexer}" == 1 || "${cmanager}" == 1 || "${clb}" == 1 ) ]]; then
|
||||
if [[ -z "${2}" || ! "${2}" == /* ]]; then
|
||||
common_logger -e "Error on arguments. Probably missing </path/to/tmp_dir> or path does not start with '/'."
|
||||
getHelp
|
||||
exit 1
|
||||
else
|
||||
cert_tmp_path="${2}"
|
||||
shift 2
|
||||
fi
|
||||
else
|
||||
common_logger -e "Error: -tmp must be used along with one of these options: -a, -A, -ca, -wi, -wd, -wm, -lb"
|
||||
getHelp
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: ${1}"
|
||||
getHelp
|
||||
esac
|
||||
done
|
||||
|
||||
common_logger "Verbose logging redirected to ${logfile}"
|
||||
|
||||
cert_validateAgentSan
|
||||
cert_validateApiSan
|
||||
|
||||
if [[ -d "${base_path}"/wazuh-certificates ]]; then
|
||||
if [ -n "$(ls -A "${base_path}"/wazuh-certificates)" ]; then
|
||||
common_logger -e "Directory wazuh-certificates already exists in the same path as the script. Please, remove the certs directory to create new certificates."
|
||||
exit 1
|
||||
fi
|
||||
# Removed so the temporary directory is moved to this name and not inside it.
|
||||
rmdir "${base_path}"/wazuh-certificates
|
||||
fi
|
||||
|
||||
cert_createTmpDir
|
||||
|
||||
cert_readConfig
|
||||
|
||||
if [[ -n "${all}" || -n "${cmanager}" ]]; then
|
||||
cert_checkListenerReachability "warning"
|
||||
fi
|
||||
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
debug="2>&1 | tee -a ${logfile}"
|
||||
fi
|
||||
|
||||
if [[ -n "${cadmin}" ]]; then
|
||||
cert_checkRootCA
|
||||
cert_generateAdmincertificate
|
||||
common_logger "Admin certificates created."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${all}" ]]; then
|
||||
cert_checkRootCA "create"
|
||||
cert_generateAdmincertificate
|
||||
common_logger "Admin certificates created."
|
||||
if cert_generateIndexercertificates; then
|
||||
common_logger "Wazuh indexer certificates created."
|
||||
fi
|
||||
if cert_generateManagercertificates; then
|
||||
common_logger "Wazuh manager certificates created."
|
||||
fi
|
||||
if cert_generateDashboardcertificates; then
|
||||
common_logger "Wazuh dashboard certificates created."
|
||||
fi
|
||||
# Only when config.yml carries a load_balancer section: it is optional and
|
||||
# its absence is not an error.
|
||||
if cert_generateLoadbalancercertificates; then
|
||||
common_logger "Load balancer certificates created."
|
||||
fi
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
cert_verifyRemotedcertificates "${base_path}/wazuh-certificates"
|
||||
cert_verifyLoadbalancercertificates "${base_path}/wazuh-certificates"
|
||||
fi
|
||||
|
||||
if [[ -n "${ca}" ]]; then
|
||||
cert_generateRootCAcertificate
|
||||
cp "${cert_ca_dir}/root-ca.pem" "${cert_tmp_path}/root-ca.pem"
|
||||
common_logger "The root CA is in ${cert_ca_dir}. Its private key, root-ca.key, stays there."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${cindexer}" ]]; then
|
||||
if [ ${#indexer_node_names[@]} -gt 0 ]; then
|
||||
cert_checkRootCA
|
||||
cert_generateIndexercertificates
|
||||
common_logger "Wazuh indexer certificates created."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
else
|
||||
common_logger -e "Indexer node not present in config.yml."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${cmanager}" ]]; then
|
||||
if [ ${#manager_node_names[@]} -gt 0 ]; then
|
||||
cert_checkRootCA
|
||||
cert_generateManagercertificates
|
||||
common_logger "Wazuh manager certificates created."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
cert_verifyRemotedcertificates "${base_path}/wazuh-certificates"
|
||||
else
|
||||
common_logger -e "Manager node not present in config.yml."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${clb}" ]]; then
|
||||
if [ ${#lb_node_names[@]} -gt 0 ]; then
|
||||
cert_checkRootCA
|
||||
cert_generateLoadbalancercertificates
|
||||
common_logger "Load balancer certificates created."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
cert_verifyLoadbalancercertificates "${base_path}/wazuh-certificates"
|
||||
else
|
||||
common_logger -e "Load balancer section not present in config.yml."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${cdashboard}" ]]; then
|
||||
if [ ${#dashboard_node_names[@]} -gt 0 ]; then
|
||||
cert_checkRootCA
|
||||
cert_generateDashboardcertificates
|
||||
common_logger "Wazuh dashboard certificates created."
|
||||
cert_cleanFiles
|
||||
cert_setpermisions
|
||||
if [ -n "${debugEnabled}" ]; then
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates"
|
||||
else
|
||||
mv "${cert_tmp_path}" "${base_path}/wazuh-certificates" > /dev/null 2>&1
|
||||
fi
|
||||
else
|
||||
common_logger -e "Dashboard node not present in config.yml."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
getHelp
|
||||
fi
|
||||
|
||||
}
|
||||
@@ -0,0 +1,957 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Shared credential helpers for Wazuh package scripts.
|
||||
#
|
||||
# This file is a library. Source it with:
|
||||
#
|
||||
# . /usr/share/wazuh-<component>/lib/wazuh-credentials.sh
|
||||
#
|
||||
# Importing it performs no action and does not change the caller's shell
|
||||
# options, umask, IFS, working directory, or traps.
|
||||
#
|
||||
# Public functions and return values
|
||||
# ----------------------------------
|
||||
# wazuh_base_get_dir / wazuh_env_get_file
|
||||
# Base: process WAZUH_BASE_DIR or /etc/wazuh. ENV: <base>/credentials.env.
|
||||
# The base cannot come from that file (circular lookup). Empty is invalid.
|
||||
# Getters do not create anything; writers create missing parents safely.
|
||||
# All helpers on a host MUST use the same base to share the same lock.
|
||||
# wazuh_ca_get_dir
|
||||
# Prints the resolved CA directory. Resolution order is the value in
|
||||
# <base>/credentials.env, then WAZUH_CA_DIR from the process
|
||||
# environment, with <base>/ca as default. Empty is invalid.
|
||||
# WAZUH_CA_DIR moves only the CA, never the ENV or the lock.
|
||||
#
|
||||
# wazuh_ca_validate
|
||||
# Returns 0 for a valid anchor, with or without its matching private key.
|
||||
# Returns non-zero for an absent, partial, invalid, or insecure CA.
|
||||
#
|
||||
# wazuh_ca_ensure
|
||||
# Creates root-ca.pem and root-ca.key only when both are absent. Existing
|
||||
# material is validated and never regenerated. An anchor without a key is
|
||||
# a valid external CA; a key without an anchor is an error.
|
||||
#
|
||||
# wazuh_env_get NAME
|
||||
# Reads data only; unquoted values or single/double quoted single lines.
|
||||
# Writes require a newline-terminated file; multiline values are rejected.
|
||||
# Prints the last value assigned to NAME in credentials.env without
|
||||
# sourcing the file. Returns 0 when found, 1 when absent, and 2 when the
|
||||
# file or request is invalid.
|
||||
#
|
||||
# wazuh_env_set NAME VALUE
|
||||
# Adds or replaces NAME inside the Wazuh-managed block only.
|
||||
#
|
||||
# wazuh_env_unset NAME
|
||||
# Removes NAME from the Wazuh-managed block only.
|
||||
#
|
||||
# wazuh_password_generate
|
||||
# Prints a 32-character password generated from /dev/urandom, drawn from
|
||||
# the password character set below, with at least one character of each
|
||||
# of its four classes.
|
||||
#
|
||||
# wazuh_password_validate VALUE
|
||||
# Enforces 12-64 characters drawn only from the password character set
|
||||
# A-Z a-z 0-9 . , _ + : @ % ^ = ~ -, with at least one uppercase letter,
|
||||
# one lowercase letter, one digit and one symbol. The rejected value is
|
||||
# never included in diagnostics.
|
||||
#
|
||||
# The library deliberately uses flock(1), GNU stat(1), OpenSSL, awk, and the
|
||||
# usual Linux userland (including ln -T) on Debian- and RPM-based systems.
|
||||
# Capture password output; do not use shell xtrace around secret operations.
|
||||
# Pin BOTH helper files to matching versions: the manager uses private helpers.
|
||||
|
||||
_wazuh_error() (
|
||||
printf '%s\n' "wazuh-credentials: $*" >&2
|
||||
)
|
||||
|
||||
# Notices go to stderr too, so they never mix with the values callers capture.
|
||||
_wazuh_info() (
|
||||
printf '%s\n' "wazuh-credentials: $*" >&2
|
||||
)
|
||||
|
||||
wazuh_base_get_dir() (
|
||||
_wazuh_base=${WAZUH_BASE_DIR-/etc/wazuh}
|
||||
_wazuh_validate_absolute_path "$_wazuh_base" || return 1
|
||||
printf '%s\n' "$_wazuh_base"
|
||||
)
|
||||
|
||||
wazuh_env_get_file() (
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
printf '%s/credentials.env\n' "$_wazuh_base"
|
||||
)
|
||||
|
||||
# Validate from the root down; never traverse an unchecked symlink first.
|
||||
# Missing components are allowed by this read-only helper.
|
||||
_wazuh_check_existing_tree() (
|
||||
[ "$1" = / ] && { _wazuh_validate_directory_node / ''; return $?; }
|
||||
_wazuh_parent=${1%/*}
|
||||
[ -n "$_wazuh_parent" ] || _wazuh_parent=/
|
||||
_wazuh_check_existing_tree "$_wazuh_parent" || return 1
|
||||
if [ -e "$1" ] || [ -L "$1" ]; then
|
||||
_wazuh_validate_directory_node "$1" '' || return 1
|
||||
fi
|
||||
)
|
||||
|
||||
# Create one component at a time, never chmod/chown an existing directory.
|
||||
# Parent validation excludes group/world writers, including sticky /tmp.
|
||||
_wazuh_make_secure_tree() (
|
||||
[ "$(id -u)" = 0 ] || { _wazuh_error 'root is required'; return 1; }
|
||||
[ "$1" = / ] && { _wazuh_validate_directory_node / ''; return $?; }
|
||||
_wazuh_parent=${1%/*}
|
||||
[ -n "$_wazuh_parent" ] || _wazuh_parent=/
|
||||
_wazuh_make_secure_tree "$_wazuh_parent" || return 1
|
||||
if [ ! -e "$1" ] && [ ! -L "$1" ]; then
|
||||
# Another cooperating process may create it first; always revalidate.
|
||||
(umask 077; mkdir -m 0700 -- "$1") 2>/dev/null || {
|
||||
[ -d "$1" ] || { _wazuh_error "cannot create directory: $1"; return 1; }
|
||||
}
|
||||
fi
|
||||
_wazuh_validate_directory_node "$1" ''
|
||||
)
|
||||
|
||||
_wazuh_validate_name() (
|
||||
case ${1-} in
|
||||
''|[0-9]*|*[!ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_]*)
|
||||
_wazuh_error "invalid environment variable name"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
_wazuh_validate_absolute_path() (
|
||||
_wazuh_path=${1-}
|
||||
|
||||
case $_wazuh_path in
|
||||
''|/)
|
||||
_wazuh_error "directory must be a non-empty absolute path other than /"
|
||||
return 1
|
||||
;;
|
||||
/*) ;;
|
||||
*)
|
||||
_wazuh_error "directory must be an absolute path"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case $_wazuh_path in
|
||||
*'//'*)
|
||||
_wazuh_error "directory must not contain repeated slashes"
|
||||
return 1
|
||||
;;
|
||||
*/./*|*/.|*/../*|*/..)
|
||||
_wazuh_error "directory must not contain . or .. path components"
|
||||
return 1
|
||||
;;
|
||||
*/)
|
||||
_wazuh_error "directory must not end with a slash"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case $_wazuh_path in
|
||||
*"
|
||||
"*)
|
||||
_wazuh_error "directory must not contain a newline"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
_wazuh_cr=$(printf '\r')
|
||||
case $_wazuh_path in
|
||||
*"$_wazuh_cr"*)
|
||||
_wazuh_error "directory must not contain a carriage return"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
_wazuh_validate_directory_node() (
|
||||
_wazuh_path=${1-}
|
||||
_wazuh_exact_mode=${2-}
|
||||
|
||||
if [ -L "$_wazuh_path" ]; then
|
||||
_wazuh_error "refusing symbolic-link directory: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -d "$_wazuh_path" ]; then
|
||||
_wazuh_error "not a directory: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_owner=$(stat -c '%u:%g' -- "$_wazuh_path" 2>/dev/null) || {
|
||||
_wazuh_error "cannot inspect directory: $_wazuh_path"
|
||||
return 1
|
||||
}
|
||||
if [ "$_wazuh_owner" != '0:0' ]; then
|
||||
_wazuh_error "directory must be owned by root:root: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_mode=$(stat -c '%a' -- "$_wazuh_path" 2>/dev/null) || return 1
|
||||
if [ -n "$_wazuh_exact_mode" ]; then
|
||||
if [ "$_wazuh_mode" != "$_wazuh_exact_mode" ]; then
|
||||
_wazuh_error "directory $_wazuh_path must have mode $_wazuh_exact_mode (found $_wazuh_mode)"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
_wazuh_world=${_wazuh_mode#${_wazuh_mode%?}}
|
||||
_wazuh_prefix=${_wazuh_mode%?}
|
||||
_wazuh_group=${_wazuh_prefix#${_wazuh_prefix%?}}
|
||||
case $_wazuh_group$_wazuh_world in
|
||||
*[2367]*)
|
||||
_wazuh_error "directory must not be group- or world-writable: $_wazuh_path"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
_wazuh_validate_ancestors() (
|
||||
_wazuh_parent=${1%/*}
|
||||
[ -n "$_wazuh_parent" ] || _wazuh_parent=/
|
||||
_wazuh_check_existing_tree "$_wazuh_parent" || return 1
|
||||
_wazuh_validate_directory_node "$_wazuh_parent" ''
|
||||
)
|
||||
_wazuh_validate_regular_file() (
|
||||
_wazuh_path=${1-}
|
||||
_wazuh_required_mode=${2-}
|
||||
|
||||
if [ -L "$_wazuh_path" ]; then
|
||||
_wazuh_error "refusing symbolic-link file: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f "$_wazuh_path" ]; then
|
||||
_wazuh_error "not a regular file: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_owner=$(stat -c '%u:%g' -- "$_wazuh_path" 2>/dev/null) || {
|
||||
_wazuh_error "cannot inspect file: $_wazuh_path"
|
||||
return 1
|
||||
}
|
||||
if [ "$_wazuh_owner" != '0:0' ]; then
|
||||
_wazuh_error "file must be owned by root:root: $_wazuh_path"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_mode=$(stat -c '%a' -- "$_wazuh_path" 2>/dev/null) || return 1
|
||||
if [ "$_wazuh_mode" != "$_wazuh_required_mode" ]; then
|
||||
_wazuh_error "file $_wazuh_path must have mode $_wazuh_required_mode (found $_wazuh_mode)"
|
||||
return 1
|
||||
fi
|
||||
)
|
||||
|
||||
_wazuh_restorecon() (
|
||||
_wazuh_path=${1-}
|
||||
if command -v restorecon >/dev/null 2>&1; then
|
||||
restorecon "$_wazuh_path" >/dev/null 2>&1 || {
|
||||
_wazuh_error "failed to restore the SELinux context of $_wazuh_path"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
)
|
||||
|
||||
_wazuh_validate_base_dir_if_present() (
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
_wazuh_check_existing_tree "$_wazuh_base" || return 1
|
||||
if [ -e "$_wazuh_base" ] || [ -L "$_wazuh_base" ]; then
|
||||
_wazuh_validate_directory_node "$_wazuh_base" 700 || return 1
|
||||
fi
|
||||
)
|
||||
|
||||
_wazuh_ensure_base_dir() (
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
_wazuh_make_secure_tree "$_wazuh_base" || return 1
|
||||
_wazuh_validate_directory_node "$_wazuh_base" 700 || return 1
|
||||
_wazuh_restorecon "$_wazuh_base"
|
||||
)
|
||||
|
||||
_wazuh_validate_credentials_file() (
|
||||
_wazuh_validate_base_dir_if_present || return 1
|
||||
_wazuh_file=$(wazuh_env_get_file) || return 1
|
||||
_wazuh_validate_regular_file "$_wazuh_file" 600
|
||||
)
|
||||
|
||||
_wazuh_with_lock() (
|
||||
_wazuh_ensure_base_dir || return 1
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
_wazuh_lock=$_wazuh_base/.credentials.lock
|
||||
|
||||
if [ -L "$_wazuh_lock" ]; then
|
||||
_wazuh_error "refusing symbolic-link lock file: $_wazuh_lock"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -e "$_wazuh_lock" ]; then
|
||||
(umask 077; set -C; : >"$_wazuh_lock") 2>/dev/null || {
|
||||
[ -e "$_wazuh_lock" ] || return 1
|
||||
}
|
||||
_wazuh_restorecon "$_wazuh_lock" || return 1
|
||||
fi
|
||||
_wazuh_validate_regular_file "$_wazuh_lock" 600 || return 1
|
||||
|
||||
exec 9<>"$_wazuh_lock" || {
|
||||
_wazuh_error "cannot open lock file: $_wazuh_lock"
|
||||
return 1
|
||||
}
|
||||
flock -x 9 || {
|
||||
_wazuh_error "cannot acquire lock: $_wazuh_lock"
|
||||
return 1
|
||||
}
|
||||
|
||||
"$@"
|
||||
)
|
||||
|
||||
wazuh_env_get() (
|
||||
[ "$#" -eq 1 ] || { _wazuh_error 'usage: wazuh_env_get NAME'; return 2; }
|
||||
_wazuh_name=${1-}
|
||||
_wazuh_validate_name "$_wazuh_name" || return 2
|
||||
_wazuh_file=$(wazuh_env_get_file) || return 2
|
||||
if [ ! -e "$_wazuh_file" ] && [ ! -L "$_wazuh_file" ]; then
|
||||
_wazuh_validate_base_dir_if_present || return 2
|
||||
return 1
|
||||
fi
|
||||
_wazuh_validate_credentials_file || return 2
|
||||
|
||||
awk -v wanted="$_wazuh_name" '
|
||||
function trim_left(s) { sub(/^[[:space:]]+/, "", s); return s }
|
||||
function trim_right(s) { sub(/[[:space:]]+$/, "", s); return s }
|
||||
function decode_double(s, out, i, c, n) {
|
||||
out = ""
|
||||
for (i = 1; i <= length(s); i++) {
|
||||
c = substr(s, i, 1)
|
||||
if (c == "\\" && i < length(s)) {
|
||||
n = substr(s, i + 1, 1)
|
||||
if (n == "\\" || n == "\"" || n == "$" || n == "`") {
|
||||
out = out n
|
||||
i++
|
||||
continue
|
||||
}
|
||||
}
|
||||
out = out c
|
||||
}
|
||||
return out
|
||||
}
|
||||
{
|
||||
line = trim_left($0)
|
||||
if (line == "" || substr(line, 1, 1) == "#")
|
||||
next
|
||||
|
||||
equal = index(line, "=")
|
||||
if (!equal)
|
||||
next
|
||||
|
||||
name = trim_right(substr(line, 1, equal - 1))
|
||||
if (name != wanted)
|
||||
next
|
||||
|
||||
value = trim_left(substr(line, equal + 1))
|
||||
value = trim_right(value)
|
||||
if ((substr(value, 1, 1) == "\047" && substr(value, length(value), 1) != "\047") ||
|
||||
(substr(value, 1, 1) == "\"" && substr(value, length(value), 1) != "\"")) {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
if (length(value) >= 2 && substr(value, 1, 1) == "\047" &&
|
||||
substr(value, length(value), 1) == "\047") {
|
||||
value = substr(value, 2, length(value) - 2)
|
||||
} else if (length(value) >= 2 && substr(value, 1, 1) == "\"" &&
|
||||
substr(value, length(value), 1) == "\"") {
|
||||
value = decode_double(substr(value, 2, length(value) - 2))
|
||||
}
|
||||
result = value
|
||||
found = 1
|
||||
}
|
||||
END {
|
||||
if (!found)
|
||||
exit (bad ? 2 : 1)
|
||||
if (bad) exit 2
|
||||
print result
|
||||
}
|
||||
' "$_wazuh_file"
|
||||
)
|
||||
|
||||
_wazuh_env_mutate_locked() (
|
||||
_wazuh_action=${1-}
|
||||
_wazuh_name=${2-}
|
||||
_wazuh_value_file=${3-}
|
||||
_wazuh_file=$(wazuh_env_get_file) || return 1
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
|
||||
if [ -e "$_wazuh_file" ] || [ -L "$_wazuh_file" ]; then
|
||||
_wazuh_validate_credentials_file || return 1
|
||||
if [ -s "$_wazuh_file" ] && [ "$(tail -c 1 -- "$_wazuh_file" | od -An -tu1 | tr -d '[:space:]')" != 10 ]; then
|
||||
_wazuh_error 'credentials.env must end with a newline; refusing to alter operator bytes'
|
||||
return 1
|
||||
fi
|
||||
_wazuh_source=$_wazuh_file
|
||||
else
|
||||
if [ "$_wazuh_action" = unset ]; then
|
||||
return 0
|
||||
fi
|
||||
_wazuh_source=/dev/null
|
||||
fi
|
||||
|
||||
_wazuh_tmp=$(mktemp "$_wazuh_base/.credentials.env.XXXXXX") || {
|
||||
_wazuh_error 'cannot create a temporary credentials file'
|
||||
return 1
|
||||
}
|
||||
trap 'rm -f -- "$_wazuh_tmp"' 0
|
||||
trap 'return 130' 1 2 3 15
|
||||
|
||||
if ! awk -v action="$_wazuh_action" -v wanted="$_wazuh_name" \
|
||||
-v value_file="$_wazuh_value_file" '
|
||||
function lhs_name(line, equal, lhs) {
|
||||
sub(/^[[:space:]]+/, "", line)
|
||||
if (substr(line, 1, 1) == "#")
|
||||
return ""
|
||||
equal = index(line, "=")
|
||||
if (!equal)
|
||||
return ""
|
||||
lhs = substr(line, 1, equal - 1)
|
||||
sub(/[[:space:]]+$/, "", lhs)
|
||||
return lhs
|
||||
}
|
||||
function quote_value(s, out, i, c) {
|
||||
# The password alphabet needs no quoting; anything else is still escaped.
|
||||
if (s ~ /^[A-Za-z0-9.,_+:@%^=~-]*$/)
|
||||
return s
|
||||
out = "\""
|
||||
for (i = 1; i <= length(s); i++) {
|
||||
c = substr(s, i, 1)
|
||||
if (c == "\\" || c == "\"" || c == "$" || c == "`")
|
||||
out = out "\\"
|
||||
out = out c
|
||||
}
|
||||
return out "\""
|
||||
}
|
||||
function print_header( i) {
|
||||
for (i = 1; i <= header_lines; i++)
|
||||
print header[i]
|
||||
}
|
||||
BEGIN {
|
||||
begin_marker = "# >>> wazuh generated — do not edit <<<"
|
||||
end_marker = "# >>> end wazuh generated <<<"
|
||||
# The header follows the begin marker. Every header line, and the ones of earlier
|
||||
# versions, is dropped from the block and printed again, so it is never duplicated.
|
||||
header_lines = split("" \
|
||||
"# Written by the Wazuh packages and tools. Editing a value here changes nothing.\n" \
|
||||
"# To change a password: wazuh-passwords-tool.sh -u <user>\n" \
|
||||
"# A host only holds the keys of the components installed on it.\n" \
|
||||
"#\n" \
|
||||
"# User Key Used for\n" \
|
||||
"# Logins:\n" \
|
||||
"# admin WAZUH_INDEXER_ADMIN_PASSWORD Wazuh dashboard (web UI) and Wazuh indexer API\n" \
|
||||
"# wazuh WAZUH_MANAGER_API_PASSWORD Wazuh server API (curl, scripts)\n" \
|
||||
"# Service accounts the components connect with, not logins:\n" \
|
||||
"# kibanaserver WAZUH_INDEXER_KIBANASERVER_PASSWORD dashboard to indexer\n" \
|
||||
"# wazuh-manager WAZUH_INDEXER_MANAGER_PASSWORD manager to indexer\n" \
|
||||
"# wazuh-internal-client WAZUH_MANAGER_WUI_PASSWORD dashboard to server API\n" \
|
||||
"#", header, "\n")
|
||||
for (i = 1; i <= header_lines; i++)
|
||||
known_header[header[i]] = 1
|
||||
# Header lines of earlier versions.
|
||||
old_header_lines = split("" \
|
||||
"# Editing a value here does not change the deployment.\n" \
|
||||
"# To rotate, use wazuh-passwords-tool.sh.\n" \
|
||||
"# admin: login of the Wazuh dashboard and administrator of the indexer\n" \
|
||||
"# User Key Used for\n" \
|
||||
"# admin WAZUH_INDEXER_ADMIN_PASSWORD Wazuh dashboard (web UI) and Wazuh indexer API\n" \
|
||||
"# wazuh WAZUH_MANAGER_API_PASSWORD Wazuh server API (curl, scripts)\n" \
|
||||
"# kibanaserver WAZUH_INDEXER_KIBANASERVER_PASSWORD dashboard to indexer\n" \
|
||||
"# wazuh-manager WAZUH_INDEXER_MANAGER_PASSWORD manager to indexer\n" \
|
||||
"# wazuh-wui WAZUH_MANAGER_WUI_PASSWORD dashboard to server API", old_header, "\n")
|
||||
for (i = 1; i <= old_header_lines; i++)
|
||||
known_header[old_header[i]] = 1
|
||||
value = ""
|
||||
if (action == "set") {
|
||||
read_status = (getline value < value_file)
|
||||
close(value_file)
|
||||
if (read_status < 0) {
|
||||
print "wazuh-credentials: cannot read temporary value" > "/dev/stderr"
|
||||
exit 42
|
||||
}
|
||||
assignment = wanted "=" quote_value(value)
|
||||
}
|
||||
}
|
||||
$0 == begin_marker {
|
||||
if (inside || begin_count > 0) {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
begin_count++
|
||||
inside = 1
|
||||
print
|
||||
print_header()
|
||||
next
|
||||
}
|
||||
$0 == end_marker {
|
||||
if (!inside || end_count > 0) {
|
||||
bad = 1
|
||||
next
|
||||
}
|
||||
if (action == "set" && !written) {
|
||||
print assignment
|
||||
written = 1
|
||||
}
|
||||
end_count++
|
||||
inside = 0
|
||||
print
|
||||
next
|
||||
}
|
||||
{
|
||||
if (inside && ($0 in known_header))
|
||||
next
|
||||
if (inside && lhs_name($0) == wanted) {
|
||||
if (action == "set" && !written) {
|
||||
print assignment
|
||||
written = 1
|
||||
}
|
||||
next
|
||||
}
|
||||
print
|
||||
}
|
||||
END {
|
||||
if (inside || begin_count != end_count || begin_count > 1 || bad) {
|
||||
print "wazuh-credentials: malformed Wazuh-managed block" > "/dev/stderr"
|
||||
exit 42
|
||||
}
|
||||
if (begin_count == 0 && action == "set") {
|
||||
if (NR > 0)
|
||||
print ""
|
||||
print begin_marker
|
||||
print_header()
|
||||
print assignment
|
||||
print end_marker
|
||||
}
|
||||
}
|
||||
' "$_wazuh_source" >"$_wazuh_tmp"; then
|
||||
_wazuh_error 'credentials file was not modified'
|
||||
return 1
|
||||
fi
|
||||
|
||||
chown root:root "$_wazuh_tmp" || return 1
|
||||
chmod 0600 "$_wazuh_tmp" || return 1
|
||||
mv -f -- "$_wazuh_tmp" "$_wazuh_file" || {
|
||||
_wazuh_error 'cannot replace credentials.env atomically'
|
||||
return 1
|
||||
}
|
||||
trap - 0 1 2 3 15
|
||||
_wazuh_restorecon "$_wazuh_file" || return 1
|
||||
_wazuh_validate_credentials_file
|
||||
)
|
||||
|
||||
wazuh_env_set() (
|
||||
if [ "$#" -ne 2 ]; then
|
||||
_wazuh_error 'usage: wazuh_env_set NAME VALUE'
|
||||
return 1
|
||||
fi
|
||||
_wazuh_name=$1
|
||||
_wazuh_value=$2
|
||||
_wazuh_validate_name "$_wazuh_name" || return 1
|
||||
|
||||
case $_wazuh_value in
|
||||
*"
|
||||
"*)
|
||||
_wazuh_error "value for $_wazuh_name must not contain a newline"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
_wazuh_cr=$(printf '\r')
|
||||
case $_wazuh_value in
|
||||
*"$_wazuh_cr"*)
|
||||
_wazuh_error "value for $_wazuh_name must not contain a carriage return"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
_wazuh_ensure_base_dir || return 1
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
_wazuh_value_file=$(mktemp "$_wazuh_base/.credential-value.XXXXXX") || {
|
||||
_wazuh_error 'cannot create a temporary value file'
|
||||
return 1
|
||||
}
|
||||
trap 'rm -f -- "$_wazuh_value_file"' 0
|
||||
trap 'return 130' 1 2 3 15
|
||||
chmod 0600 "$_wazuh_value_file" || return 1
|
||||
printf '%s' "$_wazuh_value" >"$_wazuh_value_file" || return 1
|
||||
|
||||
_wazuh_with_lock _wazuh_env_mutate_locked set "$_wazuh_name" "$_wazuh_value_file"
|
||||
)
|
||||
|
||||
wazuh_env_unset() (
|
||||
if [ "$#" -ne 1 ]; then
|
||||
_wazuh_error 'usage: wazuh_env_unset NAME'
|
||||
return 1
|
||||
fi
|
||||
_wazuh_validate_name "$1" || return 1
|
||||
_wazuh_with_lock _wazuh_env_mutate_locked unset "$1" ''
|
||||
)
|
||||
|
||||
wazuh_ca_get_dir() (
|
||||
_wazuh_ca_dir=
|
||||
_wazuh_ca_dir_is_set=0
|
||||
|
||||
_wazuh_status=0
|
||||
_wazuh_file_value=$(wazuh_env_get WAZUH_CA_DIR) || _wazuh_status=$?
|
||||
case $_wazuh_status in
|
||||
0)
|
||||
_wazuh_ca_dir=$_wazuh_file_value
|
||||
_wazuh_ca_dir_is_set=1
|
||||
;;
|
||||
1) ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
|
||||
if [ "${WAZUH_CA_DIR+x}" = x ]; then
|
||||
_wazuh_ca_dir=${WAZUH_CA_DIR-}
|
||||
_wazuh_ca_dir_is_set=1
|
||||
fi
|
||||
|
||||
if [ "$_wazuh_ca_dir_is_set" -eq 0 ]; then
|
||||
_wazuh_base=$(wazuh_base_get_dir) || return 1
|
||||
_wazuh_ca_dir=$_wazuh_base/ca
|
||||
fi
|
||||
|
||||
_wazuh_validate_absolute_path "$_wazuh_ca_dir" || return 1
|
||||
printf '%s\n' "$_wazuh_ca_dir"
|
||||
)
|
||||
|
||||
_wazuh_validate_ca_files() (
|
||||
_wazuh_ca_dir=${1-}
|
||||
_wazuh_cert=$_wazuh_ca_dir/root-ca.pem
|
||||
_wazuh_key=$_wazuh_ca_dir/root-ca.key
|
||||
|
||||
_wazuh_validate_ancestors "$_wazuh_ca_dir" || return 1
|
||||
_wazuh_validate_directory_node "$_wazuh_ca_dir" 700 || return 1
|
||||
|
||||
_wazuh_cert_exists=0
|
||||
_wazuh_key_exists=0
|
||||
if [ -e "$_wazuh_cert" ] || [ -L "$_wazuh_cert" ]; then
|
||||
_wazuh_cert_exists=1
|
||||
fi
|
||||
if [ -e "$_wazuh_key" ] || [ -L "$_wazuh_key" ]; then
|
||||
_wazuh_key_exists=1
|
||||
fi
|
||||
|
||||
if [ "$_wazuh_cert_exists" -eq 0 ] && [ "$_wazuh_key_exists" -eq 0 ]; then
|
||||
_wazuh_error "CA material is absent from $_wazuh_ca_dir"
|
||||
return 1
|
||||
fi
|
||||
if [ "$_wazuh_cert_exists" -eq 0 ]; then
|
||||
_wazuh_error "root-ca.key exists without root-ca.pem in $_wazuh_ca_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_validate_regular_file "$_wazuh_cert" 644 || return 1
|
||||
if ! openssl x509 -in "$_wazuh_cert" -noout >/dev/null 2>&1; then
|
||||
_wazuh_error "invalid X.509 certificate: $_wazuh_cert"
|
||||
return 1
|
||||
fi
|
||||
if ! openssl x509 -in "$_wazuh_cert" -checkend 0 -noout >/dev/null 2>&1; then
|
||||
_wazuh_error "expired X.509 certificate: $_wazuh_cert"
|
||||
return 1
|
||||
fi
|
||||
_wazuh_text=$(LC_ALL=C openssl x509 -in "$_wazuh_cert" -noout -text 2>/dev/null) || return 1
|
||||
case $_wazuh_text in
|
||||
*'CA:TRUE'*) ;;
|
||||
*) _wazuh_error "certificate is not a CA: $_wazuh_cert"; return 1 ;;
|
||||
esac
|
||||
openssl verify -CAfile "$_wazuh_cert" "$_wazuh_cert" >/dev/null 2>&1 || {
|
||||
_wazuh_error "CA certificate is not currently valid: $_wazuh_cert"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Anchor-only is the expected state for an externally managed CA.
|
||||
if [ "$_wazuh_key_exists" -eq 0 ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
_wazuh_validate_regular_file "$_wazuh_key" 400 || return 1
|
||||
if ! openssl pkey -in "$_wazuh_key" -passin pass: -check -noout </dev/null >/dev/null 2>&1; then
|
||||
_wazuh_error "invalid private key: $_wazuh_key"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_wazuh_cert_pub=$(mktemp "$_wazuh_ca_dir/.cert-pub.XXXXXX") || return 1
|
||||
_wazuh_key_pub=$(mktemp "$_wazuh_ca_dir/.key-pub.XXXXXX") || {
|
||||
rm -f -- "$_wazuh_cert_pub"
|
||||
return 1
|
||||
}
|
||||
trap 'rm -f -- "$_wazuh_cert_pub" "$_wazuh_key_pub"' 0
|
||||
trap 'return 130' 1 2 3 15
|
||||
chmod 0600 "$_wazuh_cert_pub" "$_wazuh_key_pub" || return 1
|
||||
|
||||
openssl x509 -in "$_wazuh_cert" -pubkey -noout >"$_wazuh_cert_pub" 2>/dev/null || return 1
|
||||
openssl pkey -in "$_wazuh_key" -passin pass: -pubout </dev/null >"$_wazuh_key_pub" 2>/dev/null || return 1
|
||||
if ! cmp -s -- "$_wazuh_cert_pub" "$_wazuh_key_pub"; then
|
||||
_wazuh_error 'root-ca.key does not match root-ca.pem'
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -f -- "$_wazuh_cert_pub" "$_wazuh_key_pub"
|
||||
trap - 0 1 2 3 15
|
||||
)
|
||||
|
||||
_wazuh_ensure_ca_directory() (
|
||||
_wazuh_ca_dir=${1-}
|
||||
_wazuh_validate_absolute_path "$_wazuh_ca_dir" || return 1
|
||||
|
||||
if [ -L "$_wazuh_ca_dir" ]; then
|
||||
_wazuh_error "refusing symbolic-link CA directory: $_wazuh_ca_dir"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -e "$_wazuh_ca_dir" ]; then
|
||||
_wazuh_make_secure_tree "$_wazuh_ca_dir" || {
|
||||
_wazuh_error "cannot create CA directory: $_wazuh_ca_dir"
|
||||
return 1
|
||||
}
|
||||
_wazuh_restorecon "$_wazuh_ca_dir" || return 1
|
||||
fi
|
||||
|
||||
_wazuh_validate_ancestors "$_wazuh_ca_dir" || return 1
|
||||
_wazuh_validate_directory_node "$_wazuh_ca_dir" 700
|
||||
)
|
||||
|
||||
_wazuh_ca_validate_locked() (
|
||||
_wazuh_ca_dir=$(wazuh_ca_get_dir) || return 1
|
||||
_wazuh_validate_ca_files "$_wazuh_ca_dir"
|
||||
)
|
||||
|
||||
wazuh_ca_validate() (
|
||||
_wazuh_with_lock _wazuh_ca_validate_locked
|
||||
)
|
||||
|
||||
_wazuh_ca_ensure_locked() (
|
||||
_wazuh_ca_dir=$(wazuh_ca_get_dir) || return 1
|
||||
_wazuh_ensure_ca_directory "$_wazuh_ca_dir" || return 1
|
||||
|
||||
_wazuh_cert=$_wazuh_ca_dir/root-ca.pem
|
||||
_wazuh_key=$_wazuh_ca_dir/root-ca.key
|
||||
|
||||
_wazuh_cert_exists=0
|
||||
_wazuh_key_exists=0
|
||||
if [ -e "$_wazuh_cert" ] || [ -L "$_wazuh_cert" ]; then
|
||||
_wazuh_cert_exists=1
|
||||
fi
|
||||
if [ -e "$_wazuh_key" ] || [ -L "$_wazuh_key" ]; then
|
||||
_wazuh_key_exists=1
|
||||
fi
|
||||
|
||||
if [ "$_wazuh_cert_exists" -eq 1 ] || [ "$_wazuh_key_exists" -eq 1 ]; then
|
||||
_wazuh_validate_ca_files "$_wazuh_ca_dir"
|
||||
return $?
|
||||
fi
|
||||
|
||||
command -v openssl >/dev/null 2>&1 || {
|
||||
_wazuh_error 'openssl is required to generate the root CA'
|
||||
return 1
|
||||
}
|
||||
|
||||
_wazuh_tmp_dir=$(mktemp -d "$_wazuh_ca_dir/.root-ca.XXXXXX") || {
|
||||
_wazuh_error "cannot create a temporary directory in $_wazuh_ca_dir"
|
||||
return 1
|
||||
}
|
||||
trap 'rm -rf -- "$_wazuh_tmp_dir"' 0
|
||||
trap 'return 130' 1 2 3 15
|
||||
chmod 0700 "$_wazuh_tmp_dir" || return 1
|
||||
_wazuh_config=$_wazuh_tmp_dir/openssl.cnf
|
||||
|
||||
(umask 077; printf '%s\n' \
|
||||
'[req]' \
|
||||
'distinguished_name = dn' \
|
||||
'x509_extensions = v3_ca' \
|
||||
'prompt = no' \
|
||||
'[dn]' \
|
||||
'OU = Wazuh' \
|
||||
'O = Wazuh' \
|
||||
'L = California' \
|
||||
'[v3_ca]' \
|
||||
'basicConstraints = critical, CA:TRUE' \
|
||||
'keyUsage = critical, keyCertSign, cRLSign' \
|
||||
'subjectKeyIdentifier = hash' \
|
||||
'authorityKeyIdentifier = keyid:always' \
|
||||
>"$_wazuh_config") || return 1
|
||||
|
||||
if ! (umask 077; openssl req -x509 -new -nodes -newkey rsa:2048 \
|
||||
-sha256 -days 3650 -batch -config "$_wazuh_config" \
|
||||
-keyout "$_wazuh_tmp_dir/root-ca.key" \
|
||||
-out "$_wazuh_tmp_dir/root-ca.pem" >/dev/null 2>&1); then
|
||||
_wazuh_error 'OpenSSL failed to generate the root CA'
|
||||
return 1
|
||||
fi
|
||||
|
||||
chown root:root "$_wazuh_tmp_dir/root-ca.key" "$_wazuh_tmp_dir/root-ca.pem" || return 1
|
||||
chmod 0400 "$_wazuh_tmp_dir/root-ca.key" || return 1
|
||||
chmod 0644 "$_wazuh_tmp_dir/root-ca.pem" || return 1
|
||||
|
||||
# Publishing the key first (hard links refuse existing targets) makes an interrupted installation fail closed as an
|
||||
# explicit key-without-certificate state instead of silently looking like
|
||||
# an externally managed anchor.
|
||||
ln -T -- "$_wazuh_tmp_dir/root-ca.key" "$_wazuh_key" || return 1
|
||||
ln -T -- "$_wazuh_tmp_dir/root-ca.pem" "$_wazuh_cert" || return 1
|
||||
_wazuh_restorecon "$_wazuh_key" || return 1
|
||||
_wazuh_restorecon "$_wazuh_cert" || return 1
|
||||
|
||||
rm -rf -- "$_wazuh_tmp_dir"
|
||||
trap - 0 1 2 3 15
|
||||
_wazuh_validate_ca_files "$_wazuh_ca_dir" || return 1
|
||||
_wazuh_info "created a new CA in $_wazuh_ca_dir. Hosts of the same deployment must share one CA: use the installation assistant, or place this CA in $_wazuh_ca_dir on the other hosts before installing their packages."
|
||||
)
|
||||
|
||||
wazuh_ca_ensure() (
|
||||
_wazuh_with_lock _wazuh_ca_ensure_locked
|
||||
)
|
||||
|
||||
_wazuh_random_below() (
|
||||
_wazuh_limit=${1-}
|
||||
case $_wazuh_limit in
|
||||
''|*[!0-9]*|0) return 1 ;;
|
||||
esac
|
||||
|
||||
_wazuh_ceiling=$((65536 - (65536 % _wazuh_limit)))
|
||||
while :; do
|
||||
_wazuh_number=$(od -An -N2 -tu2 /dev/urandom 2>/dev/null) || return 1
|
||||
_wazuh_number=$(printf '%s' "$_wazuh_number" | tr -d '[:space:]')
|
||||
case $_wazuh_number in
|
||||
''|*[!0-9]*) return 1 ;;
|
||||
esac
|
||||
if [ "$_wazuh_number" -lt "$_wazuh_ceiling" ]; then
|
||||
printf '%s\n' $((_wazuh_number % _wazuh_limit))
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
)
|
||||
|
||||
_wazuh_random_char() (
|
||||
_wazuh_alphabet=${1-}
|
||||
_wazuh_length=${#_wazuh_alphabet}
|
||||
[ "$_wazuh_length" -gt 0 ] || return 1
|
||||
_wazuh_index=$(_wazuh_random_below "$_wazuh_length") || return 1
|
||||
_wazuh_position=$((_wazuh_index + 1))
|
||||
printf '%s' "$_wazuh_alphabet" | cut -c "$_wazuh_position"
|
||||
)
|
||||
|
||||
_wazuh_replace_char() (
|
||||
_wazuh_text=${1-}
|
||||
_wazuh_position=${2-}
|
||||
_wazuh_character=${3-}
|
||||
|
||||
if [ "$_wazuh_position" -le 1 ]; then
|
||||
_wazuh_prefix=
|
||||
else
|
||||
_wazuh_prefix=$(printf '%s' "$_wazuh_text" | cut -c "1-$((_wazuh_position - 1))")
|
||||
fi
|
||||
_wazuh_suffix=$(printf '%s' "$_wazuh_text" | cut -c "$((_wazuh_position + 1))-" )
|
||||
printf '%s%s%s' "$_wazuh_prefix" "$_wazuh_character" "$_wazuh_suffix"
|
||||
)
|
||||
|
||||
wazuh_password_generate() (
|
||||
# The password character set; wazuh_password_validate accepts exactly this.
|
||||
_wazuh_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,_+:@%^=~-'
|
||||
|
||||
# Finite entropy reads avoid SIGPIPE under a caller's pipefail. Rejection
|
||||
# sampling (bytes < 219 for a 73-character alphabet) avoids modulo bias.
|
||||
_wazuh_password=
|
||||
while [ "${#_wazuh_password}" -lt 32 ]; do
|
||||
_wazuh_bytes=$(od -An -v -N128 -tu1 /dev/urandom) || return 1
|
||||
[ -n "$_wazuh_bytes" ] || return 1
|
||||
_wazuh_chunk=$(printf '%s\n' "$_wazuh_bytes" | awk -v a="$_wazuh_alphabet" '
|
||||
{ for (i=1; i<=NF; i++) if ($i < 219) printf "%s", substr(a, ($i % 73)+1, 1) }
|
||||
') || return 1
|
||||
_wazuh_password=$_wazuh_password$_wazuh_chunk
|
||||
done
|
||||
_wazuh_password=$(printf '%s' "$_wazuh_password" | cut -c 1-32) || return 1
|
||||
|
||||
_wazuh_index=$(_wazuh_random_below 32) || return 1
|
||||
_wazuh_pos_lower=$((_wazuh_index + 1))
|
||||
while :; do
|
||||
_wazuh_index=$(_wazuh_random_below 32) || return 1
|
||||
_wazuh_pos_upper=$((_wazuh_index + 1))
|
||||
[ "$_wazuh_pos_upper" -ne "$_wazuh_pos_lower" ] && break
|
||||
done
|
||||
while :; do
|
||||
_wazuh_index=$(_wazuh_random_below 32) || return 1
|
||||
_wazuh_pos_digit=$((_wazuh_index + 1))
|
||||
if [ "$_wazuh_pos_digit" -ne "$_wazuh_pos_lower" ] &&
|
||||
[ "$_wazuh_pos_digit" -ne "$_wazuh_pos_upper" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
while :; do
|
||||
_wazuh_index=$(_wazuh_random_below 32) || return 1
|
||||
_wazuh_pos_symbol=$((_wazuh_index + 1))
|
||||
if [ "$_wazuh_pos_symbol" -ne "$_wazuh_pos_lower" ] &&
|
||||
[ "$_wazuh_pos_symbol" -ne "$_wazuh_pos_upper" ] &&
|
||||
[ "$_wazuh_pos_symbol" -ne "$_wazuh_pos_digit" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
_wazuh_char=$(_wazuh_random_char 'abcdefghijklmnopqrstuvwxyz') || return 1
|
||||
_wazuh_password=$(_wazuh_replace_char "$_wazuh_password" "$_wazuh_pos_lower" "$_wazuh_char") || return 1
|
||||
_wazuh_char=$(_wazuh_random_char 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') || return 1
|
||||
_wazuh_password=$(_wazuh_replace_char "$_wazuh_password" "$_wazuh_pos_upper" "$_wazuh_char") || return 1
|
||||
_wazuh_char=$(_wazuh_random_char '0123456789') || return 1
|
||||
_wazuh_password=$(_wazuh_replace_char "$_wazuh_password" "$_wazuh_pos_digit" "$_wazuh_char") || return 1
|
||||
_wazuh_char=$(_wazuh_random_char '.,_+:@%^=~-') || return 1
|
||||
_wazuh_password=$(_wazuh_replace_char "$_wazuh_password" "$_wazuh_pos_symbol" "$_wazuh_char") || return 1
|
||||
|
||||
wazuh_password_validate "$_wazuh_password" >/dev/null || return 1
|
||||
printf '%s\n' "$_wazuh_password"
|
||||
)
|
||||
|
||||
wazuh_password_validate() (
|
||||
if [ "$#" -ne 1 ]; then
|
||||
_wazuh_error 'usage: wazuh_password_validate VALUE'
|
||||
return 1
|
||||
fi
|
||||
_wazuh_password=$1
|
||||
|
||||
# Only the generator's character set, spelled out rather than as ranges so
|
||||
# the match does not depend on the locale. It is checked first because it
|
||||
# makes every accepted value ASCII: the length below then means the same
|
||||
# under dash (bytes) as under bash and the consumers (characters). It also
|
||||
# excludes whitespace, control characters (newline and carriage return
|
||||
# included), quotes and the characters that need escaping in the file, in
|
||||
# a shell or in an HTTP Basic credential.
|
||||
case $_wazuh_password in
|
||||
*[!ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,_+:@%^=~-]*)
|
||||
_wazuh_error 'password must only contain characters from A-Z a-z 0-9 . , _ + : @ % ^ = ~ -'
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
_wazuh_length=${#_wazuh_password}
|
||||
if [ "$_wazuh_length" -lt 12 ] || [ "$_wazuh_length" -gt 64 ]; then
|
||||
_wazuh_error 'password must contain between 12 and 64 characters'
|
||||
return 1
|
||||
fi
|
||||
case $_wazuh_password in
|
||||
*[abcdefghijklmnopqrstuvwxyz]*) ;;
|
||||
*)
|
||||
_wazuh_error 'password must contain at least one lowercase letter'
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
case $_wazuh_password in
|
||||
*[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) ;;
|
||||
*)
|
||||
_wazuh_error 'password must contain at least one uppercase letter'
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
case $_wazuh_password in
|
||||
*[0123456789]*) ;;
|
||||
*)
|
||||
_wazuh_error 'password must contain at least one digit'
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
case $_wazuh_password in
|
||||
*[.,_+:@%^=~-]*) ;;
|
||||
*)
|
||||
_wazuh_error 'password must contain at least one symbol from . , _ + : @ % ^ = ~ -'
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
)
|
||||
@@ -0,0 +1,116 @@
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: wazuh-falco-agent
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wazuh-falco-agent
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wazuh-falco-agent
|
||||
spec:
|
||||
automountServiceAccountToken: false
|
||||
securityContext:
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
volumes:
|
||||
- name: agent-etc
|
||||
hostPath:
|
||||
path: /var/lib/wazuh-falco-agent/etc
|
||||
type: DirectoryOrCreate
|
||||
- name: falco-events
|
||||
hostPath:
|
||||
path: /var/log/falco
|
||||
type: Directory
|
||||
initContainers:
|
||||
- name: initialize-agent-etc
|
||||
image: wazuh/wazuh-agent:5.0.0-rc1
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
set -eu
|
||||
if [ ! -f /agent-etc/ossec.conf ]; then
|
||||
cp -a /var/ossec/etc/. /agent-etc/
|
||||
fi
|
||||
if ! grep -Fq '<location>/var/log/falco/events.json</location>' /agent-etc/ossec.conf; then
|
||||
cat >> /agent-etc/ossec.conf <<'EOF'
|
||||
|
||||
<ossec_config>
|
||||
<localfile>
|
||||
<location>/var/log/falco/events.json</location>
|
||||
<log_format>json</log_format>
|
||||
</localfile>
|
||||
</ossec_config>
|
||||
EOF
|
||||
fi
|
||||
chown root:101 /agent-etc
|
||||
chmod 0750 /agent-etc
|
||||
for config in ossec.conf internal_options.conf local_internal_options.conf; do
|
||||
if [ -f "/agent-etc/$config" ]; then
|
||||
chown root:101 "/agent-etc/$config"
|
||||
chmod 0640 "/agent-etc/$config"
|
||||
fi
|
||||
done
|
||||
# The unprivileged agent writes downloaded shared configuration here.
|
||||
chown 101:101 /agent-etc/shared
|
||||
chmod 0750 /agent-etc/shared
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
add: ["CHOWN", "DAC_OVERRIDE", "FOWNER"]
|
||||
volumeMounts:
|
||||
- name: agent-etc
|
||||
mountPath: /agent-etc
|
||||
containers:
|
||||
- name: wazuh-agent
|
||||
image: wazuh/wazuh-agent:5.0.0-rc1
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 300m
|
||||
memory: 512Mi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
# The packaged agent drops privileges to its wazuh user.
|
||||
add: ["CHOWN", "DAC_OVERRIDE", "FOWNER", "KILL", "SETGID", "SETUID", "SYS_CHROOT"]
|
||||
startupProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'status=$(/var/ossec/bin/wazuh-control status) && ! printf "%s\n" "$status" | grep -q "not running"'
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 24
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'status=$(/var/ossec/bin/wazuh-control status) && ! printf "%s\n" "$status" | grep -q "not running"'
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
env:
|
||||
- name: WAZUH_AGENT_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: spec.nodeName
|
||||
- name: WAZUH_ENROLLMENT_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: falco-agent-enrollment
|
||||
key: token
|
||||
volumeMounts:
|
||||
- name: agent-etc
|
||||
mountPath: /var/ossec/etc
|
||||
- name: falco-events
|
||||
mountPath: /var/log/falco
|
||||
readOnly: true
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "Falco Runtime Detections",
|
||||
"type": "detector",
|
||||
"detector_type": "falco",
|
||||
"enabled": true,
|
||||
"schedule": {
|
||||
"period": {
|
||||
"interval": 1,
|
||||
"unit": "MINUTES"
|
||||
}
|
||||
},
|
||||
"inputs": [
|
||||
{
|
||||
"detector_input": {
|
||||
"description": "Falco Warning and higher events from Wazuh 5",
|
||||
"indices": ["wazuh-events-v5-security"],
|
||||
"custom_rules": [
|
||||
{"id": "a9088c4a-748e-4622-8c28-f2d1b43aee9c"},
|
||||
{"id": "7dce0e18-b662-45c7-a08f-4248378a92b2"}
|
||||
],
|
||||
"pre_packaged_rules": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"triggers": []
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "decoder/falco-json/0",
|
||||
"enabled": true,
|
||||
"parents": ["decoder/core-wazuh-message/0"],
|
||||
"metadata": {
|
||||
"title": "Falco JSON event",
|
||||
"author": "Homelab",
|
||||
"description": "Normalize Falco detections and their Kubernetes, container, process and user context."
|
||||
},
|
||||
"check": "exists($_tmp_json.rule) AND exists($_tmp_json.priority) AND exists($_tmp_json.output_fields)",
|
||||
"normalize": [
|
||||
{
|
||||
"map": [
|
||||
{"@timestamp": "get_date()"},
|
||||
{"event.kind": "event"},
|
||||
{"event.dataset": "falco"},
|
||||
{"event.module": "falco"},
|
||||
{"event.action": "$_tmp_json.rule"},
|
||||
{"log.level": "$_tmp_json.priority"},
|
||||
{"message": "$_tmp_json.output"},
|
||||
{"host.name": "$_tmp_json.hostname"},
|
||||
{"orchestrator.namespace": "$_tmp_json.output_fields.k8s\\.ns\\.name"},
|
||||
{"orchestrator.resource.name": "$_tmp_json.output_fields.k8s\\.pod\\.name"},
|
||||
{"container.id": "$_tmp_json.output_fields.container\\.id"},
|
||||
{"container.name": "$_tmp_json.output_fields.container\\.name"},
|
||||
{"container.image.name": "$_tmp_json.output_fields.container\\.image\\.repository"},
|
||||
{"process.name": "$_tmp_json.output_fields.proc\\.name"},
|
||||
{"process.executable": "$_tmp_json.output_fields.proc\\.exepath"},
|
||||
{"process.command_line": "$_tmp_json.output_fields.proc\\.cmdline"},
|
||||
{"user.name": "$_tmp_json.output_fields.user\\.name"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"category": "security",
|
||||
"enabled": true,
|
||||
"metadata": {
|
||||
"title": "falco",
|
||||
"author": "Homelab",
|
||||
"description": "Falco runtime detections collected by the Wazuh agent.",
|
||||
"references": ["https://falco.org/docs/concepts/alerts/"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "decoder/core-wazuh-message/0",
|
||||
"enabled": true,
|
||||
"metadata": {
|
||||
"title": "Wazuh message decoder for Falco",
|
||||
"author": "Homelab",
|
||||
"description": "Parse the agent's JSON log before Falco normalization."
|
||||
},
|
||||
"normalize": [
|
||||
{
|
||||
"map": [
|
||||
{"_tmp_json": "parse_json($event.original)"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"metadata": {
|
||||
"title": "Falco critical: {{event.action}} on {{host.name}}",
|
||||
"author": "Homelab",
|
||||
"description": "A Falco runtime detection with Critical, Alert, or Emergency priority."
|
||||
},
|
||||
"enabled": true,
|
||||
"status": "experimental",
|
||||
"level": "critical",
|
||||
"logsource": {"product": "falco"},
|
||||
"detection": {
|
||||
"condition": "selection",
|
||||
"selection": {
|
||||
"event.dataset": "falco",
|
||||
"log.level": ["Critical", "Alert", "Emergency"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"metadata": {
|
||||
"title": "Falco: {{event.action}} on {{host.name}}",
|
||||
"author": "Homelab",
|
||||
"description": "A Falco runtime detection with Warning or Error priority."
|
||||
},
|
||||
"enabled": true,
|
||||
"status": "experimental",
|
||||
"level": "medium",
|
||||
"logsource": {"product": "falco"},
|
||||
"detection": {
|
||||
"condition": "selection",
|
||||
"selection": {
|
||||
"event.dataset": "falco",
|
||||
"log.level": ["Warning", "Error"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: wazuh-agent
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- falco-agent-ds.yaml
|
||||
- network-policy.yaml
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: wazuh-agent
|
||||
labels:
|
||||
# Required for the node-local Falco log and the agent's persistent identity.
|
||||
pod-security.kubernetes.io/enforce: privileged
|
||||
pod-security.kubernetes.io/warn: baseline
|
||||
@@ -0,0 +1,44 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: default-deny-all
|
||||
spec:
|
||||
podSelector: {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
- Egress
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: falco-agent-traffic
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-falco-agent
|
||||
policyTypes:
|
||||
- Ingress
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: wazuh
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 1517
|
||||
- to:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: kube-system
|
||||
podSelector:
|
||||
matchLabels:
|
||||
k8s-app: kube-dns
|
||||
ports:
|
||||
- protocol: UDP
|
||||
port: 53
|
||||
- protocol: TCP
|
||||
port: 53
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: falco-agent-manager-ingress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: wazuh-agent
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-falco-agent
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 1517
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: manager-egress-external
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- ipBlock:
|
||||
cidr: 0.0.0.0/0
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 443
|
||||
@@ -0,0 +1,19 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: manager-egress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-indexer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9200
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: wazuh-api-ingress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-dashboard
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 55000
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 1516
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: wazuh-worker-egress
|
||||
namespace: wazuh
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: worker
|
||||
policyTypes:
|
||||
- Egress
|
||||
egress:
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 1516
|
||||
- to:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 55000
|
||||
@@ -0,0 +1,28 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh manager Service: Wazuh 5.x agent communication and enrollment
|
||||
#
|
||||
# Since 5.0.0 remoted serves a single HTTPS channel that carries both the agent
|
||||
# traffic and the enrollment, so this port replaces the 1514/1515 pair for 5.x
|
||||
# agents. Every manager node answers it, master included, mirroring the way the
|
||||
# Docker multi-node deployment balances 1517 across the whole cluster.
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-agents
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- name: agents-https
|
||||
port: 1517
|
||||
targetPort: 1517
|
||||
@@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh master Service: API and registration (authd)
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-api
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
annotations:
|
||||
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
ports:
|
||||
- name: api
|
||||
port: 55000
|
||||
targetPort: 55000
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh cluster Service: Manager nodes communication
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-cluster
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-manager
|
||||
ports:
|
||||
- name: cluster
|
||||
port: 1516
|
||||
targetPort: 1516
|
||||
clusterIP: None
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh workers service: Agent reporting
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-events
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-manager
|
||||
node-type: worker
|
||||
ports:
|
||||
- name: agents-events
|
||||
port: 1514
|
||||
targetPort: 1514
|
||||
@@ -0,0 +1,237 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh master StatefulSet
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-manager-master
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
serviceName: wazuh-cluster
|
||||
podManagementPolicy: Parallel
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
name: wazuh-manager-master
|
||||
spec:
|
||||
# No workload talks to the Kubernetes API.
|
||||
automountServiceAccountToken: false
|
||||
volumes:
|
||||
# The Secret gets the pod's fsGroup and group read, so the service user
|
||||
# could read it: an init container copies it to a root-only file.
|
||||
- name: wazuh-credentials
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
sizeLimit: 1Mi
|
||||
- name: wazuh-credentials-secret
|
||||
secret:
|
||||
secretName: manager-credentials
|
||||
defaultMode: 0400
|
||||
- name: wazuh-manager-certs-raw
|
||||
secret:
|
||||
secretName: manager-certs
|
||||
defaultMode: 0400
|
||||
- name: wazuh-manager-certs
|
||||
emptyDir: {}
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
initContainers:
|
||||
- name: install-credentials
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'umask 077 && cp /credentials-secret/wazuh-credentials /run/secrets/wazuh-credentials && chmod 0400 /run/secrets/wazuh-credentials'
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials-secret
|
||||
mountPath: /credentials-secret
|
||||
readOnly: true
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
- name: init-wazuh-etc
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
set -eu
|
||||
if [ -z "$(ls -A /pvc-etc)" ]; then
|
||||
cp -a /var/wazuh-manager/etc/* /pvc-etc/
|
||||
chown root:101 /pvc-etc/certs
|
||||
chmod 1770 /pvc-etc/certs
|
||||
fi
|
||||
# data/ is not in the image's permanent-data snapshot.
|
||||
if [ -z "$(ls -A /pvc-data)" ]; then
|
||||
cp -a /var/wazuh-manager/data/. /pvc-data/
|
||||
fi
|
||||
cp /tmp/certs-raw/root-ca.pem /etc/wazuh-certs-final/root-ca.pem
|
||||
cp /tmp/certs-raw/manager.pem /etc/wazuh-certs-final/indexer-connector.pem
|
||||
cp /tmp/certs-raw/manager-key.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
chown root:101 /etc/wazuh-certs-final/root-ca.pem /etc/wazuh-certs-final/indexer-connector.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
chmod 0640 /etc/wazuh-certs-final/root-ca.pem /etc/wazuh-certs-final/indexer-connector.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
# The agent listener pair is read by remoted after the manager drops
|
||||
# privileges, so it is owned by the manager user (101:101) instead of
|
||||
# root:101 like the files above.
|
||||
cp /tmp/certs-raw/manager-remoted.pem /etc/wazuh-certs-final/remoted.pem
|
||||
cp /tmp/certs-raw/manager-remoted-key.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
chown 101:101 /etc/wazuh-certs-final/remoted.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
chmod 0640 /etc/wazuh-certs-final/remoted.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
# The Server API pair, read by the API after it drops privileges.
|
||||
# Only the master runs the API.
|
||||
cp /tmp/certs-raw/manager-apid.pem /etc/wazuh-certs-final/apid.pem
|
||||
cp /tmp/certs-raw/manager-apid-key.pem /etc/wazuh-certs-final/apid-key.pem
|
||||
chown 101:101 /etc/wazuh-certs-final/apid.pem /etc/wazuh-certs-final/apid-key.pem
|
||||
chmod 0640 /etc/wazuh-certs-final/apid.pem /etc/wazuh-certs-final/apid-key.pem
|
||||
volumeMounts:
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /pvc-etc
|
||||
subPath: wazuh/var/wazuh-manager/etc
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /pvc-data
|
||||
subPath: wazuh/var/wazuh-manager/data
|
||||
- name: wazuh-manager-certs-raw
|
||||
mountPath: /tmp/certs-raw
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /etc/wazuh-certs-final
|
||||
containers:
|
||||
- name: wazuh-manager
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
resources:
|
||||
limits:
|
||||
cpu: 400m
|
||||
memory: 1280Mi
|
||||
securityContext:
|
||||
capabilities:
|
||||
add: ["SYS_CHROOT"]
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
readOnly: true
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/api/configuration
|
||||
subPath: wazuh/var/wazuh-manager/api/configuration
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/etc
|
||||
subPath: wazuh/var/wazuh-manager/etc
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/root-ca.pem
|
||||
subPath: root-ca.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/indexer-connector.pem
|
||||
subPath: indexer-connector.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/indexer-connector-key.pem
|
||||
subPath: indexer-connector-key.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/remoted.pem
|
||||
subPath: remoted.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/remoted-key.pem
|
||||
subPath: remoted-key.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/apid.pem
|
||||
subPath: apid.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/apid-key.pem
|
||||
subPath: apid-key.pem
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/logs
|
||||
subPath: wazuh/var/wazuh-manager/logs
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/queue
|
||||
subPath: wazuh/var/wazuh-manager/queue
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/var/multigroups
|
||||
subPath: wazuh/var/wazuh-manager/var/multigroups
|
||||
- name: wazuh-manager-master
|
||||
mountPath: /var/wazuh-manager/data
|
||||
subPath: wazuh/var/wazuh-manager/data
|
||||
ports:
|
||||
- containerPort: 1517
|
||||
name: agents-https
|
||||
- containerPort: 1515
|
||||
name: registration
|
||||
- containerPort: 1516
|
||||
name: cluster
|
||||
- containerPort: 55000
|
||||
name: api
|
||||
startupProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 12
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 5
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 5
|
||||
env:
|
||||
- name: WAZUH_INDEXER_HOSTS
|
||||
value: 'wazuh-indexer-0.wazuh-indexer:9200,wazuh-indexer-1.wazuh-indexer:9200,wazuh-indexer-2.wazuh-indexer:9200'
|
||||
- name: WAZUH_NODE_NAME
|
||||
value: 'master'
|
||||
- name: WAZUH_NODE_TYPE
|
||||
value: 'master'
|
||||
- name: WAZUH_REMOTE_BIND_ADDR
|
||||
value: '0.0.0.0'
|
||||
- name: WAZUH_CLUSTER_BIND_ADDR
|
||||
value: '0.0.0.0'
|
||||
- name: WAZUH_CLUSTER_NODES
|
||||
value: 'wazuh-manager-master-0.wazuh-cluster'
|
||||
- name: WAZUH_CLUSTER_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wazuh-cluster-key
|
||||
key: key
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: wazuh-manager-master
|
||||
namespace: wazuh
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 2Gi
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh master Service: API and registration (authd)
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wazuh-registration
|
||||
namespace: wazuh
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
spec:
|
||||
selector:
|
||||
app: wazuh-manager
|
||||
node-type: master
|
||||
ports:
|
||||
- name: registration
|
||||
port: 1515
|
||||
targetPort: 1515
|
||||
@@ -0,0 +1,234 @@
|
||||
# Copyright (C) 2019, Wazuh Inc.
|
||||
#
|
||||
# This program is a free software; you can redistribute it
|
||||
# and/or modify it under the terms of the GNU General Public
|
||||
# License (version 2) as published by the FSF - Free Software
|
||||
# Foundation.
|
||||
|
||||
# Wazuh workers StatefulSet
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: wazuh-manager-worker
|
||||
namespace: wazuh
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: worker
|
||||
serviceName: wazuh-cluster
|
||||
podManagementPolicy: Parallel
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wazuh-manager
|
||||
node-type: worker
|
||||
name: wazuh-manager-worker
|
||||
spec:
|
||||
# No workload talks to the Kubernetes API.
|
||||
automountServiceAccountToken: false
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 100
|
||||
podAffinityTerm:
|
||||
topologyKey: kubernetes.io/hostname
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: wazuh-manager
|
||||
node-type: worker
|
||||
volumes:
|
||||
# The Secret gets the pod's fsGroup and group read, so the service user
|
||||
# could read it: an init container copies it to a root-only file.
|
||||
- name: wazuh-credentials
|
||||
emptyDir:
|
||||
medium: Memory
|
||||
sizeLimit: 1Mi
|
||||
- name: wazuh-credentials-secret
|
||||
secret:
|
||||
secretName: manager-credentials
|
||||
defaultMode: 0400
|
||||
- name: wazuh-manager-certs-raw
|
||||
secret:
|
||||
secretName: manager-certs
|
||||
defaultMode: 0400
|
||||
- name: wazuh-manager-certs
|
||||
emptyDir: {}
|
||||
securityContext:
|
||||
fsGroup: 101
|
||||
initContainers:
|
||||
- name: install-credentials
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- 'umask 077 && cp /credentials-secret/wazuh-credentials /run/secrets/wazuh-credentials && chmod 0400 /run/secrets/wazuh-credentials'
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 128Mi
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials-secret
|
||||
mountPath: /credentials-secret
|
||||
readOnly: true
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
- name: init-wazuh-etc
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
if [ -z "$(ls -A /pvc-etc)" ]; then
|
||||
cp -a /var/wazuh-manager/etc/* /pvc-etc/
|
||||
chown root:101 /pvc-etc/certs
|
||||
chmod 1770 /pvc-etc/certs
|
||||
fi
|
||||
# data/ is not in the image's permanent-data snapshot.
|
||||
if [ -z "$(ls -A /pvc-data)" ]; then
|
||||
cp -a /var/wazuh-manager/data/. /pvc-data/
|
||||
fi
|
||||
cp /tmp/certs-raw/root-ca.pem /etc/wazuh-certs-final/root-ca.pem
|
||||
cp /tmp/certs-raw/manager.pem /etc/wazuh-certs-final/indexer-connector.pem
|
||||
cp /tmp/certs-raw/manager-key.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
chown root:101 /etc/wazuh-certs-final/root-ca.pem /etc/wazuh-certs-final/indexer-connector.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
chmod 0640 /etc/wazuh-certs-final/root-ca.pem /etc/wazuh-certs-final/indexer-connector.pem /etc/wazuh-certs-final/indexer-connector-key.pem
|
||||
# The agent listener pair is read by remoted after the manager drops
|
||||
# privileges, so it is owned by the manager user (101:101) instead of
|
||||
# root:101 like the files above.
|
||||
cp /tmp/certs-raw/manager-remoted.pem /etc/wazuh-certs-final/remoted.pem
|
||||
cp /tmp/certs-raw/manager-remoted-key.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
chown 101:101 /etc/wazuh-certs-final/remoted.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
chmod 0640 /etc/wazuh-certs-final/remoted.pem /etc/wazuh-certs-final/remoted-key.pem
|
||||
volumeMounts:
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /pvc-etc
|
||||
subPath: wazuh/var/wazuh-manager/etc
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /pvc-data
|
||||
subPath: wazuh/var/wazuh-manager/data
|
||||
- name: wazuh-manager-certs-raw
|
||||
mountPath: /tmp/certs-raw
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /etc/wazuh-certs-final
|
||||
containers:
|
||||
- name: wazuh-manager
|
||||
image: 'wazuh/wazuh-manager:5.0.0-rc1'
|
||||
resources:
|
||||
limits:
|
||||
cpu: 400m
|
||||
memory: 1280Mi
|
||||
securityContext:
|
||||
capabilities:
|
||||
add: ["SYS_CHROOT"]
|
||||
volumeMounts:
|
||||
- name: wazuh-credentials
|
||||
mountPath: /run/secrets
|
||||
readOnly: true
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/api/configuration
|
||||
subPath: wazuh/var/wazuh-manager/api/configuration
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/etc
|
||||
subPath: wazuh/var/wazuh-manager/etc
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/root-ca.pem
|
||||
subPath: root-ca.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/indexer-connector.pem
|
||||
subPath: indexer-connector.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/indexer-connector-key.pem
|
||||
subPath: indexer-connector-key.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/remoted.pem
|
||||
subPath: remoted.pem
|
||||
- name: wazuh-manager-certs
|
||||
mountPath: /var/wazuh-manager/etc/certs/remoted-key.pem
|
||||
subPath: remoted-key.pem
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/logs
|
||||
subPath: wazuh/var/wazuh-manager/logs
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/queue
|
||||
subPath: wazuh/var/wazuh-manager/queue
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/var/multigroups
|
||||
subPath: wazuh/var/wazuh-manager/var/multigroups
|
||||
- name: wazuh-manager-worker
|
||||
mountPath: /var/wazuh-manager/data
|
||||
subPath: wazuh/var/wazuh-manager/data
|
||||
ports:
|
||||
- containerPort: 1517
|
||||
name: agents-https
|
||||
- containerPort: 1514
|
||||
name: agents-events
|
||||
- containerPort: 1516
|
||||
name: cluster
|
||||
startupProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -v apid | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 12
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -v apid | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 5
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- /var/wazuh-manager/bin/wazuh-manager-control status 2>/dev/null | grep -v apid | grep -qE 'not running|failed to start|refused its configuration' && exit 1 || exit 0
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 5
|
||||
env:
|
||||
- name: WAZUH_INDEXER_HOSTS
|
||||
value: 'wazuh-indexer-0.wazuh-indexer:9200,wazuh-indexer-1.wazuh-indexer:9200,wazuh-indexer-2.wazuh-indexer:9200'
|
||||
- name: WAZUH_NODE_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: WAZUH_NODE_TYPE
|
||||
value: 'worker'
|
||||
- name: WAZUH_REMOTE_BIND_ADDR
|
||||
value: '0.0.0.0'
|
||||
- name: WAZUH_CLUSTER_BIND_ADDR
|
||||
value: '0.0.0.0'
|
||||
- name: WAZUH_CLUSTER_NODES
|
||||
value: 'wazuh-manager-master-0.wazuh-cluster'
|
||||
- name: WAZUH_CLUSTER_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wazuh-cluster-key
|
||||
key: key
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: wazuh-manager-worker
|
||||
namespace: wazuh
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 500Mi
|
||||
Reference in new issue
Block a user