Cilium

使用BPF和XDP实现API感知网络和安全性。(API-aware Networking and Security for Containers based on BPF.)

Github stars Tracking Chart

Cilium是一款开源软件,用于在应用程序工作负载(如应用程序容器或进程)之间提供透明的网络连接保护和负载平衡。Cilium在第3/4层提供传统的网络和安全服务,在第7层保护和安全使用HTTP、gRPC和Kafka等现代应用程序协议。Cilium集成到公共编配框架中,如Kubernetes和Mesos。

一种名为BPF的新Linux内核技术是Cilium的基础。 它支持在各种集成点(例如,网络IO,应用程序套接字和跟踪点)将BPF字节码动态插入Linux内核,以实现安全性、网络和可见性逻辑。 BPF非常高效灵活。 要了解有关BPF的更多信息,请阅读我们广泛的BPF和XDP参考指南中的更多内容。

功能概述

透明地保护和安全API

能够保护现代应用程序协议,如REST/HTTP、gRPC和Kafka。传统防火墙在第3层和第4层运行。在特定端口上运行的协议要么完全受信任,要么完全阻止。 Cilium提供了过滤各个应用程序协议请求的功能,例如:

  • 允许所有使用方法GET和路径/public/.*的HTTP请求。拒绝所有其他请求。
  • 在Kafka主题topic1 和service2 上产生`service1 代码>到 消费topic1 `。拒绝所有其他卡夫卡消息。
  • 允许service1在Kafka主题topic1和service2上生成以在topic1上使用。拒绝所有其他Kafka消息。
  • 要求在所有REST调用中都存在"HTTP标头X-Token:[0-9]+"。

有关支持的协议的最新列表以及如何使用它的示例,请参阅我们的文档中的第7层策略一节。

基于身份确保服务通信的安全服务

现代分布式应用程序依赖于诸如应用程序容器之类的技术来促进部署中的敏捷性并按需扩展。这导致在短时间内启动大量应用容器。典型的容器防火墙通过过滤源IP地址和目标端口来保护工作负载。这个概念要求在集群中的任何位置启动容器时都要操作所有服务器上的防火墙。

为了避免这种限制扩展的情况,Cilium为共享相同安全策略的应用程序容器组分配安全标识。然后,该标识与应用程序容器发出的所有网络数据包相关联,从而允许验证接收节点处的身份。使用键值存储执行安全身份管理。

安全访问外部服务

基于标签的安全性是集群内部访问控制的首选工具。为了保护对外部服务的访问,支持入口和出口的传统基于CIDR的安全策略。这允许限制对应用程序容器的访问以及对特定IP范围的访问。

简单的网络

一个简单的平面第3层网络能够跨越多个集群,连接所有应用程序容器。使用主机范围分配器可以简化IP分配。这意味着每个主机可以在主机之间没有任何协调的情况下分配IP。

支持以下多节点网络模式:

  • 覆盖:基于封装的虚拟网络产生所有主机。目前VXLAN和Geneve已经完成,但可以启用Linux支持的所有封装格式。 何时使用此模式:此模式具有最小的基础架构和集成要求。它适用于几乎所有网络基础设施,因为唯一的要求是主机之间的IP连接,这通常已经给出。
  • 本地路由:使用Linux主机的常规路由表。网络必须能够路由应用程序容器的IP地址。 何时使用此模式:此模式适用于高级用户,需要了解底层网络基础结构。此模式适用于:
    • 本地IPv6网络
    • 与云网络路由器配合使用
    • 如果您已经在运行路由守护进程

负载平衡

应用程序容器之间的流量的分布式负载平衡 EXTErnal服务。负载平衡是使用BPF使用高效实现的 哈希表允许几乎无限的规模和支持直接服务器 如果未在源上执行负载平衡操作,则返回(DSR) 主机。

应用程序容器和外部服务之间的流量的分布式负载平衡。负载平衡是使用BPF实现的,它使用高效的散列表,允许几乎不受限制的扩展,如果负载平衡操作不在源主机上执行,则支持直接服务器返回(DSR)。注意:负载平衡需要启用连接跟踪。这是默认值。

