Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
feifeiq
docker_practice
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
docker_practice
/
security
/
kernel_capability.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
26 lines (19 loc) · 2.22 KB
master
Breadcrumbs
docker_practice
/
security
/
kernel_capability.md
Copy path
Top
File metadata and controls
Code
Blame
26 lines (19 loc) · 2.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
内核能力机制
[
能力机制
(
Capability
)](
https
:
//man7.org/linux/man-pages/man7/capabilities.7.html) 是 Linux 内核一个强大的特性,可以提供细粒度的权限访问控制。
Linux
内核自
2.2
版本起就支持能力机制
,
它将权限划分为更加细粒度的操作能力
,
既可以作用在进程上
,
也可以作用在文件上
。
例如
,
一个
Web
服务进程只需要绑定一个低于
1024
的端口的权限
,
并不需要
root
权限
。
那么它只需要被授权
`
net_bind_service
`
能力即可
。
此外
,
还有很多其他的类似能力来避免进程获取
root
权限
。
默认情况下
,
Docker
启动的容器被严格限制只允许使用内核的一部分能力
。
使用能力机制对加强
Docker
容器的安全有很多好处
。
通常
,
在服务器上会运行一堆需要特权权限的进程
,
包括有
ssh
、
cron
、
syslogd
、
硬件管理工具模块
(
例如负载模块
)、
网络配置工具等等
。
容器跟这些进程是不同的
,
因为几乎所有的特权进程都由容器以外的支持系统来进行管理
。
*
ssh
访问被主机上ssh服务来管理
;
*
cron
通常应该作为用户进程执行
,
权限交给使用它服务的应用来处理
;
*
日志系统可由
Docker
或第三方服务管理
;
*
硬件管理无关紧要
,
容器中也就无需执行
udevd
以及类似服务
;
*
网络管理也都在主机上设置
,
除非特殊需求
,
容器不需要对网络进行配置
。
从上面的例子可以看出
,
大部分情况下
,
容器并不需要
“
真正的
”
root
权限
,
容器只需要少数的能力即可
。
为了加强安全
,
容器可以禁用一些没必要的权限
。
*
完全禁止任何
mount
操作
;
*
禁止直接访问本地主机的套接字
;
*
禁止访问一些文件系统的操作
,
比如创建新的设备
、
修改文件属性等
;
*
禁止模块加载
。
这样
,
就算攻击者在容器中取得了
root
权限
,
也不能获得本地主机的较高权限
,
能进行的破坏也有限
。
默认情况下
,
Docker采用
[
白名单
](
https
:
//github.com/moby/moby/blob/master/oci/caps/defaults.go) 机制,禁用必需功能之外的其它权限。
当然
,
用户也可以根据自身需求来为
Docker
容器启用额外的权限
。
You can’t perform that action at this time.