《OpenShift / RHEL / DevSecOps 汇总目录》
文本已在 OpenShift 4.11 + RHACS 3.72.0 环境中进行验证。
请在开始以下操作前先参照《OpenShift Security (2) - 安装 Red Hat Advanced Cluster Security(RHACS)》完成 RHACS 环境安装。
...
FROM registry.access.redhat.com/openjdk/openjdk-11-rhel7:1.12-1
...
...
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>2.13.3version>
dependency>
...
$ git clone https://github.com/liuxiaoyu-git/openshift-demo && cd openshift-demo/bin
$ ./setup_cicd_projects.sh
NEXUS_PVC_SIZE="300Gi"
JENKINS_PVC_SIZE="10Gi"
SONAR_PVC_SIZE="10Gi"
$ ./setup_nexus.sh
$ echo https://$(oc get route nexus -n ci-cd -o jsonpath='{.spec.host}')


$ NEXUS_REGISTRY=$(oc get route nexus-registry -n ci-cd -o jsonpath='{.spec.host}') && echo $NEXUS_REGISTRY
$ yum install skopeo -y
$ NEXUS_PASSWORD=<PASSWORD>
$ allImages="backend:v1 backend:11-ubuntu backend:CVE-2020-36518 frontend-js:v1 frontend-js:node log4shell:latest backend-native:v1 backend-native:v1-distroless"
$ for image in $allImages
do
echo "############## Copy $image ##############"
skopeo copy --src-tls-verify=true --dest-tls-verify=false --src-no-creds --dest-username admin --dest-password $NEXUS_PASSWORD \
docker://quay.io/voravitl/$image docker://$NEXUS_REGISTRY/$image
done


执行命令,安装 Jenkins。
$ ./setup_jenkins.sh
执行命令,安装 Sonarqube。
$ ./setup_sonar.sh
在安装完 Jenkins、Nexus、Sonar 后确认在 ci-cd 项目中应该部署好了以下资源:



