Aller au contenu

Jenkins


Des étapes d'analyse peuvent être ajoutées à votre Jenkinsfile en utilisant notre installateur CLI.

Avant cela, vous devez rendre disponible dans vos identifiants le Jeton d'API BoostSecurity. Si vous n'avez pas encore créé de jeton API, vous pouvez en créer un depuis le tableau de bord Page des paramètres.

De plus, le CLI devra s'exécuter dans un contexte où il peut récupérer depuis le dépôt Git distant afin de prendre en charge l'analyse différentielle.

Lorsque tout est prêt, une étape d'analyse peut être ajoutée, par exemple :

pipeline {
  agent any

  environment {
    // Expose the api token as an environment variable
    BOOST_API_TOKEN = credentials('boost-api-token')
  }

  options {
    // Skip default checkout so that we may expose env vars later
    skipDefaultCheckout(true)
  }

  stages {
    stage('BoostSecurity Scanner') {
      steps {
        script {
          // Ensure SCM parameters are exposed as env vars
          def scmVars = checkout scm
          scmVars.each { k, v ->
            env."${k}" = v
          }
        }

        sh label: "download the boost cli",
          script: """
            curl -s https://assets.build.boostsecurity.io/boost-cli/get-boost-cli | bash
          """

        // Expose GIT credentials to support pulling.
        withCredentials([gitUsernamePassword(credentialsId: "github-token")]) {
          // Execute the BoostSecurity Semgrep scanner module
          sh label: "scan with boostsecurityio/semgrep",
            script: """
              export BOOST_SCANNER_REGISTRY_MODULE="boostsecurityio/semgrep"
              "${env.WORKSPACE_TMP}/boost-cli/latest" scan repo
            """
        }
      }
    }
  }
}

Jenkins pour l'analyse du code source


Cette configuration convient aux modules de scan pour l'analyse SAST ou pour la génération d'un inventaire SBOM à partir du code source.

Note

Même si le pipeline est configuré pour exécuter le scanner SBOM sur les pull requests, le scanner SBOM ne collecte pas l'inventaire des composants sur les pull requests.

  stages {
    stage('BoostSecurity Scanner') {
      steps {
        script {
          def scmVars = checkout scm
          scmVars.each { k, v ->
            env."${k}" = v
          }
        }

        sh label: "download the boost cli",
          script: """
            curl -s https://assets.build.boostsecurity.io/boost-cli/get-boost-cli | bash
          """

        withCredentials([gitUsernamePassword(credentialsId: "github-token")]) {
          sh label: "scan with boostsecurityio/semgrep",
            script: """
              export BOOST_SCANNER_REGISTRY_MODULE="boostsecurityio/semgrep"
              "${env.WORKSPACE_TMP}/boost-cli/latest" scan repo
            """
        }
      }
    }

    stage('BoostSecurity SBOM') {
      when {
        // SBOM generation should only occur on the main branch
        branch 'main'
      }

      steps {
        script {
          def scmVars = checkout scm
          scmVars.each { k, v ->
            env."${k}" = v
          }
        }

        sh label: "download the boost cli",
          script: """
            curl -s https://assets.build.boostsecurity.io/boost-cli/get-boost-cli | bash
          """

        withCredentials([gitUsernamePassword(credentialsId: "github-token")]) {
          sh label: "scan with boostsecurityio/trivy-sbom",
            script: """
              export BOOST_SCANNER_REGISTRY_MODULE="boostsecurityio/trivy-sbom"
              "${env.WORKSPACE_TMP}/boost-cli/latest" scan repo
            """
        }
      }
    }
  }

Jenkins pour l'analyse d'artefacts générés


Cette configuration convient aux modules de scan qui analysent des artefacts générés par le processus de build. Par exemple, les modules de scan qui génèrent des SBOM à partir d'images conteneurs ou qui recherchent des vulnérabilités doivent d'abord générer l'image conteneur.

Ajoutez le bloc lié au module de scan BoostSecurity à votre pipeline de build, par exemple :

  stages {
    stage('BoostSecurity Scanner') {
      steps {
        script {
          def scmVars = checkout scm
          scmVars.each { k, v ->
            env."${k}" = v
          }
        }

        sh label: "download the boost cli",
          script: """
            curl -s https://assets.build.boostsecurity.io/boost-cli/get-boost-cli | bash
          """

        def dockerfile = 'Dockerfile.test'
        def customImage = docker.build("my-image:${env.BUILD_ID}",
                                       "-f ${dockerfile} ./dockerfiles")

        withCredentials([gitUsernamePassword(credentialsId: "github-token")]) {
          sh label: "scan with boostsecurityio/trivy-image",
            script: """
              export BOOST_IMAGE_NAME="my-image:${env.BUILD_ID}"
              export BOOST_SCANNER_REGISTRY_MODULE="boostsecurityio/trivy-image"
              "${env.WORKSPACE_TMP}/boost-cli/latest" scan repo
            """
        }
      }
    }