How To Achieve Devsecops With Gitlab Ci/Cd: Shift Left With Built-In Security Tools and Best Practices
How To Achieve Devsecops With Gitlab Ci/Cd: Shift Left With Built-In Security Tools and Best Practices
How To Achieve Devsecops With Gitlab Ci/Cd: Shift Left With Built-In Security Tools and Best Practices
DEVSECOPS WITH
GITLAB CI/CD
Shift left with built-in security
tools and best practices
!
Table of Contents
03 INTRODUCTION 20 WHY GITLAB
Introduction
DevOps practices have enabled software developers (devs) and operations (ops) teams to
accelerate delivery through automation, collaboration, smarter feedback loops, and iteration.
DevOps goes beyond the Agile and lean practices it came from to make faster software
delivery possible. DevOps represents a cultural shift that focuses on not only speed, but
efficiency as well.
While DevOps has removed many of the barriers to faster delivery, one area of development
has sometimes felt like an outsider looking in: security.
Traditional application security is usually a final step of the development lifecycle. Dedicated
security professionals run tests to identify vulnerabilities, prioritize them by risk, and
then triage for remediation. Looking at security as an afterthought in the development
process doesn’t breed optimal results and causes bigger problems in the long run. With
security acting as a gatekeeper for deployment, it can feel like a roadblock to innovation by
developers and engineers, rather than an equal partner.
With security and compliance being so important, especially with "#$!%$&'()"*!"#($+"% out
there today, teams are realizing that it’s not enough to just practice DevOps with security
thrown in at the end. Balancing business velocity with security is possible. For teams wanting
to innovate, going beyond traditional DevOps will not only be important, it will be essential.
In the past, security tools were highly specialized and not “Automated testing and continuous integration have made
necessarily 0$1$/23$(45()$-0/*. Developers wanted command- our deployments safer and more optimized. Now everyone
line tools that could be automated, customized for various in the team has the permission to deploy the code.”
configurations, and imported into bug trackers. But traditional
To achieve DevSecOps, a robust CI/CD strategy with built-in
security scanners were made for security teams and CISOs,
security features will be a main component. GitLab’s open DevOps
whose goals are governance, security policy compliance, and risk
platform with built-in CI/CD brings these requirements into the
management – not necessarily development velocity.
development lifecycle naturally. Teams that adopt a .220!;<=
;8!%"(+"$.* are not only able to develop better, faster software,
Over time, security vendors and developer platforms have
they also improve business outcomes, identify bugs, and catch
adapted their products to address the needs of both: Analytics
vulnerabilities before they ever reach users.
and reports needed by CISOs with integrated workflows needed
by developers. CI/CD pipelines can incorporate security testing
either natively or as an integration from a third-party vendor. This
has allowed security to shift left while also being robust enough to
identify vulnerabilities. Teams are more poised than ever to adopt
a real DevSecOps culture.
DevSecOps in action:
Tanuki Pets
Rachel is the configuration manager. Delaney is the development lead. Sasha is a new developer.
They are responsible for the version They started developing the company They just joined Tanuki Pets as a developer
control tool and repository, manages website four years ago. Delaney still and report to Delaney. Sasha joined
manual and automatic deployment maintains the code and last year Tanuki Pets because they like pets, they
of environments, and develops best got promoted to a team lead. have a dog and two cats at home, and
practices and processes in the area they thought it would be fun to develop a
of coding and code management. website for pets. They love open source.
Parker is the product manager. Simone is the QA engineer. Presley is the product designer.
They work closely with Presley, the Their responsibility is to ensure that They are creative and come up with
product designer, to define new the team releases high quality products great ideas and solutions. Presley’s
functionality that will increase the that are usable and with a fun user job is to translate the product’s
company business. Parker tries to push experience. Most tests are manual. mission into an effective, empathetic,
for releasing features to production and efficient user experience.
fast – but this usually doesn’t happen.
Sasha: “What about the manual tasks that eat a lot of time,
like deploying a test environment and testing the code? If we
We will need to test this extensively could just automate these things and have automatic security
for security and performance with scans, it could easily save us ten days or more.”
an external company, as well as
get CEO sign-off final approval.
The soonest we can deliver this to
Delaney: “Honestly, I can barely keep up with the processes
production is seven to eight weeks.
we have today.”
Maybe nine. Okay, okay...10 weeks.
When >+?)-.!"#$!&+%$!52(!;<=;8, or any new technology, IT leaders GitLab is an open DevOps platform, delivered as a single application,
need to be convinced that adopting new tools or processes will be including built-in CI/CD. As a single application, it has all components
worth it in the long run. Shifting to DevSecOps requires an investment the team needs in one place: single UI, single data storage, and single
in time and resources that can sometimes take years. vendor.
The team signs up for the GitLab free trial which gives them access to all
GitLab Ultimate features they’ll need for this project, including:
»! Agile project management
»! Infrastructure-as-code
I just created a group for our team and added all of you. Then I
created a project in our group and pushed Tanuki-Pets source
code to it in less than two minutes. Now all of us can clone the
code from the GitLab repository and start developing locally.
GitLab makes implementing and configuring CI easier out-of-the box with Auto DevOps. Rather
than building a YAML file from scratch, or trying to configure existing scripts, Auto DevOps
provides 3($0$5)-$0!;<=;8!&2-5).'(+")2-% that automatically detect, build, test, deploy, and
monitor applications. Since it’s enabled by default, all the Tanuki Pets team needs to do is start
a pipeline job and Auto DevOps does the rest. Everytime there’s a code change, GitLab will
trigger a CI/CD pipeline to build and test the code.
Auto DevOps
settings
Configuring continuous integration 3. For the Filename, type `.gitlab-ci.yml` and in the larger
window, paste this sample code:
While Auto DevOps makes it easy to get started right away, GitLab CI/
CD can be configured for any need. GitLab uses 3)3$/)-$!+%!&20$ and build-job:
a `.gitlab-ci.yml` file saved in the root of the repository. GitLab stage: build
will detect the syntax automatically and run the steps defined once script:
new code is pushed. - echo "Hello, $GITLAB_USER_LOGIN!"
test-job1:
Creating a new `.gitlab-ci.yml` file )%!+-!$+%*!3(2&$%%.
stage: test
script:
1. Go to Project overview > Details.
- echo "This job tests something"
test-job2:
2. Above the file list, select the branch you want to commit stage: test
to, click the plus icon, then select New file: script:
- echo "This job tests something, but takes
more time than test-job1."
- echo "After the echo commands complete,
it runs the sleep command for 20 seconds"
- echo "which simulates a test that runs 20
seconds longer than test-job1"
- sleep 20
deploy-prod:
stage: deploy
script:
- echo "This job deploys something from the
$CI_COMMIT_BRANCH branch."
This is by no means an exhaustive list. GitLab has even more scans 8$3$-0$-&*!9&+--)-. Analyze your dependencies for
known vulnerabilities.
available that can be added at any time, depending on your needs.
8*-+>)&!A33/)&+")2-! Analyze running web applications
9$&'()"*!B$%")-.!C8A9BD for known vulnerabilities.
GitLab also provides support for $-04"24$-0!"$%")-.!H)"#!9$/$-)'>! extremely valuable for large applications so that you can know that
+-0!I$G0()1$(<:. While unit tests are used the majority of the time, the deployment went as intended, that your infrastructure is up and
end-to-end testing, also called broad-stack or full-stack testing, is running, and that all of your code works well together.
To add a deploy job: add deploy stage, and paste this job
template.
I usually spend at least two days
configuring and deploying test deploy-test:
environments. With GitLab CI/ image: "registry.gitlab.com/gitlab-org/cluster-
CD, can I automate this process? integration/auto-deploy-image:v1.0.7"
stage: deploy
script:
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy ensure_namespace
- auto-deploy initialize_tiller
- auto-deploy create_secret
- auto-deploy deploy
- auto-deploy persist_environment_url
environment:
name: deploy/$CI_COMMIT_REF_NAME
url: http://$CI_PROJECT_ID-$CI_ENVIRONMENT_
The easiest way to make this happen will be to build a Docker image SLUG.$KUBE_INGRESS_BASE_DOMAIN
from the code and deploy it using Kubernetes. GitLab has a robust artifacts:
J'G$(-$"$%!)-"$.(+")2- and provides cloud-agnostic support for paths: [environment_url.txt, tiller.log]
cloud native development so that you can deploy anything you want, when: always
anywhere, anytime. rules:
- if: '$CI_KUBERNETES_ACTIVE == null || $CI_
KUBERNETES_ACTIVE == ""'
You can use a predefined template for building the docker image and when: never
a CI job template to orchestrate the deployment. - if: '$CI_COMMIT_BRANCH == "master"'
when: never
To create a Docker image and push it to GitLab container - if: '$REVIEW_DISABLED'
registry, include this template in your CI config file: when: never
Jobs/Build.gitlab-ci.yml - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
Once the cluster is created and connected to your project, you can
deploy your app to it.
The merge request is also +!&2//+G2(+")2-!"22/ that allows team members to review each
others’ code and provide feedback on potential changes. Everyone has visibility into the
changes and a wide variety of "$%"!($%'/"%!+-0!($32("% are available in the merge requests.
You can define approval rules to prevent merging any changes if a security report contains
vulnerabilities or if a compliance report contains a denied license.
Review app
Test results
GITLAB RUNNERS
For teams using GitLab’s SaaS version, GitLab offers Linux and
Windows %#+($0!('--$(% hosted on GitLab.com for executing your
pipelines. This is the version that Tanuki Pets is currently using. We’ve created the pipeline configuration, added
tests to it, but how do we actually run the pipeline?
But what if Tanuki Pets wants to move GitLab to their on-premise Do we need to maintain dedicated build machines?
data center and use their own infrastructure in the future? N)"@+G!
M'--$( is open source and written in Go. Once Runner software is
installed, it will download a Docker image with all the dev tools in it
and run the job inside the image, so minimal to no extra maintenance
of the runners is required. Each job will run on a clean image for
increased security and stability.
Why GitLab
GitLab is an open DevOps platform that unifies development, operations, and security
teams into a single application. With GitLab, DevSecOps architecture is built into the CI/
CD process. Every merge request is scanned through its pipeline for security issues and
vulnerabilities in the code and its dependencies using automated tests.
GitLab helps teams accelerate software delivery from weeks to minutes while reducing
development costs and security risks.
“One tool for SCM+CI/CD was a big initial win. Now wrapping security scans into
that tool as well has already increased our visibility into security vulnerabilities.
The integrated Docker registry has also been very helpful for us. Issue/Product
management features let everyone operate in the same space regardless of role.”
Dev and Ops teams working together In this eBook, we hope you’ve learned about some of the core capabilities that
»! Everyone working in the same system help millions of users around the world to develop better applications faster:
»! Smart feedback loops »! Get started with GitLab, registration, creating a group and a project
»! No messy integrations or plugins »! Enable Auto DevOps - GitLab automatically configure the CI/CD for you,
based on years of experience and best practices from thousands of
customers
Get value to customers faster
»! Manually configuration of CI/CD with YAML
»! Issues addressed earlier
»! Add security scans and test automation
»! Fast cycle times
»! Deploy test environment on Kubernetes
»! Quality control
»! Review test results
Reduce security and compliance risk »! GitLab runners - the agents that run the jobs.
»! Every change is fully tested and secure
»! Audit logs for every action
»! Single sign-on and datastore
GitLab Ultimate provides Enterprise-grade priority support and embeds key Ready to see what DevSecOps
security controls directly into CI/CD pipelines, all from a single application. Dev, can do for your team?
sec, and ops collaborate in a single interface for maximum visibility across the
entire development lifecycle. Try GitLab free for 30 days
!!
About GitLab
GitLab is a DevOps platform built from the ground up as a single application for
all stages of the DevOps lifecycle enabling product, development, QA, security,
and operations teams to work concurrently on the same project. GitLab
About the Author provides a single data store, one user interface, and one permission model
across the DevOps lifecycle. This allows teams to significantly reduce cycle
times through more efficient collaboration and enhanced focus.
Itzik Gan-Baruch is a veteran of
creating creative technical content
which bridges gaps between business Built on open source, GitLab works alongside its growing community, which is
and technology, and helps non-
technical users understand the value composed of thousands of developers and millions of users, to continuously
of technology. He creates software deliver new DevOps innovations. More than 100,000 organizations from startups
demo systems, demo tools, YouTube
videos, analysts demos, plans content to global enterprises, including Ticketmaster, Jaguar Land Rover, NASDAQ, Dish
for demo booths at tech shows, and
speaks at industry events. He is a
Network, and Comcast trust GitLab to deliver great software faster. All-remote
senior technical marketing manager at since 2014, GitLab has more than 1,300 team members in 68 countries.
GitLab with over 21 years of experience
in the IT industry focusing on
application delivery, agile and software
testing, and is a father of three.