K8sネットワークポリシーセキュリティ実践:デフォルト拒否からゼロトラストまで6つの防御パターン
あなたのK8sクラスタ、ネットワークは丸見えですか?
デフォルト設定のKubernetesクラスタでは、すべてのPodが自由に通信できます。フロントエンドPodがデータベースPodに直接アクセスでき、テスト名前空間が本番名前空間に到達でき、侵害されたPodがクラスタ内の任意のサービスに横移動できます。2025年、ある金融会社がネットワークポリシーのないPodを侵害され、攻撃者は30分以内に決済システムに横移動し、200万件のユーザーデータを盗みました。これは映画の筋書きではなく、実際に起きたセキュリティインシデントです。
Kubernetes NetworkPolicyはクラスタネットワークセキュリティの基盤です。デフォルト拒否からマイクロセグメンテーション、Cilium eBPFからゼロトラストアーキテクチャまで、本記事は6つの防御パターンを網羅し、クラスタネットワークの露出を防ぎます。
コア概念クイックリファレンス
| 概念 | 説明 | キーワード |
|---|---|---|
| NetworkPolicy | K8sネイティブネットワークポリシーリソース、Pod間トラフィックを制御 | ingress/egress、selector |
| Default Deny | デフォルトですべてのトラフィックを拒否、正当なトラフィックのみ明示的に許可 | ホワイトリスト、ゼロトラスト基盤 |
| Micro-segmentation | ラベルベースのきめ細かいネットワーク分離 | ラベルセレクタ、名前空間分離 |
| Cilium | eBPFベースのCNIプラグイン、L3-L7ポリシーをサポート | eBPF、L7ポリシー、オブザーバビリティ |
| eBPF | カーネルレベルのプログラマブル技術、高性能ネットワークフィルタリングを実現 | カーネル空間、ゼロコピー、XDP |
| mTLS | 相互TLS認証、サービス間の暗号化通信 | 証明書ローテーション、アイデンティティ認証 |
| Zero Trust | ゼロトラストネットワークアーキテクチャ:決して信頼せず、常に検証する | 継続的検証、最小権限 |
問題の深掘り:K8sネットワークセキュリティの5つの課題
| 課題 | 現状 | リスクレベル | 根本原因 |
|---|---|---|---|
| デフォルトオール許可 | クラスタ内のPod間にネットワーク制限なし | 🔴 重大 | K8sはデフォルトでNetworkPolicyを設定しない |
| 横移動 | 攻撃者が1つのPodを突破後、すべてのサービスにアクセス可能 | 🔴 重大 | マイクロセグメンテーションポリシーの欠如 |
| ポリシー爆発 | 大規模クラスタでNetworkPolicy数が制御不能に | 🟡 中程度 | ラベル設計の不備 |
| DNS依存 | サービスディスカバリがCoreDNSに依存、DNSポリシーが不在 | 🟡 中程度 | DNSレイヤーのセキュリティ軽視 |
| オブザーバビリティ不足 | ネットワークポリシーの効果を検証・監査が困難 | 🟠 高い | ポリシー監査ツールの欠如 |
パターン1:デフォルトですべてのトラフィックを拒否
デフォルト拒否はゼロトラストネットワーキングの第一歩です。NetworkPolicyのない名前空間では、すべてのPodが自由に通信でき、これが最も危険な状態です。
名前空間レベルのデフォルト拒否
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-egress
namespace: production
spec:
podSelector: {}
policyTypes:
- Egress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
DNS解決の許可(egressに必須)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns-egress
namespace: production
spec:
podSelector: {}
policyTypes:
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
全名前空間へのデフォルト拒否一括適用
#!/bin/bash
NAMESPACES=$(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}')
for ns in $NAMESPACES; do
if [ "$ns" = "kube-system" ] || [ "$ns" = "kube-public" ]; then
echo "Skipping system namespace: $ns"
continue
fi
kubectl apply -f - <<EOF
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: $ns
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
EOF
echo "Applied default-deny-all to namespace: $ns"
done
デフォルト拒否ポリシーの検証
kubectl get networkpolicy -n production
kubectl describe networkpolicy default-deny-all -n production
kubectl run test-client --image=busybox:1.36 -n production --rm -it -- \
wget -qO- --timeout=2 http://api-service.production.svc.cluster.local:8080
パターン2:ラベルベースのマイクロセグメンテーション
マイクロセグメンテーションはラベルセレクタを使用してきめ細かいPod間アクセス制御を実現します。NetworkPolicyのコア機能です。
3層アプリケーションのマイクロセグメンテーション
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: frontend-policy
namespace: production
spec:
podSelector:
matchLabels:
app: web
tier: frontend
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
env: production
podSelector:
matchLabels:
app: ingress-nginx
ports:
- protocol: TCP
port: 8080
- protocol: TCP
port: 8443
egress:
- to:
- podSelector:
matchLabels:
app: api
tier: backend
ports:
- protocol: TCP
port: 8080
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: backend-policy
namespace: production
spec:
podSelector:
matchLabels:
app: api
tier: backend
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: web
tier: frontend
ports:
- protocol: TCP
port: 8080
egress:
- to:
- podSelector:
matchLabels:
app: postgres
tier: database
ports:
- protocol: TCP
port: 5432
- to:
- podSelector:
matchLabels:
app: redis
tier: cache
ports:
- protocol: TCP
port: 6379
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: database-policy
namespace: production
spec:
podSelector:
matchLabels:
tier: database
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: api
tier: backend
ports:
- protocol: TCP
port: 5432
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
名前空間間ポリシー
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-monitoring
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
purpose: monitoring
podSelector:
matchLabels:
app: prometheus
ports:
- protocol: TCP
port: 9090
名前空間ラベル管理
kubectl label namespace monitoring purpose=monitoring
kubectl label namespace staging env=staging
kubectl label namespace production env=production
kubectl label namespace kube-system kubernetes.io/metadata.name=kube-system
kubectl get namespaces --show-labels
パターン3:Cilium eBPF高度ネットワークポリシー
CiliumはeBPF技術を活用し、K8sネイティブNetworkPolicyのL3/L4制限を突破し、L7 HTTP/gRPC/Kafkaプロトコルポリシーをサポートします。
Ciliumのインストール
helm repo add cilium https://helm.cilium.io/
helm install cilium cilium/cilium \
--namespace kube-system \
--set kubeProxyReplacement=strict \
--set hubble.enabled=true \
--set hubble.relay.enabled=true \
--set hubble.ui.enabled=true \
--set operator.prometheus.enabled=true
L7 HTTPポリシー
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: l7-http-policy
namespace: production
spec:
endpointSelector:
matchLabels:
app: api
tier: backend
ingress:
- fromEndpoints:
- matchLabels:
app: web
tier: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: GET
path: "/api/v1/.*"
- method: POST
path: "/api/v1/orders"
- method: PUT
path: "/api/v1/orders/.*"
Kafkaプロトコルポリシー
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: kafka-policy
namespace: production
spec:
endpointSelector:
matchLabels:
app: kafka
ingress:
- fromEndpoints:
- matchLabels:
app: order-service
toPorts:
- ports:
- port: "9092"
protocol: TCP
rules:
kafka:
- role: produce
topic: orders
- role: consume
topic: orders
- fromEndpoints:
- matchLabels:
app: payment-service
toPorts:
- ports:
- port: "9092"
protocol: TCP
rules:
kafka:
- role: produce
topic: payments
- role: consume
topic: payments
DNSベースのegressポリシー
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: external-api-egress
namespace: production
spec:
endpointSelector:
matchLabels:
app: api
tier: backend
egress:
- toFQDNs:
- matchName: "api.stripe.com"
- matchName: "api.sendgrid.com"
- matchPattern: "*.amazonaws.com"
toPorts:
- ports:
- port: "443"
protocol: TCP
- toEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
rules:
dns:
- matchPattern: "*"
Hubbleオブザーバビリティ
cilium hubble port-forward &
hubble observe --namespace production --since 1m
hubble observe --namespace production --label app=api --verdict DROPPED
hubble observe --namespace production --http-path "/api/v1/.*" --method GET
パターン4:DNSベースのネットワークポリシー
ネイティブNetworkPolicyはドメインベースのポリシーをサポートしていませんが、CiliumとCalicoがこの機能を拡張し、より柔軟なegress制御を実現します。
Cilium FQDNポリシー
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: allow-external-services
namespace: production
spec:
endpointSelector:
matchLabels:
app: payment-service
egress:
- toFQDNs:
- matchName: "api.stripe.com"
- matchName: "api.paypal.com"
toPorts:
- ports:
- port: "443"
protocol: TCP
- toFQDNs:
- matchName: "s3.amazonaws.com"
- matchPattern: "*.s3.amazonaws.com"
toPorts:
- ports:
- port: "443"
protocol: TCP
- toEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
rules:
dns:
- matchPattern: "*"
Calico GlobalNetworkPolicy DNSポリシー
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-external-dns
spec:
selector: app == "payment-service"
order: 100
types:
- Egress
egress:
- action: Allow
protocol: TCP
destination:
domains:
- "api.stripe.com"
- "api.paypal.com"
ports:
- 443
- action: Allow
protocol: UDP
destination:
selector: k8s-app == "kube-dns"
ports:
- 53
DNSポリシーモニタリング
cilium hubble observe --dns --namespace production
cilium hubble observe --fqdn "api.stripe.com" --namespace production
kubectl logs -n kube-system -l k8s-app=kube-dns --tail=100
kubectl get endpoints kube-dns -n kube-system
パターン5:サービスメッシュmTLS
サービスメッシュはサイドカープロキシを通じて自動mTLSを実装し、サービス間通信の暗号化とアイデンティティ認証を提供します。
Istio Strict mTLSモード
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: backend-mtls
namespace: production
spec:
selector:
matchLabels:
tier: backend
mtls:
mode: STRICT
portLevelMtls:
8080:
mode: STRICT
Istio AuthorizationPolicy
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: backend-authz
namespace: production
spec:
selector:
matchLabels:
app: api
tier: backend
rules:
- from:
- source:
principals:
- "cluster.local/ns/production/sa/frontend"
to:
- operation:
methods: ["GET", "POST"]
paths: ["/api/v1/*"]
- from:
- source:
namespaces: ["monitoring"]
principals:
- "cluster.local/ns/monitoring/sa/prometheus"
to:
- operation:
methods: ["GET"]
paths: ["/metrics"]
Cilium Cluster Mesh mTLS
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
name: allow-mtls-traffic
spec:
endpointSelector: {}
ingress:
- fromRequires:
- matchLabels:
io.cilium.k8s.policy.serviceaccount: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
ingress:
- fromEndpoints:
- matchLabels:
io.cilium.k8s.policy.serviceaccount: monitoring
toPorts:
- ports:
- port: "9090"
protocol: TCP
証明書管理
istioctl analyze -n production
istioctl proxy-config secret deploy/frontend.production
kubectl get certificates -n production
kubectl describe certificate backend-cert -n production
kubectl logs -n istio-system -l app=citadel --tail=50
パターン6:ゼロトラストネットワークアーキテクチャブループリント
ゼロトラストは単一の技術ではなく、セキュリティアーキテクチャの哲学です:決して信頼せず、常に検証し、最小権限の原則を守る。
ゼロトラストネットワークアーキテクチャの階層化
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: zero-trust-foundation
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector: {}
ports: []
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
ゼロトラストアイデンティティレイヤー
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: identity-based-policy
namespace: production
spec:
endpointSelector:
matchLabels:
app: api
tier: backend
env: production
ingress:
- fromRequires:
- matchLabels:
app: web
tier: frontend
env: production
io.cilium.k8s.policy.serviceaccount: frontend-sa
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: GET
path: "/api/v1/.*"
- method: POST
path: "/api/v1/orders"
ゼロトラスト監査レイヤー
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: RequestResponse
resources:
- group: networking.k8s.io
resources: ["networkpolicies"]
verbs: ["create", "update", "delete"]
- level: Metadata
resources:
- group: cilium.io
resources: ["ciliumnetworkpolicies", "ciliumclusterwidenetworkpolicies"]
verbs: ["create", "update", "delete"]
ゼロトラストオブザーバビリティ
cilium hubble observe --namespace production --type trace --type drop
cilium hubble observe --verdict DROPPED --since 5m --namespace production
kubectl get ciliumnetworkpolicies -A
kubectl get ciliumclusterwidenetworkpolicies
kubectl get networkpolicies -A
cilium connectivity test --namespace production
ゼロトラストアーキテクチャ検証スクリプト
#!/bin/bash
echo "=== Zero Trust Network Audit ==="
echo "[1] Checking default deny policies..."
for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
count=$(kubectl get networkpolicy -n "$ns" 2>/dev/null | grep -c "default-deny" || true)
if [ "$count" -eq 0 ] && [ "$ns" != "kube-system" ]; then
echo " WARNING: No default-deny policy in namespace: $ns"
fi
done
echo "[2] Checking mTLS status..."
istioctl proxy-config secret -n production 2>/dev/null || echo " Istio not installed or no proxies found"
echo "[3] Checking Cilium policy status..."
cilium policy get 2>/dev/null || echo " Cilium not available"
echo "[4] Checking for overly permissive policies..."
kubectl get networkpolicies -A -o json | \
python3 -c "
import json, sys
policies = json.load(sys.stdin)
for p in policies.get('items', []):
ns = p['metadata']['namespace']
name = p['metadata']['name']
ingress = p.get('spec', {}).get('ingress', [])
for i in ingress:
if not i.get('from') and not i.get('ports'):
print(f' WARNING: {ns}/{name} has empty ingress from selector')
egress = p.get('spec', {}).get('egress', [])
for e in egress:
if not e.get('to') and not e.get('ports'):
print(f' WARNING: {ns}/{name} has empty egress to selector')
"
echo "=== Audit Complete ==="
5つのよくある落とし穴
落とし穴1:DNSトラフィックの許可を忘れる
# ❌ 間違い:すべてのegressを拒否するとDNS解決もできなくなる
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
# ✅ 正しい:DNS egressを明示的に許可する必要がある
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
落とし穴2:名前空間にラベルがない
# ❌ 間違い:namespaceSelectorがどの名前空間にもマッチしない
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-monitoring
spec:
podSelector: {}
ingress:
- from:
- namespaceSelector:
matchLabels:
purpose: monitoring
# ✅ 正しい:先に名前空間にラベルを付ける
# kubectl label namespace monitoring purpose=monitoring
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-monitoring
spec:
podSelector: {}
ingress:
- from:
- namespaceSelector:
matchLabels:
purpose: monitoring
podSelector:
matchLabels:
app: prometheus
落とし穴3:CNIがNetworkPolicyをサポートしていない
# ❌ 間違い:FlannelはNetworkPolicyをサポートせず、ポリシーが有効にならない
# FlannelをCNIとして使用
# ✅ 正しい:NetworkPolicy対応のCNIを使用する
# kubectl get pods -n kube-system -l k8s-app=calico-node
# kubectl get pods -n kube-system -l k8s-app=cilium
# kubectl get pods -n kube-system -l app=antrea
落とし穴4:ポリシーの順序による上書き
# ❌ 間違い:許可ポリシーの後に拒否ポリシーを書いても、拒否は許可を上書きしない
# NetworkPolicyは加算的で、優先度の概念がない
# ✅ 正しい:NetworkPolicyはホワイトリストモデル、すべてのポリシーが加算される
# 優先度が必要な場合は、CalicoのGlobalNetworkPolicyまたはCiliumポリシーを使用
# Calicoはorderフィールドで優先度を制御
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: deny-suspicious
spec:
order: 50
selector: all()
types:
- Ingress
ingress:
- action: Deny
source:
selector: app == "compromised-service"
落とし穴5:kube-system名前空間の無視
# ❌ 間違い:kube-systemにデフォルト拒否を適用するとクラスタ機能が異常になる
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: kube-system
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
# ✅ 正しい:kube-systemは特別な処理が必要、必要なトラフィックを許可する
# kube-system名前空間のデフォルト拒否ポリシーはスキップする
# またはkube-systemの重要コンポーネントに正確な許可ポリシーを設定する
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: kube-system-allow
namespace: kube-system
spec:
podSelector:
matchLabels:
k8s-app: kube-dns
policyTypes:
- Ingress
ingress:
- from: []
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
エラートラブルシューティング表
| エラー現象 | 考えられる原因 | 診断コマンド | 解決策 |
|---|---|---|---|
| Pod間で通信できない | デフォルト拒否ポリシーが厳しすぎる | kubectl get networkpolicy -A |
正確なingress/egressルールを追加 |
| サービスディスカバリの失敗 | DNS egressがブロックされている | kubectl exec -it <pod> -- nslookup api-service |
DNS egress許可ルールを追加 |
| NetworkPolicyが有効にならない | CNIがサポートしていない | kubectl get pods -n kube-system -l k8s-app |
Calico/Cilium/Antreaに切り替え |
| 名前空間間アクセスが拒否される | 名前空間にラベルがない | kubectl get ns --show-labels |
名前空間に必要なラベルを追加 |
| Hubbleが観測できない | Cilium Hubbleが有効になっていない | cilium status |
Helmインストール時にHubbleを有効化 |
| mTLS接続の失敗 | 証明書の期限切れまたは未発行 | istioctl proxy-config secret <pod> |
Certificateリソースの状態を確認 |
| L7ポリシーが動作しない | Ciliumのバージョンが低い | cilium version |
Cilium 1.14+にアップグレード |
| DNSポリシーが動作しない | CoreDNSのバージョンが低い | kubectl get deploy coredns -n kube-system -o yaml |
CoreDNSをアップグレード |
| ポリシー数の爆発 | ラベル設計が不適切 | kubectl get networkpolicy -A | wc -l |
ラベル体系を再設計 |
| Calicoポリシーの競合 | GlobalNetworkPolicyの優先度の問題 | calicoctl get globalnetworkpolicy -o yaml |
orderフィールドを調整 |
高度な最適化
Policy as Code(PaC)
GitOpsでNetworkPolicyを管理し、ポリシー変更がコードレビューを経るようにする:
git checkout -b feature/add-network-policy
mkdir -p k8s/network-policies/production
cat > k8s/network-policies/production/default-deny.yaml << 'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
EOF
git add . && git commit -m "feat: add default deny policy for production"
git push origin feature/add-network-policy
ポリシーの自動テスト
cilium connectivity test \
--test "echo-ingress-l7" \
--namespace production \
--force-deploy
kubectl run policy-test \
--image=busybox:1.36 \
-n production \
--rm -it -- \
wget -qO- --timeout=2 http://api-service:8080/healthz
kubectl run dns-test \
--image=busybox:1.36 \
-n production \
--rm -it -- \
nslookup api-service.production.svc.cluster.local
ポリシーパフォーマンス最適化
cilium config | grep policy
cilium bpf policy list
kubectl get ciliumnetworkpolicies -A -o json | \
python3 -c "
import json, sys
policies = json.load(sys.stdin)
print(f'Total CiliumNetworkPolicies: {len(policies.get(\"items\", []))}')
for p in policies.get('items', []):
ns = p['metadata']['namespace']
name = p['metadata']['name']
ingress = len(p.get('spec', {}).get('ingress', []))
egress = len(p.get('spec', {}).get('egress', []))
print(f' {ns}/{name}: ingress={ingress}, egress={egress}')
"
CNIプラグイン比較
| 機能 | Calico | Cilium | Antrea | Weave Net |
|---|---|---|---|---|
| NetworkPolicyサポート | ✅ 完全 | ✅ 完全+L7 | ✅ 完全 | ⚠️ 基本 |
| L7ポリシー | ❌ | ✅ HTTP/gRPC/Kafka | ❌ | ❌ |
| FQDNポリシー | ✅ | ✅ | ❌ | ❌ |
| eBPFデータプレーン | ✅ オプション | ✅ デフォルト | ✅ オプション | ❌ |
| オブザーバビリティ | ❌ | ✅ Hubble | ⚠️ Flow Exporter | ❌ |
| 暗号化 | ✅ WireGuard | ✅ WireGuard/IPsec | ✅ IPsec | ✅ IPsec |
| パフォーマンス | 高 | 非常に高い | 高 | 中 |
| マルチクラスタ | ✅ | ✅ Cluster Mesh | ✅ | ❌ |
| Service Mesh | ❌ | ✅ 内蔵 | ❌ | ❌ |
| コミュニティの活発さ | 高 | 非常に高い | 高 | 低 |
| ユースケース | 汎用本番 | 高性能+L7 | vSphere環境 | 開発/テスト |
まとめ
Kubernetesネットワークセキュリティは一朝一夕で構築できるものではありません。漸進的なハードニングのプロセスです。デフォルト拒否から始め、マイクロセグメンテーションを段階的に実装し、Cilium eBPFでL7能力を獲得し、DNSポリシーで外部アクセスを制御し、サービスメッシュでmTLSを実現し、最終的にゼロトラストネットワークアーキテクチャを構築します。各ステップが攻撃面を縮小し、各レイヤーが防御の深さを増します。覚えておいてください:NetworkPolicyのないK8sクラスタは、攻撃者の遊び場です。
おすすめツール
- JSONフォーマッター — NetworkPolicy YAML/JSON設定のフォーマット
- Base64エンコード — 証明書とキーデータのエンコード
- ハッシュ計算 — 設定ファイルのハッシュ値を計算して整合性検証
ブラウザローカルツールを無料で試す →