<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Zachary Conger</title>
    <description>The latest articles on Forem by Zachary Conger (@zconger).</description>
    <link>https://forem.com/zconger</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F376383%2F51355945-6645-4292-9b9f-26b33417e86e.jpg</url>
      <title>Forem: Zachary Conger</title>
      <link>https://forem.com/zconger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zconger"/>
    <language>en</language>
    <item>
      <title>Add AppSec to Your CircleCI Pipeline With the StackHawk Orb</title>
      <dc:creator>Zachary Conger</dc:creator>
      <pubDate>Wed, 29 Apr 2020 21:00:30 +0000</pubDate>
      <link>https://forem.com/zconger/add-appsec-to-your-circleci-pipeline-with-the-stackhawk-orb-12pl</link>
      <guid>https://forem.com/zconger/add-appsec-to-your-circleci-pipeline-with-the-stackhawk-orb-12pl</guid>
      <description>&lt;p&gt;&lt;em&gt;When you check in a new web app vulnerability, do you get an alert and guidance on how to fix it? With the new StackHawk CircleCI Orb you can, and it’s easy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The modern CI/CD environment bristles with automation. When you check in your code, an invisible army of robots goes to work linting, compiling, unit testing, and integrating your software.&lt;/p&gt;

&lt;p&gt;These processes help us code &lt;em&gt;faster&lt;/em&gt; since you don’t have to spend time manually building and testing, and &lt;em&gt;better&lt;/em&gt; since you get quick feedback and guidance on code quality. Now you can add test-driven &lt;em&gt;security&lt;/em&gt; to your pipeline with StackHawk.&lt;/p&gt;

&lt;p&gt;In this post, we will use the &lt;a href="https://circleci.com/orbs/registry/orb/stackhawk/stackhawk"&gt;StackHawk CircleCI Orb&lt;/a&gt; to build an app, fire it up in a container, and scan it for vulnerabilities, all within the CircleCI build environment.&lt;br&gt;
The Application&lt;/p&gt;

&lt;p&gt;I will be building and scanning &lt;a href="https://github.com/stackhawk/vuln_django_play"&gt;Vulny Django&lt;/a&gt;. It’s a small web poll app that StackHawk’s Chief Security Officer, Scott Gerlach, built from the &lt;a href="https://docs.djangoproject.com/en/3.0/intro/tutorial01/"&gt;Django tutorial&lt;/a&gt;. We often use it to test scans and pipelines because it’s simple, quick to build, and it has a good set of routes and potential security flaws.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Orb
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://circleci.com/orbs/"&gt;CircleCI&lt;/a&gt; Orbs are a clever way to package complicated bits of code to make your pipeline configuration code clean and DRY. We recently launched our own orb, which makes it simple to weave scans into your pipeline. It exposes all the features of StackHawk, including the ability to scan any web app, find routes by spidering, parse an OpenAPI spec, and even probe GraphQL.&lt;/p&gt;

&lt;p&gt;The orb provides two jobs, &lt;a href="https://circleci.com/orbs/registry/orb/stackhawk/stackhawk#jobs-hawkscan-remote"&gt;hawkscan-remote&lt;/a&gt;, and &lt;a href="https://circleci.com/orbs/registry/orb/stackhawk/stackhawk#jobs-hawkscan-local"&gt;hawkscan-local&lt;/a&gt;. Each has advantages, but one is generally better suited for remote scans, and the other is best for running a self-contained scan within the CircleCI build environment.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the two options.&lt;/p&gt;
&lt;h3&gt;
  
  
  stackhawk/hawkscan-remote
&lt;/h3&gt;

&lt;p&gt;This is the faster and simpler of the two scan jobs, but it requires a remote instance of your app to be up and running. This is great if you have an existing integration environment accessible to CircleCI. All you need is to add a valid &lt;code&gt;stackhawk.yml&lt;/code&gt; configuration file to your source repository, and add your StackHawk API key as a &lt;a href="https://circleci.com/docs/2.0/env-vars/#secrets-masking"&gt;secret&lt;/a&gt; environment variable &lt;code&gt;HAWK_API_KEY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s an example CircleCI configuration to use the hawkscan-remote job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .circleci/config.yml&lt;/span&gt;
&lt;span class="na"&gt;orbs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;stackhawk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;stackhawk/stackhawk@x.y.z&lt;/span&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.1&lt;/span&gt;
&lt;span class="na"&gt;workflows&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;scan-remote&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;stackhawk/hawkscan-remote&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And here’s an example StackHawk configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# stackhawk.yml&lt;/span&gt;
&lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;applicationId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;xxXXXXXX-xXXX-xxXX-XXxX-xXXxxXXXXxXX&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://example.com&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Development&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  stackhawk/hawkscan-local
&lt;/h3&gt;

