fw-policy, k8s labelによるタグ制御
Tungsten Fabricの4.1以降では、webui にSecurity, Tags といったタブが追加されている。
このタブは、fw-policy の設定に使用可能で、仮想ネットワーク間のアクセス制御や、vm間のアクセス制御に使用できる。
https://github.com/Juniper/contrail-controller/wiki/Contrail-FW-Security-enhancements
また、ポリシーの適用がvmi を通過したタイミングで実施されることから、同じ仮想ネットワーク内のvmに対するアクセス制御 (マイクロセグメンテーション) にも使用できる。
サンプルとして、k8s-default-pod-network に、cirros1/cirros2 を払いだし、こちらで制御を行ってみる。
※ yaml はこちらを使用: https://github.com/tnaganawa/contrail-k8s-tutorial/tree/master/yml/1_initial
[root@ip-172-31-8-163 1_initial]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE cirros1 1/1 Running 0 13m 10.47.255.251 ip-172-31-6-88.ap-northeast-1.compute.internal cirros2 1/1 Running 0 28s 10.47.255.250 ip-172-31-6-88.ap-northeast-1.compute.internal [root@ip-172-31-8-163 1_initial]# [root@ip-172-31-8-163 1_initial]# kubectl exec -it cirros1 sh / # ping 10.47.255.250 PING 10.47.255.250 (10.47.255.250): 56 data bytes 64 bytes from 10.47.255.250: seq=0 ttl=63 time=0.446 ms 64 bytes from 10.47.255.250: seq=1 ttl=63 time=0.079 ms 64 bytes from 10.47.255.250: seq=2 ttl=63 time=0.080 ms 64 bytes from 10.47.255.250: seq=3 ttl=63 time=0.079 ms ^C --- 10.47.255.250 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 0.079/0.171/0.446 ms / #
まず、Configure > Tags > Global Tags から、各cirros に対応するタグ label: (pod名) を設定する。
また、Configure > Networking > Ports から、各port に タグを割り当てておく。
この後、Configure > Security > Global Policies から、Firewall Policies を選択し、
Create から、以下のようなfw-policy を設定する。
この後、Application Policy Sets に戻り、default-application-policy-set について、edit を実行し、Select Firewall Policy から、先ほどの policy1 の紐付けを実施する。
※ Application Tag として、application=k8s を指定する必要がある
実行後、policy によって、icmp がブロックされ、それ以外の通信が許可されていることを確認できる。
/ # ping 10.47.255.250 PING 10.47.255.250 (10.47.255.250): 56 data bytes ^C --- 10.47.255.250 ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss / # / # ssh cirros@10.47.255.250 cirros@10.47.255.250's password: $ ip -o a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1\ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 1: lo inet 127.0.0.1/8 scope host lo\ valid_lft forever preferred_lft forever 1: lo inet6 ::1/128 scope host \ valid_lft forever preferred_lft forever 13: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue \ link/ether 02:9e:23:8d:1a:56 brd ff:ff:ff:ff:ff:ff 13: eth0 inet 10.47.255.250/12 scope global eth0\ valid_lft forever preferred_lft forever 13: eth0 inet6 fe80::c25:33ff:fe16:4995/64 scope link \ valid_lft forever preferred_lft forever $
また、pingを実行した状態で、
Monitor > Security > Dashboard を開くことで、トラフィックがブロックされていることと、実際にブロックに使用されているポリシーを確認できる。
追記:
なお、タグの定義と、vmi へのタグの割り当ては、yaml 内のmetadata で実施することも出来る (TF5.0以降)
一旦cirros1/cirros2 を削除し、以下のようなyaml で作り直すと、タグの作成、およびタグの割り当てが自動で行われることを確認できた。
apiVersion: v1 kind: Pod metadata: name: cirros1 labels: name: cirros1 label: cirros1 <-- 追記 spec: containers: - name: cirros1 image: cirros ports: - containerPort: 22