Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KubeCon_CNCon_2018_recap_internal

makocchi
January 16, 2019

 KubeCon_CNCon_2018_recap_internal

社内向け KubeCon/CNCon 2018 Recap

makocchi

January 16, 2019
Tweet

More Decks by makocchi

Other Decks in Technology

Transcript

  1. ,6#&$0/3&$"1 1
    Adtech Division
    @makocchi
    KubeCon/CNCon 2018 NA
    Recap

    View Slide

  2. ,6#&$0/3&$"1 2
    みなさん 普段からセキュリティを意識していますか?
    普段はあまり(゚ε゚)キニシナイ!!ですよね?

    View Slide

  3. ,6#&$0/3&$"1 3
    というわけで今日は KubeCon/CNCon 2018 NA の
    セッションの中から
    セキュリティまわりのセッションを紹介します

    View Slide

  4. ,6#&$0/3&$"1 4
    「Kata and gVisor: A Quantitative Comparison」
    And
    「Falco Deep Dive」

    View Slide

  5. ,6#&$0/3&$"1 5
    https://schd.ws/hosted_files/kccna18/39/kata-containers-and-gvisor-a-quantitave-comparison.pdf

    View Slide

  6. ,6#&$0/3&$"1 6
    https://schd.ws/hosted_files/kccna18/39/kata-containers-and-gvisor-a-quantitave-comparison.pdf

    View Slide

  7. ,6#&$0/3&$"1 7
    https://schd.ws/hosted_files/kccna18/39/kata-containers-and-gvisor-a-quantitave-comparison.pdf

    View Slide

  8. ,6#&$0/3&$"1 8
    https://schd.ws/hosted_files/kccna18/39/kata-containers-and-gvisor-a-quantitave-comparison.pdf

    View Slide

  9. ,6#&$0/3&$"1 9
    続きまして
    「Falco Deep Dive」
    のセッション内容をご紹介します

    View Slide

  10. ,6#&$0/3&$"1 10
    What is Falco?

    View Slide

  11. ,6#&$0/3&$"1 11
    Container Native Runtime Security
    つまり、コンテナ環境のセキュリティをモニタリングしてく
    れるソフトウェア
    オープンソース
    最近 CNCF の sanbox プロジェクトになった
    Falco joins CNCF Sandbox
    https://sysdig.com/blog/falco-cncf-sandbox/
    主に開発しているのは sysdig
    注意する点としては、モニタリングをするだけで実際に処理
    をブロックしたりすることはしない
    WHAT IS FALCO?

    View Slide

  12. ,6#&$0/3&$"1 12
    どうやってモニタリングしてるの?

    View Slide

  13. ,6#&$0/3&$"1 13
    https://schd.ws/hosted_files/kccna18/cc/Falco-DeepDive-Kubecon.pdf

    View Slide

  14. ,6#&$0/3&$"1 14
    Falco を実行すると DKMS(Dynamic Kernel Module Support) に
    よって module が build & install される
    Install される module は falco_probe
    なので falco 自体をコンテナ環境で使う場合は privileged が必要
    $ lsmod | grep falco
    falco_probe 622592 2
    HOW TO MONITOR?

    View Slide

  15. ,6#&$0/3&$"1 15
    Rule を yaml で記述することでモニタリングするイベントを定義する
    例えばこんな感じの rule
    - rule: Write below binary dir
    desc: an attempt to write to any file below a set of binary directories
    condition: >
    bin_dir and open_write
    output: >
    File below a known binary directory opened for writing (user=%user.name
    command=%proc.cmdline file=%fd.name parent=%proc.pname pcmdline=%proc.pcmdline gparent=%proc.aname[2])
    priority: ERROR
    tags: [filesystem]
    この場合は bin_dir を write 権限で open しようとすると検知してくれる
    ちなみに bin_dir は別の場所で定義されていて /bin, /sbin, /usr/bin, /usr/sbin が相当する
    HOW TO MONITOR?

    View Slide

  16. ,6#&$0/3&$"1 16
    実際に /usr/bin 以下に書き込もうとすると・・・
    kenshiro $ sudo touch /usr/bin/you_are_shock
    # falco ͷ log
    11:46:38.977124899: Error File below a known binary directory opened for writing (user=root command=touch /
    usr/bin/you_are_shock file=/usr/bin/you_are_shock parent=sudo pcmdline=sudo touch /usr/bin/you_are_shock
    gparent=bash)
    このように検知してくれる
    HOW TO MONITOR?

    View Slide

  17. ,6#&$0/3&$"1 17
    検知したイベントを外部に通知したい

    View Slide

  18. ,6#&$0/3&$"1 18
    Falco には検知した際にプログラムを実行する仕組みがある
    その仕組を使えば外部へ webhook とかすることでいろいろな通知が可能になる (slack等)
    やりかたは簡単
    falco.yaml の設定を変更する
    # json Ͱͷ output Λ༗ޮʹ͢Δ
    json_output: true
    # program_output Ͱ slack ͷ webhook Λઃఆ͢Δ
    program_output:
    enabled: true
    keep_alive: false
    program: "jq '{text: .output}' | curl -d @- -X POST https://hooks.slack.com/services/foo/bar/baz"
    HOW TO NOTIFY?

    View Slide

  19. ,6#&$0/3&$"1 19
    こんな感じに slack に通知されます
    さすがにこのままだと味もそっけもないので・・・もうすこし頑張ってみると・・・
    HOW TO NOTIFY?

    View Slide

  20. ,6#&$0/3&$"1 20
    こんな感じに通知することも可能です
    HOW TO NOTIFY?

    View Slide

  21. ,6#&$0/3&$"1 21
    Falco で Kubernetes の audit log をモニタリングする

    View Slide

  22. ,6#&$0/3&$"1 22
    そもそも Kubernetes の audit log とは?

    View Slide

  23. ,6#&$0/3&$"1 23
    Kubernetes API サーバーに対して行われた呼び出しを時
    系列でログに記録することができる
    怪しい API リクエストの調査、統計情報の収集、不要な
    API 呼び出しをモニタリングする為には audit logging
    を有効にする必要がある
    ログの出力先はファイル以外にも対応している
    (Webhook 等)
    最近の Falco (0.13.0) で audit log もモニタリングで
    きるようになった
    Falco 0.13.0 Released: Kubernetes Audit Events Support
    https://sysdig.com/blog/falco-0-13-released-kubernetes-audit-support/
    K8S AUDIT LOGGING

    View Slide

  24. ,6#&$0/3&$"1 24
    さっそく audit logging を有効にしてみよう
    ちなみに GKE では default で有効になっている
    Falco が port 8765 で webhook の endpoint とし
    て待ち構えてくれるので、そこに対して audit log を
    投げつける!
    K8S AUDIT LOGGING
    ちなみに audit まわりの kube-apiserver の option はというと・・

    View Slide

  25. ,6#&$0/3&$"1 25
    K8S AUDIT LOGGING
    --audit-dynamic-configuration
    --audit-log-batch-buffer-size
    --audit-log-batch-max-size
    --audit-log-batch-max-wait
    --audit-log-batch-throttle-burst
    --audit-log-batch-throttle-enable
    --audit-log-batch-throttle-qps
    --audit-log-format
    --audit-log-maxage
    --audit-log-maxbackup
    --audit-log-maxsize
    --audit-log-mode
    --audit-log-path
    --audit-log-truncate-enabled
    --audit-log-truncate-max-batch-size
    --audit-log-truncate-max-event-size
    --audit-log-version
    --audit-policy-file
    --audit-webhook-batch-buffer-size
    --audit-webhook-batch-max-size
    --audit-webhook-batch-max-wait
    --audit-webhook-batch-throttle-burst
    --audit-webhook-batch-throttle-enable
    --audit-webhook-batch-throttle-qps
    --audit-webhook-config-file
    --audit-webhook-initial-backoff
    --audit-webhook-mode
    --audit-webhook-truncate-enabled
    --audit-webhook-truncate-max-batch-size
    --audit-webhook-truncate-max-event-size
    --audit-webhook-version

    View Slide

  26. ,6#&$0/3&$"1 26
    K8S AUDIT LOGGING
    --audit-dynamic-configuration
    --audit-log-batch-buffer-size
    --audit-log-batch-max-size
    --audit-log-batch-max-wait
    --audit-log-batch-throttle-burst
    --audit-log-batch-throttle-enable
    --audit-log-batch-throttle-qps
    --audit-log-format
    --audit-log-maxage
    --audit-log-maxbackup
    --audit-log-maxsize
    --audit-log-mode
    --audit-log-path
    --audit-log-truncate-enabled
    --audit-log-truncate-max-batch-size
    --audit-log-truncate-max-event-size
    --audit-log-version
    --audit-policy-file
    --audit-webhook-batch-buffer-size
    --audit-webhook-batch-max-size
    --audit-webhook-batch-max-wait
    --audit-webhook-batch-throttle-burst
    --audit-webhook-batch-throttle-enable
    --audit-webhook-batch-throttle-qps
    --audit-webhook-config-file
    --audit-webhook-initial-backoff
    --audit-webhook-mode
    --audit-webhook-truncate-enabled
    --audit-webhook-truncate-max-batch-size
    --audit-webhook-truncate-max-event-size
    --audit-webhook-version

    View Slide

  27. ,6#&$0/3&$"1 27
    webhook の設定と policy は falco の repository にsample が用意されている
    例えば webhook の設定はこんな感じ
    (kube-apiserver と同じ host で falco が port 8765 で受け付ける場合)
    K8S AUDIT LOGGING
    apiVersion: v1
    kind: Config
    clusters:
    - name: falco
    cluster:
    server: http://127.0.0.1:8765/k8s_audit
    contexts:
    - context:
    cluster: falco
    user: ""
    name: default-context
    current-context: default-context
    preferences: {}
    users: []

    View Slide

  28. ,6#&$0/3&$"1 28
    audit policy は rbac に近い設定で定義する
    K8S AUDIT LOGGING
    apiVersion: audit.k8s.io/v1beta1 # This is required.
    kind: Policy
    # Don't generate audit events for all requests in RequestReceived stage.
    omitStages:
    - "RequestReceived"
    rules:
    # Log pod changes at RequestResponse level
    - level: RequestResponse
    resources:
    - group: ""
    # Resource "pods" doesn't match requests to any subresource of pods,
    # which is consistent with the RBAC policy.
    resources: ["pods", "deployments"]
    . . . .

    View Slide

  29. ,6#&$0/3&$"1 29
    webhook と audit policy を有効にして kube-apiserver を再起動して設定を反映させる
    --audit-webhook-config-file=/etc/falco/webhook-config.yaml
    --audit-policy-file=/etc/falco/audit-policy.yaml
    あとは audit log を発火させれば OK
    “demo” user が kubectl get deployment をした時にはこんな感じで通知される
    K8S AUDIT LOGGING
    10:20:20.540762112: Warning K8s Operation performed by user not in allowed list of users
    (user=demo target=/deployments verb=list uri=/apis/extensions/v1beta1/namespaces/
    default/deployments?limit=500 resp=200)
    ね?簡単でしょ?

    View Slide

  30. ,6#&$0/3&$"1 30
    https://schd.ws/hosted_files/kccna18/cc/Falco-DeepDive-Kubecon.pdf

    View Slide

  31. ,6#&$0/3&$"1 31
    audit の log を元に、rbac の manifest を自動生成してくれるツールも存在する
    https://github.com/liggitt/audit2rbac
    demo 動画もあって、是非見てもらいたい
    https://youtu.be/n2cD20moYe8
    これを使えば足りない rbac を検知して、必要に応じて rbac を適用することができる
    クラスター管理者とかはけっこう嬉しいツールなんじゃないかな?
    K8S AUDIT LOGGING

    View Slide

  32. ,6#&$0/3&$"1 32
    Kubernetes に falco を install する

    View Slide

  33. ,6#&$0/3&$"1 33
    HOW TO INSTALL
    Helm の chart があるのでそれを使うのが楽 (stable/falco)
    https://github.com/helm/charts/tree/master/stable/falco
    Falco operator もある
    https://github.com/mumoshu/falco-operator
    さくっと入れられる!(Helm もしくは operator)
    Kubernetes 環境だけではなくて、もちろん docker run でも OK (falcosecurity/falco:tag)
    いろんなミドルウェアの rule を書いてくれている人も居る
    https://github.com/draios/falco-extras

    View Slide

  34. ,6#&$0/3&$"1 34
    Adtech Division
    @makocchi
    KubeCon/CNCon 2018 NA
    Recap
    ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂʂ

    View Slide