&lt;p&gt;This job allows you to spin up your own ephemeral integration environment right in your CircleCI pipeline.&lt;/p&gt;

&lt;p&gt;When hawkscan-local runs, it starts a build VM, checks out your source code, runs a series of steps you provide, and then launches a &lt;a href="https://hub.docker.com/r/stackhawk/hawkscan"&gt;stackhawk/hawkscan&lt;/a&gt; container. In the steps you provide, you can launch local services or containers to be scanned, right there in the CircleCI cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting It All Together
&lt;/h2&gt;

&lt;p&gt;We will use the second job, &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt;, to demonstrate using the orb to run an integration test in your CircleCI pipeline. Let’s get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Get a StackHawk API Key
&lt;/h3&gt;

&lt;p&gt;Go to &lt;a href="https://stackhawk.com"&gt;https://stackhawk.com&lt;/a&gt; to sign up. Create an account, and get an API key. Be sure to save a copy in a secure undisclosed location. You will need it later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clone the Vulny Django Repository
&lt;/h3&gt;

&lt;p&gt;Head over to &lt;a href="https://github.com/stackhawk/vuln_django_play"&gt;https://github.com/stackhawk/vuln_django_play&lt;/a&gt; and fork our repository. You can also clone it and copy it up to Bitbucket if you like. The key is to have your own copy to play with, and to set up as a project in CircleCI.&lt;/p&gt;

&lt;p&gt;Take a glance at the files in this repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── .circleci/
│   └── config.yml
├── .gitlab-ci.yml
├── Dockerfile
├── README.md
├── nginx.default
├── src/
├── stackhawk-circleci.yml
├── stackhawk-gitlab.yml
├── stackhawk.yml
└── start-server.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;src&lt;/code&gt; directory contains the app itself. And the &lt;code&gt;Dockerfile&lt;/code&gt; file will be used to build the app and containerize it. There are other files associated with other build systems, such as &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; for GitLab. For our purposes we will focus on these three files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;stackhawk.yml&lt;/code&gt; – The HawkScan configuration file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; – An additional HawkScan configuration file that we’ll use to customize our scan for CircleCI&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.circleci/config.yml&lt;/code&gt; – The CircleCI project configuration file&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Configure HawkScan
&lt;/h3&gt;

