当前位置:网站首页>eBPF Cilium实战(1) - 基于团队的网络隔离
eBPF Cilium实战(1) - 基于团队的网络隔离
2022-07-07 05:09:00 【Rainbond】
在 Rainbond 集群中,每个团队对应于底层 Kubernetes 的一个 Namespace ,由于之前使用的底层网络无法进行 Namespace 级别的网络管理,所以在 Rainbond 同一集群下的不同团队间,所以组件可以自由的进行互相访问,用户无法对此做出任何限制,这也导致了底层网络的安全隐患一直存在。现在由 cilium 提供网络服务的 Kubernetes 集群可以很好的解决这一问题,用户可以根据自己的需求,制定针对每个团队、每个组件的网络策略,加强底层网络管理,实现网络层的安全把控。
使用 cilium 作为 Kubernetes 网络服务
使用从主机安装时,修改 network.plugin 值为 none

安装 helm
wget https://goodrain-pkg.oss-cn-shanghai.aliyuncs.com/pkg/helm && chmod +x helm && mv helm /usr/local/bin/- 部署 cilium
helm repo add cilium https://helm.cilium.io/helm install cilium cilium/cilium --version 1.11.2 --namespace kube-system --set operator.replicas=1kubectl get pods --all-namespaces -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,HOSTNETWORK:.spec.hostNetwork --no-headers=true | grep '<none>' | awk '{print "-n "$1" "$2}' | xargs -L 1 -r kubectl delete pod- 验证 cilium
下载 cilium 命令行工具
curl -L --remote-name-all https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz{,.sha256sum}sha256sum --check cilium-linux-amd64.tar.gz.sha256sumsudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/binrm cilium-linux-amd64.tar.gz{,.sha256sum}- 确认状态
$ cilium status --wait/¯¯\/¯¯\__/¯¯\ Cilium: OK\__/¯¯\__/ Operator: OK/¯¯\__/¯¯\ Hubble: disabled\__/¯¯\__/ ClusterMesh: disabled\__/DaemonSet cilium Desired: 2, Ready: 2/2, Available: 2/2Deployment cilium-operator Desired: 2, Ready: 2/2, Available: 2/2Containers: cilium-operator Running: 2cilium Running: 2Image versions cilium quay.io/cilium/cilium:v1.9.5: 2cilium-operator quay.io/cilium/operator-generic:v1.9.5: 2- 测试网络联通性(国内服务器测试时,涉及到外部网络的测试可能会失败,不影响正常使用)
$ cilium connectivity test️ Monitor aggregation detected, will skip some flow validation steps [k8s-cluster] Creating namespace for connectivity check...(...)--------------------------------------------------------------------------------------------------------------------- Test Report--------------------------------------------------------------------------------------------------------------------- 69/69 tests successful (0 warnings)
设置团队网络隔离
Cilium 的网络隔离策略遵循白名单机制,在不创建网络策略的情况下,对于网络不作任何限制,在为指定类型的 pod 集合创建网络策略后,除策略中允许的访问地址外,其它请求都会被拒绝。
前期准备
- 创建两个开发团队和测试团队,英文名称设置为 dev 和 test
- 在开发团队和测试团队下创建 nginx-dev 和 nginx-test 组件,开启对内端口,内部域名分别设置为 nginx-dev 和 nginx-test
- 在开发和测试团队下创建客户端组件
不做任何限制
在不做限制的情况下,各个团队之间的所有服务均可以自由通信,不受任何特殊限制


限制只允许本团队内组件互相访问,隔绝其它团队访问
在实际生产中,一个集群内部可能会同时部署开发、测试、生产等多个团队,基于安全性的考虑,需要对每个的团队做出网络隔离,禁止其它团队可以对其进行访问,下面以开发团队为例说明如何限制不允许其它团队对其访问。

- Cilium 网络策略文件(dev-ingress.yaml)
apiVersion: "cilium.io/v2"kind: CiliumNetworkPolicymetadata:name: "dev-namespace-ingress"spec:endpointSelector:matchLabels:"k8s:io.kubernetes.pod.namespace": devingress:- fromEndpoints:- matchLabels:"k8s:io.kubernetes.pod.namespace": dev- 创建策略
kubectl create -f dev-ingress.yaml -n dev- 确认策略
$ kubectl get CiliumNetworkPolicy -ANAMESPACE NAME AGEdev dev-namespace-ingress 39s- 测试效果


设置开发团队下的 nginx-dev 组件只允许测试团队下的组件访问
在某些情况下,一些组件的安全要求会更为严格,可能只会允许本团队内符合要求的部分组件进行访问,下面以 nginx-dev 为例说明如何限制仅允许部分组件进行访问。

- Cilium 网络策略文件(nginx-dev-ingress0.yaml)
apiVersion: "cilium.io/v2"kind: CiliumNetworkPolicymetadata:name: "nginx-dev-ingress"spec:endpointSelector:matchLabels:name: grc156cbingress:- fromEndpoints:- matchLabels:name: - 创建策略
kubectl create -f nginx-dev-ingress0.yaml -n dev- 确认策略
$ kubectl get CiliumNetworkPolicy -ANAMESPACE NAME AGEdev nginx-dev-ingress0 85s- 测试效果


设置开发团队允许本团队下组件访问的同时,允许开发团队下的 nginx-dev 组件被测试团队中任意组件访问
在设置了团队网络隔离的情况下,有时候需要临时开放一些组件给其它团队访问以便进行调试,下面以 nginx-dev 组件为例说明如何在设置网络隔离的情况下开放外部团队的访问权限。

- Cilium 网络策略文件(nginx-dev-ingress1.yaml)
apiVersion: "cilium.io/v2"kind: CiliumNetworkPolicymetadata:name: "nginx-dev-ingress1"spec:endpointSelector:matchLabels:name: grc156cbingress:- fromEndpoints:- matchLabels:"k8s:io.kubernetes.pod.namespace": test- 创建策略
kubectl create -f dev-ingress.yaml -n devkubectl create -f nginx-dev-ingress.yaml -n dev- 确认策略
$ kubectl get CiliumNetworkPolicy -ANAMESPACE NAME AGEdev dev-namespace-ingress 19sdev nginx-dev-ingress1 12s- 测试效果


边栏推荐
- The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
- 基于Pytorch 框架手动完成线性回归
- Dedecms collects content without writing rules
- Qinglong panel -- Huahua reading
- Lattice coloring - matrix fast power optimized shape pressure DP
- 【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
- Thinkcmf6.0 installation tutorial
- 芯片 设计资料下载
- 【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
- 【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
猜你喜欢

Avatary's livedriver trial experience

Linux server development, redis protocol and asynchronous mode

Bugku CTF daily one question chessboard with only black chess

Linux server development, MySQL transaction principle analysis

漏洞复现-Fastjson 反序列化

Main window in QT learning 27 application

Implementation of replacement function of shell script

Force buckle 145 Binary Tree Postorder Traversal

Interactive book delivery - signed version of Oracle DBA work notes

The largest 3 same digits in the string of leetcode simple question
随机推荐
Excel import function of jeesite form page
积分商城管理系统中应包含的四大项
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
Padavan manually installs PHP
QT learning 26 integrated example of layout management
Merging binary trees by recursion
Hisense TV starts the developer mode
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne
Search for an element in a binary search tree (BST)
基于Pytorch 框架手动完成线性回归
Myabtis_ Plus
ROS bridge notes (05) - Carla_ ackermann_ Control function package (convert Ackermann messages into carlaegovehiclecontrol messages)
互动送书-《Oracle DBA工作笔记》签名版
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
Niu Mei's mathematical problem --- combinatorial number
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number