|
| 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 | + |
| 32 | + |
| 33 | +- Enable the logging for the DevOps project. |
| 34 | + |
| 35 | + |
| 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 | + |
| 63 | +- Make a note of the `Knowledge base OCID`. |
| 64 | + |
| 65 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 87 | + |
| 88 | +- Under the `Build pipeline` tab click `+` and add a `Managed Build` stage. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +- Add necessary details. |
| 93 | + |
| 94 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 131 | + |
| 132 | +- Click and view the details against the `audit run`. |
| 133 | + |
| 134 | + |
| 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 | + |
| 156 | + |
| 157 | +- To validate the dependency vulnerability scanning repo, switch to the `knowledge base` >`Vulnerability Audits` tab. |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 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 | + |
0 commit comments