{"id":491,"date":"2016-06-28T17:20:05","date_gmt":"2016-06-28T17:20:05","guid":{"rendered":"http:\/\/blog.mozilla.org\/webqa\/?p=491"},"modified":"2016-06-28T17:20:05","modified_gmt":"2016-06-28T17:20:05","slug":"dockerized-owasp-zap-security-scanning-in-jenkins-part-two","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/fxtesteng\/2016\/06\/28\/dockerized-owasp-zap-security-scanning-in-jenkins-part-two\/","title":{"rendered":"Dockerized, OWASP-ZAP security scanning, in Jenkins, part two"},"content":{"rendered":"<p>Following up from my <a href=\"http:\/\/blog.mozilla.org\/webqa\/2016\/05\/11\/docker-owasp-zap-part-one\/\">earlier blog post<\/a>, I was able to get a Dockerized ZAP-CLI up and running in a Jenkins instance!<\/p>\n<p>I\u2019ll break this down into five main parts, as follows:<\/p>\n<ol>\n<li>\n<h5>Installing Jenkins<\/h5>\n<\/li>\n<li>\n<h5>Installing Docker<\/h5>\n<\/li>\n<li>\n<h5>Configuring and running ZAP-CLI within Jenkins<\/h5>\n<\/li>\n<li>\n<h5>Configuring Docker further<\/h5>\n<\/li>\n<li>\n<h5>Running the build<\/h5>\n<\/li>\n<\/ol>\n<h1><strong>Installing Jenkins<\/strong><\/h1>\n<p>I followed the directions from this page: <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Installing+Jenkins+on+Red+Hat+distributions\">https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Installing+Jenkins+on+Red+Hat+distributions<\/a><\/p>\n<p>Before I could use wget to grab the Jenkins install script, I had to get wget itself, like so:<\/p>\n<pre><code>$ sudo dnf install wget<\/code><\/pre>\n<p>Next, it was just a matter of:<\/p>\n<pre><code>$ sudo wget -O \/etc\/yum.repos.d\/jenkins.repo http:\/\/pkg.jenkins-ci.org\/redhat-stable\/jenkins.repo<\/code><\/pre>\n<p>Then:<\/p>\n<pre><code>$ sudo rpm --import https:\/\/jenkins-ci.org\/redhat\/jenkins-ci.org.key<\/code>\n<code>$ sudo dnf install jenkins<\/code><\/pre>\n<p>And now, even though Jenkins is installed, I also needed to install Java, which I did:<\/p>\n<pre><code>$ sudo dnf install java<\/code><\/pre>\n<p>And, finally<\/p>\n<pre><code>$ sudo service jenkins start<\/code>\n<code>$ sudo chkconfig jenkins on<\/code><\/pre>\n<h1><strong>Installing Docker<\/strong><\/h1>\n<p>From the official instructions on <a href=\"https:\/\/docs.docker.com\/engine\/installation\/linux\/fedora\/\">Docker&#8217;s Installation on Fedora page<\/a>, I chose the \u201cInstall with the script\u201d option.<\/p>\n<pre><code>$ sudo dnf update<\/code>\n\n<code>$ curl -fsSl https:\/\/get.docker.com\/ | sh<\/code>\n\n<code>$ sudo systemctl start docker<\/code>\n\n<code>$ sudo docker run hello-world<\/code>\n\n<code>$ sudo groupadd docker<\/code>\n<code>$ sudo usermod -aG docker jenkins<\/code><\/pre>\n<p>The following command enables Docker on system startup:<\/p>\n<pre><code>$ sudo systemctl enable docker<\/code><\/pre>\n<p>Separately, now, both Jenkins and Docker (in that order) should be set up and ready. However, a few more installations of binaries and plugins are needed to make the two work together.<\/p>\n<h1><strong>Configuring and running ZAP-CLI within Jenkins<\/strong><\/h1>\n<p>To configure Jenkins to pull and run the <a href=\"https:\/\/github.com\/stephendonner\/docker-zap\">docker-zap shell script<\/a>, let\u2019s do the following.<\/p>\n<ol>\n<li>Load our Jenkins URL (with default :8080 port)<\/li>\n<li>Click on New Item<\/li>\n<li>In the \u201cItem name\u201d field, I\u2019ll choose \u201cdocker-zap-cli\u201d and choose \u201cFreestyle project\u201d<\/li>\n<li>Oops! We know that we\u2019ll be using a GitHub (and thus, Git) project, so we\u2019ll need a Git\/GitHub binary\/executable, as well as its Jenkins plugins<\/li>\n<li>OK, so from the command-line, let\u2019s do (from <a href=\"http:\/\/www.liquidweb.com\/kb\/how-to-install-and-configure-git-on-fedora-23\/\">How to Install and Configure Git on Fedora 23<\/a>)\n<pre><code>$ dnf -y install git<\/code><\/pre>\n<\/li>\n<li>Type\n<pre><code>which git<\/code><\/pre>\n<p>to let us know where it installed to, successfully.\u00a0 That should be:<\/p>\n<pre><code>\/usr\/bin\/git<\/code><\/pre>\n<\/li>\n<li>Now, let\u2019s go to \u201cManage Jenkins\u201d<\/li>\n<li>Click on \u201cManage Plugins\u201d<\/li>\n<li>Click on the \u201cAvailable\u201d tab<\/li>\n<li>In the top-right\u2019s \u201cFilter\u201d textfield, let\u2019s type \u201cgit\u201d and see what it offers us<\/li>\n<li>We need: Git client plugin, Git plugin, GitHub API Plugin, and the GitHub Authentication Plugin<\/li>\n<li>Let\u2019s choose those, and then choose \u201cDownload now and install after restart,\u201d just to be safe<\/li>\n<li>(There will be a full list of other dependencies which will also be installed, and that\u2019s expected.)<\/li>\n<li>Let\u2019s make sure our Git binary installation works.\u00a0 Under the \/configure URL, in \u201cGit\u201d let\u2019s provide the \u201cPath to Git executable\u201d which, as we\u2019ve seen above, should be\n<pre><code>usr\/bin\/git<\/code><\/pre>\n<\/li>\n<li>Now, let\u2019s go back to our \u201cdocker-zap-cli\u201d job in Jenkins, and choose \u201cConfigure\u201d<\/li>\n<li>Under Source Code Management, now, we should see a \u201cGit\u201d option.\u00a0 Click on that and enter https:\/\/github.com\/stephendonner\/docker-zap.git<\/li>\n<li>Scroll down to the \u201cBuild\u201d option, choose \u201cAdd build step\u201d and pick \u201cExecute shell\u201d<\/li>\n<li>In the \u201cCommand\u201d textfield, let\u2019s put\n<pre><code>.\/run-docker.sh<\/code><\/pre>\n<\/li>\n<li>Click \u201cSave\u201d<\/li>\n<li>Now, let\u2019s click \u201cBuild Now\u201d<\/li>\n<li>If you see any \u201cpermission denied\u201d errors, particularly with\n<pre><code>\/bin\/docker<\/code><\/pre>\n<p>and can confirm with the <a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/6\/html\/Security-Enhanced_Linux\/chap-Security-Enhanced_Linux-Troubleshooting.html\">SELinux audit log<\/a>, then try the following:<\/li>\n<\/ol>\n<h5>Disabling SELinux support<\/h5>\n<p>I should note that, once I identified the SELinux-related issues with Docker in Fedora, I didn&#8217;t spend much time trying to fully understand how to make them work.  I do plan on returning to this in future work, as <strong>disabling SELinux is *NOT* recommended.<\/strong>  There&#8217;s an official FAQ here: <a href=\"https:\/\/fedoraproject.org\/wiki\/SELinux_FAQ\">https:\/\/fedoraproject.org\/wiki\/SELinux_FAQ<\/a>. (In fact, the <a href=\"https:\/\/docs.docker.com\/v1.10\/engine\/reference\/commandline\/daemon\/\">Docker Daemon docs<\/a> reference the <strong>&#8211;selinux-enabled<\/strong> option.) However, to go about disabling SELinux on a test system, per <a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/6\/html\/Security-Enhanced_Linux\/sect-Security-Enhanced_Linux-Enabling_and_Disabling_SELinux-Disabling_SELinux.html\">RedHat&#8217;s docs<\/a>, we need to change<\/p>\n<pre><code>SELINUX=enforcing<\/code><\/pre>\n<p>to read<\/p>\n<pre><code>SELINUX=disabled<\/code><\/pre>\n<p>in<\/p>\n<pre><code>\/etc\/selinux\/config<\/code><\/pre>\n<p>So do:<\/p>\n<pre><code>$ sudo vi \/etc\/selinux\/config<\/code><\/pre>\n<p>and make the edit.<\/p>\n<p>We need a logout\/restart, here, so let&#8217;s do:<\/p>\n<pre><code>$ systemctl stop jenkins.service<\/code>\n<code>$ systemctl stop docker.service<\/code>\n<code>$ shutdown -r now<\/code><\/pre>\n<h1><strong>Configuring Docker further<\/strong><\/h1>\n<p>Now, because we&#8217;re using a Fedora version which has systemd, we want to <a href=\"https:\/\/docs.docker.com\/engine\/admin\/configuring\/#configuring-docker\">configure Docker using systemd<\/a>.<\/p>\n<p>We want to put in the following:<\/p>\n<pre><code>$ sudo mkdir \/etc\/systemd\/system\/docker.service.d<\/code>\n<code>$ sudo vi \/etc\/systemd\/system\/docker.service.d\/docker.conf<\/code><\/pre>\n<pre><code>EnvironmentFile=-\/etc\/sysconfig\/docker\nEnvironmentFile=-\/etc\/sysconfig\/docker-storage\nEnvironmentFile=-\/etc\/sysconfig\/docker-network\n$DOCKER_STORAGE_OPTIONS \\\n$DOCKER_NETWORK_OPTIONS \\\n$BLOCK_REGISTRY \\\n$INSECURE_REGISTRY\nExecStart=\nExecStart=\/usr\/bin\/dockerd -D -H tcp:\/\/127.0.0.1:2375<\/code><\/pre>\n<p>Now we also want to <a href=\"https:\/\/coreos.com\/os\/docs\/latest\/customizing-docker.html\">make Docker available via that TCP port<\/a> we specified, 2375:<\/p>\n<pre><code>$ sudo vi \/etc\/systemd\/system\/docker-tcp.socket<\/code><\/pre>\n<p>Put in the following:<\/p>\n<pre><code>[Unit]\nDescription=Docker Socket for the API\n\n[Socket]\nListenStream=2375\nBindIPv6Only=both\nService=docker.service\n\n[Install]\nWantedBy=sockets.target<\/code><\/pre>\n<p>Now, let&#8217;s enable and start Docker&#8217;s binding to TCP:2375:<\/p>\n<pre><code>$ systemctl stop docker.service<\/code>\n<code>$ systemctl enable docker-tcp.socket<\/code>\n<code>$ systemctl start docker-tcp.socket<\/code>\n<code>$ systemctl start docker.service<\/code><\/pre>\n<p>(Here&#8217;s also a <a href=\"http:\/\/superuser.com\/questions\/860869\/how-does-docker-tcp-socket-actually-enable-dockers-remote-api-on-coreos\">nice article<\/a> for more in-depth info on the above.)<\/p>\n<h1><strong>Running the build<\/strong><\/h1>\n<p>Now that we&#8217;ve installed and configured Jenkins, Docker, and Git and other necessary plugins, it&#8217;s time to build!<\/p>\n<ol>\n<li>In Jenkins, for the docker-zap-cli job view, click on &#8220;Build&#8221; in the left<\/li>\n<li>If all goes well, you should see something very close to the following:<\/li>\n<\/ol>\n<pre><code>GitHub-repo pulling...\n<\/code><\/pre>\n<pre><code>20:47:20 [INFO]            Accessing URL https:\/\/www.allizom.org\/en-US\/firefox\/\n20:47:34 [INFO]            Running spider...\n20:49:15 [INFO]            Running an active scan...\n<\/code><\/pre>\n<pre><code>6310 [ZAP-daemon] INFO org.zaproxy.zap.DaemonBootstrap  - ZAP is now listening on 127.0.0.1:2375\n43023 [Thread-9] INFO org.zaproxy.zap.extension.spider.SpiderThread  - Starting spidering scan on SpiderApi-0 at Tue Jun 28 20:47:34 UTC 2016\n43028 [Thread-9] INFO org.zaproxy.zap.spider.Spider  - Spider initializing...\n43055 [Thread-9] INFO org.zaproxy.zap.spider.Spider  - Starting spider...\n<\/pre>\n<p><\/code><\/p>\n<pre><code>105166 [pool-1-thread-2] INFO org.zaproxy.zap.spider.Spider  - Spidering process is complete. Shutting down...\n105174 [Thread-10] INFO org.zaproxy.zap.extension.spider.SpiderThread  - Spider scanning complete: true\n<\/pre>\n<p><\/code><\/p>\n<pre><code>20:49:35 155113 [Thread-12] INFO org.parosproxy.paros.core.scanner.HostProcess  - completed host https:\/\/www.allizom.org in 11.491s\n20:49:35 155115 [Thread-11] INFO org.parosproxy.paros.core.scanner.Scanner  - scanner completed in 11.532s\n20:49:35 c7017c8e9ca40054acf9e1a88dc36c14d1866419da6ca974efd61298b423c43f\n20:49:35 Finished: SUCCESS<\/code><\/pre>\n<p>Here's a <a href=\"http:\/\/pastebin.com\/ezqAvMH1\">Pastebin entry<\/a> with the full output.<\/p>\n<p>In fact, the output should very nearly match that in <a href=\"https:\/\/blog.mozilla.org\/webqa\/2016\/05\/11\/docker-owasp-zap-part-one\/\">https:\/\/blog.mozilla.org\/webqa\/2016\/05\/11\/docker-owasp-zap-part-one\/<\/a> , since Docker is just executing the commands we've already set up.<\/p>\n<p>I plan on continuing to work further in <a href=\"https:\/\/github.com\/stephendonner\/docker-zap\/\">my GitHub repository<\/a>, so keep an eye on and\/or add to <a href=\"https:\/\/github.com\/stephendonner\/docker-zap\/issues\">Issues<\/a>\/<a href=\"https:\/\/github.com\/stephendonner\/docker-zap\/pulls\">Pull Requests<\/a>!<\/p>\n<p>I'd absolutely love more help and feedback on how to make this more useful; thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following up from my earlier blog post, I was able to get a Dockerized ZAP-CLI up and running in a Jenkins instance! I\u2019ll break this down into five main parts, &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/fxtesteng\/2016\/06\/28\/dockerized-owasp-zap-security-scanning-in-jenkins-part-two\/\">Read more<\/a><\/p>\n","protected":false},"author":512,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[228,69],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/491"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}