今天以及明天主要會針對在準備考試的時候在網路上以及網站學習時遇到的問題進行整理。
考試時對 apparmor 的題目主要是有幾個重點:
(1) 設定對 read, write 的限制
(2) 取得 apparmor 的名稱
(3) pod 指定 apparmor
使用時可以在 k8s.io 中查詢 apparmor 當中就含有如何配置 deny read write 的權限
在配置完後可以透過指令建立 profileapparmor_parser -q <file_name>
查看建立後的 profileaa-status
apiVersion: v1
kind: Pod
metadata:
name: hello-apparmor
spec:
containers:
- name: hello
image: busybox:1.28
command: [ "sh", "-c", "echo 'Hello AppArmor!' && sleep 1h" ]
securityContext:
appArmorProfile:
type: Localhost
localhostProfile: k8s-apparmor-example-deny-write # 將apparmor 的 profile 設定於此
主要是在檢查 Dockfile 以及 pod/deployment 的 yaml 有無安全問題
有幾個重點
securityContext
中做設定
前言 - 似乎 kube-bench 的指令有修改,以往只要kube-bench
就會自動執行,這次在準備時發現會需要指定benchmark
。
(1) 檢查內容
kube-bench --benchmark cis-1.9
(2) 按照需求進行修改
會需要大概記一下各個 config 檔的位置,剩下的可以直接照說明修改
/etc/kubernetes/manifests/kube-controller-manager.yaml
/etc/kubernetes/manifests/kube-scheduler.yaml
/var/lib/kubelet/
/var/lib/etcd
Falco 主要是會考 log 的篩選
以及輸出
需要記一下 Falco 的網站 https://falco.org/
(1) 規則尋找
falco 會提供 default 的規則做參考所有的配置檔會放在 /etc/falco
例如尋找Directory traversal monitored file read
對應的規則在哪
grep "Directory traversal monitored file read" -A 10 -B 10 -r ./
-A 顯示該行的後面幾行
-B 顯示該行的前面幾行
-r 針對哪個資料夾做尋找
(2) ouput 修改
(3) 重啟
修改完後 systemctl daemon-reload
以及 systemctl restart falco
或者直接執行 falco
如果是針對 image 的 policy 就會是透過 ImagePolicyWebhook 設定,可以直接至 k8s.io 中查詢 ImagePolicyWebhook
ImagePolicyWebhook 的 Configuration 會有兩種形式
imagePolicy:
kubeConfigFile: /path/to/kubeconfig/for/backend
# time in s to cache approval
allowTTL: 50
# time in s to cache denial
denyTTL: 50
# time in ms to wait between retries
retryBackoff: 500
# determines behavior if the webhook backend fails
defaultAllow: true
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: ImagePolicyWebhook
path: imagepolicyconfig.yaml
...
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: ImagePolicyWebhook
configuration:
imagePolicy:
kubeConfigFile: <path-to-kubeconfig-file>
allowTTL: 50
denyTTL: 50
retryBackoff: 500
defaultAllow: true
需要特別注意要修改 defaultAllow: true
至/etc/kubernetes/manifests/kube-apiserver.yaml
增加配置
- --enable-admission-plugins=
加上ImagePolicyWebhook
- --admission-control-config-file
位置設定完後 crictl pod
查看 control plane 是否有重啟
重啟後可以透過 kubectl get pods
查看是否修改成功,若配置有錯誤會無法呼叫 kube-apiserver The connection to the server controlplane:6443 was refused - did you specify the right host or port?
(1) Security account automatically mounted 關閉
可在 k8s.io 查詢 servcieaccount pod
apiVersion: v1
kind: ServiceAccount
metadata:
name: build-robot
automountServiceAccountToken: false
在 ingress 中主要會考的是 tls 以及 https 的 ingress 建立
tls secret 建立有三種
kubectl create secret tls
開頭建立詳細內容可以至 k8s.io 中搜尋 ingress
並尋找 TLS 相關的說明
不同的配置會依據不同雲所使用的 controller 而有所不同,但是在考試中主要考的是 nginx 的 controller
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tls-example-ingress
spec:
tls:
- hosts:
- https-example.foo.com
secretName: testsecret-tls
rules:
- host: https-example.foo.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
audit log 以考試而言會比較單純,主要是考:
(1) config 檔配置:需要注意類別會是複數 ex. namespaces, deployments, secrets...
(2) log 儲存:需要注意要使用 volume 以及 volume mount
(3) 單一檔案大小限制、儲存天數、儲存檔案數
相關配置可以在 k8s.io 中查詢audit
取得
可以在 k8s.io 中以關鍵字 pod security standard namespace
查詢,
考試時主要會是需要在指定的 namespace 上加上 label
istio 會是透過 mesh 的形式在每個 pod 建立 sidecar container,考試時會有兩個可以注意:
(1) 在 namesapce 上加上 label
Sidecar or ambient?
istio-injection=enabled
配置到 namespace 上apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
name: default
namespace: default # 可按照需求加上 namespace
spec:
mtls:
mode: STRICT