Fre*_*aud 9 linux privileges perf docker
我试图在Docker容器中使用perf工具来记录给定的命令.
kernel.perf_event_paranoid设置为1,但是当我没有放置--privileged标志时,容器的行为就像2那样.
我可以使用--privileged,但是我运行perf的代码不受信任,如果我通过允许perf工具承担轻微的安全风险,那么在容器上给予特权权限似乎是不同的风险级别.
有没有其他方法在容器内使用perf?
~$ docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: 7392c3b/17.03.1-ce
Built: Tue May 30 17:59:44 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: 7392c3b/17.03.1-ce
Built: Tue May 30 17:59:44 2017
OS/Arch: linux/amd64
Experimental: false
~$ cat /proc/sys/kernel/perf_event_paranoid
1
~$ perf record ./my-executable
perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 1 (Operation not permitted)
perf_event_open(..., 0) failed unexpectedly with error 1 (Operation not permitted)
Error:
You may not have permission to collect stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid:
-1 - Not paranoid at all
0 - Disallow raw tracepoint access for unpriv
1 - Disallow cpu events for unpriv
2 - Disallow kernel profiling for unpriv
Run Code Online (Sandbox Code Playgroud)
Fre*_*aud 16
经过一些研究,问题不在于perf_event_paranoid,但事实上perf_event_open(系统调用)已在docker中列入黑名单:
https://docs.docker.com/engine/security/seccomp/"Docker v17.06:Seccomp安全配置文件对于Docker"
默认配置文件阻止了重要的系统调用
perf_event_open跟踪/分析系统调用,可能会泄漏主机上的大量信息.
我的第一个解决方法是使用一个脚本下载官方的seccomp文件https://github.com/moby/moby/blob/master/profiles/seccomp/default.json,并添加perf_event_open到白色列表中 -列出的系统调用.
然后我开始使用docker --security-opt seccomp=my-seccomp.json
| 归档时间: |
|
| 查看次数: |
2893 次 |
| 最近记录: |