监测和故障排除

获得可见性和解决问题的能力是任何分布式系统运行的基础。虽然我们学会了喜欢tcpdump和ping这样的工具,虽然他们总会在我们心中找到一个特殊的地方,但我们会努力为故障排除提供更好的工具。这包括提供以下工具:

  • 使用元数据进行事件监控:当数据包被丢弃时,该工具不仅仅报告数据包的源IP和目标IP,该工具还提供了许多其他信息中发送方和接收方的完整标签信息。
  • 策略决策追踪:为什么丢弃数据包或拒绝请求。策略跟踪框架允许跟踪运行工作负载和基于任意标签定义的策略决策过程。
  • 通过Prometheus导出指标:通过Prometheus导出关键指标,以便与现有仪表板集成。

集成

入门

什么是eBPF和XDP?

伯克利数据包过滤器(Berkeley Packet Filter,BPF)是最初用于过滤网络数据包的Linux内核字节码解释器,例如,用于tcpdump和套接字过滤器。最近,BPF指令集和周围架构已经通过其他数据结构(如散列表和数组)进行了大量重新设计,以保持状态以及支持数据包重整、转发、封装等的其他操作。此外,LLVM的编译器后端允许程序用C编写并编译成BPF指令。内核验证程序确保BPF程序可以安全运行,并且JIT编译器将BPF字节代码转换为CPU体系结构特定指令,以实现本机执行效率。 BPF程序可以在内核中的各个挂钩点运行,例如传入数据包,传出数据包,系统调用,kprobes,uprobes,tracepoints等。

每个新的Linux版本,BPF都在不断发展并获得更多功能。 Cilium利用BPF执行核心数据路径过滤,修改,监控和重定向,并且需要任何Linux内核版本4.8.0或更高版本(最新的当前稳定Linux内核为4.14.x)中的BPF功能。

许多Linux发行版,包括CoreOS、Debian、Docker的LinuxKit、Fedora、openSUSE和Ubuntu,已经发布了内核版本= 4.8.x。您可以通过运行uname -a来检查Linux内核版本。如果您还没有运行最新的内核,请查看Linux发行版的文档,了解如何运行Linux内核4.9.x或更高版本。

要阅读必要的内核版本以运行BPF运行时,请参阅先决条件部分。

XDP是进一步发展的一步,它支持从网络驱动程序直接访问数据包的DMA缓冲区来运行特定风格的BPF程序。根据定义,这是软件堆栈中可能的最早的点,在这里可以附加程序,以便在Linux内核网络数据路径中使用可编程的高性能数据包处理器。

有关针对开发人员的BPF和XDP的更多信息,请参阅BPF和XDP参考指南

Overview

Name With Ownercilium/cilium
Primary LanguageGo
Program languageGo (Language Count: 13)
PlatformLinux
License:Apache License 2.0
Release Count629
Last Release Name1.15.4 (Posted on 2024-04-11 15:22:36)
First Release Namev0.8.0 (Posted on )
Created At2015-12-16 12:33:31
Pushed At2024-04-21 13:30:39
Last Commit At
Stargazers Count18.5k
Watchers Count308
Fork Count2.7k
Commits Count28.4k
Has Issues Enabled
Issues Count9187
Issue Open Count964
Pull Requests Count19152
Pull Requests Open Count194
Pull Requests Close Count3476
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

|logo|

|cii| |build-status| |pulls| |slack| |go-report| |go-doc| |rtd| |apache| |gpl|

Cilium is open source software for providing and transparently securing network
connectivity and loadbalancing between application workloads such as
application containers or processes. Cilium operates at Layer 3/4 to provide
traditional networking and security services as well as Layer 7 to protect and
secure use of modern application protocols such as HTTP, gRPC and Kafka. Cilium
is integrated into common orchestration frameworks such as Kubernetes and Mesos.

A new Linux kernel technology called BPF is at the foundation of Cilium. It
supports dynamic insertion of BPF bytecode into the Linux kernel at various
integration points such as: network IO, application sockets, and tracepoints to
implement security, networking and visibility logic. BPF is highly efficient
and flexible. To learn more about BPF, read more in our extensive
BPF and XDP Reference Guide_.