$ ROX_CENTRAL_ADDRESS=$(oc get route central -n stackrox -o jsonpath='{.spec.host}'):443
$ roxctl --insecure-skip-tls-verify -e ${ROX_CENTRAL_ADDRESS} image check --image=${NEXUS_REGISTRY}/backend:v1 --output=table --token-file=acs-token
Policy check results for image: nexus-registry-ci-cd.apps.cluster-k8qw5.k8qw5.sandbox638.opentlc.com/backend:v1
(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-2022-42003 | Use your package manager to |
| Important | | | fixable vulnerabilities with | (CVSS 7.5) (severity | update to a fixed version in |
| | | | a Severity Rating at least | Important) found in component | future builds or speak with |
| | | | Important | 'jackson-databind' (version | your security team to mitigate |
| | | | | 2.13.3), resolved by version | the vulnerabilities. |
| | | | | 2.14.0 | |
| | | | | | |
| | | | | - Fixable CVE-2022-42004 | |
| | | | | (CVSS 7.5) (severity | |
| | | | | Important) found in component | |
| | | | | 'jackson-databind' (version | |
| | | | | 2.13.3), resolved by version | |
| | | | | 2.13.4 | |
| | | | | | |
| | | | | - Fixable RHSA-2022:6878 | |
| | | | | (CVSS 9.8) (severity | |
| | | | | Important) found in | |
| | | | | component 'expat' (version | |
| | | | | 2.2.5-8.el8_6.2.x86_64), | |
| | | | | resolved by version | |
| | | | | 0:2.2.5-8.el8_6.3 | |
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
| Red Hat Package Manager in | LOW | - | Alert on deployments with | - Image includes component | Run `rpm -e --nodeps $(rpm -qa |
| Image | | | components of the Red | 'microdnf' (version | '*rpm*' '*dnf*' '*libsolv*' |
| | | | Hat/Fedora/CentOS package | 3.8.0-2.el8.x86_64) | '*hawkey*' 'yum*')` in the |
| | | | management system. | | image build for production |
| | | | | - Image includes | containers. |
| | | | | component 'rpm' (version | |
| | | | | 4.14.3-23.el8.x86_64) | |
+--------------------------------+----------+--------------+--------------------------------+--------------------------------+--------------------------------+
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
$ roxctl --insecure-skip-tls-verify -e ${ROX_CENTRAL_ADDRESS} image scan --image=${NEXUS_REGISTRY}/backend:v1 --output=table --token-file=acs-token
Scan results for image: nexus-registry-ci-cd.apps.cluster-k8qw5.k8qw5.sandbox638.opentlc.com/backend:v1
(TOTAL-COMPONENTS: 41, TOTAL-VULNERABILITIES: 86, LOW: 37, MODERATE: 0, IMPORTANT: 0, CRITICAL: 0)
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
| COMPONENT | VERSION | CVE | SEVERITY | LINK |
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
| arc | 2.12.3.final | CVE-2005-2945 | LOW | https://nvd.nist.gov/vuln/detail/CVE-2005-2945 |
+ + +------------------+-----------+---------------------------------------------------------+
| | | CVE-2005-2992 | LOW | https://nvd.nist.gov/vuln/detail/CVE-2005-2992 |
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
...
...
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
| systemd-libs | 239-58.el8_6.7.x86_64 | CVE-2018-20839 | MODERATE | https://access.redhat.com/security/cve/CVE-2018-20839 |
+ + +------------------+-----------+---------------------------------------------------------+
| | | CVE-2021-3997 | MODERATE | https://access.redhat.com/security/cve/CVE-2021-3997 |
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
| zlib | 1.2.11-18.el8_5.x86_64 | CVE-2022-37434 | MODERATE | https://access.redhat.com/security/cve/CVE-2022-37434 |
+--------------------------+-----------------------------+------------------+-----------+---------------------------------------------------------+
WARN: A total of 94 vulnerabilities were found in 50 components
$ roxctl --insecure-skip-tls-verify -e ${ROX_CENTRAL_ADDRESS} deployment check --file=../manifests/backend-bad-example.yaml --token-file=acs-token
Policy check results for deployments: [backend-v2]
(TOTAL: 2, LOW: 0, MEDIUM: 2, HIGH: 0, CRITICAL: 0)
+--------------------------------+----------+---------------+------------+--------------------------------+--------------------------------+--------------------------------+
| POLICY | SEVERITY | BREAKS DEPLOY | DEPLOYMENT | DESCRIPTION | VIOLATION | REMEDIATION |
+--------------------------------+----------+---------------+------------+--------------------------------+--------------------------------+--------------------------------+
| No resource requests or limits | MEDIUM | - | backend-v2 | Alert on deployments that have | - CPU limit set to 0 cores for | Specify the requests and |
| specified | | | | containers without resource | container 'backend' | limits of CPU and Memory for |
| | | | | requests and limits | | your deployment. |
| | | | | | - CPU request set to 0 cores | |
| | | | | | for container 'backend' | |
| | | | | | | |
| | | | | | - Memory limit set to 0 MB for | |
| | | | | | container 'backend' | |
| | | | | | | |
| | | | | | - Memory request set to 0 MB | |
| | | | | | for container 'backend' | |
+--------------------------------+----------+---------------+------------+--------------------------------+--------------------------------+--------------------------------+
| Pod Service Account Token | MEDIUM | - | backend-v2 | Protect pod default service | - Deployment mounts the | Add |
| Automatically Mounted | | | | account tokens from compromise | service account tokens. | `automountServiceAccountToken: |
| | | | | by minimizing the mounting | | false` or a value distinct |
| | | | | of the default service | - Namespace has name 'default' | from 'default' for the |
| | | | | account token to only those | | `serviceAccountName` key |
| | | | | pods whose application | - Service Account is set to | to the deployment's Pod |
| | | | | requires interaction with the | 'default' | configuration. |
| | | | | Kubernetes API. | | |
+--------------------------------+----------+---------------+------------+--------------------------------+--------------------------------+--------------------------------+
WARN: A total of 2 policies have been violated
执行命令,根据 acs-token 文件生成 secret,该 secret 会在 Jenkins 中被使用。
$ oc create secret generic stackrox-token -n ci-cd --from-file=token=acs-token
$ GIT_ACCOUNT=liuxiaoyu-git
$ cat ../manifests/backend-build-stackrox-pipeline.yaml | \
sed 's/value: NEXUS_REGISTRY/value: '$NEXUS_REGISTRY'/' | \
sed 's/GIT_ACCOUNT/'${GIT_ACCOUNT}'/' | \
oc create -n ci-cd -f -
$ oc get buildconfig -n ci-cd
NAME TYPE FROM LATEST
backend-build-stackrox-pipeline JenkinsPipeline Git@cve 1
$ oc start-build backend-build-stackrox-pipeline




strategy:
type: Docker
dockerStrategy:
dockerfilePath: src/main/docker/Dockerfile.jvm
https://catalog.redhat.com/software/containers/openjdk/openjdk-11-rhel7/5bf57185dd19c775cddc4ce5?architecture=amd64&tag=1.12-1&container-tabs=security


...
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>2.13.3version>
dependency>
...

...
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>2.14.0-rc2version>
dependency>
...
$ oc start-build backend-build-stackrox-pipeline



$ oc start-build backend-build-stackrox-pipeline

如果在 Jenkins 中安装了 Blue Ocean 插件,可以看到以下执行结果。


以下问题是由于 ACS 的 scanner 组件无法访问造成的,请确认该组件对应的 Pod 运行正常。
ERROR: checking image failed after 3 retries: could not check build-time alerts: rpc error: code = Internal desc = image enrichment error: error scanning image: nexus-registry-ci-cd.apps.cluster-k8qw5.k8qw5.sandbox638.opentlc.com/backend:v1 error: scanning "nexus-registry-ci-cd.apps.cluster-k8qw5.k8qw5.sandbox638.opentlc.com/backend:v1" with scanner "Stackrox Scanner": Get "https://scanner.stackrox.svc:8080/scanner/sha/sha256:1fb8cb4ceb8153b374d85017c83f167fd99ce7039b6e2162d64de1c16e1d06de": dial tcp 172.30.5.237:8080: i/o timeout
https://github.com/rhthsa/openshift-demo
https://gitlab.com/ocp-demo/backend_quarkus/-/blob/master/docs/JENKINS.md