acammies
2018-04-23 01a1407850cac9e87471d6c2c0d2909906c85833
Merge pull request #186 from rht-labs/exercise5/security-scanning

Exercise5/security scanning
4 files added
3 files modified
167 ■■■■ changed files
exercises/4-an-enslaved-hope/README.md 18 ●●●● patch | view | raw | blame | history
exercises/5-non-functionals-strike-back/README.md 147 ●●●●● patch | view | raw | blame | history
exercises/_sidebar.md 2 ●●● patch | view | raw | blame | history
exercises/images/exercise5/jenkins-arachni.png patch | view | raw | blame | history
exercises/images/exercise5/report-arachni.png patch | view | raw | blame | history
exercises/images/exercise5/report-location.png patch | view | raw | blame | history
exercises/images/exercise5/stages.png patch | view | raw | blame | history
exercises/4-an-enslaved-hope/README.md
@@ -230,14 +230,14 @@
3. This should have created the following files:
    - `templates/jenkins-slave-generic-template.yml`
    - `params/zap-build-pod` and `params/arachni-build-pod`
    - `params/jenkins-slave-zap` and `params/jenkins-slave-arachni`
3. Create an object in `inventory/host_vars/ci-cd-tooling.yml` called `zap-build-pod` and add the following content:
3. Create an object in `inventory/host_vars/ci-cd-tooling.yml` called `jenkins-slave-zap` and add the following content:
```yaml
    - name: "zap-build-pod"
    - name: "jenkins-slave-zap"
      namespace: "{{ ci_cd_namespace }}"
      template: "{{ playbook_dir }}/templates/jenkins-slave-generic-template.yml"
      params: "{{ playbook_dir }}/params/zap-build-pod"
      params: "{{ playbook_dir }}/params/jenkins-slave-zap"
      tags:
      - zap
```
@@ -255,18 +255,18 @@
     -e "filter_tags=zap"
```
3. Head to (https://console.somedomain.com/console/project/<YOUR_NAME>-ci-cd/browse/builds) on Openshift and you should see `zap-build-pod`.
3. Head to (https://console.somedomain.com/console/project/<YOUR_NAME>-ci-cd/browse/builds) on Openshift and you should see `jenkins-slave-zap`.
include screenshot here.
#### Part 3b - Arachni Scan
> _Arachni is a feature-full, modular, high-performance Ruby framework aimed towards helping penetration testers and administrators evaluate the security of web applications._
3. Create an object in `inventory/host_vars/ci-cd-tooling.yml` called `arachni-build-pod` with the following content:
3. Create an object in `inventory/host_vars/ci-cd-tooling.yml` called `jenkins-slave-arachni` with the following content:
```yaml
    - name: "arachni-build-pod"
    - name: "jenkins-slave-arachni"
      namespace: "{{ ci_cd_namespace }}"
      template: "{{ playbook_dir }}/templates/jenkins-slave-generic-template.yml"
      params: "{{ playbook_dir }}/params/arachni-build-pod"
      params: "{{ playbook_dir }}/params/jenkins-slave-arachni"
      tags:
      - arachni
