前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >两个 Krew:Bulk-Action 和 KubeSec-Scan

两个 Krew:Bulk-Action 和 KubeSec-Scan

作者头像
崔秀龙
发布2019-07-22 15:28:24
3740
发布2019-07-22 15:28:24
举报
文章被收录于专栏:伪架构师

Bulk Action

简介

顾名思义,Bulk Action 是一个用于进行批量操作的插件。 它使用 kubectl bulk <resourceType> [<parameters>] [action] [<fields>] 形式的命令,对指定资源的字段进行批量操作。

这个插件是使用 Shell 脚本通过大量的 grepsed 完成操作的,对完整资源并无认识,因此操作还是具有一定的危险性的,请慎重使用写操作。

基本用法

get

这个命令用于读取特定对象的指定字段值。

例如获取所有 Deployment 中的特定字段的内容:

代码语言:javascript
复制
$ kubectl bulk-action deploy get image
image fields are getting
image: dustise/flaskapp
image: dustise/flaskapp
- image: dustise/sleep
- image: dustise/sleep

上面的输出内容中,也能很清晰的分辨出 sh 的操作痕迹。推测 labels 这种字段就无法获取了:

代码语言:javascript
复制
$ kubectl bulk-action deploy get labels
labels fields are getting
labels:
labels:
...
list

这个命令是 bulk-action 的缺省操作,用 yaml 的形式列出所有指定类型的资源。

create

根据目前的资源,经过一定的替换之后生成新资源。

例如复制一个 Deployment

代码语言:javascript
复制
$ kubectl bulk-action deploy create name sleep-v2 sleep-v3
creating new resource with changing name: sleep-v2 to name: sleep-v3 for all  deploy
deployment.extensions/sleep-v3 created
Error from server (AlreadyExists): deployments.extensions "flaskapp-v1" already exists
Error from server (AlreadyExists): deployments.extensions "flaskapp-v2" already exists
Error from server (AlreadyExists): deployments.extensions "sleep-v1" already exists

前面说过,这个工具的操作是通过 grep sed 等完成的,因此这里的情况就比较有趣:sleep-v2 被替换生成新的 Deployment,其它 Deployment 不包含这段文本,因此无效。

delete

选择指定资源执行删除操作,例如删除所有的 Service

这个操作相当危险。 这里有个 bug,可以 mv ~/.krew/bin/kubectl-bulk_action ~/.krew/bin/kubectl-bulk 来纠正。

update

Create 类似,不过这里调用的是 kubectl replace

结论

古怪的功能,危险的操作。非常不建议采用。

Kubesec Scan

简介

使用 kubesec.io 提供的功能对集群进行扫描,得到安全相关的问题以及对应的建议。

基本用法

kubectl kubesec-scan [resource-type] [-n namespace] <resource-name>

例如:

代码语言:javascript
复制
$  kubectl kubesec-scan daemonset  -n kube-system cilium
scanning daemonset cilium in namespace kube-system
kubesec.io score: -44
-----------------
Critical
1. containers[] .securityContext .privileged == true
Privileged containers can allow almost completely unrestricted host access
2. .spec .hostNetwork
Sharing the host's network namespace permits processes in the pod to communicate with processes bound to the host's loopback adapter
3. .spec .volumes[] .hostPath .path == "/var/run/docker.sock"
Mounting the docker.socket leaks information about other containers and can allow container breakout
-----------------
Advise1. containers[] .securityContext .runAsNonRoot == true
Force the running image to run as a non-root user to ensure least privilege
2. containers[] .securityContext .capabilities .drop
Reducing kernel capabilities available to a container limits its attack surface
3. containers[] .securityContext .readOnlyRootFilesystem == true
An immutable root filesystem can prevent malicious binaries being added to PATH and increase attack cost
4. containers[] .securityContext .runAsUser > 10000
Run as a high-UID user to avoid conflicts with the host's user table
5. containers[] .securityContext .capabilities .drop | index("ALL")
Drop all capabilities and add only those required to reduce syscall attack surface

参考链接

  • Kubesec: https://kubesec.io/
  • Bulk Action: https://github.com/emreodabas/kubectl-plugins
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-06-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 伪架构师 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Bulk Action
    • 简介
      • 基本用法
        • get
        • list
        • create
        • delete
        • update
      • 结论
      • Kubesec Scan
        • 简介
          • 基本用法
          • 参考链接
          相关产品与服务
          容器服务
          腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档