• OpenShift 4 - 定制 RHACS 安全策略,阻断生产集群使用高风险 Registry


    OpenShift 4.x HOL教程汇总
    说明:本文已经在OpenShift 4.10 / RHACS 3.71环境中验证

    ACS 安全策略场景

    在 RHACS 中自带丰富的安全策略,可以帮助用户实现从镜像到容器、从网络到宿主机操作系统等各方面的安全检查。用户也可以定制个性化的策略来实现特性安全检查需求。

    本示例将创建一个定制安全策略,该策略只针对 “生产集群” ,它不允许在生产环境中部署来自安全高风险的 docker.io 的容器镜像。
    在这里插入图片描述

    创建 ACS 安全策略

    1. 进入 RHACS 的 Platform Configuration -> Policy Management 菜单,然后点击 Create Policy 按钮。
    2. 在 Create policy 页面中的 Policy details 步骤中提供以下配置,然后点击 Next。
      Name:Image Policy - Production
      Severity:Medium
      Categories:Production
      Description:在生产环境中使用了来自 docker.io 的镜像
      Rationale:在生产环境中使用来自 docker.io 的镜像安全风险较高
      Guidance:不能在生产环境中使用来自 docker.io 的镜像
    3. 在 Create policy 页面中的 Policy behavior 步骤中提供以下配置,然后点击 Next。
      Lifecycle stages:Deploy
      Response method:Inform and enforce
      Deploy:Enforce on Deploy
      在这里插入图片描述
    4. 在 Create policy 页面中的 Policy criteria 步骤中将右侧的 Image registry 拖拽到 Drop a policy field inside,然后在下方填入 docker.io。进行点击 Next。
      在这里插入图片描述
    5. 在 Create policy 页面中的 Policy scope 步骤中打开 Add inclusion scope,在 Cluster 中选择需要保护的 OpenShift 集群。然后点击 Next。
      在这里插入图片描述
    6. 在最后一步中 Save 即可。

    部署测试镜像

    1. 在 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    1. 确认出现以下错误提示。
      在这里插入图片描述
    2. 将镜像换成 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    参考

    https://docs.openshift.com/acs/3.71/operating/manage-security-policies.html

  • 相关阅读:
    【Linux】:Linux软件包管理器yum
    Springboot整合Redis集群实战详解
    less学习笔记
    【uni-app系列】uni-ui扩展组件和uViewUI的安装使用
    定时任务之基础实现方式(分布式任务调度)
    使用docker安装本地pdf工具集合Stirling-PDF
    (四)笔记.net core学习之应用配置、多环境配置、日志与路由
    v-on的修饰符
    2023届双非计算机硕士算法岗秋招总结
    c#中的析构函数
  • 原文地址:https://blog.csdn.net/weixin_43902588/article/details/125816727