GithubHelp home page GithubHelp logo

mandeepsharma007 / codefresh-pipeline-snyk-app-docker-scan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snyk-playground/codefresh-pipeline-snyk-app-docker-scan

0.0 1.0 0.0 52 KB

JavaScript 100.00%

codefresh-pipeline-snyk-app-docker-scan's Introduction

Snyk Security Scanning

Snyk Codefresh Example

This example application has a sample application along with a Codefresh pipeline that can build, scan, and promote a Docker image.

Notice These instructions are new, if you run into any issues running this yourself, please create an issue.

Using the plugin

Scan Code

  SnykAppScan:
    title: Snyk Test Application Dependencies
    stage: scan
    image: '${{BuildingDockerImage}}'
    working_directory: IMAGE_WORK_DIR
    environment:
      - SNYK_TOKEN=${{SNYK_TOKEN}}
      - SNYK_ORG=${{SNYK_ORG}}
    commands:
      - npm install -g snyk
      - snyk test --severity-threshold=high
    on_success:
      metadata:
        set:
          - '${{BuildingDockerImage.imageId}}':
              - CF_QUALITY: true
    on_fail:
      metadata:
        set:
          - '${{BuildingDockerImage.imageId}}':
              - CF_QUALITY: false

Scan Docker Image

  SnykScanImage:
      stage: scan
      type: composition
      composition:
        version: '2'
        services:
          targetimage:
            image: ${{BuildingDockerImage}} # Must be the Docker build step name
            command: sh -c "exit 0"
            labels:
              build.image.id: ${{CF_BUILD_ID}} # Provides a lookup for the composition
      composition_candidates:
        scan_service:
          image: aarlaudsnyk/snyk-container-scan-docker
          command: python snyk-cli.py "${{IMAGE_NAME}}:${{CF_BRANCH_TAG_NORMALIZED}}"
          environment:
          - SNYK_TOKEN=${{SNYK_TOKEN}}
          - SNYK_ORG=${{SNYK_ORG}}
          - CFCR_ACCOUNT=${{CFCR_ACCOUNT}}
          - CF_USER_NAME=${{CF_USER_NAME}}
          - CFCR_LOGIN_TOKEN=${{CFCR_LOGIN_TOKEN}}
          depends_on:
            - targetimage
          volumes: # Volumes required to run DIND
            - /var/run/docker.sock:/var/run/docker.sock
            - /var/lib/docker:/var/lib/docker
      add_flow_volume_to_composition: true
      on_success: # Execute only once the step succeeded
        metadata: # Declare the metadata attribute
          set: # Specify the set operation
            - ${{BuildingDockerImage.imageId}}: # Select any number of target images
              - SECURITY_SCAN: true

      on_fail: # Execute only once the step failed
        metadata: # Declare the metadata attribute
          set: # Specify the set operation
            - ${{BuildingDockerImage.imageId}}: # Select any number of target images
              - SECURITY_SCAN: false

Instructions

Pre-requisites

  • Codefresh account (free or paid)
  • Snyk account (free or paid - Docker scanning is a paid feature, contact Snyk at snyk.io about it)
  • Dockerhub account (Optional)

Add Repo to Codefresh

Signin to Codefresh and click "Add Repository" from the repositories screen. Paste in the url for this repo and click next. Then select "I have a Codefresh.yml" and put ./.codefresh/codefresh.yml for the path. This will preview the Codefresh yaml, then follow the instructions to finish creating the pipeline.

Add Environmental Variables

You can type in the variables by hand, or just copy and paste the following:

PORT=8080
SNYK_ORG=<your snyk organization name>
IMAGE_NAME=<imagename of your choice>
SNYK_TOKEN=<Snyk API token>
CFCR_ACCOUNT=<your Codefresh Registry account>
CF_USER_NAME=<your Codefresh username>
CFCR_LOGIN_TOKEN=<your Codefresh Registry login token>

Select "Import from Text" to import.

We'll also add a token from Snyk. You can get this from your Snyk account settings. Add this variable with SNYK_TOKEN as the key. Then check encrypt to store the token securely. The Codefresh registry bit is optional (remove the lines from the yaml if you do not want to use it). We are testing the docker image built and stored in Codefresh registry before pushing it to Docker Hub if all Snyk tests are successful.

Add Dockerhub (optional)

Codefresh has a built-in private Docker registry. In this example we're building and pushing a public image so we'll use Docker hub. Follow the instructions in the Docker Registry integration page.

You can skip this step by removing the promote to Dockerhub step. If using your own registry, update the name in the push to repo step at the end of the pipeline.

Go run your pipelne.

codefresh-pipeline-snyk-app-docker-scan's People

Contributors

aarlaud avatar todaywasawesome avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.