&lt;p&gt;Check out the primary configuration file, &lt;code&gt;stackhawk.yml&lt;/code&gt;. We use this project to test lots of command line and automation scenarios, so we put all of our common configs in here, such as authentication parameters (&lt;code&gt;app.authentication&lt;/code&gt;), and scan depth (&lt;code&gt;hawk.spider&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For my CircleCI pipeline, I wanted to customize a few of these parameters, so I created &lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; and put my overrides there. These will be merged on top of the main configuration file. Here’s the whole file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# stackhawk-circleci.yml&lt;/span&gt;
&lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;applicationId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${APP_ID}&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://vulny-django:8020&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will override the &lt;code&gt;app.applicationId&lt;/code&gt; and &lt;code&gt;app.host&lt;/code&gt; entries from the main configuration. I’ll be setting the &lt;code&gt;APP_ID&lt;/code&gt; environment variable in the CircleCI build configuration below by using the &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt; parameter, &lt;code&gt;app-id&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure CircleCI
&lt;/h3&gt;

&lt;p&gt;Let’s look at the CircleCI build configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .circleci/config.yml&lt;/span&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.1&lt;/span&gt;

&lt;span class="na"&gt;orbs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;stackhawk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;stackhawk/stackhawk@1.0.1&lt;/span&gt;

&lt;span class="na"&gt;workflows&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build-and-scan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;stackhawk/hawkscan-local&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;configuration-files&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./stackhawk.yml ./stackhawk-circleci.yml&lt;/span&gt;
          &lt;span class="na"&gt;docker-network&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;scan_net&lt;/span&gt;
          &lt;span class="na"&gt;app-id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;685847dd-0a74-4f02-b4d2-53f2396c93ed&lt;/span&gt;
          &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build Vulny Django&lt;/span&gt;
                &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker build -t vulny_django:latest .&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run Vulny Django&lt;/span&gt;
                &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
                  &lt;span class="s"&gt;docker network create scan_net&lt;/span&gt;
                  &lt;span class="s"&gt;docker run --detach --network scan_net --name vulny-django --rm vulny_django:latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we pull in the orb as &lt;code&gt;stackhawk&lt;/code&gt;, and use it in our simple workflow, &lt;code&gt;build-and-scan&lt;/code&gt;. We define a single job in the workflow using the orb job, &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt;. The orb has several optional parameters, and we use three of them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;docker-network&lt;/code&gt; tells hawkscan-local to start the dockerized scanner to run on a named bridge network called &lt;code&gt;scan_net&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;app-id&lt;/code&gt; sets the environment variable, &lt;code&gt;APP_ID&lt;/code&gt;, that we use in &lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; above to dynamically set &lt;code&gt;app.applicationId&lt;/code&gt; at runtime. Be sure to update this with your own app ID!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;steps&lt;/code&gt; sends a series of job steps to the orb to run on the VM before the scan starts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In our three job steps, we build the app, create a docker bridge network, &lt;code&gt;scan_net&lt;/code&gt;, and start our new container on that network.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add your Vulny Django Project to CircleCI
&lt;/h3&gt;

&lt;p&gt;Head over to &lt;a href="https://app.circleci.com/"&gt;CircleCI&lt;/a&gt; and add your GitHub repo as a project in CircleCI. In your project settings, add your StackHawk API key as a &lt;a href="https://circleci.com/docs/2.0/env-vars/#secrets-masking"&gt;secret&lt;/a&gt; environment variable, &lt;code&gt;HAWK_API_KEY&lt;/code&gt;. This will automatically get picked up in the &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt; job and used to send scan results to your StackHawk console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the Pipeline
&lt;/h3&gt;

&lt;p&gt;Make a commit to your repo and push it to GitHub to trigger a pipeline run. Then watch the job run in the CircleCI console. Here’s what you should see.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u9iA-CV6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/jmmcqB6zbewvkMyCgeGWZJ3k1aPVVTNbp1td6CsBMf03cP9vq92v4Rjv_KIRIxq8TLoqYEEDqjXdhIdgmvzS-l2SgV4Jwzac80VXZNeoebNXZ9vqDJ3idbqRxVzVM4-LMP_IuJoA" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u9iA-CV6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/jmmcqB6zbewvkMyCgeGWZJ3k1aPVVTNbp1td6CsBMf03cP9vq92v4Rjv_KIRIxq8TLoqYEEDqjXdhIdgmvzS-l2SgV4Jwzac80VXZNeoebNXZ9vqDJ3idbqRxVzVM4-LMP_IuJoA" alt="CircleCI Workflow Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the job is finished, check your scan results in the StackHawk console. You can go directly to it by copying and pasting the link at the bottom of the Run HawkScan step in CircleCI. It should look like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;View on StackHawk platform: https://app.stackhawk.com/scans/xxXXXXXX-xXXX-xxXX-XXxX-xXXxxXXXXxXX&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After following that link to the StackHawk console, you should see scan results similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R03V_NbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/Z3wPqkCUfXfSW7h61vsicz-TEyjvV-QWMPwbPF1WruXjhqtd8d5U96EpV0o3JB1F3pI-s7GDcakq0y6RYDOQoSyaKUVIiLfn2QBVm8ZfNGyQp_x2vDSIpXuJJxkObdSeU66qFQ28" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R03V_NbX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/Z3wPqkCUfXfSW7h61vsicz-TEyjvV-QWMPwbPF1WruXjhqtd8d5U96EpV0o3JB1F3pI-s7GDcakq0y6RYDOQoSyaKUVIiLfn2QBVm8ZfNGyQp_x2vDSIpXuJJxkObdSeU66qFQ28" alt="StackHawk Scan Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  🦅 KAA-KAWW!!!
&lt;/h1&gt;

&lt;p&gt;☝️ That feeling when your scan works. To experience it yourself, visit &lt;a href="https://www.stackhawk.com"&gt;https://www.stackhawk.com&lt;/a&gt; to get signed up for our early access release. Get started on the command line with our helpful &lt;a href="https://docs.stackhawk.com/"&gt;Docs&lt;/a&gt;, and be sure to check out our &lt;a href="https://docs.stackhawk.com/continuous-integration/"&gt;integration guides&lt;/a&gt; for other popular CI/CD platforms.&lt;/p&gt;

&lt;p&gt;Thanks, and good night!&lt;/p&gt;

&lt;p&gt;Originally posted at &lt;a href="https://www.stackhawk.com"&gt;stackhawk.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>devops</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
