Skip to content

Commit e7ac1a9

Browse files
authored
Merge pull request #24 from oracle-devrel/adm
adm checks
2 parents 93a7bc8 + 6e7e846 commit e7ac1a9

25 files changed

+342
-1
lines changed

oci-build-examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ All about OCI devops build samples ..
1818
<details>
1919
<summary>Security & Quality - click to expand</summary>
2020

21-
* [Integrate sonarqube with OCI devops build runner.](./oci_buildrunner_with_sonarqube/)
2221
* [Container image scanning before deploy.](./oci_imagescan_before_deploy/)
22+
* [Integrate sonarqube with OCI devops build runner.](./oci_buildrunner_with_sonarqube/)
23+
* [Scanning code for vulnerabilities for Maven packages](./oci-devops-vulnerability-audit-management)
24+
2325

2426
</details>
2527

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
**.DS_Store
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Maven build container
2+
3+
FROM maven:3.8.5-openjdk-11 AS maven_build
4+
5+
COPY pom.xml /tmp/
6+
7+
COPY src /tmp/src/
8+
9+
WORKDIR /tmp/
10+
11+
RUN --mount=type=cache,target=/root/.m2 mvn package
12+
13+
#pull base image
14+
15+
FROM openjdk
16+
17+
#expose port 8080
18+
EXPOSE 8080
19+
20+
#default command
21+
CMD java -jar /data/hello-world-0.1.0.jar
22+
23+
#copy hello world to docker image from builder image
24+
25+
COPY --from=maven_build /tmp/target/hello-world-0.1.0.jar /data/hello-world-0.1.0.jar
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
A sample illustration of Code Vulnerabilities for Maven packages
2+
------
3+
4+
The Application Dependency Management (ADM) service provides you with an integrated vulnerability knowledge base that you can use from the Oracle Cloud Infrastructure (OCI) DevOps build pipelines to detect vulnerabilities in the packages used for the build.
5+
6+
7+
Objective
8+
---
9+
10+
- Create an OCI build pipeline with a sample java - maven-based application.
11+
- Instantiate a vulnerability scan and demonstrate success and failure conditions.
12+
13+
* Specific instruction to clone only this example.
14+
15+
```
16+
$ git init oci-devops-vulnerability-audit-management
17+
$ cd oci-devops-vulnerability-audit-management
18+
$ git remote add origin <url to this git repo>
19+
$ git config core.sparsecheckout true
20+
$ echo "oci-build-examples/oci-devops-vulnerability-audit-management/*">>.git/info/sparse-checkout
21+
$ git pull --depth=1 origin main
22+
23+
```
24+
25+
Procedure to use the illustration
26+
-------
27+
- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic
28+
- Create a DevOps project - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm#create_a_project.
29+
- Associate with the notification topic.
30+
31+
![](images/oci_devops_project.png)
32+
33+
- Enable the logging for the DevOps project.
34+
35+
![](images/oci_devops_logs.png)
36+
37+
38+
- Create an OCI Dynamic group and add the below rules. - https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm
39+
40+
```markdown
41+
ALL {resource.type = 'devopsbuildpipeline', resource.compartment.id = 'COMPARMENT OCID'}
42+
43+
ALL {resource.type = 'devopsrepository', resource.compartment.id = 'COMPARMENT OCID'}
44+
```
45+
46+
- Create an OCI policy and add the below policies - https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policies.htm
47+
48+
```markdown
49+
Allow dynamic-group "NAME OF THE DynamicGroup" to manage repos in compartment "COMPARTMENT NAME"
50+
Allow dynamic-group "NAME OF THE DynamicGroup" to use ons-topics in compartment "COMPARTMENT NAME"
51+
```
52+
53+
- Follow the below steps and create a knowledge base - https://docs.oracle.com/en-us/iaas/Content/application-dependency-management/concepts/getting-started.htm
54+
55+
- In the `Oracle Cloud Console`, open the navigation menu, and click `Developer Services`. Under `Application Dependency Management`, click `Knowledge Bases`.
56+
- Click Create Knowledge Base. You are prompted to enter information to describe the new knowledge base.
57+
- Enter the following information:
58+
- Name: Give the knowledge base a name. For example, "Sample Knowledge Base".
59+
- Create in Compartment: Select the compartment from the compartment drop-down list.
60+
- (Optional) Provide a list of one or more unique tag key-value pairs to describe the knowledge base.
61+
62+
![](images/oci_kb.png)
63+
- Make a note of the `Knowledge base OCID`.
64+
65+
![](images/oci_kb_ocid.png)
66+
67+
- Switch back to `OCI DevOps Project ` and create an OCI Code repo - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm#create_repo
68+
69+
![](images/oci_repo.png)
70+
71+
- Push the content to OCI Code repo - https://docs.oracle.com/en-us/iaas/Content/devops/using/clone_repo.htm
72+
73+
- You may use other support version control repos as well (like Github.com,Bitbucket.com, Bitbucket Cloud etc). You may also need to adjust the policies according to connection and setup external connections accordingly - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_connection.htm
74+
75+
- Create a new build pipeline. - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm
76+
77+
![](images/oci_new_buildpipeline.png)
78+
79+
- Under the build pipeline, add below `Parameters`
80+
81+
```markdown
82+
VA_COMPARTMENT_OCID - Add the Compartment OCID as the default value.
83+
KB_OCID - Add the OCID of the knowledge base as the default value
84+
```
85+
86+
![](images/oci_build_param.png)
87+
88+
- Under the `Build pipeline` tab click `+` and add a `Managed Build` stage.
89+
90+
![](images/oci_build_managedbuild_stage.png)
91+
92+
- Add necessary details.
93+
94+
![](images/oci_build_stage_1.png)
95+
96+
- Click `Select` under `primary code repository` and associate with the code repo created.
97+
- You can give any name as `source name`
98+
99+
![](images/oci_buildstage_primary_repo.png)
100+
101+
- Keep all other values by default.
102+
- Before we do the test, let us see what is with in the managed build, the instructions are defined under the [build_spec.yaml](build_spec.yaml) file.
103+
104+
- `VulnerabilityAudit` is the step where we are assessing the application dependencies against the knowledge base and based on the `maxPermissibleCvssV2Score` and `maxPermissibleCvssV3Score` values marking its success or failure.
105+
106+
```markdown
107+
- type: VulnerabilityAudit
108+
name: "Vulnerability Audit Step"
109+
configuration:
110+
buildType: maven
111+
pomFilePath: ${OCI_PRIMARY_SOURCE_DIR}/pom.xml
112+
maxPermissibleCvssV2Score: 6.0
113+
maxPermissibleCvssV3Score: 7.0
114+
knowledgeBaseId: ${KB_OCID}
115+
vulnerabilityAuditCompartmentId: ${VA_COMPARTMENT_OCID}
116+
vulnerabilityAuditName: build_sample_${OCI_PRIMARY_SOURCE_SOURCE_BRANCH_NAME}
117+
```
118+
- Only if it's successful it will do the further steps as a docker image build.
119+
120+
Let's test
121+
------------
122+
123+
- Switch to `Build pipeline` and click on `Start manual run`
124+
- Wait for all the build steps to end, at this run, it will be successful.
125+
126+
![](images/oci_buildrun_ok.png)
127+
128+
- The execution is successful as we set the CvvsV2Score as 6 and CvssV3Score as 7 . To validate the dependency vulnerability scanning repo, switch to the `knowledge base` >`Vulnerability Audits` tab.
129+
130+
![](images/oci_kb_audit_1.png)
131+
132+
- Click and view the details against the `audit run`.
133+
134+
![](images/oci_kb_audit_2.png)
135+
136+
- Change the file [build_spec.yaml](build_spec.yaml) and update `maxPermissibleCvssV2Score` as `2.0` and `maxPermissibleCvssV3Score` as `3.0` .
137+
138+
```markdown
139+
140+
- type: VulnerabilityAudit
141+
name: "Vulnerability Audit Step"
142+
configuration:
143+
buildType: maven
144+
pomFilePath: ${OCI_PRIMARY_SOURCE_DIR}/pom.xml
145+
maxPermissibleCvssV2Score: 2.0
146+
maxPermissibleCvssV3Score: 3.0
147+
knowledgeBaseId: ${KB_OCID}
148+
vulnerabilityAuditCompartmentId: ${VA_COMPARTMENT_OCID}
149+
vulnerabilityAuditName: build_sample_${OCI_PRIMARY_SOURCE_SOURCE_BRANCH_NAME}
150+
```
151+
- Push the changed file back to `OCI Code repo` and re-run the `Build pipeline` using the `Start manual run` option.
152+
153+
- The build run will fail at the steps `Vulnerability Audit Step`.
154+
155+
![](images/oci_buildrun_failed.png)
156+
157+
- To validate the dependency vulnerability scanning repo, switch to the `knowledge base` >`Vulnerability Audits` tab.
158+
159+
![](images/oci_kb_failed.png)
160+
161+
![](images/oci_kb_failed_details.png)
162+
163+
Read more
164+
---
165+
166+
- OCI Devops service - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm
167+
168+
Contributors
169+
===========
170+
171+
- Author: Rahul M R.
172+
- Collaborators: Doug Clarke.
173+
- Last release: June 2022
174+
175+
### Back to examples.
176+
----
177+
178+
- 🍿 [Back to OCI Devops Build sample](./../README.md)
179+
- 🏝️ [Back to OCI Devops sample](./../../README.md)
180+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: 0.1
2+
component: build
3+
timeoutInSeconds: 1000
4+
shell: bash
5+
env:
6+
# these are local variables to the build config
7+
variables:
8+
9+
# exportedVariables are made available to use as parameters in sucessor Build Pipeline stages
10+
# For this Build to run, the Build Pipeline needs to have a BUILDRUN_HASH parameter set
11+
exportedVariables:
12+
# To export variables/
13+
14+
steps:
15+
- type: VulnerabilityAudit
16+
name: "Vulnerability Audit Step"
17+
configuration:
18+
buildType: maven
19+
pomFilePath: ${OCI_PRIMARY_SOURCE_DIR}/pom.xml
20+
maxPermissibleCvssV2Score: 6.0
21+
maxPermissibleCvssV3Score: 7.0
22+
knowledgeBaseId: ${KB_OCID}
23+
vulnerabilityAuditCompartmentId: ${VA_COMPARTMENT_OCID}
24+
vulnerabilityAuditName: build_sample_${OCI_PRIMARY_SOURCE_SOURCE_BRANCH_NAME}
25+
- type: Command
26+
name: "Docker build"
27+
command: |
28+
docker build -t "hello-world-java" .
29+
echo "DONE"
30+
onFailure:
31+
- type: Command
32+
command: |
33+
echo "Handling Failure"
34+
build_result=FAILURE
35+
echo "Failure successfully handled"
36+
# outputArtifacts:
37+
# - name: Build_output_image
38+
# type: DOCKER_IMAGE
39+
# location: "hello-world-java"
72.7 KB
Loading
114 KB
Loading
109 KB
Loading
445 KB
Loading
490 KB
Loading

0 commit comments

Comments
 (0)