|
| 1 | +# Security Scanning Tools []( https://g.codefresh.io/repositories/SC-TechDev/docker-security-scanner/builds?filter=trigger:build;branch:master;service:59e62c5410e3d100019e7f3d~docker-security-scanner) |
| 2 | + |
| 3 | +Docker image which invokes security script using TwistCLI (Nexus coming soon) |
| 4 | + |
| 5 | +### Prerequisites: |
| 6 | + |
| 7 | +Codefresh Subscription (Dedicated Infrastructure) - https://codefresh.io/ |
| 8 | + |
| 9 | +Twistlock Subscription - https://www.twistlock.com/ |
| 10 | + |
| 11 | +### Documentation: |
| 12 | + |
| 13 | +Twistlock CLI: https://twistlock.desk.com/customer/en/portal/articles/2875595-twistcli?b_id=16619 |
| 14 | + |
| 15 | +Nexus IQ CLI: TBD |
| 16 | + |
| 17 | +## Script Library |
| 18 | + |
| 19 | +### twistlock.py |
| 20 | + |
| 21 | +Executes TwistCLI to scan Docker image given. |
| 22 | + |
| 23 | +### options |
| 24 | + |
| 25 | +To use an ENVIRONMENT VARIABLE you need to add the variables to your Codefresh Pipeline and also to your codefresh.yaml. |
| 26 | + |
| 27 | + |
| 28 | +Example `codefresh.yml` build is below with required ENVIRONMENT VARIABLES in place. |
| 29 | + |
| 30 | + |
| 31 | +| ENVIRONMENT VARIABLE | SCRIPT ARGUMENT | DEFAULT | TYPE | REQUIRED | DESCRIPTION | |
| 32 | +|----------------------------|--------------------------------------|----------|---------|----------|---------------------------------------------------------------------------------------------------------------------------------| |
| 33 | +| CF_METADATA | [ -c, --cf_metadata ] | null | boolean | No | In combination with TL_UPLOAD stores Twistlock Report URL in TL_REPORT_URL var for Codefresh metadata annotation | |
| 34 | +| TL_CONSOLE_HOSTNAME | [ -C, --tl_console_hostname ] | null | string | Yes | hostname/ip | |
| 35 | +| TL_CONSOLE_PORT | [ -P, --tl_console_port ] | null | string | Yes | port | |
| 36 | +| TL_CONSOLE_USERNAME | [ -U, --tl_console_username ] | null | string | Yes | username | |
| 37 | +| TL_CONSOLE_PASSWORD | [ -X, --tl_console_password ] | null | string | Yes | password | |
| 38 | +| TL_ONLY | [ -Z, --tl_only ] | null | boolean | Yes | Twistlock Console Only (Required for now Nexus TBD) | |
| 39 | +| TL_TLS_ENABLED | [ -T, --tl_tls_enabled ] | null | boolean | No | enable TLS | |
| 40 | +| TL_HASH | [ -H, --tl_hash ] | [ sha1 ] | string | No | [ md5, sha1, sha256 ] hashing algorithm | |
| 41 | +| TL_UPLOAD | [ -R, --tl_upload ] | null | boolean | No | ( ignores all options below if set and only returns report url ) uploads report to Twistlock to be used later via Twistlock API | |
| 42 | +| TL_DETAILS | [ -D, --tl_details ] | null | boolean | No | prints an itemized list of each vulnerability found by the scanner | |
| 43 | +| TL_ONLY_FIXED | [ -O, --tl_only_fixed ] | null | boolean | No | reports just the vulnerabilites that have fixes available | |
| 44 | +| TL_COMPLIANCE_THRESHOLD | [ -M, --tl_compliance_threshold ] | null | string | No | [ low, medium, high ] sets the the minimal severity compliance issue that returns a fail exit code | |
| 45 | +| TL_VULNERABILITY_THRESHOLD | [ -V, --tl_vulnerability_threshold ] | null | string | No | [ low, medium, high, critical ] sets the minimal severity vulnerability that returns a fail exit code | |
| 46 | + |
| 47 | +### codefresh.yml |
| 48 | + |
| 49 | +Codefresh Build Step to execute Twistlock scan. |
| 50 | +All `${{var}}` variables must be put into Codefresh Build Parameters |
| 51 | +codefresh.yml |
| 52 | +```console |
| 53 | + buildimage: |
| 54 | + type: build |
| 55 | + title: Build Runtime Image |
| 56 | + dockerfile: Dockerfile |
| 57 | + image_name: # Image you're building/scanning [repository/image] |
| 58 | + tag: latest-cf-build-candidate |
| 59 | + |
| 60 | + nexus_iq_scan_build_stage: |
| 61 | + type: composition |
| 62 | + composition: |
| 63 | + version: '2' |
| 64 | + services: |
| 65 | + imagebuild: |
| 66 | + image: ${{buildimage}} |
| 67 | + command: sh -c "exit 0" |
| 68 | + labels: |
| 69 | + build.image.id: ${{CF_BUILD_ID}} |
| 70 | + composition_candidates: |
| 71 | + scan_service: |
| 72 | + image: sctechdev/docker-security-scanner |
| 73 | + environment: |
| 74 | + - TL_CONSOLE_HOSTNAME=${{TL_CONSOLE_HOSTNAME}} |
| 75 | + - TL_CONSOLE_PORT=${{TL_CONSOLE_PORT}} |
| 76 | + - TL_CONSOLE_USERNAME=${{TL_CONSOLE_USERNAME}} |
| 77 | + - TL_CONSOLE_PASSWORD=${{TL_CONSOLE_PASSWORD}} |
| 78 | + - TL_ONLY=${{TL_ONLY}} |
| 79 | + command: twistlock.py -i "$$(docker inspect $$(docker inspect $$(docker ps -aqf label=build.image.id=${{CF_BUILD_ID}}) -f {{.Config.Image}}) -f {{.Id}} | sed 's/sha256://g')" |
| 80 | + depends_on: |
| 81 | + - imagebuild |
| 82 | + volumes: |
| 83 | + - /var/run/docker.sock:/var/run/docker.sock |
| 84 | + - /var/lib/docker:/var/lib/docker |
| 85 | + # Everything below this line is Optional for CF_METADATA |
| 86 | + - '${{CF_VOLUME_NAME}}:/codefresh/volume' |
| 87 | + add_flow_volume_to_composition: true |
| 88 | + |
| 89 | + export: |
| 90 | + title: "Exporting variables..." |
| 91 | + image: alpine |
| 92 | + commands: |
| 93 | + - echo "Exporting variables..." |
| 94 | + |
| 95 | + set_metadata: |
| 96 | + title: "Setting metadata on image..." |
| 97 | + image: alpine |
| 98 | + commands: |
| 99 | + - echo "Setting metadata on image..." |
| 100 | + on_finish: |
| 101 | + metadata: |
| 102 | + set: |
| 103 | + - '${{build_step.imageId}}': |
| 104 | + - TwistlockSecurityReport: ${{TL_REPORT_URL}} |
| 105 | +``` |
0 commit comments