```
@@ -278,7 +278,7 @@
     -e "filter_tags=arachni"
```
3. Head to (https://console.somedomain.com/console/project/<YOUR_NAME>-ci-cd/browse/builds) on Openshift and you should see `arachni-build-pod`.
3. Head to (https://console.somedomain.com/console/project/<YOUR_NAME>-ci-cd/browse/builds) on Openshift and you should see `jenkins-slave-arachni`.
![todolist-fe-multi](../images/exercise4/builds-zap-arachni.png)
_____
exercises/5-non-functionals-strike-back/README.md
@@ -1,11 +1,11 @@
# The Non Functionals Strike back
# The Non-Functionals Strike back
> In this exercise we explore the non-functional side of testing. 
_____
## Learning Outcomes
As a learner you will be able to
- Create additional Jenkins stages to scan for security vulnerabilities in the Apps
- Assess test quiality by producing coveage reports as part of a build
- Assess test quality by producing coverage reports as part of a build
- Improve code readability with linting
- Do some light performance testing to monitor throughput of APIs
@@ -20,7 +20,7 @@
_____
## 10,000 Ft View
> This lesson will use the Exerisise 4's Zap Slave and Arachni scanner to improve the pipeline. Linting will be included in the build and code coverage too.
> This lesson will use the Exercise 4's Zap Slave and Arachni scanner to improve the pipeline. Linting will be included in the build and code coverage too.
2. Add a parallel stage after the e2e tests on the front end to run OWASP Zap and Arachni against the deployed apps.
@@ -34,14 +34,144 @@
> This is a well structured guide with references to exact filenames and indications as to what should be done.
### Part 1 - Add Security scanning to the pipeline 
> _In this exercise the first of our non-functional testing is explored in the form of some security scanning_
> _In this exercise the first of our non-functional testing is explored in the form of some security scanning. We will add the scans to our Jenkinsfile and have them run as new stages_
2. Do thing using tool X.
2. Insert blah into `file1.txt`
2. Open the `todolist-fe` application's `Jenkinsfile` in your favourite editor. The file is stored in the root of the project.
2. The file is layed out with a collection of stages that correspond to each part of our build as seen below. We will create a new stage to execute in parallel.
![stages](../images/exercise5/stages.png)
2. Create a new Parallel Stage called `security scanning` underneath the `stage("e2e test") { }` section as shown below. The contents of the `e2e test` have been removed for simplicity.
```groovy
        stage("e2e test") {
            // ... stuff in here ....
        }
        stage("security scanning") {
            parallel {
                stage('OWASP Scan') {
                }
                stage('Arachni Scan') {
                }
            }
        }
```
export SOME_THING=biscuits
2. Let's start filling out the configuration for the OWASP Zap scan first. We will set the label to our slave created in previous exercise and a `when` condition of the master or develop branch.
```groovy
stage('OWASP Scan') {
    agent {
        node {
            label "jenkins-slave-zap"
        }
    }
    when {
        expression { GIT_BRANCH ==~ /(.*master|.*develop)/ }
    }
}
```
2. Open console and navigate to `New Item` and click it ![new-item](./images/new-item.png)
2.  A command to run the tool by passing in the URL of the app we're going to test.
```groovy
stage('OWASP Scan') {
    agent {
        node {
            label "jenkins-slave-zap"
        }
    }
    when {
        expression { GIT_BRANCH ==~ /(.*master|.*develop)/ }
    }
    steps {
        sh '''
            /zap/zap-baseline.py -r index.html -t ${E2E_TEST_ROUTE}
        '''
    }
}
```
2.  Finally add the reporting for Jenkins in `post` hook of our Declarative Pipeline. This is to report the findings of the scan in Jenkins as a HTML report.
```groovy
stage('OWASP Scan') {
    agent {
        node {
            label "jenkins-slave-zap"
        }
    }
    when {
        expression { GIT_BRANCH ==~ /(.*master|.*develop)/ }
    }
    steps {
        sh '''
            /zap/zap-baseline.py -r index.html -t http://${E2E_TEST_ROUTE}
            exit $?
        '''
    }
    post {
        always {
          // publish html
          publishHTML target: [
              allowMissing: false,
              alwaysLinkToLastBuild: false,
              keepAll: true,
              reportDir: '/zap/wrk',
              reportFiles: 'index.html',
              reportName: 'Zap Branniscan'
            ]
        }
    }
}
```
2. Let's add our Arachni Scan to the second part of the parallel block. The main difference between these sections is Jenkins will report an XML report too for failing the build accordingly. Below is the snippet for the Arachni scanning.
```groovy
    stage('Arachni Scan') {
        agent {
            node {
                label "jenkins-slave-arachni"
            }
        }
        when {
            expression { GIT_BRANCH ==~ /(.*master|.*develop)/ }
        }
        steps {
            sh '''
                /arachni/bin/arachni http://${E2E_TEST_ROUTE} --report-save-path=arachni-report.afr
                /arachni/bin/arachni_reporter arachni-report.afr --reporter=xunit:outfile=report.xml --reporter=html:outfile=web-report.zip
                unzip web-report.zip -d arachni-web-report
            '''
        }
        post {
            always {
                junit 'report.xml'
                publishHTML target: [
                    allowMissing: false,
                    alwaysLinkToLastBuild: false,
                    keepAll: true,
                    reportDir: 'arachni-web-report',
                    reportFiles: 'index.html',
                    reportName: 'Arachni Web Crawl'
                    ]
            }
        }
    }
```
2. With this config in place run a build on Jenkins. To do this; commit your code (from your terminal):
```bash
$ git add .
$ git commit -m "ADD - security scanning tools to pipeline"
$ git push
```
2. Once the Jobs have completed; navigate to the Jobs status and see the scores. You can find the graphs and test reports on overview of the Job. Explore the results!
![report-arachni](../images/exercise5/report-arachni.png)
![jenkins-arachni](../images/exercise5/jenkins-arachni.png)
<p class="tip">
NOTE - your build may have failed but the reports should still be generated!
</p>
### Part 2 - Add Code Coverage & Linting to the pipeline
> _prefix of exercise and why we're doing it_
@@ -55,6 +185,7 @@
 - Add Black Duck or other package scanning tooling for our NodeJS app
 - Add Container Vulnerability scanning tooling to the pipeline
 - Add security scanning tools to the API
## Additional Reading
> List of links or other reading that might be of use / reference for the exercise
exercises/_sidebar.md
@@ -4,7 +4,7 @@
* [2. Attack of the Pipelines](2-attack-of-the-pipelines/README.md)
* [3. Revenge of the Automated Testing](3-revenge-of-the-automated-testing/README.md)
* [4. An Enslaved Hope](4-an-enslaved-hope/README.md)
* [5. The Non Functionals Strike Back](5-non-functionals-strike-back/README.md)
* [5. The Non-Functionals Strike Back](5-non-functionals-strike-back/README.md)
* [6. Return of the Monitoring](6-return-of-the-app-monitoring/README.md)
* [7. The Cluster Awakens](7-the-cluster-awakens/README.md)
* [8. The Last Unicorn Dev](8-the-last-unicorn-dev/README.md)
exercises/images/exercise5/jenkins-arachni.png
exercises/images/exercise5/report-arachni.png
exercises/images/exercise5/report-location.png
exercises/images/exercise5/stages.png