antony@notes:~/container$ cat "Untitled-1.md"
Untitled
ybean@alp:~$ ls -al /bin/bbsuid —s–x–x 1 root root 14064 Jun 30 00:21 /bin/bbsuid0927 s 代表 setuid
bigred@alp:/setuid$ sudo chown root myfile; sudo chmod 4755 myfile
bigred@alp:/setuid$ ls -al myfile
-rwsr-xr-x 1 root bigred 1958405 Sep 27 11:36 myfile
#4755的4是代表 setuid
執行程式時會去使用system library(linux作業系統提供)來做為輔助執行,並藉由system library操作kernel 若是駭客攻入process,很有可能藉著system library進入kernel進行攻擊 所以使用seccomp做為第一層防守,限制systen library的使用,當有需要時才給用
setuid是程式執行時進入程序時會把執行的權限轉成owner的身分執行,但使用者還是要有x的權限,否則仍無法執行,注意檔案要轉成mashine code
countainer 一定會共用那台主機的kernel
bigred@alp:~/r2d2$ sudo chroot rootfs /bin/bash
chroot: failed to run command ‘/bin/bash’: No such file or directory在做chroot之前,要先確定rootfs有/bin/bash
bigred@alp:~/c3po$ sudo chroot --userspec=bigred:bigred rootfs/ /bin/sh
@alp:/$ whoami
whoami: unknown uid 1000
@alp:/$ tail -n 6 /etc/passwd
cyrus:x:85:12::/usr/cyrus:/sbin/nologin
vpopmail:x:89:89::/var/vpopmail:/sbin/nologin
ntp:x:123:123:NTP:/var/empty:/sbin/nologin
smmsp:x:209:209:smmsp:/var/spool/mqueue:/sbin/nologin
guest:x:405:100:guest:/dev/null:/sbin/nologin
nobody:x:65534:65534:nobody:/:/sbin/nologin
@alp:/$ exitoverlay2是container所使用的堆疊型檔案系統
由上而下依序為:
- container mount(merge):掛載upper&lower堆疊後的結果,一般都在這層做操作(刪除、新增檔案等)
merged功能一
- (whiteout 立可白):當upper與lower具有相同檔名的檔案時,堆疊後的結果會呈現upper的檔案,相同檔名的檔案進行刪除時,會將upper的檔案修改為c(字元檔案),並且不顯示在merged中。
merged功能二
- (copy up 向上複製)若檔案只存在lower,進行修改時會先複製到upper,再進入upper修改
- container layer(upper):具有可讀以及可寫的特色,在merged新建的檔案會存在這層
- image layer(lower):僅具有可讀取的功能,要有sudo的權限才能做檔案增減
Control Group
- 用來分配對象資源
- control group的對象是proess
- 我們要掌控的是PID
Httpd
igred@alp:~/ov2$ dir /sys/fs/cgroup/memory
- 在alpine linux裡面有啟動CGroup,在CGroup裡面有一個記憶體的目錄區,在目錄區里有兩個檔案:
- memory.limit_in_bytes 限制可以用多大的記憶體
- Task 是決定誰受到限制
sudo mkdir /sys/fs/cgroup/memory/demo
bigred@alp:~/ov2$ ls -al /sys/fs/cgroup/memory/demo total 0 drwxr-xr-x 2 root root 0 Sep 29 10:10 . dr-xr-xr-x 3 root root 0 Sep 23 15:02 .. -rw-r–r– 1 root root 0 Sep 29 10:10 cgroup.clone_children –w–w–w- 1 root root 0 Sep 29 10:10 cgroup.event_control -rw-r–r– 1 root root 0 Sep 29 10:10 cgroup.procs -rw-r–r– 1 root root 0 Sep 29 10:10 memory.failcnt –w——- 1 root root 0 Sep 29 10:10 memory.force_empty -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.failcnt -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.limit_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.max_usage_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.tcp.failcnt -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.tcp.limit_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.kmem.tcp.max_usage_in_bytes -r–r–r– 1 root root 0 Sep 29 10:10 memory.kmem.tcp.usage_in_bytes -r–r–r– 1 root root 0 Sep 29 10:10 memory.kmem.usage_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.limit_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.max_usage_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.memsw.failcnt -rw-r–r– 1 root root 0 Sep 29 10:10 memory.memsw.limit_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.memsw.max_usage_in_bytes -r–r–r– 1 root root 0 Sep 29 10:10 memory.memsw.usage_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.move_charge_at_immigrate -rw-r–r– 1 root root 0 Sep 29 10:10 memory.oom_control ———- 1 root root 0 Sep 29 10:10 memory.pressure_level -rw-r–r– 1 root root 0 Sep 29 10:10 memory.soft_limit_in_bytes -r–r–r– 1 root root 0 Sep 29 10:10 memory.stat -rw-r–r– 1 root root 0 Sep 29 10:10 memory.swappiness -r–r–r– 1 root root 0 Sep 29 10:10 memory.usage_in_bytes -rw-r–r– 1 root root 0 Sep 29 10:10 memory.use_hierarchy -rw-r–r– 1 root root 0 Sep 29 10:10 notify_on_release -rw-r–r– 1 root root 0 Sep 29 10:10 tasks
- 在memory下新建一個目錄,會把上層的目錄複製下來
[ ! -d /sys/fs/cgroup/memory/demo ]
- 判斷/sys/cgroup/memory/demo目錄是否存在
sudo mount -t overlay myov2 -o lowerdir=/home/bigred/ov2/lower:/home/bigred/c3po/rootfs,upperdir=/home/bigred/ov2/upper,workdir=/home/bigred/ov2/work /home/bigred/ov2/merged
merged資料夾 裡面存放alpine linux的系統檔案
父程序限制會延續到子程序
vi /etc/resolv.conf
按i進入編輯
輸入nameserver 8.8.8.8
Esc
:wq