|
| 1 | +# cf-twistlock-plugin |
| 2 | +## Codefresh Twistlock Plugin |
| 3 | + |
| 4 | +Dockerhub repo: https://hub.docker.com/r/codefresh/cfstep-twistlock/tags/ |
| 5 | + |
| 6 | +The Docker image uses the Twistlock API v2.3: https://twistlock.desk.com/customer/en/portal/articles/2912404-twistlock-api-2-3 |
| 7 | + |
| 8 | +Plugin that allow users to perform Twistlocl Security Scans on their images. |
| 9 | + |
| 10 | +This plugin **does not** require access to Docker Daemon. |
| 11 | + |
| 12 | + |
| 13 | +## Prerequisites: |
| 14 | + |
| 15 | +- Codefresh Subscription - https://codefresh.io/ |
| 16 | +- Twistlock Subscription - https://www.twistlock.com/ |
| 17 | + |
| 18 | +## Options |
| 19 | +These options are set as Environment Variables at your pipeline (either at Pipeline configuraion, and/or Step definition) |
| 20 | +To use an ENVIRONMENT VARIABLE you need to add the variables to your Codefresh Pipeline and also to your codefresh.yaml. |
| 21 | + |
| 22 | +| ENVIRONMENT VARIABLE | DEFAULT | TYPE | REQUIRED | DESCRIPTION | |
| 23 | +|--|--|--|--|--| |
| 24 | +| TL_CONSOLE_HOSTNAME | null | string | Yes | hostname/ip | |
| 25 | +| TL_CONSOLE_PORT | null | string | Yes | port | |
| 26 | +| TL_CONSOLE_USERNAME | null | string | Yes | username | |
| 27 | +| TL_CONSOLE_PASSWORD | null | string | Yes | password | |
| 28 | +| TL_COMPLIANCE_THRESHOLD | null | string | Yes | [ low, medium, high, critical ] sets the the minimal severity compliance issue that returns a fail exit code | |
| 29 | +| TL_VULNERABILITY_THRESHOLD | null | string | Yes | [ low, medium, high, critical ] sets the minimal severity vulnerability that returns a fail exit code | |
| 30 | +| TL_REGISTRY | null | string | Yes | Registry URL. (e.g.: docker.io, cfcr.io). This should match the Registry URL set at Twistlock Console | |
| 31 | +| TL_IMAGE_NAME | null | string | Yes | The full image name (excluding the registry URL) (e.g.: myrepo/myimage) | |
| 32 | +| TL_IMAGE_TAG | null | string | Yes | The tag of the image to scan. | |
| 33 | + |
| 34 | +> **Threshold description** |
| 35 | +> |
| 36 | +> - low: the most **restrictive**. When thresholds are set to this level, the scanning process will fail with any issue or vulnearability found. |
| 37 | +> - critical: the most **permissive**. When thresholds are set to this level, the scanning process will fail only if a critical issue or vulnearability is found (or a combination of lower level vulnerabilities that summed up result in a risk score higher than 1000). |
| 38 | +
|
| 39 | + |
| 40 | + |
| 41 | +## How to use it (example) |
| 42 | + |
| 43 | +Summary: in this example, we're going to scan an image built by Codefresh. |
| 44 | + |
| 45 | +The image's Dockerfile is defined in this sample repo: https://github.com/francisco-codefresh/twistlock_demo |
| 46 | + |
| 47 | +For scanning purposes, the image will be pushed to a temporary registry, which can be seen as a "Registry of unscanned images". Once there, we can initiate the scan in Twistlock console. |
| 48 | + |
| 49 | +In order for this to work, the registry to scan must be previously added to TwistlocK Console. |
| 50 | + |
| 51 | +Once the security scan finishes, we annote the image based on the Security Report created by Twistlock. |
| 52 | + |
| 53 | +In our example pipeline, if the compliance and vulnerability thresholds are not exceeded, then, we push the resulting image to our final, curated, registry. |
| 54 | + |
| 55 | +### Configure the registry to scan in Twistlock |
| 56 | + |
| 57 | +In your Twistlock dashboard go to `#!/defend/vulnerabilities/registry` . And add a new "registry settings" record. |
| 58 | + |
| 59 | +In this case, we are going to use Docker Hub as our temporary registry. And these are the settings used: |
| 60 | + |
| 61 | +- Version: Docker Registry v2 |
| 62 | +- Registry: docker.io |
| 63 | +- Repository name: franciscocodefresh/twistlockdemo-temp |
| 64 | +- Tag: <empty> |
| 65 | +- Username: <your_user_name> |
| 66 | +- Password: <your_password> |
| 67 | + |
| 68 | +### Set up a pipeline with the following configuration |
| 69 | + |
| 70 | +Now, create a pipeline associated to your repo, in this case, our demo repo is "twistlock_demo" (mentioned above) |
| 71 | + |
| 72 | +#### Environment Variables (configured at Pipeline Configuration): |
| 73 | + |
| 74 | +``` |
| 75 | +TL_CONSOLE_HOSTNAME=169.254.169.254 |
| 76 | +TL_CONSOLE_PORT=8083 |
| 77 | +TL_CONSOLE_USERNAME=myuser |
| 78 | +TL_CONSOLE_PASSWORD=mypassword |
| 79 | +TL_COMPLIANCE_THRESHOLD=critical |
| 80 | +TL_VULNERABILITY_THRESHOLD=critical |
| 81 | +``` |
| 82 | + |
| 83 | +For this example, we're being permissive (critical for both thresholds). Of course those values can be set to any of the other options. |
| 84 | + |
| 85 | +#### Pipeline YAML (Codefresh.yml) |
| 86 | + |
| 87 | +```yaml |
| 88 | +version: '1.0' |
| 89 | +steps: |
| 90 | + BuildingDockerImage: |
| 91 | + title: Building Docker Image |
| 92 | + type: build |
| 93 | + image_name: franciscocodefresh/twistlockdemo |
| 94 | + working_directory: ./ |
| 95 | + tag: '${{CF_SHORT_REVISION}}' |
| 96 | + dockerfile: Dockerfile |
| 97 | + |
| 98 | + PushingToTEMPDockerRegistry: |
| 99 | + title: Pushing to Temporal Docker Registry (for unscanned images -> to be scanned) |
| 100 | + type: push |
| 101 | + candidate: '${{BuildingDockerImage}}' |
| 102 | + image_name: franciscocodefresh/twistlockdemo-temp |
| 103 | + tags: |
| 104 | + - '${{CF_SHORT_REVISION}}' |
| 105 | + |
| 106 | + TL_Scan: |
| 107 | + title: Twistlock Scan |
| 108 | + image: codefresh/cfstep-twistlock |
| 109 | + environment: |
| 110 | + - TL_REGISTRY=docker.io |
| 111 | + - TL_IMAGE_NAME=franciscocodefresh/twistlockdemo-temp |
| 112 | + - TL_IMAGE_TAG=${{CF_SHORT_REVISION}} |
| 113 | + on_success: |
| 114 | + metadata: |
| 115 | + set: |
| 116 | + - ${{BuildingDockerImage.imageId}}: |
| 117 | + - SECURITY_SCAN: true |
| 118 | + on_fail: |
| 119 | + metadata: |
| 120 | + set: |
| 121 | + - ${{BuildingDockerImage.imageId}}: |
| 122 | + - SECURITY_SCAN: false |
| 123 | + |
| 124 | + PushingDockerRegistry: |
| 125 | + title: Pushing to FINAL Docker Registry (curated registry of scanned images) |
| 126 | + type: push |
| 127 | + candidate: '${{BuildingDockerImage}}' |
| 128 | + image_name: franciscocodefresh/twistlockdemo |
| 129 | + tags: |
| 130 | + - '${{CF_SHORT_REVISION}}' |
| 131 | +``` |
| 132 | +
|
| 133 | +
|
| 134 | +
|
0 commit comments