Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made some changes so this runs on 4.12+ cluster #64

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e3de053
adding all the changes need for this to work in a 4.12+ cluster
afouladi7 Jul 10, 2023
c2683f6
Delete users.htpasswd
afouladi7 Jul 10, 2023
1e52799
added the changes for gitops and bc for cosign
afouladi7 Jul 11, 2023
1103bba
Merge branch 'main' of https://github.com/afouladi7/devsecops-demo
afouladi7 Jul 11, 2023
89b005a
adding all the changes for 4.12+
afouladi7 Jul 11, 2023
171d349
changing the gitops app config
afouladi7 Jul 18, 2023
90f165c
adiing sbom to the pipeline
afouladi7 Jul 20, 2023
fe8a435
Updated ACS policy enforcement guidance to permit initial pipeline to
rseip-rh Jul 20, 2023
d8692bb
Create trust_quay_from_another_cluster.md
cmays20 Jul 20, 2023
78d6128
Adds single command for Fedora to install all prerequisite tools.
rseip-rh Jul 21, 2023
cc266e6
adding sbom signing and supporting tasks
afouladi7 Jul 24, 2023
8fa9f2a
Update cosign-build.yaml.j2
afouladi7 Jul 25, 2023
3d0067b
changing to the latest ubi
afouladi7 Jul 25, 2023
4070550
changing to the latest ubi
afouladi7 Jul 26, 2023
ca5681d
adding sbom, attestion, image verify to demo.sh
afouladi7 Jul 26, 2023
665c1bf
adding signing to demo.sh
afouladi7 Jul 26, 2023
cfb459c
adding signing to demo.sh
afouladi7 Jul 26, 2023
7b3c4b0
Merge pull request #1 from redhat-dod-sa/rseip-doc-edits
afouladi7 Aug 1, 2023
1b17f72
updating gogs and quay
afouladi7 Aug 23, 2023
b0635c4
Fixing ArgoCD CR: Cannot specify both keycloak and dex
kincl Aug 28, 2023
e0dd56f
Merge pull request #2 from kincl/fix-argocd
afouladi7 Aug 28, 2023
48792e2
fixing the argo issue with OCP dex
afouladi7 Aug 28, 2023
7191453
Merge branch 'afouladi7:main' into main
afouladi7 Aug 28, 2023
c287a00
updated the readme for the credits
afouladi7 Aug 28, 2023
db788bb
Merge branch 'afouladi7:main' into main
afouladi7 Aug 28, 2023
6e9970e
Removing update to add keycloak for now
kincl Aug 28, 2023
d171b5b
Adding Quay to doc and status.sh
kincl Sep 5, 2023
299a21f
Merge pull request #3 from kincl/fix-argocd
afouladi7 Sep 5, 2023
9542d03
Merge pull request #4 from kincl/add-quay-doc
afouladi7 Sep 5, 2023
3b39326
Merge pull request #2 from redhat-dod-sa/main
afouladi7 Oct 16, 2023
996baa8
adding secure route for gogs
afouladi7 Nov 6, 2023
0818aa3
Tell it to ignore cert validation for the gogs url
cmays20 Nov 6, 2023
b53c3a7
Merge pull request #6 from cmays20/patch-2
afouladi7 Nov 7, 2023
a33f1d4
Merge pull request #1 from cmays20/patch-1
afouladi7 Nov 7, 2023
535ea36
putting quay and acs on a diet
afouladi7 Nov 8, 2023
8419f48
Merge pull request #3 from redhat-dod-sa/main
afouladi7 Nov 8, 2023
151f96f
Update cicd-gogs.yaml.j2
afouladi7 Nov 13, 2023
a022d00
Update cicd.yaml
afouladi7 Nov 13, 2023
1517216
adding console link for acs
afouladi7 Nov 14, 2023
3831d93
adding the https for gogs
afouladi7 Dec 5, 2023
e496fbb
adding the https for gogs
afouladi7 Dec 5, 2023
c053508
adding the https for gogs
afouladi7 Dec 5, 2023
dea453c
adding the https for gogs
afouladi7 Dec 6, 2023
9576f1e
adding the https for gogs
afouladi7 Dec 7, 2023
309d515
Update quay-subscription.yaml.j2
afouladi7 Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DevSecOps CICD pipeline demo using several technologies such as:
- [OpenShift Pipelines](https://www.openshift.com/learn/topics/ci-cd)
- [OpenShift GitOps](https://www.openshift.com/blog/announcing-openshift-gitops)
- [OpenShift Advanced Cluster Security for Kubernetes](https://www.redhat.com/en/resources/advanced-cluster-security-for-kubernetes-datasheet)
- [OpenShift Container Registry](https://docs.openshift.com/container-platform/latest/registry/architecture-component-imageregistry.html)
- [Red Hat Quay](https://www.redhat.com/en/resources/quay-datasheet)

Vulnerability and configuration management methods included in this demo are the following:

Expand Down Expand Up @@ -41,7 +41,7 @@ On every push to the spring-petclinic git repository on Gogs git server, the fol
1. [Dependency report](docs/Steps.md#dependency-report) from the source code is generated and uploaded to the report server repository.
2. [Unit tests](docs/Steps.md#unit-tests) are executed and in parallel the code is [analyzed by Sonarqube](docs/Steps.md#code-analysis-sonarqube) for anti-patterns.
3. Application is packaged as a JAR and [released to Sonatype Nexus](docs/Steps.md#release-app) snapshot repository
4. A [container image is built](docs/Steps.md#build-image) in DEV environment using S2I, and pushed to OpenShift internal registry, and tagged with spring-petclinic:[branch]-[commit-sha] and spring-petclinic:latest
4. A [container image is built](docs/Steps.md#build-image) in DEV environment using S2I and pushed to local instance of Red Hat Quay tagged with spring-petclinic:[branch]-[commit-sha] and spring-petclinic:latest

## 2. DevSecOps steps using Advanced Cluster Security for Kubernetes

Expand Down Expand Up @@ -181,6 +181,13 @@ Install some extra Python dependency:
pip3 install jmespath
```

* On Fedora workstations/servers, these prequisities can be fulfilled with the following single command:

```sh
sudo dnf install -y git ansible ansible-collection-kubernetes-core python3-kubernetes python3-openshift python3-jmespath jq
```


## Bootstrap

Fully automated deployment and integration of every resource and tool needed for this demo.
Expand Down Expand Up @@ -217,7 +224,7 @@ cd ..
./demo.sh start
```

NOTE: This pipeline will fail if you don't [disable the "Fixable at least Important"](docs/disable_policy_enforcement.md) policy enforcement behaviour of ACS. This is expected to demonstrate the failure when a violation of the system policy occurs.
NOTE: This pipeline will fail if you don't [disable the "Fixable Severity at least Important"](docs/disable_policy_enforcement.md) policy enforcement behaviour of ACS. This is expected to demonstrate the failure when a violation of the system policy occurs. Without disabling this policy (or at least changing the behaviour from "inform and enforce" to just "inform"), the image-check stage of the pipeline will fail (and break the build).

## Quick Video with the Demo

Expand All @@ -238,4 +245,4 @@ NOTE: This pipeline will fail if you don't [disable the "Fixable at least Import

# Credits

Big thanks for the [contributors](https://github.com/rcarrata/devsecops-demo/graphs/contributors) and reviews that helped so much in this demo! We grow as we share!
Big thanks for the [contributors](https://github.com/afouladi7/devsecops-demo/graphs/contributors) and reviews that helped so much in this demo! We grow as we share!
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ spec:
project: spring-petclinic
source:
path: environments/dev
repoURL: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
repoURL: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
targetRevision: HEAD
syncPolicy:
automated:
prune: false
selfHeal: false
prune: true
selfHeal: true
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ spec:
project: spring-petclinic
source:
path: environments/stage
repoURL: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
repoURL: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
targetRevision: HEAD
syncPolicy:
automated:
prune: false
selfHeal: false
prune: true
selfHeal: true
8 changes: 4 additions & 4 deletions bootstrap/roles/ocp4-install-acs/templates/central.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ spec:
scanner:
analyzer:
scaling:
autoScaling: Enabled
maxReplicas: 5
minReplicas: 2
replicas: 3
autoScaling: Disabled
maxReplicas: 1
minReplicas: 1
replicas: 1
scannerComponent: Enabled

3 changes: 2 additions & 1 deletion bootstrap/roles/ocp4-install-cicd/tasks/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@

- name: Wait for gogs and gogs-postgresql to be running
uri:
url: http://{{ r_gogs_route.resources[0].spec.host }}
url: https://{{ r_gogs_route.resources[0].spec.host }}
status_code: 200
validate_certs: false
register: result
until: result.status == 200
retries: 10
Expand Down
10 changes: 9 additions & 1 deletion bootstrap/roles/ocp4-install-cicd/templates/cicd-gogs.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ spec:
containers:
- name: gogs
imagePullPolicy: Always
image: quay.io/rcarrata/gogs:stable
image: quay.io/allenfouladi/gogs:stable
ports:
- containerPort: 3000
protocol: TCP
Expand Down Expand Up @@ -179,7 +179,15 @@ metadata:
namespace: cicd
spec:
to:
kind: Service
name: gogs
weight: 100
port:
targetPort: 3000-tcp
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
wildcardPolicy: None
---
kind: PersistentVolumeClaim
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
volumeMounts:
- mountPath: /fileuploads
name: staticfiles
- image: quay.io/siamaksade/nginx:latest
- image: quay.io/allenfouladi/nginx:latest
name: nginx
ports:
- containerPort: 8080
Expand Down
66 changes: 33 additions & 33 deletions bootstrap/roles/ocp4-install-gitops/tasks/gitops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,39 @@
state: present
definition: "{{ lookup('template', 'subs-pipelines.yml.j2') }}"

- name: Adapt to the openshift_cluster_version LESS than 4.9
when: ocp4_cluster_version is version_compare('4.9', '<')
block:

- name: Wait for Pipelines CRD to exist
kubernetes.core.k8s_info:
api_version: "apiextensions.k8s.io/v1beta1"
kind: CustomResourceDefinition
name: "{{ item }}"
loop: "{{ pipelines_expected_crds }}"
register: crds
until: crds.resources|length > 0
retries: 30
delay: 10

- name: Adapt to the openshift_cluster_version MORE than 4.9
when: ocp4_cluster_version is version_compare('4.9', '>=')
block:

- name: Wait for Pipelines CRD to exist
kubernetes.core.k8s_info:
api_version: "apiextensions.k8s.io/v1"
kind: CustomResourceDefinition
name: "{{ item }}"
loop: "{{ pipelines_expected_crds }}"
register: crds
until: crds.resources|length > 0
retries: 30
delay: 10
# - name: Adapt to the openshift_cluster_version LESS than 4.9
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afouladi7 why we are removing these checks? I've tested in 4.13 and worked like a charm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you running this on BM? I tested this on both BM and RHPDS on 4.12.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VMs (Hetzner + libvirt + 4.13) and I'll do it in RHPDS 4.11 as well :)

# when: ocp4_cluster_version is version_compare('4.9', '<')
# block:

# - name: Wait for Pipelines CRD to exist
# kubernetes.core.k8s_info:
# api_version: "apiextensions.k8s.io/v1beta1"
# kind: CustomResourceDefinition
# name: "{{ item }}"
# loop: "{{ pipelines_expected_crds }}"
# register: crds
# until: crds.resources|length > 0
# retries: 30
# delay: 10

# - name: Adapt to the openshift_cluster_version MORE than 4.9
# when: ocp4_cluster_version is version_compare('4.9', '>=')
# block:

# - name: Wait for Pipelines CRD to exist
# kubernetes.core.k8s_info:
# api_version: "apiextensions.k8s.io/v1"
# kind: CustomResourceDefinition
# name: "{{ item }}"
# loop: "{{ pipelines_expected_crds }}"
# register: crds
# until: crds.resources|length > 0
# retries: 30
# delay: 10

- name: Wait for Pipelines Operator to be up and running
pause:
minutes: 1

- name: Add ClusterRoleBinding to the openshift-gitops-controller
kubernetes.core.k8s:
Expand All @@ -96,10 +100,6 @@
- name: Patch the CM of Openshift GitOps to add role admin by default
command: oc patch cm/argocd-rbac-cm -n openshift-gitops --type=merge -p '{"data":{"policy.default":"role:admin"}}'

- name: Add SSO Keycloak in Openshift GitOps by default
shell: |
oc -n openshift-gitops patch argocd openshift-gitops --type='json' -p='[{"op": "add", "path": "/spec/sso", "value": {"provider": "keycloak"} }]'

- name: Get ArgoCD route
kubernetes.core.k8s_info:
kind: Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ spec:
enabled: false
initialSSHKnownHosts: {}
sso:
provider: keycloak
provider: dex
dex:
openShiftOAuth: true
applicationSet:
resources:
limits:
Expand All @@ -55,8 +57,6 @@ spec:
kinds:
- TaskRun
- PipelineRun
dex:
openShiftOAuth: true
ha:
enabled: false
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: openshift-gitops-operator
namespace: openshift-operators
spec:
channel: stable
channel: latest
installPlanApproval: Automatic
name: openshift-gitops-operator
source: redhat-operators
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/roles/ocp4-install-noobaa/tasks/noobaa-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
shell: |
oc get noobaas.noobaa.io/noobaa -n openshift-storage -o jsonpath='{.status.phase}'
register: noobaa_status
retries: 10
retries: 20
delay: 20
until:
- noobaa_status.stdout == "Ready"
Expand Down Expand Up @@ -114,7 +114,7 @@
shell: |
oc get BackingStore/"{{ backing_store_name }}" -n openshift-storage -o jsonpath='{.status.phase}'
register: backing_store
retries: 10
retries: 20
delay: 20
until:
- backing_store.stdout == "Ready"
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/roles/ocp4-install-pipelines/tasks/pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- ./templates/task-rox-image-check.yaml.j2
- ./templates/task-s2i-java-11.yaml.j2
- ./templates/task-zap-proxy.yaml.j2
- ./templates/task-syft-sbom.yaml.j2
- ./templates/task-signing-sbom.yaml.j2

- name: Create OpenShift Objects for Openshift Pipeline Triggers
k8s:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ spec:
- name: APP_SOURCE_GIT
type: string
description: The application git repository
default: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic
default: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic
- name: APP_SOURCE_REVISION
type: string
description: The application git revision
default: master
- name: APP_MANIFESTS_GIT
type: string
description: The application manifests git repository
default: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
default: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
- name: APP_IMAGE_TAG
type: string
default: latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ spec:
- name: APP_SOURCE_GIT
type: string
description: The application git repository
default: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic
default: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic
- name: APP_SOURCE_REVISION
type: string
description: The application git revision
default: master
- name: APP_MANIFESTS_GIT
type: string
description: The application manifests git repository
default: http://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
default: https://{{ r_gogs_route.resources[0].spec.host }}/gogs/spring-petclinic-config
- name: APP_IMAGE_TAG
type: string
default: latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ spec:
# git commit -m "[$(context.pipelineRun.name)] Image digest updated"
git commit -m "[ci] Image digest updated"

git remote add auth-origin $(echo $(params.GIT_REPOSITORY) | sed -E "s#http://(.*)#http://$(params.GIT_USERNAME):$(params.GIT_PASSWORD)@\1#g")
git remote add auth-origin $(echo $(params.GIT_REPOSITORY) | sed -E "s#https://(.*)#https://$(params.GIT_USERNAME):$(params.GIT_PASSWORD)@\1#g")
git push auth-origin master

RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ spec:
registry.redhat.io/rhel8/buildah@sha256:180c4d9849b6ab0e5465d30d4f3a77765cf0d852ca1cb1efb59d6e8c9f90d467
name: build
resources: {}
securityContext:
capabilities:
add:
- SETFCAP
afouladi7 marked this conversation as resolved.
Show resolved Hide resolved
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
Expand All @@ -127,6 +131,10 @@ spec:
image: registry.redhat.io/rhel8/buildah@sha256:180c4d9849b6ab0e5465d30d4f3a77765cf0d852ca1cb1efb59d6e8c9f90d467
name: push-tag
resources: {}
securityContext:
capabilities:
add:
- SETFCAP
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
Expand All @@ -142,6 +150,10 @@ spec:
image: registry.redhat.io/rhel8/buildah@sha256:180c4d9849b6ab0e5465d30d4f3a77765cf0d852ca1cb1efb59d6e8c9f90d467
name: push-latest
resources: {}
securityContext:
capabilities:
add:
- SETFCAP
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
Expand Down
Loading