k8s 中安装 falco

参考资料:https://falco.org/zh/docs/installation/https://jishuin.proginn.com/p/763bfbd3012c
环境:kubernetes 17.3 docker模拟3个节点的集群

将Falco作为Kubernetes的DaemonSet运行

  1. 克隆Falco仓库并切换,清单目录

    git clone https://github.com/falcosecurity/falco/
    # 当前master分支,已经没有了integrations目录 切换到 add-context-to-rules-errors 分支
    cd falco
    git checkout add-context-to-rules-errors
    cd integrations/k8s-using-daemonset
    
  2. 创建一个Kubernetes service account并提供必要的RBAC权限。Falco使用这个service account连接到Kubernetes API服务器并获取资源元数据。

    kubectl apply -f k8s-with-rbac/falco-account.yaml
    

    GKE 中执行报 警告
    serviceaccount/falco-account created
    Warning: rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole
    clusterrole.rbac.authorization.k8s.io/falco-cluster-role created
    Warning: rbac.authorization.k8s.io/v1beta1 ClusterRoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRoleBinding
    clusterrolebinding.rbac.authorization.k8s.io/falco-cluster-role-binding created

  3. 为Falco pods创建一个Kubernetes service

    kubectl apply -f k8s-with-rbac/falco-service.yaml
    
  4. 部署DaemonSet还依赖Kubernetes ConfigMap来存储Falco配置,并使Falco pod可以使用该配置。

    mkdir -p k8s-with-rbac/falco-config
    k8s-using-daemonset$ cp ../../falco.yaml k8s-with-rbac/falco-config/
    k8s-using-daemonset$ cp ../../rules/falco_rules.* k8s-with-rbac/falco-config/
    k8s-using-daemonset$ cp ../../rules/k8s_audit_rules.yaml k8s-with-rbac/falco-config/
    
  5. 将环境中的自定义规则添加到falco_rules.local.yaml,它们将被Falco启动时候,读取。按照以下方式创建configMap:

    kubectl create configmap falco-config --from-file=k8s-with-rbac/falco-config
    
  6. 创建完成configMpa依赖后,就可以创建DaemonSet了

    kubectl apply -f k8s-with-rbac/falco-daemonset-configmap.yaml
    

    falco-daemonset-configmap.yaml文件中需要修改两处:第1行改为apps/v1;添加第9~11行的selector。

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: falco-daemonset
      labels:
        app: falco-example
        role: security
    spec:
      selector:
        matchLabels:
          app: falco-example
      template:
        metadata:
          labels:
            app: falco-example
            role: security
        spec:
          serviceAccount: falco-account
          containers:
            - name: falco
              image: falcosecurity/falco:latest
              securityContext:
                privileged: true
    # Uncomment the 3 lines below to enable eBPF support for Falco.
    # This allows Falco to run on Google COS.
    # Leave blank for the default probe location, or set to the path
    # of a precompiled probe.
    #          env:
    #          - name: SYSDIG_BPF_PROBE
    #            value: ""
              args: [ "/usr/bin/falco", "--cri", "/host/run/containerd/containerd.sock", "-K", "/var/run/secrets/kubernetes.io/serviceaccount/token", "-k", "https://$(KUBERNETES_SERVICE_HOST)
    ", "-pk"]
              volumeMounts:
                - mountPath: /host/var/run/docker.sock
                  name: docker-socket
                - mountPath: /host/run/containerd/containerd.sock
                  name: containerd-socket
                - mountPath: /host/dev
                  name: dev-fs
                - mountPath: /host/proc
                  name: proc-fs
                  readOnly: true
                - mountPath: /host/boot
                  name: boot-fs
                  readOnly: true
                - mountPath: /host/lib/modules
                  name: lib-modules
                  readOnly: true
                - mountPath: /host/usr
                  name: usr-fs
                  readOnly: true
                - mountPath: /host/etc/
                  name: etc-fs
                  readOnly: true
                - mountPath: /etc/falco
                  name: falco-config
          volumes:
            - name: docker-socket
              hostPath:
                path: /var/run/docker.sock
            - name: containerd-socket
              hostPath:
                path: /run/containerd/containerd.sock
            - name: dev-fs
              hostPath:
                path: /dev
            - name: proc-fs
              hostPath:
                path: /proc
            - name: boot-fs
              hostPath:
                path: /boot
            - name: lib-modules
              hostPath:
                path: /lib/modules
            - name: usr-fs
              hostPath:
                path: /usr
            - name: etc-fs
              hostPath:
                path: /etc
            - name: falco-config
              configMap:
                name: falco-config
    
    
  7. 验证Falco正确启动。

    kubectl logs -l app=falco-example
    

测试

  1. 创建nginx pod

    kubectl run --generator=run-pod/v1 nginx --image=nginx
    

    或者通过下面方式创建 nginx pod

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
    
    kubectl apply -f nginx-pod.yml
    

    观察pod是running状态

    kubectl get pod nginx -o wide
    

    在这里插入图片描述

  2. 获取pods

    kubectl get pods
    

    在这里插入图片描述

  3. 打开一个命令窗口,执行

    kubectl logs -f falco-daemonset-lr5gz
    
  4. 再打开另一个命令窗口,执行如下命令,并观察第一个命令窗口是否有日志输出。

    [root@k8s-node1 k8s-using-daemonset]# kubectl exec -it nginx -- bash
    或者  kubectl exec -it nginx -- /bin/bash
    或者  kubectl exec -it nginx -- /bin/sh
    root@nginx:/# cat /etc/shadow
    root@nginx:/# exit
    

    操作截图
    在这里插入图片描述
    日志截图
    在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装Sysdig Falco,您可以按照以下步骤进行操作: 1. 部署收集程序:使用以下命令在Docker运行Falco收集程序,并指定展示程序地址: ``` docker run -d \ -p 2801:2801 \ --name falcosidekick \ -e WEBUI_URL=http://192.168.130.145:2802 \ falcosecurity/falcosidekick ``` 这将在Docker启动Falco收集程序,并将展示程序地址设置为http://192.168.130.145:2802。# vim falco.yaml ...... json_output: true ...... http_output: enabled: true url: "http://192.168.130.145:2801/" user_agent: "falcosecurity/falco" [root@k8s-node1 falco# systemctl restart falco-custom ``` 这将修改Falco配置文件,使其以JSON格式输出,并启用HTTP输出,并将收集程序地址设置为http://192.168.130.145:2801。然后重新启动Falco服务。123 #### 引用[.reference_title] - *1* *3* [K8s进阶7——Sysdig、Falco、审计日志](https://blog.csdn.net/yi_qingjun/article/details/130260005)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [Sysdig Falco:你不可不知的Docker安全监控利器](https://blog.csdn.net/weixin_34376562/article/details/89594095)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值