|
| 1 | + |
| 2 | +CREATE SEQUENCE IF NOT EXISTS public.resource_scan_execution_result_id_seq; |
| 3 | + |
| 4 | +CREATE table if not exists public.resource_scan_execution_result ( |
| 5 | + id integer DEFAULT nextval('public.resource_scan_execution_result_id_seq'::regclass) NOT NULL, |
| 6 | + image_scan_execution_history_id integer NOT NULL, |
| 7 | + scan_data_json text, |
| 8 | + format integer, |
| 9 | + types integer[], |
| 10 | + scan_tool_id int, |
| 11 | + PRIMARY KEY ("id"), |
| 12 | + CONSTRAINT image_scan_execution_history_id_fkey |
| 13 | + FOREIGN KEY("image_scan_execution_history_id") |
| 14 | + REFERENCES"public"."image_scan_execution_history" ("id") |
| 15 | + ); |
| 16 | + |
| 17 | +ALTER TABLE public.image_scan_execution_history ADD column IF NOT exists source_type integer NULL; |
| 18 | +ALTER TABLE public.image_scan_execution_history ADD column IF NOT exists source_sub_type integer NULL; |
| 19 | +ALTER TABLE public.image_scan_execution_history RENAME COLUMN scan_event_json TO source_metadata_json; |
| 20 | + |
| 21 | + |
| 22 | +UPDATE scan_tool_step |
| 23 | +SET cli_command = 'trivy image -f json -o {{.OUTPUT_FILE_PATH}} --timeout {{.timeout}} {{.IMAGE_NAME}} --username {{.USERNAME}} --password {{.PASSWORD}} {{.EXTRA_ARGS}}' |
| 24 | +WHERE scan_tool_id=3 and index=1 and step_execution_type='CLI'; |
| 25 | +UPDATE scan_tool_step |
| 26 | +SET cli_command = '(export AWS_ACCESS_KEY_ID={{.AWS_ACCESS_KEY_ID}} AWS_SECRET_ACCESS_KEY={{.AWS_SECRET_ACCESS_KEY}} AWS_DEFAULT_REGION={{.AWS_DEFAULT_REGION}}; trivy image -f json -o {{.OUTPUT_FILE_PATH}} --timeout {{.timeout}} {{.IMAGE_NAME}} {{.EXTRA_ARGS}})' |
| 27 | +WHERE scan_tool_id=3 and index=2 and step_execution_type='CLI'; |
| 28 | +UPDATE scan_tool_step |
| 29 | +SET cli_command = 'GOOGLE_APPLICATION_CREDENTIALS="{{.FILE_PATH}}/credentials.json" trivy image -f json -o {{.OUTPUT_FILE_PATH}} --timeout {{.timeout}} {{.IMAGE_NAME}} {{.EXTRA_ARGS}}' |
| 30 | +WHERE scan_tool_id=3 and index=3 and step_execution_type='CLI'; |
| 31 | +UPDATE scan_tool_step |
| 32 | +SET cli_command = 'trivy image -f json -o {{.OUTPUT_FILE_PATH}} --timeout {{.timeout}} {{.IMAGE_NAME}} {{.EXTRA_ARGS}}' |
| 33 | +WHERE scan_tool_id=3 and index=5 and step_execution_type='CLI'; |
| 34 | + |
| 35 | + |
| 36 | +INSERT INTO plugin_metadata (id,name,description,type,icon,deleted,created_on,created_by,updated_on,updated_by) |
| 37 | +VALUES (nextval('id_seq_plugin_metadata'),'Vulnerabilty_Scanner v1.0.0' , 'Checks code vulnerability types in the Post-CI stage','PRESET','https://raw.githubusercontent.com/devtron-labs/devtron/main/assets/devtron-logo-plugin.png',false,'now()',1,'now()',1); |
| 38 | + |
| 39 | + |
| 40 | +INSERT INTO plugin_stage_mapping (id,plugin_id,stage_type,created_on,created_by,updated_on,updated_by)VALUES (nextval('id_seq_plugin_stage_mapping'), |
| 41 | + (SELECT id from plugin_metadata where name='Vulnerabilty_Scanner v1.0.0'),1,'now()',1,'now()',1); |
| 42 | + |
| 43 | +INSERT INTO "plugin_pipeline_script" ("id", "script","type","deleted","created_on", "created_by", "updated_on", "updated_by") |
| 44 | +VALUES ( nextval('id_seq_plugin_pipeline_script'), |
| 45 | + E'#!/bin/bash |
| 46 | +
|
| 47 | +json_data="$CI_CD_EVENT" |
| 48 | +base_url="$IMAGE_SCANNER_ENDPOINT" |
| 49 | +
|
| 50 | +
|
| 51 | +url="$base_url/scanner/image" |
| 52 | +
|
| 53 | +ciProjectDetails=$(echo "$json_data" | jq -r \'.commonWorkflowRequest.ciProjectDetails\') |
| 54 | +ciWorkflowId=$(echo "$json_data" | jq -r \'.workflowId\') |
| 55 | +sourceType=2 |
| 56 | +sourceSubType=1 |
| 57 | +
|
| 58 | +
|
| 59 | +new_payload=$(cat <<EOF |
| 60 | +{ |
| 61 | + "ciProjectDetails": $ciProjectDetails, |
| 62 | + "ciWorkflowId" : $ciWorkflowId, |
| 63 | + "sourceType" : $sourceType, |
| 64 | + "sourceSubType" : $sourceSubType |
| 65 | +
|
| 66 | +} |
| 67 | +EOF |
| 68 | +) |
| 69 | +
|
| 70 | +
|
| 71 | +response=$(curl -s -X POST -H "Content-Type: application/json" -d "$new_payload" "$url") |
| 72 | +
|
| 73 | + export LOW=-1 |
| 74 | + export MEDIUM=-1 |
| 75 | + export HIGH=-1 |
| 76 | + export CRITICAL=-1 |
| 77 | + export UNKNOWN=-1 |
| 78 | +
|
| 79 | +
|
| 80 | +if [[ $(echo "$response" | jq -r \'.status\') == "OK" ]]; then |
| 81 | + # Extract severity values from the response JSON and replace null with zero |
| 82 | + LOW=$(echo "$response" | jq -r \'.result.codeScanResponse.misConfigurations.list[0].summary.severities.LOW // 0\') |
| 83 | + MEDIUM=$(echo "$response" | jq -r \'.result.codeScanResponse.misConfigurations.list[0].summary.severities.MEDIUM // 0\') |
| 84 | + HIGH=$(echo "$response" | jq -r \'.result.codeScanResponse.misConfigurations.list[0].summary.severities.HIGH // 0\') |
| 85 | + CRITICAL=$(echo "$response" | jq -r \'.result.codeScanResponse.misConfigurations.list[0].summary.severities.CRITICAL // 0\') |
| 86 | + UNKNOWN=$(echo "$response" | jq -r \'.result.codeScanResponse.misConfigurations.list[0].summary.severities.UNKNOWN // 0\') |
| 87 | + else |
| 88 | + echo "Response not OK: $response" |
| 89 | + fi |
| 90 | +
|
| 91 | +
|
| 92 | + echo "LOW = $LOW" |
| 93 | + echo "MEDIUM = $MEDIUM" |
| 94 | + echo "HIGH = $HIGH" |
| 95 | + echo "CRITICAL = $CRITICAL" |
| 96 | + echo "UNKNOWN = $UNKNOWN"', |
| 97 | + |
| 98 | + 'SHELL', |
| 99 | + 'f', |
| 100 | + 'now()', |
| 101 | + 1, |
| 102 | + 'now()', |
| 103 | + 1 |
| 104 | +); |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +INSERT INTO "plugin_step" ("id", "plugin_id","name","description","index","step_type","script_id","deleted", "created_on", "created_by", "updated_on", "updated_by") VALUES (nextval('id_seq_plugin_step'), (SELECT id FROM plugin_metadata WHERE name='Vulnerabilty_Scanner v1.0.0'),'Step 1','Step 1 - Vulnerabilty_Scanner v1.0.0','1','INLINE',(SELECT last_value FROM id_seq_plugin_pipeline_script),'f','now()', 1, 'now()', 1); |
| 109 | +INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by) |
| 110 | +VALUES |
| 111 | +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Vulnerabilty_Scanner v1.0.0' and ps."index"=1 and ps.deleted=false),'LOW','NUMBER','Number of LOW vulnerability,','t','f',null,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), |
| 112 | +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Vulnerabilty_Scanner v1.0.0' and ps."index"=1 and ps.deleted=false),'MEDIUM','NUMBER','Number of MEDIUM vulnerability,','t','f',null,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), |
| 113 | +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Vulnerabilty_Scanner v1.0.0' and ps."index"=1 and ps.deleted=false),'HIGH','NUMBER','Number of HIGH vulnerability,','t','f',null,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), |
| 114 | +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Vulnerabilty_Scanner v1.0.0' and ps."index"=1 and ps.deleted=false),'CRITICAL','NUMBER','Number of CRITICAL vulnerability,','t','f',null,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1), |
| 115 | +(nextval('id_seq_plugin_step_variable'),(SELECT ps.id FROM plugin_metadata p inner JOIN plugin_step ps on ps.plugin_id=p.id WHERE p.name='Vulnerabilty_Scanner v1.0.0' and ps."index"=1 and ps.deleted=false),'UNKNOWN','NUMBER','Number of UNKNOWN vulnerability,','t','f',null,null,'OUTPUT','NEW',null,1,null,null,'f','now()',1,'now()',1); |
| 116 | + |
0 commit comments