.. image:: https://cdn.rawgit.com/cilium/cilium/master/Documentation/images/cilium-arch.png
:align: center

Stable Releases

The Cilium community maintains minor stable releases for the last three major
Cilium versions. Older Cilium stable versions from major releases prior to that
are considered EOL. Listed below are the actively maintained release branches
along with their latest minor release, corresponding image pull tags and their
release notes:

+-------------------------------------------------------+------------+-------------------------------------+---------------------------------------------------------------------------+------------------------------------------------------------------------+
| v1.6 <https://github.com/cilium/cilium/tree/v1.6>__ | 2019-12-17 | docker.io/cilium/cilium:v1.6.5 | Release Notes <https://github.com/cilium/cilium/releases/tag/v1.6.5>__ | General Announcement <https://cilium.io/blog/2019/08/20/cilium-16>__ |
+-------------------------------------------------------+------------+-------------------------------------+---------------------------------------------------------------------------+------------------------------------------------------------------------+
| v1.5 <https://github.com/cilium/cilium/tree/v1.5>__ | 2019-12-17 | docker.io/cilium/cilium:v1.5.11 | Release Notes <https://github.com/cilium/cilium/releases/tag/v1.5.11>__ | General Announcement <https://cilium.io/blog/2019/04/24/cilium-15>__ |
+-------------------------------------------------------+------------+-------------------------------------+---------------------------------------------------------------------------+------------------------------------------------------------------------+
| v1.4 <https://github.com/cilium/cilium/tree/v1.4>__ | 2019-12-17 | docker.io/cilium/cilium:v1.4.10 | Release Notes <https://github.com/cilium/cilium/releases/tag/v1.4.10>_ | General Announcement <https://cilium.io/blog/2019/02/12/cilium-14>__ |
+-------------------------------------------------------+------------+-------------------------------------+---------------------------------------------------------------------------+------------------------------------------------------------------------+

Functionality Overview

.. begin-functionality-overview

Protect and secure APIs transparently

Ability to secure modern application protocols such as REST/HTTP, gRPC and
Kafka. Traditional firewalls operates at Layer 3 and 4. A protocol running on a
particular port is either completely trusted or blocked entirely. Cilium
provides the ability to filter on individual application protocol requests such
as:

  • Allow all HTTP requests with method GET and path /public/.*. Deny all
    other requests.
  • Allow service1 to produce on Kafka topic topic1 and service2 to
    consume on topic1. Reject all other Kafka messages.
  • Require the HTTP header X-Token: [0-9]+ to be present in all REST calls.

See the section Layer 7 Policy_ in our documentation for the latest list of
supported protocols and examples on how to use it.

Secure service to service communication based on identities

Modern distributed applications rely on technologies such as application
containers to facilitate agility in deployment and scale out on demand. This
results in a large number of application containers to be started in a short
period of time. Typical container firewalls secure workloads by filtering on
source IP addresses and destination ports. This concept requires the firewalls
on all servers to be manipulated whenever a container is started anywhere in
the cluster.

In order to avoid this situation which limits scale, Cilium assigns a security
identity to groups of application containers which share identical security
policies. The identity is then associated with all network packets emitted by
the application containers, allowing to validate the identity at the receiving
node. Security identity management is performed using a key-value store.

Secure access to and from external services

Label based security is the tool of choice for cluster internal access control.
In order to secure access to and from external services, traditional CIDR based
security policies for both ingress and egress are supported. This allows to
limit access to and from application containers to particular IP ranges.

Simple Networking

A simple flat Layer 3 network with the ability to span multiple clusters
connects all application containers. IP allocation is kept simple by using host
scope allocators. This means that each host can allocate IPs without any
coordination between hosts.

The following multi node networking models are supported:

  • Overlay: Encapsulation-based virtual network spanning all hosts.
    Currently VXLAN and Geneve are baked in but all encapsulation formats
    supported by Linux can be enabled.

    When to use this mode: This mode has minimal infrastructure and integration
    requirements. It works on almost any network infrastructure as the only
    requirement is IP connectivity between hosts which is typically already
    given.

  • Native Routing: Use of the regular routing table of the Linux host.
    The network is required to be capable to route the IP addresses of the
    application containers.

    When to use this mode: This mode is for advanced users and requires some
    awareness of the underlying networking infrastructure. This mode works well
    with:

    • Native IPv6 networks
    • In conjunction with cloud network routers
    • If you are already running routing daemons

