加固 Docker 容器镜像
Istio 的 默认镜像 基于 ubuntu
,并添加了一些额外的工具。 还有一个基于 Distroless 镜像 的替代镜像。
这些镜像去除了所有不必要的可执行文件和库,提供以下好处:
- 攻击面减少了,因为它们包含尽可能少的漏洞。
- 镜像更小,这可以加快启动速度。
另请参见 Distroless 官方自述文件中的 为什么我应该使用 Distroless 镜像? 部分。
安装 Distroless 镜像
按照 安装步骤 设置 Istio。 添加 variant
选项以使用 Distroless 镜像。
$ istioctl install --set values.global.variant=distroless
如果您只对将 Distroless 镜像用于注入代理镜像感兴趣,您也可以在 代理配置 中使用 image.imageType
字段。 请注意,上面的 variant
标志会自动为您设置此选项。
调试
Distroless 镜像缺少所有调试工具(包括 shell!)。 虽然这对安全性非常有帮助,但它限制了使用 kubectl exec
进入代理容器进行即时调试的能力。
幸运的是,临时容器 可以帮助解决这个问题。 kubectl debug
可以将一个临时容器附加到 Pod。 通过使用具有额外工具的镜像,我们可以像以前一样进行调试。
$ kubectl debug --image istio/base --target istio-proxy -it app-65c6749c9d-t549t
Defaulting debug container name to debugger-cdftc.
If you don't see a command prompt, try pressing enter.
root@app-65c6749c9d-t549t:/# curl example.com
这将使用 istio/base
部署一个新的临时容器。 这是非 Distroless Istio 镜像中使用的相同基本镜像,包含各种用于调试 Istio 的有用工具。 但是,任何镜像都可以使用。 该容器还附加到边车代理的进程命名空间 (--target istio-proxy
) 和 Pod 的网络命名空间。