《OpenShift 4.x HOL教程汇总》
本文在 OpenShift 4.14 环境中进行验证。
如果不安装 Gitea,可以在后面的步骤中直接使用 https://github.com/liuxiaoyu-git/quarkus-build-options 作为 Git 源。
$ oc apply -f https://raw.githubusercontent.com/liuxiaoyu-git/gitea-operator/master/catalog_source.yaml
$ oc new-project gitea
$ cat << EOF | oc apply -f -
apiVersion: gpte.opentlc.com/v1
kind: Gitea
metadata:
name: gitea
namespace: gitea
spec:
giteaSsl: true
giteaAdminUser: gitea
giteaAdminPassword: gitea
giteaAdminEmail: opentlc-[email protected]
EOF
$ oc new-project workshop-int
然后参照下图基于 https://
在创建完上述应用资源后会自动启动 Pipeline 运行,并在成功运行后可以访问 workshop-app 对应的路由 URL。
为 RHACS 增加一个新的安全策略,来查找包含漏洞编号为 RHSA-2020:4908 的容器镜像。
- name: java-old-image
annotations:
description: Build and run Java applications using Maven and OpenJDK 8.
iconClass: icon-rh-openjdk
openshift.io/display-name: Red Hat OpenJDK 8 (UBI 8)
sampleContextDir: undertow-servlet
sampleRepo: 'https://github.com/jboss-openshift/openshift-quickstarts'
supports: 'java:8,java'
tags: 'builder,java,openjdk'
version: '8'
from:
kind: DockerImage
name: 'registry.redhat.io/openjdk/openjdk-11-rhel7:1.1-9'
generation: 4
importPolicy: {}
referencePolicy:
type: Local
STEP-ROX-IMAGE-CHECK
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
31 54.5M 31 17.1M 0 0 117M 0 --:--:-- --:--:-- --:--:-- 116M
100 54.5M 100 54.5M 0 0 142M 0 --:--:-- --:--:-- --:--:-- 142M
Getting roxctl
Policy check results for image: image-registry.openshift-image-registry.svc:5000/workshop-int/workshop@sha256:b4f863396e8d255f996fc1c52b6345c6190984247554dc380ffbaa1cb9ee8d47
(TOTAL: 2, LOW: 1, MEDIUM: 0, HIGH: 1, CRITICAL: 0)
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
| POLICY | SEVERITY | BREAKS BUILD | DESCRIPTION | VIOLATION | REMEDIATION |
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
| Fixable Severity at least | HIGH | X | Alert on deployments with | - Fixable CVE-2021-37136 (CVSS | Use your package manager to |
| Important | | | fixable vulnerabilities with | 7.5) (severity Important) | update to a fixed version in |
| | | | a Severity Rating at least | found in component 'netty' | future builds or speak with |
| | | | Important | (version 4.1.65.final), | your security team to mitigate |
| | | | | resolved by version 4.1.68 | the vulnerabilities. |
| | | | | | |
| | | | | - Fixable CVE-2021-37136 (CVSS | |
| | | | | 7.5) (severity Important) | |
| | | | | found in component 'quarkus' | |
| | | | | (version 2.1.1.final), | |
| | | | | resolved by version 2.2.4 | |
| | | | | | |
| | | | | - Fixable CVE-2021-37137 (CVSS | |
| | | | | 7.5) (severity Important) | |
| | | | | found in component 'netty' | |
| | | | | (version 4.1.65.final), | |
| | | | | resolved by version 4.1.68 | |
| | | | | | |
| | | | | - Fixable CVE-2021-37137 (CVSS | |
| | | | | 7.5) (severity Important) | |
| | | | | found in component 'quarkus' | |
| | | | | (version 2.1.1.final), | |
| | | | | resolved by version 2.2.4 | |
| | | | | | |
| | | | | - Fixable CVE-2022-0981 (CVSS | |
| | | | | 8.8) (severity Important) | |
| | | | | found in component 'quarkus' | |
| | | | | (version 2.1.1.final), | |
| | | | | resolved by version 2.7.1 | |
| | | | | | |
| | | | | - Fixable RHSA-2022:1066 | |
| | | | | (CVSS 7.5) (severity | |
| | | | | Important) found in component | |
| | | | | 'openssl-libs' (version | |
| | | | | 1:1.0.2k-24.el7_9.x86_64), | |
| | | | | resolved by version | |
| | | | | 1:1.0.2k-25.el7_9 | |
| | | | | | |
| | | | | - Fixable RHSA-2022:1069 (CVSS | |
| | | | | 9.8) (severity Important) | |
| | | | | found in component 'expat' | |
| | | | | (version 2.1.0-12.el7.x86_64), | |
| | | | | resolved by version | |
| | | | | 0:2.1.0-14.el7_9 | |
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
| Red Hat Package Manager in | LOW | - | Alert on deployments with | - Image includes | Run `rpm -e --nodeps $(rpm -qa |
| Image | | | components of the Red | component 'rpm' (version | '*rpm*' '*dnf*' '*libsolv*' |
| | | | Hat/Fedora/CentOS package | 4.11.3-48.el7_9.x86_64) | '*hawkey*' 'yum*')` in the |
| | | | management system. | | image build for production |
| | | | | - Image includes | containers. |
| | | | | component 'yum' (version | |
| | | | | 3.4.3-168.el7.noarch) | |
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
WARN: A total of 2 policies have been violated
ERROR: failed policies found: 1 policies violated that are failing the check
ERROR: Policy "Fixable Severity at least Important" - Possible remediation: "Use your package manager to update to a fixed version in future builds or speak with your security team to mitigate the vulnerabilities."
ERROR: checking image failed after 3 retries: failed policies found: 1 policies violated that are failing the check
- args:
- >-
buildah from --storage-driver=vfs --tls-verify=$(params.TLSVERIFY) '$(params.IMAGE):latest' > imgname
buildah run --user=root --storage-driver=vfs `cat imgname` -- sh -c 'rpm -e $(rpm -qa *dnf*) $(rpm -qa *libsolv*) $(rpm -qa *hawkey*) $(rpm -qa yum*) $(rpm -qa *dnf*) $(rpm -qa *subscription-manager*)'
buildah run --user=root --storage-driver=vfs `cat imgname` -- sh -c 'rpm -e $(rpm -qa *rpm*)'
buildah commit --storage-driver=vfs --tls-verify=$(params.TLSVERIFY) `cat imgname` '$(params.IMAGE):latest'
command:
- /bin/sh
- '-c'
image: $(params.BUILDER_IMAGE)
name: remove-package-mgr
resources: {}
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- mountPath: /gen-source
name: gen-source
workingDir: /gen-source
在 RHACS 控制台中进入Platform Configuration中的Policies菜单,确认可以找到名为 Log4Shell 的安全策略。
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-coreartifactId>
<version>2.9.1version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-apiartifactId>
<version>2.9.1version>
dependency>
package org.acme;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Add import here
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
@Path("/hello")
public class GreetingResource {
// Add Logger instantiation here
private Logger logger = LogManager.getLogger(GreetingResource.class.getName());
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello RESTEasy";
}
}
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-coreartifactId>
<version>2.17.1version>
dependency>
<dependency>
<groupId>org.apache.logging.log4jgroupId>
<artifactId>log4j-apiartifactId>
<version>2.17.1version>
dependency>
视频
https://devsecops-workshop.github.io/