Load balancing

Distributed load balancing for traffic between application containers and to
external services. The loadbalancing is implemented using BPF using efficient
hashtables allowing for almost unlimited scale and supports direct server
return (DSR) if the loadbalancing operation is not performed on the source
host.
Note: load balancing requires connection tracking to be enabled. This is the
default.

Monitoring and Troubleshooting

The ability to gain visibility and to troubleshoot issues is fundamental to the
operation of any distributed system. While we learned to love tools like
tcpdump and ping and while they will always find a special place in our
hearts, we strive to provide better tooling for troubleshooting. This includes
tooling to provide:

  • Event monitoring with metadata: When a packet is dropped, the tool doesn't
    just report the source and destination IP of the packet, the tool provides
    the full label information of both the sender and receiver among a lot of
    other information.

  • Policy decision tracing: Why is a packet being dropped or a request rejected.
    The policy tracing framework allows to trace the policy decision process for
    both, running workloads and based on arbitrary label definitions.

  • Metrics export via Prometheus: Key metrics are exported via Prometheus for
    integration with your existing dashboards.

  • Hubble_: An observability platform specifically written for Cilium. It
    provides service dependency maps, operational monitoring and alerting,
    and application and security visibility based on flow logs.

.. _Hubble: https://github.com/cilium/hubble/

Integrations

  • Network plugin integrations: CNI_, libnetwork_
  • Container runtime events: containerd_
  • Kubernetes: NetworkPolicy_, Labels_, Ingress_, Service_

.. _CNI: https://github.com/containernetworking/cni
.. _libnetwork: https://github.com/docker/libnetwork
.. _containerd: https://github.com/containerd/containerd
.. _service: https://kubernetes.io/docs/concepts/services-networking/service/
.. _Ingress: https://kubernetes.io/docs/concepts/services-networking/ingress/
.. _NetworkPolicy: https://kubernetes.io/docs/concepts/services-networking/network-policies/
.. _Labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
.. _Layer 7 Policy: http://docs.cilium.io/en/stable/policy/#layer-7

.. end-functionality-overview

Getting Started

  • Why Cilium?_
  • Getting Started_
  • Architecture and Concepts_
  • Installing Cilium_
  • Frequently Asked Questions_
  • Contributing_

What is eBPF and XDP?

Berkeley Packet Filter (BPF) is a Linux kernel bytecode interpreter originally
introduced to filter network packets, e.g. for tcpdump and socket filters. The
BPF instruction set and surrounding architecture has recently been
significantly reworked with additional data structures such as hash tables and
arrays for keeping state as well as additional actions to support packet
mangling, forwarding, encapsulation, etc. Furthermore, a compiler back end for
LLVM allows for programs to be written in C and compiled into BPF instructions.
An in-kernel verifier ensures that BPF programs are safe to run and a JIT
compiler converts the BPF bytecode to CPU architecture specific instructions
for native execution efficiency. BPF programs can be run at various hooking
points in the kernel such as for incoming packets, outgoing packets, system
calls, kprobes, uprobes, tracepoints, etc.

BPF continues to evolve and gain additional capabilities with each new Linux
release. Cilium leverages BPF to perform core data path filtering, mangling,
monitoring and redirection, and requires BPF capabilities that are in any Linux
kernel version 4.8.0 or newer (the latest current stable Linux kernel is
4.14.x).

Many Linux distributions including CoreOS, Debian, Docker's LinuxKit, Fedora,
openSUSE and Ubuntu already ship kernel versions >= 4.8.x. You can check your Linux
kernel version by running uname -a. If you are not yet running a recent
enough kernel, check the Documentation of your Linux distribution on how to run
Linux kernel 4.9.x or later.

To read up on the necessary kernel versions to run the BPF runtime, see the
section Prerequisites_.

