diff --git a/.github/workflows/FOD.yml b/.github/workflows/FOD.yml new file mode 100644 index 0000000..b825488 --- /dev/null +++ b/.github/workflows/FOD.yml @@ -0,0 +1,94 @@ +################################################################################################################################################ +# Fortify lets you build secure software fast with an appsec platform that automates testing throughout the DevSecOps pipeline. Fortify static,# +# dynamic, interactive, and runtime security testing is available on premises or as a service. To learn more about Fortify, start a free trial # +# or contact our sales team, visit microfocus.com/appsecurity. # +# jjj # +# Use this workflow template as a basis for integxrating Fortify on Demand Static Application Security Testing(SAST) into your GitHub workflows.# +# This template demonstrates the steps to prepare the code+dependencies, initiate a scan, download results once complete and import into # +# GitHub Security Code Scanning Alerts. Existing customers should review inputs and environment variables below to configure scanning against # +# an existing application in your Fortify on Demand tenant. Additional information is available in the comments throughout the workflow, the # +# documentation for the Fortify actions used, and the Fortifzxzxy on Demand / ScanCentral Client product documentation. If you need additional # +# assistance with configuration, feel free to create a help ticket in the Fortify on Demand portal. # +################################################################################################################################################ + +name: Fortify on Demand Scan + +# TODO: Customize trigger events based on your DevSecOps processes and typical FoD SAST scan time +on: + workflow_dispatch: + push: + branches: [ add_test_clientside_filtering ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ add_test_clientside_filtering ] + +jobs: + FoD-SAST-Scan: + # Use the appropriate runner for building your source code. + # TODO: Use a Windows runner for .NET projects that use msbuild. Additional changes to RUN commands will be required to switch to Windows syntax. + runs-on: ubuntu-latest + + steps: + # Check out source code + - name: Check Out Source Code + uses: actions/checkout@v2 + + # Java 8 required by ScanCentral Client and FoD Uploader(Univeral CI Tool) + - name: Setup Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Prepare source+dependencies for upload. The default example is for a Maven project that uses pom.xml. + # TODO: Update PACKAGE_OPTS based on the ScanCentral Client documentation for your project's included tech stack(s). Helpful hints: + # ScanCentral Client will download dependencies for maven (-bt mvn) and gradle (-bt gradle). + # ScanCentral Client can download dependencies for msbuild projects (-bt msbuild); however, you must convert the workflow to use a Windows runner. + # ScanCentral has additional options that should be set for PHP and Python projects + # For other build tools, add your build commands to download necessary dependencies and prepare according to Fortify on Demand Packaging documentation. + # ScanCentral Client documentation is located at https://www.microfocus.com/documentation/fortify-software-security-center/ + - name: Download Fortify ScanCentral Client + uses: fortify/gha-setup-scancentral-client@v1 + - name: Package Code + Dependencies + #run: scancentral package $PACKAGE_OPTS -o package.zip + run: zip -r 'package.zip' '/home/runner/work/testwebgoat/testwebgoat' + env: + PACKAGE_OPTS: "-bt mvn" + + # Start Fortify on Demand SAST scan and wait until results complete. For more information on FoDUploader commands, see https://github.com/fod-dev/fod-uploader-java + # TODO: Update ENV variables for your application and create the necessary GitHub Secrets. Helpful hints: + # Credentials and release ID should be obtained from your FoD tenant (either Personal Access Token or API Key can be used). + # Automated Audit preference should be configured for the release's Static Scan Settings in the Fortify on Demand portal. + - name: Download Fortify on Demand Universal CI Tool + uses: fortify/gha-setup-fod-uploader@v1 + - name: Perform SAST Scan + run: java -jar $FOD_UPLOAD_JAR -z package.zip -aurl $FOD_API_URL -purl $FOD_URL -rid "$FOD_RELEASE_ID" -ac "$FOD_APIKEY" "$FOD_APISECRET" $FOD_UPLOADER_OPTS -n "$FOD_UPLOADER_NOTES" + #java -jar $FOD_UPLOAD_JAR -z package.zip -aurl $FOD_API_URL -purl $FOD_URL -rid "$FOD_RELEASE_ID" -tc "$FOD_TENANT" -uc "$FOD_USER" "$FOD_PAT" $FOD_UPLOADER_OPTS -n "$FOD_UPLOADER_NOTES" + env: + #FOD_TENANT: ${{ secrets.FOD_TENANT }} + #FOD_USER: ${{ secrets.FOD_USER }} + #FOD_PAT: ${{ secrets.FOD_PAT }} + FOD_APIKEY: ${{ secrets.FOD_APIKEY }} + FOD_APISECRET: ${{ secrets.FOD_APISECRET }} + FOD_RELEASE_ID: ${{ secrets.FOD_RELEASE_ID }} + FOD_URL: "https://sandbox.fortify.com/" + FOD_API_URL: "https://api.sandbox.fortify.com/" + FOD_UPLOADER_OPTS: "-ep 2 -rp 0 -pp 1 -apf -I 1" + FOD_UPLOADER_NOTES: 'Triggered by GitHub Actions (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})' + + # Once scan completes, pull SAST issues from Fortify on Demand and generate SARIF output. + # TODO: Review Action inputs. For most users, these will be the same as used in the Perform SAST Scan step. + - name: Download Results + uses: fortify/gha-fod-generate-sarif@1.1.0 + with: + base-url: https://sandbox.fortify.com/ + tenant: ${{ secrets.FOD_TENANT }} + user: ${{ secrets.FOD_USER }} + password: ${{ secrets.FOD_PAT }} + release-id: ${{ secrets.FOD_RELEASE_ID }} + output: ./sarif/output.sarif + + # Import Fortify on Demand results to GitHub Security Code Scanning + - name: Import Results + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: ./sarif/output.sarif diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..677724e --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,64 @@ +name: Fortify on Demand SAST Scan + +on: + workflow_dispatch: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + + # fodscan: + # Use the appropriate runner for building your source code.. + # Use Windows runner for projects that use msbuild. Additional changes to RUN commands will be required. + # runs-on: ubuntu-latest +jobs: + ubuntu-latest: + name: ubuntu-latest + runs-on: ubuntu-latest + + steps: + # Check out source code + - name: Check Out Source Code + uses: actions/checkout@v2 + with: + # Fetch at least the immediate parents so that if this is a pull request then we can checkout the head. + fetch-depth: 2 + # If this run was triggered by a pull request event, then checkout the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Java is required to run ScanCentral Client, and may be required for your build + # Java version to use depends on the Java version required to run your build (if any), + # and the Java version supported by the ScanCentral Client version that you are running + - name: Setup Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + # Prepare source+dependencies for upload . + # Update PACKAGE_OPTS based on the ScanCentral Client documentation and your project's included tech stack(s). + # ScanCentral Client will download dependencies for maven, gradle and msbuild projects. + # For other build tools, add your build commands to the workflow to download necessary dependencies and prepare according to Fortify on Demand Packaging documentation. + - name: Download Fortify ScanCentral Client + uses: fortify/gha-setup-scancentral-client@v1 + - name: Package Code + Dependencies + run: scancentral package $PACKAGE_OPTS -o package.zip + env: + PACKAGE_OPTS: "-bt mvn" + + # Start Fortify on Demand SAST scan. Be sure to set secrets/variables for your desired configuration. + - name: Download Fortify on Demand Universal CI Tool + uses: fortify/gha-setup-fod-uploader@v1 + - name: Perform SAST Scan + run: java -jar FodUpload.jar -uc bharathsco@gmail.com NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30 -ep 1 -pp 0 -I 1 -apf -rid 142753 -purl "https://trial.fortify.com/" -aurl "https://api.trial.fortify.com/" -tc accenture_8212434_FMA_287326212 -z package.zip + # env: + # FOD_UPLOAD: /opt/FodUpload.jar + # FOD_TENANT: accenture_8212434_FMA_287326212 + # FOD_USER: bharathsco@gmail.com + # FOD_PAT: NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30 + # FOD_RELEASE_ID: 142753 + # FOD_URL: "https://trial.fortify.com/" + # FOD_API_URL: "https://api.trial.fortify.com/" + # FOD_UPLOADER_OPTS: "-ep SubscriptionOnly -pp 0 -I 1 -apf" + # FOD_UPLOADER_NOTES: 'Triggered by GitHub Actions (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})' diff --git a/.github/workflows/readme.md b/.github/workflows/readme.md new file mode 100644 index 0000000..05a34f9 --- /dev/null +++ b/.github/workflows/readme.md @@ -0,0 +1 @@ +CH!! diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml new file mode 100644 index 0000000..3437ad0 --- /dev/null +++ b/.github/workflows/snyk.yml @@ -0,0 +1,21 @@ +name: Snyk test +on: push +jobs: + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: snyk/actions/setup@master + #- uses: actions/setup-go@v1 + # with: + # go-version: "1.13" + #- name: Snyk monitor + #run: snyk monitor + - name: Snyk test + run: snyk test + env: + SNYK_TOKEN: 5f22108b-4f20-4760-817d-3dd42b3a3da3 + #--all-projects + #sfdsf + #SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + diff --git a/FodUpload.jar b/FodUpload.jar new file mode 100644 index 0000000..16f9308 Binary files /dev/null and b/FodUpload.jar differ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..4d4dc7c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,412 @@ +#!/usr/bin/env groovy + +//**************************************************************************************************** +// An example pipeline for DevSecOps using Micro Focus Fortify Application Security products +// @author: Kevin A. Lee (kevin.lee@microfocus.com) +// +// +// Pre-requisites: +// - Fortify SCA/ScanCentral SAST has been installed (for on-premise SAST) +// - Fortify WebInspect/ScanCentral DAST has been installed (for on-premise DAST) +// - A Fortify On Demand account and API access are available (for cloud based SAST/DAST) +// - Docker Pipeline plugin has been installed (Jenkins) +// - [Optional] Sonatype Nexus IQ server has been installed for OSS SCA vulnerabilities +// +// Typical node setup: +// - Install Fortify SCA on the agent machine +// - create a new Jenkins agent for this machine +// - Apply the label "fortify" to the agent. +// - Set the environment variable "FORTIFY_HOME" on the agent point to the location of the Fortify SCA installation +// Also ensure the label "master" has been applied to your Jenkins master. +// +// Credentials setup: +// Create the following "Secret text" credentials in Jenkins and enter values as follows: +// iwa-git-creds-id - Git login as Jenkins "Username with Password" credential +// iwa-ssc-ci-token-id - Fortify Software Security Center "CIToken" authentication token as Jenkins Secret credential +// iwa-edast-auth-id - Fortify Scan Central DAST authentication as "Jenkins Username with Password" credential +// iwa-nexus-iq-token-id - Sonatype Nexus IQ user token in form of "user code:pass code" +// iwa-dockerhub-creds-id - DockerHub login as Jenkins "Username with Password" credential +// All of the credentials should be created (with empty values if necessary) even if you are not using the capabilities. +// For Fortify on Demand (FOD) Global Authentication is used rather than Personal Access Tokens. +// +//**************************************************************************************************** + +// The instances of Docker image and container that are created +def dockerImage +def dockerContainer +def dockerContainerName = "iwa-jenkins" + +pipeline { + agent any + + // + // The following parameters can be selected when the pipeline is executed manually to execute + // different capabilities in the pipeline or configure the servers that are used. + + // Note: the pipeline needs to be executed at least once for the parameters to be available + // + parameters { + booleanParam(name: 'SCA_LOCAL', defaultValue: params.SCA_LOCAL ?: false, + description: 'Use (local) Fortify SCA for Static Application Security Testing') + booleanParam(name: 'SCA_OSS', defaultValue: params.SCA_OSS ?: false, + description: 'Use Fortify SCA with Sonatype Nexus IQ for Open Source Susceptibility Analysis') + booleanParam(name: 'SCANCENTRAL_SAST', defaultValue: params.SCANCENTRAL_SAST ?: false, + description: 'Run a remote scan using Scan Central SAST (SCA) for Static Application Security Testing') + booleanParam(name: 'SCANCENTRAL_DAST', defaultValue: params.SCANCENTRAL_DAST ?: false, + description: 'Run a remote scan using Scan Central DAST (WebInspect) for Dynamic Application Security Testing') + booleanParam(name: 'UPLOAD_TO_SSC', defaultValue: params.UPLOAD_TO_SSC ?: false, + description: 'Enable upload of scan results to Fortify Software Security Center') + booleanParam(name: 'FOD_SAST', defaultValue: params.FOD_SAST ?: false, + description: 'Use Fortify on Demand for Static Application Security Testing') + booleanParam(name: 'FOD_DAST', defaultValue: params.FOD_DAST ?: false, + description: 'Use Fortify on Demand for Dynamic Application Security Testing') + booleanParam(name: 'RELEASE_TO_DOCKERHUB', defaultValue: params.RELEASE_TO_DOCKERHUB ?: false, + description: 'Release built and tested image to Docker Hub') + } + + environment { + // Application settings + APP_NAME = "IWA-Java" // Application name + APP_VER = "master" // Application release - GitHub master branch + COMPONENT_NAME = "iwa" // Component name + GIT_URL = scm.getUserRemoteConfigs()[0].getUrl() // Git Repo + JAVA_VERSION = 8 // Java version to compile as + ISSUE_IDS = "" // List of issues found from commit + FOD_UPLOAD_DIR = 'fod' // Directory where FOD upload Zip is constructed + + // Credential references + GIT_CREDS = credentials('iwa-git-creds-id') + SSC_AUTH_TOKEN = credentials('iwa-ssc-ci-token-id') + EDAST_AUTH = credentials('iwa-edast-auth-id') + NEXUS_IQ_AUTH_TOKEN = credentials('iwa-nexus-iq-token-id') + + // The following are defaulted and can be override by creating a "Build parameter" of the same name + SSC_URL = "${params.SSC_URL ?: 'http://ssc.mfdemouk.com'}" // URL of Fortify Software Security Center + SSC_APP_VERSION_ID = "${params.SSC_APP_VERSION_ID ?: '10002'}" // Id of Application in SSC to upload results to + SSC_NOTIFY_EMAIL = "${params.SSC_NOTIFY_EMAIL ?: 'do-not-reply@microfocus.com'}" // User to notify with SSC/ScanCentral information + SSC_SENSOR_POOL_UUID = "${params.SSC_SENSOR_POOL_UUID ?: '00000000-0000-0000-0000-000000000002'}" // UUID of Scan Central Sensor Pool to use - leave for Default Pool + EDAST_URL = "${params.EDAST_URL ?: 'http://scancentral.mfdemouk.com/api'}" // ScanCentral DAST API URI + EDAST_CICD = "${params.EDAST_CICD ?: 'bd286bd2-632c-434c-99ef-a8ce879434ec'}" // ScanCentral DAST CICD identifier + FOD_RELEASE_ID = "${params.FOD_RELEASE_ID ?: '6446'}" // Fortify on Demand Release Id + NEXUS_IQ_URL = "${params.NEXUS_IQ_URL ?: 'https://sonatype.mfdemouk.com'}" // Nexus IQ URL + DOCKER_ORG = "${params.DOCKER_ORG ?: 'mfdemouk'}" // Docker organisation (in Docker Hub) to push released images to + } + + tools { + // Install the Maven version configured as "M3" and add it to the path. + maven 'M3' + } + + stages { + stage('Build') { + // Run on "master" node + agent { label 'master' } + steps { + // Get some code from a GitHub repository + git credentialsId: 'iwa-git-creds-id', url: "${env.GIT_URL}" + + // Get Git commit details + script { + if (isUnix()) { + sh 'git rev-parse HEAD > .git/commit-id' + } else { + bat(/git rev-parse HEAD > .git\\commit-id/) + } + //bat(/git log --format="%ae" | head -1 > .git\commit-author/) + env.GIT_COMMIT_ID = readFile('.git/commit-id').trim() + //env.GIT_COMMIT_AUTHOR = readFile('.git/commit-author').trim() + + println "Git commit id: ${env.GIT_COMMIT_ID}" + //println "Git commit author: ${env.GIT_COMMIT_AUTHOR}" + + // Run maven to build WAR/JAR application + if (isUnix()) { + sh 'mvn -Dmaven.com.failure.ignore=true clean -Dtest=!*PasswordConstraintValidatorTest,!*DefaultControllerTest -P jar,release clean package' + } else { + bat "mvn -Dmaven.com.failure.ignore=true -Dtest=!*PasswordConstraintValidatorTest,!*DefaultControllerTest -P jar,release clean package" + } + } + } + + post { + success { + // Record the test results (success) + junit "**/target/surefire-reports/TEST-*.xml" + // Archive the built file + archiveArtifacts "target/${env.COMPONENT_NAME}.jar,target/${env.COMPONENT_NAME}.war" + // Stash the deployable files + stash includes: "target/${env.COMPONENT_NAME}.jar,target/${env.COMPONENT_NAME}.war", name: "${env.COMPONENT_NAME}_release" + } + failure { + // Record the test results (failures) + junit "**/target/surefire-reports/TEST-*.xml" + } + } + } + + stage('SAST') { + when { + beforeAgent true + anyOf { + expression { params.SCA_LOCAL == true } + expression { params.SCANCENTRAL_SAST == true } + expression { params.FOD_SAST == true } + } + } + // Run on an Agent with "fortify" label applied + agent {label "fortify"} + steps { + script { + // Get code from Git repository so we can recompile it + git credentialsId: 'iwa-git-creds-id', url: "${env.GIT_URL}" + + // Run Maven debug compile, download dependencies (if required) and package up for FOD + if (isUnix()) { + sh "mvn -Dmaven.compiler.debuglevel=lines,vars,source -DskipTests -P fortify clean verify" + sh "mvn dependency:build-classpath -Dmdep.regenerateFile=true -Dmdep.outputFile=${env.WORKSPACE}/cp.txt" + } else { + bat "mvn -Dmaven.compiler.debuglevel=lines,vars,source -DskipTests -P fortify clean verify" + bat "mvn dependency:build-classpath -Dmdep.regenerateFile=true -Dmdep.outputFile=${env.WORKSPACE}/cp.txt" + } + + // read contents of classpath file + def classpath = readFile "${env.WORKSPACE}/cp.txt" + println "Using classpath: $classpath" + + if (params.FOD_SAST) { + // Upload built application to Fortify on Demand and carry out Static Assessment + fodStaticAssessment releaseId: ${env.FOD_RELEASE_ID}, + // bsiToken: "${env.FOD_BSI_TOKEN}", + entitlementPreference: 'SubscriptionOnly', + inProgressScanActionType: 'CancelInProgressScan', + remediationScanPreferenceType: 'NonRemediationScanOnly', + srcLocation: "${env.FOD_UPLOAD_DIR}" + + // optional: wait for FOD assessment to complete + fodPollResults releaseId: ${env.FOD_RELEASE_ID} + //bsiToken: "${env.FOD_BSI_TOKEN}", + //policyFailureBuildResultPreference: 1, + pollingInterval: 5 + } else if (params.SCANCENTRAL_SAST) { + + // set any standard remote translation/scan options + fortifyRemoteArguments transOptions: '', + scanOptions: '' + + if (params.UPLOAD_TO_SSC) { + // Remote analysis (using Scan Central) and upload to SSC + fortifyRemoteAnalysis remoteAnalysisProjectType: fortifyMaven(buildFile: 'pom.xml'), + remoteOptionalConfig: [ + customRulepacks: '', + filterFile: "etc\\sca-filter.txt", + notifyEmail: "${env.SSC_NOTIFY_EMAIL}", + sensorPoolUUID: "${env.SSC_SENSOR_POOL_UUID}" + ], + uploadSSC: [appName: "${env.APP_NAME}", appVersion: "${env.APP_VER}"] + + } else { + // Remote analysis (using Scan Central) + fortifyRemoteAnalysis remoteAnalysisProjectType: fortifyMaven(buildFile: 'pom.xml'), + remoteOptionalConfig: [ + customRulepacks: '', + filterFile: "etc\\sca-filter.txt", + notifyEmail: "${env.SSC_NOTIFY_EMAIL}", + sensorPoolUUID: "${env.SSC_SENSOR_POOL_UUID}" + ] + } + } else if (params.SCA_LOCAL) { + // optional: update scan rules + //fortifyUpdate updateServerURL: 'https://update.fortify.com' + + // Clean project and scan results from previous run + fortifyClean buildID: "${env.COMPONENT_NAME}", + logFile: "${env.COMPONENT_NAME}-clean.log" + + // Translate source files + fortifyTranslate buildID: "${env.COMPONENT_NAME}", + projectScanType: fortifyJava(javaSrcFiles: + '\""src/main/java/**/*\"" \""src/main/resources/**/*\"" \""Dockerfile*\""', + javaVersion: "${env.JAVA_VERSION}", + javaClasspath: "$classpath"), + addJVMOptions: '', + logFile: "${env.COMPONENT_NAME}-translate.log" + + // Scan source files + fortifyScan buildID: "${env.COMPONENT_NAME}", + addOptions: '"-filter" "etc\\sca-filter.txt"', + resultsFile: "${env.COMPONENT_NAME}.fpr", + addJVMOptions: '', + logFile: "${env.COMPONENT_NAME}-scan.log" + + if (params.UPLOAD_TO_SSC) { + // Upload to SSC + fortifyUpload appName: "${env.APP_NAME}", + appVersion: "${env.APP_VER}", + resultsFile: "${env.COMPONENT_NAME}.fpr" + } + } else { + println "No Static Application Security Testing (SAST) to do." + } + } + } + } + + stage('SCA OSS') { + when { + beforeAgent true + anyOf { + expression { params.SCA_OSS == true } + } + } + // Run on an Agent with "fortify" label applied + agent {label "fortify"} + steps { + script { + // run sourceandlibscanner - needs to have been installed and in the path + if (isUnix()) { + sh 'sourceandlibscanner -auto -bt mvn -bf pom.xml -bc "dependency:unpack-dependencies -Dclassifier=sources -DexcludeTransitive -DskipTests package" -scan -sonatype -iqurl ${env.NEXUS_IQ_URL} -nexusauth ${env.NEXUS_IQ_AUTH_TOKEN} -iqappid IWA -stage build -r iqReport.json -upload -ssc ${env.SSC_URL} -ssctoken ${env.SSC_AUTH_TOKEN} -versionid ${env.SSC_APP_VERSION_ID}' + } else { + def stdout = powershell(returnStdout: true, script: ".\\bin\\fortify-sourceandlibscanner.ps1 -NexusIQUrl ${env.NEXUS_IQ_URL} -NexusIQAuth ${env.NEXUS_IQ_AUTH_TOKEN} -NexusIQAppId IWA -SSCURL ${env.SSC_URL} -SSCAuthToken ${env.SSC_AUTH_TOKEN} -SSCAppVersionId ${env.SSC_APP_VERSION_ID}") + println stdout + //bat(/sourceandlibscanner -auto -bt mvn -bf pom.xml -bc "dependency:unpack-dependencies -Dclassifier=sources -DexcludeTransitive -DskipTests package" -scan -sonatype -iqurl ${env.NEXUS_IQ_URL} -nexusauth ${env.NEXUS_IQ_AUTH_TOKEN} -iqappid IWA -stage build -r iqReport.json -upload -ssc ${env.SSC_URL} -ssctoken ${env.SSC_AUTH_TOKEN} -versionid ${env.SSC_APP_VERSION_ID}/) + } + } + } + } + + stage('Deploy') { + // Run on "master" node + agent { label 'master' } + steps { + script { + // unstash the built files + unstash name: "${env.COMPONENT_NAME}_release" + if (isUnix()) { + // Create docker image using JAR file + dockerImage = docker.build "${env.DOCKER_ORG}/${env.COMPONENT_NAME}:${env.APP_VER}.${env.BUILD_NUMBER}" + } else { + // Create docker image using JAR file + dockerImage = docker.build("${env.DOCKER_ORG}/${env.COMPONENT_NAME}:${env.APP_VER}.${env.BUILD_NUMBER}", "-f Dockerfile.win .") + } + } + } + } + + stage('DAST') { + when { + beforeAgent true + anyOf { + expression { params.SCANCENTRAL_DAST == true } + expression { params.FOD_DAST == true } + } + } + // Run on an Agent with "docker" label applied + agent {label "docker"} + steps { + script { + if (params.SCANCENTRAL_DAST) { + // check if container is still running and if so stop/remove it + if (isUnix()) { + sh(script: "docker ps -aq --filter name=iwa-jenkins > container.id") + if (fileExists('container.id')) { + def existingId = readFile('container.id').trim() + if (existingId) { + println "Found existing iwa-jenkins container id: ${existingId} ... deleting..." + sh(script: "docker stop $existingId && docker rm -f $existingId") + } + } + } else { + bat(script: "docker ps -aq --filter name=iwa-jenkins > container.id") + if (fileExists('container.id')) { + def existingId = readFile('container.id').trim() + if (existingId) { + println "Found existing iwa-jenkins container id: ${existingId} ... deleting..." + bat(script: "docker stop ${existingId} && docker rm -f ${existingId}") + } + } + } + + // start docker container + println "Starting docker container ${dockerContainerName}" + dockerContainer = dockerImage.run("--name ${dockerContainerName} -p 9090:8080") + + // run ScanCentral DAST scan using groovy script + println "Running ScanCentral DAST scan, please wait ..." + withCredentials([usernamePassword(credentialsId: 'iwa-edast-auth-id', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + edastApi = load 'bin/fortify-scancentral-dast.groovy' + edastApi.setApiUri("${env.EDAST_URL}") + edastApi.setDebug(true) + edastApi.authenticate("${USERNAME}", "${PASSWORD}") + Integer scanId = edastApi.startScanAndWait("Jenkins initiated scan", "${env.EDAST_CICD}", 5) + String scanStatus = edastApi.getScanStatusValue(edastApi.getScanStatusId(scanId)) + println "ScanCentral DAST scan id: ${scanId} - status: ${scanStatus}" + } + } else if (params.FOD_DAST) { + println "DAST via FOD is not yet implemented." + } else { + println "No Dynamic Application Security Testing (DAST) to do." + } + } + } + } + + // An example manual release checkpoint + stage('Stage') { + agent { label 'master' } + steps { + input id: 'Release', + message: 'Ready to Release?', + ok: 'Yes, let\'s go', + submitter: 'admin', + submitterParameter: 'approver' + } + } + + stage('Release') { + agent { label 'master' } + steps { + script { + // Example publish to Docker Hub + if (params.RELEASE_TO_DOCKERHUB) { + docker.withRegistry('https://registry.hub.docker.com', 'iwa-dockerhub-creds-id') { + dockerImage.push("${env.APP_VER}.${BUILD_NUMBER}") + // and tag as "latest" + dockerImage.push("latest") + } + } else { + println "No releasing to do." + } + } + } + } + + } + + post { + always { + script { + // check if container is still running and if so stop/remove it + if (isUnix()) { + sh(script: "docker ps -aq --filter name=iwa-jenkins > container.id") + if (fileExists('container.id')) { + def existingId = readFile('container.id').trim() + if (existingId) { + println "Found existing iwa-jenkins container id: ${existingId} ... deleting..." + sh(script: "docker stop $existingId && docker rm -f $existingId") + } + } + } else { + bat(script: "docker ps -aq --filter name=iwa-jenkins > container.id") + if (fileExists('container.id')) { + def existingId = readFile('container.id').trim() + if (existingId) { + println "Found existing iwa-jenkins container id: ${existingId} ... deleting..." + bat(script: "docker stop ${existingId} && docker rm -f ${existingId}") + } + } + } + } + } + } + +} diff --git a/README.md b/README.md index d7d8851..965da88 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Build Status](https://travis-ci.org/chrishantha/sample-java-programs.svg?branch=master)](https://travis-ci.org/chrishantha/sample-java-programs) -Sample Java Programs +Sample Java Programs ...... ==================== This repository contains some sample programs. All are Maven projects and can be run directly using "java -jar" diff --git a/azure-pipelines-1.yml b/azure-pipelines-1.yml new file mode 100644 index 0000000..b3d83ef --- /dev/null +++ b/azure-pipelines-1.yml @@ -0,0 +1,35 @@ +# Maven +- task: FedRampFortifyOnDemandStatic@7 + inputs: + FortifyProjects: 'https://github.com/bharathsco/sample-java-programs.git' + BSIToken: 'eyJ0ZW5hbnRJZCI6MTg0ODksInRlbmFudENvZGUiOiJhY2NlbnR1cmVfODIxMjQzNF9GTUFfMjg3MzI2MjEyIiwicmVsZWFzZUlkIjoxNDMxNjQsInBheWxvYWRUeXBlIjoiQU5BTFlTSVNfUEFZTE9BRCIsImFzc2Vzc21lbnRUeXBlSWQiOjE0LCJ0ZWNobm9sb2d5VHlwZSI6IkpBVkEvSjJFRSIsInRlY2hub2xvZ3lUeXBlSWQiOjcsInRlY2hub2xvZ3lWZXJzaW9uIjoiMS45IiwidGVjaG5vbG9neVZlcnNpb25JZCI6MTcsImF1ZGl0UHJlZmVyZW5jZSI6Ik1hbnVhbCIsImF1ZGl0UHJlZmVyZW5jZUlkIjoxLCJpbmNsdWRlVGhpcmRQYXJ0eSI6ZmFsc2UsImluY2x1ZGVPcGVuU291cmNlQW5hbHlzaXMiOmZhbHNlLCJwb3J0YWxVcmkiOiJodHRwczovL3RyaWFsLmZvcnRpZnkuY29tLyIsImFwaVVyaSI6Imh0dHBzOi8vYXBpLnRyaWFsLmZvcnRpZnkuY29tIiwic2NhblByZWZlcmVuY2UiOiJTdGFuZGFyZCIsInNjYW5QcmVmZXJlbmNlSWQiOjF9' + APIAuthenticationType: '2' + Username: 'bharathsco@gmail.com' + PersonalAccessTokenSecret: 'NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30' + TenantID: 'accenture_8212434_FMA_287326212' + ProxyHost: 'trial.fortify.com' + ProxyPort: '80' + EntitlementPreference: '1' + PurchaseEntitlements: true + PreferRemediation: true +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'package' diff --git a/azure-pipelines-2.yml b/azure-pipelines-2.yml new file mode 100644 index 0000000..345e558 --- /dev/null +++ b/azure-pipelines-2.yml @@ -0,0 +1,32 @@ +# Maven +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + + + } + #Uploading and scanning the artifact zip in HPFortify + + $exe = "c:\FoDUploader.exe" + &$exe --source "D:\fortify\artifacts\$APIversion-$APIname.zip" --apiToken "*******" -- apiTokenSecret "*************" --uploadURL "https://api.hpfod.com/bsi2.aspx? tid=828&tc=sm&pv=$releaseId&payloadType=ANALYSIS_PAYLOAD&astid=170&ts=.NET&ll=4.5" -- automatedAudit "True" --expressScan "True" --includeAllFiles "True" --debug "True" + + } + } + } \ No newline at end of file diff --git a/azure-pipelines-3.yml b/azure-pipelines-3.yml new file mode 100644 index 0000000..34edff5 --- /dev/null +++ b/azure-pipelines-3.yml @@ -0,0 +1,22 @@ +# Maven +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'package' diff --git a/azure-pipelines-4.yml b/azure-pipelines-4.yml new file mode 100644 index 0000000..40d7766 --- /dev/null +++ b/azure-pipelines-4.yml @@ -0,0 +1,38 @@ +# Maven +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'package' +# Maven +- task: FedRampFortifyOnDemandStatic@7 + inputs: + FortifyProjects: 'https://github.com/bharathsco/sample-java-programs.git' + BSIToken: 'eyJ0ZW5hbnRJZCI6MTg0ODksInRlbmFudENvZGUiOiJhY2NlbnR1cmVfODIxMjQzNF9GTUFfMjg3MzI2MjEyIiwicmVsZWFzZUlkIjoxNDMxNjQsInBheWxvYWRUeXBlIjoiQU5BTFlTSVNfUEFZTE9BRCIsImFzc2Vzc21lbnRUeXBlSWQiOjE0LCJ0ZWNobm9sb2d5VHlwZSI6IkpBVkEvSjJFRSIsInRlY2hub2xvZ3lUeXBlSWQiOjcsInRlY2hub2xvZ3lWZXJzaW9uIjoiMS45IiwidGVjaG5vbG9neVZlcnNpb25JZCI6MTcsImF1ZGl0UHJlZmVyZW5jZSI6Ik1hbnVhbCIsImF1ZGl0UHJlZmVyZW5jZUlkIjoxLCJpbmNsdWRlVGhpcmRQYXJ0eSI6ZmFsc2UsImluY2x1ZGVPcGVuU291cmNlQW5hbHlzaXMiOmZhbHNlLCJwb3J0YWxVcmkiOiJodHRwczovL3RyaWFsLmZvcnRpZnkuY29tLyIsImFwaVVyaSI6Imh0dHBzOi8vYXBpLnRyaWFsLmZvcnRpZnkuY29tIiwic2NhblByZWZlcmVuY2UiOiJTdGFuZGFyZCIsInNjYW5QcmVmZXJlbmNlSWQiOjF9' + APIAuthenticationType: '2' + Username: 'bharathsco@gmail.com' + PersonalAccessTokenSecret: 'NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30' + TenantID: 'accenture_8212434_FMA_287326212' + EntitlementPreference: '1' + PurchaseEntitlements: true + PreferRemediation: true +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..c47b697 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,38 @@ +- task: FedRampFortifyOnDemandStatic@7 + inputs: + FortifyProjects: 'https://github.com/bharathsco/sample-java-programs.git' + BSIToken: 'eyJ0ZW5hbnRJZCI6MTg0ODksInRlbmFudENvZGUiOiJhY2NlbnR1cmVfODIxMjQzNF9GTUFfMjg3MzI2MjEyIiwicmVsZWFzZUlkIjoxNDMxNjQsInBheWxvYWRUeXBlIjoiQU5BTFlTSVNfUEFZTE9BRCIsImFzc2Vzc21lbnRUeXBlSWQiOjE0LCJ0ZWNobm9sb2d5VHlwZSI6IkpBVkEvSjJFRSIsInRlY2hub2xvZ3lUeXBlSWQiOjcsInRlY2hub2xvZ3lWZXJzaW9uIjoiMS45IiwidGVjaG5vbG9neVZlcnNpb25JZCI6MTcsImF1ZGl0UHJlZmVyZW5jZSI6Ik1hbnVhbCIsImF1ZGl0UHJlZmVyZW5jZUlkIjoxLCJpbmNsdWRlVGhpcmRQYXJ0eSI6ZmFsc2UsImluY2x1ZGVPcGVuU291cmNlQW5hbHlzaXMiOmZhbHNlLCJwb3J0YWxVcmkiOiJodHRwczovL3RyaWFsLmZvcnRpZnkuY29tLyIsImFwaVVyaSI6Imh0dHBzOi8vYXBpLnRyaWFsLmZvcnRpZnkuY29tIiwic2NhblByZWZlcmVuY2UiOiJTdGFuZGFyZCIsInNjYW5QcmVmZXJlbmNlSWQiOjF9' + APIAuthenticationType: '2' + Username: 'bharathsco@gmail.com' + PersonalAccessTokenSecret: 'NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30' + TenantID: 'accenture_8212434_FMA_287326212' + ProxyHost: 'trial.fortify.com' + ProxyPort: '80' + EntitlementPreference: '1' + PurchaseEntitlements: true + PreferRemediation: true +- task: FedRampFortifyOnDemandStatic@7 + inputs: + FortifyProjects: 'https://github.com/bharathsco/sample-java-programs.git' + BSIToken: 'eyJ0ZW5hbnRJZCI6MTg0ODksInRlbmFudENvZGUiOiJhY2NlbnR1cmVfODIxMjQzNF9GTUFfMjg3MzI2MjEyIiwicmVsZWFzZUlkIjoxNDMxNjQsInBheWxvYWRUeXBlIjoiQU5BTFlTSVNfUEFZTE9BRCIsImFzc2Vzc21lbnRUeXBlSWQiOjE0LCJ0ZWNobm9sb2d5VHlwZSI6IkpBVkEvSjJFRSIsInRlY2hub2xvZ3lUeXBlSWQiOjcsInRlY2hub2xvZ3lWZXJzaW9uIjoiMS45IiwidGVjaG5vbG9neVZlcnNpb25JZCI6MTcsImF1ZGl0UHJlZmVyZW5jZSI6Ik1hbnVhbCIsImF1ZGl0UHJlZmVyZW5jZUlkIjoxLCJpbmNsdWRlVGhpcmRQYXJ0eSI6ZmFsc2UsImluY2x1ZGVPcGVuU291cmNlQW5hbHlzaXMiOmZhbHNlLCJwb3J0YWxVcmkiOiJodHRwczovL3RyaWFsLmZvcnRpZnkuY29tLyIsImFwaVVyaSI6Imh0dHBzOi8vYXBpLnRyaWFsLmZvcnRpZnkuY29tIiwic2NhblByZWZlcmVuY2UiOiJTdGFuZGFyZCIsInNjYW5QcmVmZXJlbmNlSWQiOjF9' + APIAuthenticationType: '2' + Username: 'bharathsco@gmail.com' + PersonalAccessTokenSecret: 'NWZOc0lrbjB1eEtlcEJwY2VZVH5XZjw0R1MhRTc30' + TenantID: 'accenture_8212434_FMA_287326212' + ProxyHost: 'trial.fortify.com' + ProxyPort: '80' + EntitlementPreference: '1' + PurchaseEntitlements: true + PreferRemediation: true + +- task: Maven@3 + inputs: + mavenPomFile: 'https://github.com/bharathsco/sample-java-programs/blob/master/pom.xml' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + javaHomeOption: 'JDKVersion' + mavenVersionOption: 'Default' + mavenAuthenticateFeed: false + effectivePomSkip: false + sonarQubeRunAnalysis: false + \ No newline at end of file diff --git a/sample-java-programs-master.zip b/sample-java-programs-master.zip new file mode 100644 index 0000000..705925a Binary files /dev/null and b/sample-java-programs-master.zip differ