今天繼續是考題的整理。
(1) 取得 secret
(2) 修改為 volume 並且為 readonly 的形式
kubectl get pod
以及 kubectl get secret -o yaml
取得 pod 中所使用的 secretecho <base64 encode> | base64 -d
在 k8s.io 中查詢 secret
並參考當中的結構做修改
apiVersion: v1
kind: Secret
metadata:
name: dotfile-secret
data:
.secret-file: dmFsdWUtMg0KDQo=
---
apiVersion: v1
kind: Pod
metadata:
name: secret-dotfiles-pod
spec:
volumes:
- name: secret-volume
secret:
secretName: dotfile-secret
containers:
- name: dotfile-test-container
image: registry.k8s.io/busybox
command:
- ls
- "-l"
- "/etc/secret-volume"
volumeMounts:
- name: secret-volume
readOnly: true
mountPath: "/etc/secret-volume"
可在 k8s.io
中查詢 syscall
或者 seccomp
等關鍵字
(1) 可能會要求修改 seccomp profile,可直接參考官方文件修改
default 的配置檔位置會在 /var/lib/kubelet/seccomp/profiles/
(2) 在 pod 中加上 seccomp
apiVersion: v1
kind: Pod
metadata:
name: audit-pod
labels:
app: audit-pod
spec:
securityContext:
seccompProfile:
type: Localhost
localhostProfile: profiles/audit.json
containers:
- name: test-container
image: hashicorp/http-echo:1.0
args:
- "-text=just made some syscalls!"
securityContext:
allowPrivilegeEscalation: false
以 bom -h
查看指令
需要注意有沒有限制要輸出的格式,如果是json會需要特別修改 --format
透過bom generate
產生SPDX
至 k8s.io 中查詢 Network policy
有幾個需要注意:
(1) 名稱
(2) namesapce
(3) policy
- namespaceSelector:
matchLabels:
project: myproject
- podSelector:
matchLabels:
role: frontend
- namespaceSelector:
matchLabels:
project: myproject
podSelector: # 差異在此
matchLabels:
role: frontend
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {} # 所有pod
policyTypes:
- Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-all-ingress
spec:
podSelector: {} # 所有pod
policyTypes:
- Ingress
ingress:
- {} # 所有規則
role 主要考試會有幾種
(1) 建立對應的權限
core api
的關鍵字找到各個不同的 api group , 像是 replicaset, deployment 都是屬於 apps ;pod, configmap, secret, serviceaccount 都是屬於 core (apiGroups: [""]
)Cilium 的 policy 主要會考怎麼建立 policy,這邊會是需要直接查看 cilium 的官方文件進行修改
書寫邏輯與 NetworkPolicy 相似,唯一不同的是 Cilium 可以使用反向禁止,像是使用ingressDeny
,在使用的同時要注意 namespace
apiVersion: "cilium.io/v2"
kind: CiliumClusterwideNetworkPolicy
metadata:
name: "external-lockdown"
spec:
endpointSelector: {}
ingressDeny:
- fromEntities:
- "world"
ingress:
- fromEntities:
- "all"
kubesec 主要是會要求用來掃描 pod 的 yaml 檔,看是否有不安全的配置並進行修改
會以以下指令進行掃描kubesec scan <yaml 名稱>
在 kube-apiserver 中會有幾種考題:
(1) 修改並設定強制 kubelet 訪問
--anonymous-auth=false
--enable-admission-plugins=NodeRestriction
修改後會需要透過指定 config 訪問
kubectl --kubeconfig=<path_to_file> get pods
(2) 查看/修改目前 config 配置 kubectl config get-contexts
(3) Apiserver 只能透過 Cluster IP 訪問而不是 NodePort
刪除會修改為0
--kubernetes-service-node-port=31000
透過 sha512sum <binary>
查看其 sha512 value
直接在 k8s.io 查詢關鍵字配置