.. image:: https://cdn.rawgit.com/cilium/cilium/master/Documentation/images/bpf-overview.png
:align: center

XDP is a further step in evolution and enables to run a specific flavor of BPF
programs from the network driver with direct access to the packet's DMA buffer.
This is, by definition, the earliest possible point in the software stack,
where programs can be attached to in order to allow for a programmable, high
performance packet processor in the Linux kernel networking data path.

Further information about BPF and XDP targeted for developers can be found in
the BPF and XDP Reference Guide_.

To know more about Cilium, it's extensions and use cases around Cilium and BPF
take a look at Further Readings <FURTHER_READINGS.rst>_ section.

Community

Slack

Join the Cilium Slack channel <https://cilium.herokuapp.com/>_ to chat with
Cilium developers and other Cilium users. This is a good place to learn about
Cilium, ask questions, and share your experiences.

Special Interest Groups (SIG)

See Special Interest groups <https://docs.cilium.io/en/stable/community/#special-interest-groups>_ for a list of all SIGs and their meeting times.

Weekly Developer meeting

  • The developer community is hanging out on zoom on a weekly basis to chat.
    Everybody is welcome.
  • Weekly, Monday, 8:00 am PT, 11:00 am ET, 5:00 pm CEST
  • Join zoom <https://zoom.us/j/596609673>_

License

The cilium user space components are licensed under the
Apache License, Version 2.0 <LICENSE>. The BPF code templates are licensed
under the General Public License, Version 2.0 <bpf/COPYING>
.

.. _Why Cilium?: http://docs.cilium.io/en/stable/intro/#why-cilium
.. _Getting Started: http://docs.cilium.io/en/stable/gettingstarted/
.. _Architecture and Concepts: http://docs.cilium.io/en/stable/concepts/
.. _Installing Cilium: http://docs.cilium.io/en/stable/gettingstarted/#installation
.. _Frequently Asked Questions: https://github.com/cilium/cilium/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Akind%2Fquestion+
.. _Contributing: http://docs.cilium.io/en/stable/contributing/contributing/
.. _Prerequisites: http://docs.cilium.io/en/doc-1.0/install/system_requirements
.. _BPF and XDP Reference Guide: http://docs.cilium.io/en/stable/bpf/

.. |logo| image:: https://cdn.rawgit.com/cilium/cilium/master/Documentation/images/logo.svg
:alt: Cilium Logo
:width: 350px

.. |build-status| image:: https://jenkins.cilium.io/job/cilium-ginkgo/job/cilium/job/master/badge/icon
:alt: Build Status
:scale: 100%
:target: https://jenkins.cilium.io/job/cilium-ginkgo/job/cilium/job/master/

.. |go-report| image:: https://goreportcard.com/badge/github.com/cilium/cilium
:alt: Go Report Card
:target: https://goreportcard.com/report/github.com/cilium/cilium

.. |go-doc| image:: https://godoc.org/github.com/cilium/cilium?status.svg
:alt: GoDoc
:target: https://godoc.org/github.com/cilium/cilium

.. |rtd| image:: https://readthedocs.org/projects/docs/badge/?version=latest
:alt: Read the Docs
:target: http://docs.cilium.io/

.. |apache| image:: https://img.shields.io/badge/license-Apache-blue.svg
:alt: Apache licensed
:target: https://github.com/cilium/cilium/blob/master/LICENSE

.. |gpl| image:: https://img.shields.io/badge/license-GPL-blue.svg
:alt: GPL licensed
:target: https://github.com/cilium/cilium/blob/master/bpf/COPYING

.. |slack| image:: https://cilium.herokuapp.com/badge.svg
:alt: Join the Cilium slack channel
:target: https://cilium.herokuapp.com/

.. |cii| image:: https://bestpractices.coreinfrastructure.org/projects/1269/badge
:alt: CII Best Practices
:target: https://bestpractices.coreinfrastructure.org/projects/1269

.. |pulls| image:: https://img.shields.io/docker/pulls/cilium/cilium.svg
:alt: Cilium pulls
:target: https://hub.docker.com/r/cilium/cilium/tags/

To the top