《OpenShift 4.x HOL教程汇总》
说明:本文已经在OpenShift 4.11 / RHACS 3.71环境中验证
文章目录
ACS 安全策略场景
在 RHACS 中自带丰富的安全策略,可以帮助用户实现从镜像到容器、从网络到宿主机操作系统等各方面的安全检查。用户也可以定制个性化的策略来实现特性安全检查需求。
本示例将创建一个定制安全策略,该策略只针对 “生产集群” ,它不允许在生产环境中部署来自安全高风险的 docker.io 的容器镜像。
创建 ACS 安全策略
- 进入 RHACS 的 Platform Configuration -> Policy Management 菜单,然后点击 Create Policy 按钮。
- 在 Create policy 页面中的 Policy details 步骤中提供以下配置,然后点击 Next。
Name:Image Policy - Production
Severity:Medium
Categories:Production
Description:在生产环境中使用了来自 docker.io 的镜像
Rationale:在生产环境中使用来自 docker.io 的镜像安全风险较高
Guidance:不能在生产环境中使用来自 docker.io 的镜像 - 在 Create policy 页面中的 Policy behavior 步骤中提供以下配置,然后点击 Next。
Lifecycle stages:Deploy
Response method:Inform and enforce
Deploy:Enforce on Deploy
- 在 Create policy 页面中的 Policy criteria 步骤中将右侧的 Image registry 拖拽到 Drop a policy field inside,然后在下方填入 docker.io。进行点击 Next。
- 在 Create policy 页面中的 Policy scope 步骤中打开 Add inclusion scope,在 Cluster 中选择需要保护的 OpenShift 集群。然后点击 Next。
- 在最后一步中 Save 即可。
部署测试镜像
- 在 OpenShift 控制台中使用 “导入 YAML” 功能创建以下 Deployment,其中使用了 docker.io/openshift/hello-openshift 镜像。
kind: Deployment
apiVersion: apps/v1
metadata:
name: hello-openshift
labels:
app: hello-openshift
app.kubernetes.io/name: hello-openshift
app.kubernetes.io/part-of: hello-openshift-app
spec:
replicas: 1
selector:
matchLabels:
app: hello-openshift
template:
metadata:
labels:
app: hello-openshift
spec:
containers:
- name: hello-openshift
image: docker.io/openshift/hello-openshift
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 8888
protocol: TCP
- 确认出现以下错误提示。
- 将镜像换成 quay.io/dawnskyliu/hello-openshift 后重新创建 Deployment,确认可以成功创建。
kind: Deployment
apiVersion: apps/v1
metadata:
name: hello-openshift
labels:
app: hello-openshift
app.kubernetes.io/name: hello-openshift
app.kubernetes.io/part-of: hello-openshift-app
spec:
replicas: 1
selector:
matchLabels:
app: hello-openshift
template:
metadata:
labels:
app: hello-openshift
spec:
containers:
- name: hello-openshift
image: quay.io/dawnskyliu/hello-openshift
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 8888
protocol: TCP
演示视频
参考
https://docs.openshift.com/acs/3.71/operating/manage-security-policies.html
本文含有隐藏内容,请 开通VIP 后查看