使用 Traefik 中间件处理 Log4J 漏洞

87d26906180640e0a64c4739e19bc7e4.png

Traefik 的中间件是最让人喜欢的一个功能,为了能够扩展中间件,Traefik 官方还推出了 Pilot(https://pilot.traefik.io/) 这样的中间件 SaaS 服务,和 Traefik 深度集成,我们可以非常方便的使用平台上提供的各种中间件,在 Dashboard 上就可以无缝进行对接:

25a9aa5414cd16ba125c4b00a75cf624.png

Log4Shell(https://github.com/traefik/plugin-log4shell) 就是一个解决最近很火的 Log4J 漏洞的 Traefik 插件,相关介绍:https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44228。不过要使用该中间件需要 Traefik >= v.2.5.5 版本。

使用也是非常简单的,首先通过静态配置启用该插件,可以通过 Traefik 启动参数配置:

--pilot.token=xxx  # 去 pilot 注册实例获取的 token
--experimental.plugins.log4shell.modulename=github.com/traefik/plugin-log4shell
--experimental.plugins.log4shell.version=v0.1.2

或者配置文件:

pilot:
  token: xxx

experimental:
  plugins:
    log4shell:
      modulename: github.com/traefik/plugin-log4shell
      version: v0.1.2

为了使用 Log4Shell 插件我们首先需要创建一个中间件,比如在 Kubernetes 系统中,只需要创建如下所示的资源对象即可:

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: log4shell-foo
spec:
  plugin:
    log4shell:
      errorCode: 200

然后在 IngressRoute 中关联上上面的中间件即可修复:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: whoami
spec:
  entryPoints:
    - web
  routes:
    - kind: Rule
      match: Host(`whoami.localhost`)
      middlewares:
        - name: log4shell-foo
      services:
        - kind: Service
          name: whoami-svc
          port: 80

当然如果使用的是默认的 Ingress 资源对象,则需要通过 annotation 注解来配置:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myingress
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: default-log4shell-foo@kubernetescrd
spec:
  ingressClassName: traefik
  rules:
    - host: whoami.localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name:  whoami
                port:
                  number: 80

同样如果是使用 Docker 环境则需要通过 labels 标签进行配置:

version: '3.7'

services:
  whoami:
    image: traefik/whoami:v1.7.1
    labels:
      traefik.enable: 'true'
      traefik.http.routers.app.rule: Host(`whoami.localhost`)
      traefik.http.routers.app.entrypoints: websecure
      traefik.http.routers.app.middlewares: log4shell-foo
      traefik.http.middlewares.log4shell-foo.plugin.log4shell.errorcode: 200
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值