SlideShare a Scribd company logo
Join the conversation #DevSecCon
BY Fabian Lim
REMOVE DEVELOPERS’
SHAMEFUL SECRETS
OR SIMPLY REMOVE SHAMEFUL DEVELOPERS…
First thing First!
Materials can be found at:
github.com/
DevSecOpsSG/
devseccon2018
Do the Prerequisite!
github.com/DevSecOpsSG/devseccon2018
Disclaimer
This presentation may or may not contain information about services under GovTech. The
information contained in this presentation is classified as Public.
This presentation and its contents does not represent the views of GovTech, or any other
entities. They are the sole views of the author. I take full responsibility for my work
and any errors fall on my shoulders.
Be happy and awesome; and
help others to be happy and
awesome.
github.com/DevSecOpsSG/devseccon2018
missions:
- energetic DevSecOps Engineer and Evangelist
- physical and cyber security educator
education:
- Singapore Management University, BS Info System
- Carnegie Mellon University, MS Info Security Policy Mgmt
employers:
- Intuit Inc.
- GovTech [Formerly known as IDA] check out tech.gov.sg for more
- Nectar PaaS, security features, etc.
presentations:
- ADDO 2016 [Blue-Green Deployment] http://bit.ly/2fLfHgr
- RSA APJ 2017 [PaaS] http://bit.ly/2ylUyB9
hobbies:
- krav maga; self defense & martial arts
- food
whoami - about.me/fabian.lim
github.com/DevSecOpsSG/devseccon2018
NECTAR
GovTech’s
Platform as a Service
Read more about it here:
https://blog.gds-gov.tech/nectar-10e0eb1581cf
github.com/DevSecOpsSG/devseccon2018
Takeaways
1) Learned a thing about secret management
2) Learned a thing about design a secure workflow / pipeline
3) Learned a cool, new tool to integrate into your workflow
4) Or… Made a new friend :)
github.com/DevSecOpsSG/devseccon2018
Tone
1) Interactive
2) Technical
3) Open
github.com/DevSecOpsSG/devseccon2018
Agenda
1) Get to know each other, and the problems
2) Open discussion for designing a solution
3) Improve on current pipeline
4) Debrief and possible future integrations
My Mistakes!
OOPS! Personal mistake -
commit secrets into repository...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply remove shameful developers by Fabian Lim
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply remove shameful developers by Fabian Lim
Get to know each other, and the
problems
github.com/DevSecOpsSG/devseccon2018
Get to know each other, and the problems
1) With 2 or 3 in a group, introduce and get to know each other
2) What are some common password problems?
a) What are the credentials for X database, Y API, etc?
b) Where am I supposed to store these credentials?
c) Who should have these credentials? Can I pass it to ABC?
d) How do I rotate credentials for Y API because ABC left?
e) How do I keep track of X secrets of Y apps?
Discussion Time!
github.com/DevSecOpsSG/devseccon2018
Lab “Tech Stack”
Database (MongoDB)
Cloud Infrastructure (AWS)
App (Node)
github.com/DevSecOpsSG/devseccon2018
Lab “Tech Platforms”
Cloud Infrastructure (AWS)
Docker
Vault
App1
Jenkins
App2 App3
mlab.com
Database1 Database2 Database3
github.com/DevSecOpsSG/devseccon2018
Lab Workflow
Jenkins
Docker
App1
Source Code
github.com/<username>/
devseccon2018.git
1. Pull source code
2. Build and run in Docker
Lab
https://docs.google.com/presentation/d/12qNpVXpSxNuOE4wG9CBSGINau
c7cBjOmIiQo3w7w9AA/edit#slide=id.g31f475055f_0_238
LET’S GO!
Open discussion for designing a
solution
github.com/DevSecOpsSG/devseccon2018
How to retrieve secrets?
1. Environment variables (static)
a. How do I manage the environment variables in dev, staging and
prod?
2. Run-time API retrieval (pull)
a. What API keys to use? Where do I store it?
3. Run-time deployment variable injection (push)
a. How does the deployer trust THIS instance of build?
b. How does the deployer know what secrets THIS instance need?
Chain of Trust
Manage Trust in workflow / pipeline
github.com/DevSecOpsSG/devseccon2018
secret[0]
The idea of secret[0] is the first piece of credential, or the first entity
of trust, needed to initiate a trusted chain of actions like producing
the second piece of secret, etc.
github.com/DevSecOpsSG/devseccon2018
Shift of Responsibility to Hold secret[0]
App
Deployer / Orchestrator
SSMHuman HSM
github.com/DevSecOpsSG/devseccon2018
The App is a Box, in a Pipeline
Build
App
Source
Code
(GitHub)
Builder
(Jenkins)
App
Artifact
= Neutral Entity
= Trusted Entity
= Trusted Child Entity
github.com/DevSecOpsSG/devseccon2018
The App is a Box, in a Pipeline
= Neutral Entity
= Trusted Entity
= Trusted Child Entity
Deployer
(Jenkins)
Secret
Mgmt
Server
(Vault)
App
Artifact
Approve!
Give Token
to Jenkins
Deploy
issues
secret
App
(Node)
github.com/DevSecOpsSG/devseccon2018
The App is a Box, in a Pipeline
= Neutral Entity
= Trusted Entity
= Trusted Child Entity
Dev
Environment
Database
(MongdoDB)
App
(Node)
Improve on current pipeline
github.com/DevSecOpsSG/devseccon2018
Open discussion for designing a solution
Put on the Security Architect’s hat:
1) What’s a good technical solution that removes (or the risk of
storing) secrets in code repositories?
2) How do you establish trust in a workflow?
3) How does a good development pipeline or workflow look like?
Discussion Time!
github.com/DevSecOpsSG/devseccon2018
Scenario
• You are a new security developer in the team
• Audit flagged a high risk in the plaintext secrets that was checked
in t the code repository
Objectives
Task #1: Remove secrets in code repository, but still run
Task #2: Prevent secrets from exposing in build environment (logs)
Lab
https://docs.google.com/presentation/d/12qNpVXpSxNuOE4wG9CBSGINau
c7cBjOmIiQo3w7w9AA/edit#slide=id.g31f475055f_0_238
LET’S GO!
Debrief, and possible future
integrations
github.com/DevSecOpsSG/devseccon2018
Pipelines are Fundamental in DevSecOps
Doing so, benefits are:
• Security is built-in by design
• Containment; Blast Radius
• It can scale healthily!
• It has the ability to be re-build
By:
• Thinking like water
pipelines engineers
• Building as modular as
possible - API
• Building resilience
Because it:
• Supports SDLC; and Agile
github.com/DevSecOpsSG/devseccon2018
Find your recipe
1)
github.com/DevSecOpsSG/devseccon2018
Debrief, and possible future integrations
1) What are your takeaways?
a) Find # of hard-coded secrets
b) “Variablize” found secrets
c) Remove habits of checking in secrets
d) Remove guilty developers [optional]
2) How would you start to embark this journey and start to
communicating this with your developers?
3) What are possible integrations improvements to this workflow?
Join the conversation #DevSecCon
Thank you for your attention, patience, and
enthusiasm during the workshop!
Happy Lunar New Year!
Cheers!
Fair Warning
Although minimal, my scripts are written mainly in MacOS.
For security concerns and compatibility, you might consider executing them in a
Linux VM.
The permissions set on the services trust that developers (you) are trustworthy
and responsible, with the ability to change certain settings.
Please exercise caution while making changes and limit those changes to
your own environment in order to have a conducive learning environment.
Lab Audience and Objective
● Developers - who want to implement and fix the problem
● Managers - who wants the problem to be fixed but don’t know how
● Compliance / Auditors - who wants to see how a problem can be fixed
...
Remove and rotate secrets
Use a secret management server
Integration with Jenkins
Lab 1 - Secrets Checked In
Setup / Login GitHub
● Login to your GitHub account
● Click on “Issues”
● Click “New issue” to create an issue in the devseccon2018 project so I know
your username and I can invite you now!
Setup / Login GitHub
● Fill in some description about yourself and Click “Submit new issue”
● You will receive an email to join
● membership
● to https://github.com/DevSecOpsSG
Setup / Login GitHub
● Go to https://github.com/DevSecOpsSG/devseccon2018.git
● Click “Fork”
● You should be redirected to
https://github.com/<username>/devseccon2018.git
● This is your fork (copy) of the repository
Setup / Login GitHub
● Open a terminal and run to clone code to your local machine:
git clone https://github.com/<username>/devseccon2018.git
● You now have a local version of the code
Setup mlab (MongoDB)
● Sign up an account at https://mlab.com
● Click “Create new” for MongoDB Deployments
Setup mlab (MongoDB)
● Choose any Cloud Provider (doesn’t matter)
● Choose Plan Type SANDBOX (FREE)
● Click “Continue”
● Select a region (doesn’t matter)
● Click “Continue”
Setup mlab (MongoDB)
● Give your database a cool name (doesn’t matter)
● Click “Continue”
Setup mlab (MongoDB)
● Check your final order
● Click “SUBMIT ORDER”
Setup mlab (MongoDB)
● Click on the new database
Setup mlab (MongoDB)
● Click on “Users”
● Click on “Add database user”
Setup mlab (MongoDB)
● Enter a username and password (don't use anything personal or sensitive)
○ To avoid syntax error in the later steps, do not use the “@” symbol at all; you can use it but
you must encode the character in the script later
● Leave “Make read-only” box unchecked
● Click “Create”
Setup mlab (MongoDB)
From the database page, construct your mlab mongodb instance URL (this
contains secret) replacing <dbuser> and <dbpassword> that you previously
entered.
In my example, mine is:
mongodb://triplejhacker:<dbpassword>@ds241668.mlab.com:41668/coolname
Paste mlab URL as MONGODB_CREDENTIALS
Push changes to your fork
git add start_app_server.sh
git commit -m ‘added mongo credentials’
git push origin master
Yes, check your secret into the code repository :P
We will remove and rotate it later, don’t worry.
Access to Jenkins
Go to http://13.228.110.97:8080
Membership in
https://github.com/DevSecOpsSG
allows access to this Jenkins server.
Click “Authorize 3jmaster” (That’s me)
Denied Access to Jenkins
If you see this
Please perform steps in slide 5 and 6 to get access to the Github organization
membership
Build and Run with Jenkins
Click “New Item”
Build and Run with Jenkins
● Enter your username or any name as a project name
● Choose “Freestyle Project”
● Click “OK”
Build and Run with Jenkins
● Go to your fork of the repository and copy the URL from “Clone or download”
Build and Run with Jenkins
● Paste it in Jenkins under “Configure”, under Source Code Management ->
Git -> Repositories -> URL
Build and Run with Jenkins
● Go to: Build -> Add Build Step -> Execute Shell
Build and Run with Jenkins
● Copy and paste the contents of jenkins.build.sh from the code repository
● Replace IMG_NAME (with your username), CTNR_NAME (with your
username), PORT (with a random number between 9000 and 9999)
● Remember this PORT value, you will need to append it to the URL later
● Click “Save”
Build and Run with Jenkins
● Click “Build Now”
● Under “Build History”, there should be a
build number like “#1”
Build and Run with Jenkins
● Click on the arrow beside the build number
(shown here)
● Click on “Console Output” to show the logs
from the build
Build and Run with Jenkins
● If all goes well, it should look something like
this ending with “Finished: SUCCESS”
● If you encounter error with container name,
the CTNR_NAME that was already been
used. So, change the value of CTNR_NAME,
save project and re-run “Build Now”.
● If you encounter error with port number, a
PORT that was already been used, so change
the value of PORT, save project and re-run
“Build Now”.
Access your deployed app
● Append the port number you specified
in jenkins to
http://13.228.110.97:<specified_port>
and go to this URL in your browser
● In my example, I go to
http://13.228.110.97:9999
● A simple app should display
● Interact with the app by adding quotes
● These quotes are stored in your
mongodb in mlab. You can go back to
mlab and check the changes in
database
● Docker UI is at http://13.228.110.97:8100
● Login with username and password “readonly” to view the state and logs
of containers
Debug your deployed app
Back to Slide
https://docs.google.com/presentation/d/1jW0pPXheS2aZqsXvfPATQLbY5sD
RyGVpuNpswS5Zv4I/edit#slide=id.g31d5e508b0_0_590
Solution 1 - Remove secret from App,
secret stays in Jenkins
Rotate mlab (MongoDB) credentials
● Back on the mlab page,
● Click on “Users”
● Click on the trash bin icon to delete the user
Rotate mlab (MongoDB) credentials
● Go ahead and Click on “DELETE”
Rotate mlab (MongoDB) credentials
● Click on “Add database user”
Rotate mlab (MongoDB) credentials
● Enter a NEW username and password (don't use anything personal or
sensitive)
○ To avoid syntax error in the later steps, do not use the “@” symbol at all; you can use it but
you must encode the character in the script later
● Leave “Make read-only” box unchecked
● Click “Create”
Rotate mlab (MongoDB) credentials
From the database page, construct your mlab mongodb instance URL (this
contains secret) replacing <dbuser> and <dbpassword> that you previously
entered.
In my example, mine is:
mongodb://new_tester:<dbpassword>@ds241668.mlab.com:41668/coolname
Remove secret from code repository
From your local machine, delete or comment out the secret mongodb url:
Remove secret from code repository
From your local machine in the directory where the git repository is, run:
git add start_app_server.sh
git commit -m 'removed secret'
git push origin master
Store secrets within Jenkins
● Go to your previously created Jenkins project, under “Configure”
● Check “Use secret text(s) file(s)”
● Click “Secret Text”
Store secrets within Jenkins
● Fill Variable as “mongodb”
● Add to “Jenkins”
Store secrets within Jenkins
● Choose “Secret text” as kind
● Fill Secret as your mongodb URL (from slide 7)
● Fill Description with your username (for easy identification)
● Click “Add”
Store secrets within Jenkins
● In the “Execute Shell”, add a line under `docker run`:
“--env MONGODB_CREDENTIALS=$mongodb ”
MUST add the backslash “” at the end!
Build and Run with Jenkins
● Click “Build Now”
● Under “Build History”, there should be a
build number like “#1” or “#2” or…
Build and Run with Jenkins
● Click on the arrow beside the build number
(shown here)
● Click on “Console Output” to show the logs
from the build
Build and Run with Jenkins
● If all goes well, it should be pulling from your latest code commit, check the
commit message.
○ It should be the same as the value in “git commit -m ‘remove secret’” ran earlier
Build and Run with Jenkins
● If all goes well, it should look something like this ending with “Finished:
SUCCESS”
● Note that the secret is also masked out. Good job Jenkins!
Access your deployed app
● Append the port number you specified
in jenkins to
http://13.228.110.97:<specified_port>
and go to this URL in your browser
● In my example, I go to
http://13.228.110.97:9999
● A simple app should display
● Interact with the app by adding quotes
● These quotes are stored in your
mongodb in mlab. You can go back to
mlab and check the changes in
database
● Docker UI is at http://13.228.110.97:8100
● Login with username and password “readonly” to view the state and logs
of containers
Debug your deployed app
Congrats!
You have just removed (and rotated) a
shameful secret!
But is this good enough?
Solution 2 - Remove Secrets from App
and Jenkins, using Vault and its App
Role
What is App Role?
https://www.vaultproject.io/docs/auth/approle.html
Access to Vault
● Membership in https://github.com/DevSecOpsSG allows access to Vault
● Generate a GitHub personal access token to login -> Follow Steps 1-9 on:
https://help.github.com/articles/creating-a-personal-access-token-for-the-co
mmand-line/
● Scopes define the access for personal tokens: Check “read:org” only
Access to Vault (GUI version)
● This is Vault’s UI (web container)
Note:
Vault UI
runs on port 8300
While Vault Server
runs on port 8200
Access to Vault (CLI version)
● Download the vault binary
https://www.vaultproject.io/downloads.html
● Replace the GitHub Personal Token with your own and run:
$ export VAULT_ADDR=http://13.228.110.97:8200
$ vault auth -method=github token=<$YOUR_GITHUB_PERSONAL_TOKEN>
Successfully authenticated! You are now logged in.
The token below is already saved in the session. You do not
need to "vault auth" again with the token.
token: ************************
token_duration: 2764799
token_policies: [default]
Access to Vault (CLI version)
● Replace the username and secret with your own and run:
$ vault write secret/example/triplejhacker mongodb=<$MONGODB_URL_SECRET>
Success! Data written to: secret/example/triplejhacker
$ vault read secret/example/triplejhacker
Key Value
--- -----
refresh_interval 768h0m0s
mongodb <$MONGODB_URL_SECRET>
You can now skip slides for Access to Vault (GUI version)
This command overwrites any existing
values
Access to Vault (GUI version)
● Go to http://13.228.110.97:8300
● Paste the GitHub Personal Token and login
● If it is not showing this, then Click on settings and choose "GitHub" as Login
Method. Do not change the Vault Server URL
● Click “OK”
● Paste the GitHub Personal Token and login
Access to Vault (GUI version)
● Under Secret Backend, click
“secret/”
● Click “example/” folder
Access to Vault (GUI version)
● Click “test” item to view its key value
● Click “NEW SECRET” at the far right to create a new item
Access to Vault (GUI version)
● Fill <Insert object key> as your username
● Click on the box icon (arrow pointing) and choose “Append”,
“field:value” boxes will appear
Access to Vault (GUI version)
● Fill “field” as ‘mongodb’
● Fill “value” as the secret mongodb
URL in your app from slide 7
○ mongdb://...
● Click “Save”
Access to Vault (GUI version)
● Your secret is created in Vault, click on it to view
● Note its path: i.e.secret/example/<username>
Retrieve secret from Vault with Jenkins
● Navigate back to your Jenkins
project, under “Configure”
● Uncheck previous “Use secret
text(s) file(s)” box
● Check “Vault Plugin” box
Retrieve secret from Vault with Jenkins
● Fill Vault URL as http://172.18.0.2:8200
● Click “Add” -> “Jenkins”
● In the same terminal, run:
$ vault token-lookup
Key Value
--- -----
accessor 4fb12012-fb92-8d84-a4ed-bdb820532739
creation_time 1519349293
creation_ttl 2764800
display_name github-triplejhacker
entity_id ab3297fe-5fc2-5dca-f38e-c2716151774f
expire_time 2018-03-27T01:28:13.581448089Z
explicit_max_ttl 0
id ce38db15-****-524f-482c-************
issue_time 2018-02-23T01:28:13.581440761Z
meta map[org:DevSecOpsSG username:triplejhacker]
num_uses 0
orphan true
path auth/github/login
policies [default]
renewable true
ttl 2764132
Retrieve secret from Vault with Jenkins (CLI version)
This is your vault token
● In the same terminal, run:
$ vault read auth/approle/role/example/role-id
Key Value
--- -----
role_id e4964208-6fed-882b-7739-ace170ec5aba
$ vault write -f auth/approle/role/example/secret-id
Key Value
--- -----
secret_id acb24ed4-1232-298a-abd4-4ad0ac77c461
secret_id_accessor b84b516e-eb53-c5ff-8b5c-************
You can now skip slides for Retrieve secret from Vault with Jenkins (GUI version)
Retrieve secret from Vault with Jenkins (CLI version)
Secret-id is uniquely
generated each time
this command is ran
Retrieve secret from Vault with Jenkins (GUI version)
● Go to http://13.228.110.97:8300
● Click on the top right corner and “Show token”
● Copy the vault token
● Note: This is generated by Vault and is different from the GitHub
Token
● Sorry there’s no GUI for this!
● Paste your vault token from the previous slide
● Using curl, or https://www.getpostman.com/apps or any request tool, to GET
request:
curl --header "X-Vault-Token: <REPLACE WITH VAULT TOKEN>"
http://13.228.110.97:8200/v1/auth/approle/role/example/role-id
● Copy the role-id
○ {"request_id":"8d789757-ab4a-de80-9783-0927ac926f35","lease_id":"","renewable":false,"leas
e_duration":0,"data":{"role_id":"e4964208-6fed-882b-7739-ace170ec5aba"},"wrap_info":null,"w
arnings":null,"auth":null}
Retrieve secret from Vault with Jenkins (GUI version)
● Sorry there’s no GUI for this!
● Paste your vault token from the previous slide
● Using curl, or https://www.getpostman.com/apps or any request tool, to POST
request:
curl --header "X-Vault-Token: <REPLACE WITH VAULT TOKEN>" --request POST
http://13.228.110.97:8200/v1/auth/approle/role/example/secret-id
● Copy the secret-id
○ {"request_id":"a2bdb1d5-28d9-d7c8-da4e-94800ba496e3","lease_id":"","renewable":false,"leas
e_duration":0,"data":{"secret_id":"a6f53a92-96bd-9fc4-9d8a-**********","secret_id_accessor":"6
0e54752-c6d1-320f-574a-a1ee3f7a219b"},"wrap_info":null,"warnings":null,"auth":null}
Retrieve secret from Vault with Jenkins (GUI version)
Store secrets within Jenkins
● Choose “Vault App Role Credential” as kind
● Fill Role ID from previous, previous slide
● Fill Secret ID from previous slide
● Fill Description with your username (for easy identification)
● Click “Add”
Store secrets within Jenkins
● Choose your newly created item as the Vault Credential i.e.
“triplejhacker approle”
● Click “Add a vault secret”
Store secrets within Jenkins
● Fill Environment Variable as “mongodb” (all small caps)
● Fill the rest as illustrated matching from the Vault UI
● Click “Save”
Path
(secret/example/triplejhacker)
Key Name
(mongodb)
Build and Run with Jenkins
● Click “Build Now”
● Under “Build History”, there should be a
build number like “#1” or “#2” or…
Build and Run with Jenkins
● Click on the arrow beside the build number
(shown here)
● Click on “Console Output” to show the logs
from the build
● If all goes well, it should be pulling from your latest code commit, check the
commit message.
○ It should be the same as the value in “git commit -m ‘remove secret’” ran earlier
● We didn’t push any code changes so this is correct.
Build and Run with Jenkins
Build and Run with Jenkins
● If all goes well, it should look something like this ending with “Finished:
SUCCESS”
● Note that the secret is also masked out. Good job Jenkins!
Access your deployed app
● Append the port number you specified
in jenkins to
http://13.228.110.97:<specified_port>
and go to this URL in your browser
● In my example, I go to
http://13.228.110.97:9999
● A simple app should still display
● Interact with the app by adding quotes
● These quotes are stored in your
mongodb in mlab. You can go back to
mlab and check the changes in
database
● Docker UI is at http://13.228.110.97:8100
● Login with username and password “readonly” to view the state and logs
of containers
Debug your deployed app
Congrats!
You have just removed a shameful
secret AND use App Role to control
access to the secrets!
But is this good enough?
https://www.vaultproject.io/
Solution 3 - Remove Secrets from App
and Jenkins, using App Role and +++
… until next time...
https://www.vaultproject.io/docs/concepts/response-wrapping.html
Or try
https://medium.com/what-about-security/all-day-devops-2017-removing-dev
elopers-shameful-secrets-f5aca3960316

More Related Content

PDF
In graph we trust: Microservices, GraphQL and security challenges
PDF
DevSecCon Tel Aviv 2018 - Value driven threat modeling by Avi Douglen
PDF
DevSecCon Singapore 2018 - Maginot Line – 6 Common AppSec Anti-Patterns Preve...
PPTX
DevSecCon Tel Aviv 2018 - Security Testing for Containerised Apps by Omer Levi
PPTX
DevSecCon Tel Aviv 2018 - Security learns to sprint by Tanya Janca
PDF
DevSecCon London 2017: Hands-on secure software development from design to de...
PPTX
DevSecCon Tel Aviv 2018 - End2End containers SSDLC by Vitaly Davidoff
PPTX
DevSecCon London 2017: when good containers go bad by Tim Mackey
In graph we trust: Microservices, GraphQL and security challenges
DevSecCon Tel Aviv 2018 - Value driven threat modeling by Avi Douglen
DevSecCon Singapore 2018 - Maginot Line – 6 Common AppSec Anti-Patterns Preve...
DevSecCon Tel Aviv 2018 - Security Testing for Containerised Apps by Omer Levi
DevSecCon Tel Aviv 2018 - Security learns to sprint by Tanya Janca
DevSecCon London 2017: Hands-on secure software development from design to de...
DevSecCon Tel Aviv 2018 - End2End containers SSDLC by Vitaly Davidoff
DevSecCon London 2017: when good containers go bad by Tim Mackey

What's hot (20)

PPTX
DevSecCon Tel Aviv 2018 - Integrated Security Testing by Morgan Roman
PDF
DevSecOps Fundamentals and the Scars to Prove it.
PDF
Building a DevSecOps Pipeline Around Your Spring Boot Application
PDF
Sec4dev 2021 - Catch Me If You can : Continuous Delivery vs. Security Assurance
PDF
DevSecCon London 2018: Open DevSecOps
PDF
DevSecCon London 2017: Threat modeling in a CI environment by Steven Wierckx
PPTX
How to get the best out of DevSecOps - an operations perspective
PPTX
DevSecOps : an Introduction
KEY
DevOpsSec: Appling DevOps Principles to Security, DevOpsDays Austin 2012
PDF
Static Analysis For Security and DevOps Happiness w/ Justin Collins
PDF
Hacker Games & DevSecOps
PDF
Security as Code: A DevSecOps Approach
PPTX
You Build It, You Secure It: Introduction to DevSecOps
PDF
DevSecCon Boston 2018: Building a practical DevSecOps pipeline for free by Je...
PPTX
Continuous Security Testing with Devops - OWASP EU 2014
PDF
2019 DevSecOps Reference Architectures
PDF
[DevSecOps Live] DevSecOps: Challenges and Opportunities
PDF
DevSecOps: Minimizing Risk, Improving Security
PPTX
Stephen Sadowski - Securely automating infrastructure in the cloud
DevSecCon Tel Aviv 2018 - Integrated Security Testing by Morgan Roman
DevSecOps Fundamentals and the Scars to Prove it.
Building a DevSecOps Pipeline Around Your Spring Boot Application
Sec4dev 2021 - Catch Me If You can : Continuous Delivery vs. Security Assurance
DevSecCon London 2018: Open DevSecOps
DevSecCon London 2017: Threat modeling in a CI environment by Steven Wierckx
How to get the best out of DevSecOps - an operations perspective
DevSecOps : an Introduction
DevOpsSec: Appling DevOps Principles to Security, DevOpsDays Austin 2012
Static Analysis For Security and DevOps Happiness w/ Justin Collins
Hacker Games & DevSecOps
Security as Code: A DevSecOps Approach
You Build It, You Secure It: Introduction to DevSecOps
DevSecCon Boston 2018: Building a practical DevSecOps pipeline for free by Je...
Continuous Security Testing with Devops - OWASP EU 2014
2019 DevSecOps Reference Architectures
[DevSecOps Live] DevSecOps: Challenges and Opportunities
DevSecOps: Minimizing Risk, Improving Security
Stephen Sadowski - Securely automating infrastructure in the cloud
Ad

Similar to DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply remove shameful developers by Fabian Lim (20)

PPTX
DevSecCon SG 2018 Fabian Presentation Slides
PPT
Introduction to Behavior Driven Development
PDF
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
PDF
DevOps - A Purpose for an Institution.pdf
PPTX
Pain Driven Development by Alexandr Sugak
PPTX
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
PDF
We continue checking Microsoft projects: analysis of PowerShell
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Java and AI with LangChain4j: Jakarta EE gets AI
PPTX
MongoDB.local Atlanta: MongoDB Stitch Tutorial
ODP
Kelly potvin nosurprises_odtug_oow12
PPTX
MongoDB.local Seattle 2019: MongoDB Stitch Tutorial
PPTX
A modern architecturereview–usingcodereviewtools-ver-3.5
 
PDF
The "Holy Grail" of Dev/Ops
PDF
Workshop - The Little Pattern That Could.pdf
PPTX
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
PPT
Lunch and learn as3_frameworks
PDF
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
PDF
Tdd is not about testing
PDF
DevOops & How I hacked you DevopsDays DC June 2015
DevSecCon SG 2018 Fabian Presentation Slides
Introduction to Behavior Driven Development
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
DevOps - A Purpose for an Institution.pdf
Pain Driven Development by Alexandr Sugak
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
We continue checking Microsoft projects: analysis of PowerShell
Test-Driven Design Insights@DevoxxBE 2023.pptx
Java and AI with LangChain4j: Jakarta EE gets AI
MongoDB.local Atlanta: MongoDB Stitch Tutorial
Kelly potvin nosurprises_odtug_oow12
MongoDB.local Seattle 2019: MongoDB Stitch Tutorial
A modern architecturereview–usingcodereviewtools-ver-3.5
 
The "Holy Grail" of Dev/Ops
Workshop - The Little Pattern That Could.pdf
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
Lunch and learn as3_frameworks
Probo.ci Drupal 4 Gov Devops 1/2 day Presentation
Tdd is not about testing
DevOops & How I hacked you DevopsDays DC June 2015
Ad

More from DevSecCon (20)

PDF
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
PDF
DevSecCon London 2019: Are Open Source Developers Security’s New Front Line?
PDF
DevSecCon London 2019: How to Secure OpenShift Environments and What Happens ...
PDF
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
PPTX
DevSecCon Seattle 2019: Containerizing IT Security Knowledge
PPTX
DevSecCon Seattle 2019: Decentralized Authorization - Implementing Fine Grain...
PPTX
DevSecCon Seattle 2019: Liquid Software as the real solution for the Sec in D...
PPTX
DevSecCon Seattle 2019: Fully Automated production deployments with HIPAA/HIT...
PDF
DevSecCon Singapore 2019: Four years of reflection: How (not) to secure Web A...
PPTX
DevSecCon Singapore 2019: crypto jacking: An evolving threat for cloud contai...
PDF
DevSecCon Singapore 2019: Can "dev", "sec" and "ops" really coexist in the wi...
PDF
DevSecCon Singapore 2019: Workshop - Burp extension writing workshop
PDF
DevSecCon Singapore 2019: Embracing Security - A changing DevOps landscape
PDF
DevSecCon Singapore 2019: Web Services aren’t as secure as we think
PDF
DevSecCon Singapore 2019: An attacker's view of Serverless and GraphQL apps S...
PDF
DevSecCon Singapore 2019: The journey of digital transformation through DevSe...
PDF
DevSecCon Singapore 2019: Preventative Security for Kubernetes
PPTX
DevSecCon London 2018: Is your supply chain your achille's heel
PPTX
DevSecCon London 2018: Get rid of these TLS certificates
PDF
DevSecCon London 2018: Building effective DevSecOps teams through role-playin...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Are Open Source Developers Security’s New Front Line?
DevSecCon London 2019: How to Secure OpenShift Environments and What Happens ...
DevSecCon London 2019: A Kernel of Truth: Intrusion Detection and Attestation...
DevSecCon Seattle 2019: Containerizing IT Security Knowledge
DevSecCon Seattle 2019: Decentralized Authorization - Implementing Fine Grain...
DevSecCon Seattle 2019: Liquid Software as the real solution for the Sec in D...
DevSecCon Seattle 2019: Fully Automated production deployments with HIPAA/HIT...
DevSecCon Singapore 2019: Four years of reflection: How (not) to secure Web A...
DevSecCon Singapore 2019: crypto jacking: An evolving threat for cloud contai...
DevSecCon Singapore 2019: Can "dev", "sec" and "ops" really coexist in the wi...
DevSecCon Singapore 2019: Workshop - Burp extension writing workshop
DevSecCon Singapore 2019: Embracing Security - A changing DevOps landscape
DevSecCon Singapore 2019: Web Services aren’t as secure as we think
DevSecCon Singapore 2019: An attacker's view of Serverless and GraphQL apps S...
DevSecCon Singapore 2019: The journey of digital transformation through DevSe...
DevSecCon Singapore 2019: Preventative Security for Kubernetes
DevSecCon London 2018: Is your supply chain your achille's heel
DevSecCon London 2018: Get rid of these TLS certificates
DevSecCon London 2018: Building effective DevSecOps teams through role-playin...

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
A Presentation on Touch Screen Technology
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
A Presentation on Artificial Intelligence
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Tartificialntelligence_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
cloud_computing_Infrastucture_as_cloud_p
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Hindi spoken digit analysis for native and non-native speakers
A Presentation on Touch Screen Technology
Web App vs Mobile App What Should You Build First.pdf
OMC Textile Division Presentation 2021.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
1 - Historical Antecedents, Social Consideration.pdf
Chapter 5: Probability Theory and Statistics
WOOl fibre morphology and structure.pdf for textiles
MIND Revenue Release Quarter 2 2025 Press Release
A Presentation on Artificial Intelligence
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
SOPHOS-XG Firewall Administrator PPT.pptx
Enhancing emotion recognition model for a student engagement use case through...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Tartificialntelligence_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
cloud_computing_Infrastucture_as_cloud_p

DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply remove shameful developers by Fabian Lim

  • 1. Join the conversation #DevSecCon BY Fabian Lim REMOVE DEVELOPERS’ SHAMEFUL SECRETS OR SIMPLY REMOVE SHAMEFUL DEVELOPERS…
  • 2. First thing First! Materials can be found at: github.com/ DevSecOpsSG/ devseccon2018 Do the Prerequisite!
  • 3. github.com/DevSecOpsSG/devseccon2018 Disclaimer This presentation may or may not contain information about services under GovTech. The information contained in this presentation is classified as Public. This presentation and its contents does not represent the views of GovTech, or any other entities. They are the sole views of the author. I take full responsibility for my work and any errors fall on my shoulders. Be happy and awesome; and help others to be happy and awesome.
  • 4. github.com/DevSecOpsSG/devseccon2018 missions: - energetic DevSecOps Engineer and Evangelist - physical and cyber security educator education: - Singapore Management University, BS Info System - Carnegie Mellon University, MS Info Security Policy Mgmt employers: - Intuit Inc. - GovTech [Formerly known as IDA] check out tech.gov.sg for more - Nectar PaaS, security features, etc. presentations: - ADDO 2016 [Blue-Green Deployment] http://bit.ly/2fLfHgr - RSA APJ 2017 [PaaS] http://bit.ly/2ylUyB9 hobbies: - krav maga; self defense & martial arts - food whoami - about.me/fabian.lim
  • 5. github.com/DevSecOpsSG/devseccon2018 NECTAR GovTech’s Platform as a Service Read more about it here: https://blog.gds-gov.tech/nectar-10e0eb1581cf
  • 6. github.com/DevSecOpsSG/devseccon2018 Takeaways 1) Learned a thing about secret management 2) Learned a thing about design a secure workflow / pipeline 3) Learned a cool, new tool to integrate into your workflow 4) Or… Made a new friend :)
  • 8. github.com/DevSecOpsSG/devseccon2018 Agenda 1) Get to know each other, and the problems 2) Open discussion for designing a solution 3) Improve on current pipeline 4) Debrief and possible future integrations
  • 9. My Mistakes! OOPS! Personal mistake - commit secrets into repository...
  • 12. Get to know each other, and the problems
  • 13. github.com/DevSecOpsSG/devseccon2018 Get to know each other, and the problems 1) With 2 or 3 in a group, introduce and get to know each other 2) What are some common password problems? a) What are the credentials for X database, Y API, etc? b) Where am I supposed to store these credentials? c) Who should have these credentials? Can I pass it to ABC? d) How do I rotate credentials for Y API because ABC left? e) How do I keep track of X secrets of Y apps? Discussion Time!
  • 14. github.com/DevSecOpsSG/devseccon2018 Lab “Tech Stack” Database (MongoDB) Cloud Infrastructure (AWS) App (Node)
  • 15. github.com/DevSecOpsSG/devseccon2018 Lab “Tech Platforms” Cloud Infrastructure (AWS) Docker Vault App1 Jenkins App2 App3 mlab.com Database1 Database2 Database3
  • 18. Open discussion for designing a solution
  • 19. github.com/DevSecOpsSG/devseccon2018 How to retrieve secrets? 1. Environment variables (static) a. How do I manage the environment variables in dev, staging and prod? 2. Run-time API retrieval (pull) a. What API keys to use? Where do I store it? 3. Run-time deployment variable injection (push) a. How does the deployer trust THIS instance of build? b. How does the deployer know what secrets THIS instance need?
  • 20. Chain of Trust Manage Trust in workflow / pipeline
  • 21. github.com/DevSecOpsSG/devseccon2018 secret[0] The idea of secret[0] is the first piece of credential, or the first entity of trust, needed to initiate a trusted chain of actions like producing the second piece of secret, etc.
  • 22. github.com/DevSecOpsSG/devseccon2018 Shift of Responsibility to Hold secret[0] App Deployer / Orchestrator SSMHuman HSM
  • 23. github.com/DevSecOpsSG/devseccon2018 The App is a Box, in a Pipeline Build App Source Code (GitHub) Builder (Jenkins) App Artifact = Neutral Entity = Trusted Entity = Trusted Child Entity
  • 24. github.com/DevSecOpsSG/devseccon2018 The App is a Box, in a Pipeline = Neutral Entity = Trusted Entity = Trusted Child Entity Deployer (Jenkins) Secret Mgmt Server (Vault) App Artifact Approve! Give Token to Jenkins Deploy issues secret App (Node)
  • 25. github.com/DevSecOpsSG/devseccon2018 The App is a Box, in a Pipeline = Neutral Entity = Trusted Entity = Trusted Child Entity Dev Environment Database (MongdoDB) App (Node)
  • 26. Improve on current pipeline
  • 27. github.com/DevSecOpsSG/devseccon2018 Open discussion for designing a solution Put on the Security Architect’s hat: 1) What’s a good technical solution that removes (or the risk of storing) secrets in code repositories? 2) How do you establish trust in a workflow? 3) How does a good development pipeline or workflow look like? Discussion Time!
  • 28. github.com/DevSecOpsSG/devseccon2018 Scenario • You are a new security developer in the team • Audit flagged a high risk in the plaintext secrets that was checked in t the code repository Objectives Task #1: Remove secrets in code repository, but still run Task #2: Prevent secrets from exposing in build environment (logs)
  • 30. Debrief, and possible future integrations
  • 31. github.com/DevSecOpsSG/devseccon2018 Pipelines are Fundamental in DevSecOps Doing so, benefits are: • Security is built-in by design • Containment; Blast Radius • It can scale healthily! • It has the ability to be re-build By: • Thinking like water pipelines engineers • Building as modular as possible - API • Building resilience Because it: • Supports SDLC; and Agile
  • 33. github.com/DevSecOpsSG/devseccon2018 Debrief, and possible future integrations 1) What are your takeaways? a) Find # of hard-coded secrets b) “Variablize” found secrets c) Remove habits of checking in secrets d) Remove guilty developers [optional] 2) How would you start to embark this journey and start to communicating this with your developers? 3) What are possible integrations improvements to this workflow?
  • 34. Join the conversation #DevSecCon Thank you for your attention, patience, and enthusiasm during the workshop! Happy Lunar New Year! Cheers!
  • 35. Fair Warning Although minimal, my scripts are written mainly in MacOS. For security concerns and compatibility, you might consider executing them in a Linux VM. The permissions set on the services trust that developers (you) are trustworthy and responsible, with the ability to change certain settings. Please exercise caution while making changes and limit those changes to your own environment in order to have a conducive learning environment.
  • 36. Lab Audience and Objective ● Developers - who want to implement and fix the problem ● Managers - who wants the problem to be fixed but don’t know how ● Compliance / Auditors - who wants to see how a problem can be fixed ... Remove and rotate secrets Use a secret management server Integration with Jenkins
  • 37. Lab 1 - Secrets Checked In
  • 38. Setup / Login GitHub ● Login to your GitHub account ● Click on “Issues” ● Click “New issue” to create an issue in the devseccon2018 project so I know your username and I can invite you now!
  • 39. Setup / Login GitHub ● Fill in some description about yourself and Click “Submit new issue” ● You will receive an email to join ● membership ● to https://github.com/DevSecOpsSG
  • 40. Setup / Login GitHub ● Go to https://github.com/DevSecOpsSG/devseccon2018.git ● Click “Fork” ● You should be redirected to https://github.com/<username>/devseccon2018.git ● This is your fork (copy) of the repository
  • 41. Setup / Login GitHub ● Open a terminal and run to clone code to your local machine: git clone https://github.com/<username>/devseccon2018.git ● You now have a local version of the code
  • 42. Setup mlab (MongoDB) ● Sign up an account at https://mlab.com ● Click “Create new” for MongoDB Deployments
  • 43. Setup mlab (MongoDB) ● Choose any Cloud Provider (doesn’t matter) ● Choose Plan Type SANDBOX (FREE) ● Click “Continue” ● Select a region (doesn’t matter) ● Click “Continue”
  • 44. Setup mlab (MongoDB) ● Give your database a cool name (doesn’t matter) ● Click “Continue”
  • 45. Setup mlab (MongoDB) ● Check your final order ● Click “SUBMIT ORDER”
  • 46. Setup mlab (MongoDB) ● Click on the new database
  • 47. Setup mlab (MongoDB) ● Click on “Users” ● Click on “Add database user”
  • 48. Setup mlab (MongoDB) ● Enter a username and password (don't use anything personal or sensitive) ○ To avoid syntax error in the later steps, do not use the “@” symbol at all; you can use it but you must encode the character in the script later ● Leave “Make read-only” box unchecked ● Click “Create”
  • 49. Setup mlab (MongoDB) From the database page, construct your mlab mongodb instance URL (this contains secret) replacing <dbuser> and <dbpassword> that you previously entered. In my example, mine is: mongodb://triplejhacker:<dbpassword>@ds241668.mlab.com:41668/coolname
  • 50. Paste mlab URL as MONGODB_CREDENTIALS
  • 51. Push changes to your fork git add start_app_server.sh git commit -m ‘added mongo credentials’ git push origin master Yes, check your secret into the code repository :P We will remove and rotate it later, don’t worry.
  • 52. Access to Jenkins Go to http://13.228.110.97:8080 Membership in https://github.com/DevSecOpsSG allows access to this Jenkins server. Click “Authorize 3jmaster” (That’s me)
  • 53. Denied Access to Jenkins If you see this Please perform steps in slide 5 and 6 to get access to the Github organization membership
  • 54. Build and Run with Jenkins Click “New Item”
  • 55. Build and Run with Jenkins ● Enter your username or any name as a project name ● Choose “Freestyle Project” ● Click “OK”
  • 56. Build and Run with Jenkins ● Go to your fork of the repository and copy the URL from “Clone or download”
  • 57. Build and Run with Jenkins ● Paste it in Jenkins under “Configure”, under Source Code Management -> Git -> Repositories -> URL
  • 58. Build and Run with Jenkins ● Go to: Build -> Add Build Step -> Execute Shell
  • 59. Build and Run with Jenkins ● Copy and paste the contents of jenkins.build.sh from the code repository ● Replace IMG_NAME (with your username), CTNR_NAME (with your username), PORT (with a random number between 9000 and 9999) ● Remember this PORT value, you will need to append it to the URL later ● Click “Save”
  • 60. Build and Run with Jenkins ● Click “Build Now” ● Under “Build History”, there should be a build number like “#1”
  • 61. Build and Run with Jenkins ● Click on the arrow beside the build number (shown here) ● Click on “Console Output” to show the logs from the build
  • 62. Build and Run with Jenkins ● If all goes well, it should look something like this ending with “Finished: SUCCESS” ● If you encounter error with container name, the CTNR_NAME that was already been used. So, change the value of CTNR_NAME, save project and re-run “Build Now”. ● If you encounter error with port number, a PORT that was already been used, so change the value of PORT, save project and re-run “Build Now”.
  • 63. Access your deployed app ● Append the port number you specified in jenkins to http://13.228.110.97:<specified_port> and go to this URL in your browser ● In my example, I go to http://13.228.110.97:9999 ● A simple app should display ● Interact with the app by adding quotes ● These quotes are stored in your mongodb in mlab. You can go back to mlab and check the changes in database
  • 64. ● Docker UI is at http://13.228.110.97:8100 ● Login with username and password “readonly” to view the state and logs of containers Debug your deployed app
  • 66. Solution 1 - Remove secret from App, secret stays in Jenkins
  • 67. Rotate mlab (MongoDB) credentials ● Back on the mlab page, ● Click on “Users” ● Click on the trash bin icon to delete the user
  • 68. Rotate mlab (MongoDB) credentials ● Go ahead and Click on “DELETE”
  • 69. Rotate mlab (MongoDB) credentials ● Click on “Add database user”
  • 70. Rotate mlab (MongoDB) credentials ● Enter a NEW username and password (don't use anything personal or sensitive) ○ To avoid syntax error in the later steps, do not use the “@” symbol at all; you can use it but you must encode the character in the script later ● Leave “Make read-only” box unchecked ● Click “Create”
  • 71. Rotate mlab (MongoDB) credentials From the database page, construct your mlab mongodb instance URL (this contains secret) replacing <dbuser> and <dbpassword> that you previously entered. In my example, mine is: mongodb://new_tester:<dbpassword>@ds241668.mlab.com:41668/coolname
  • 72. Remove secret from code repository From your local machine, delete or comment out the secret mongodb url:
  • 73. Remove secret from code repository From your local machine in the directory where the git repository is, run: git add start_app_server.sh git commit -m 'removed secret' git push origin master
  • 74. Store secrets within Jenkins ● Go to your previously created Jenkins project, under “Configure” ● Check “Use secret text(s) file(s)” ● Click “Secret Text”
  • 75. Store secrets within Jenkins ● Fill Variable as “mongodb” ● Add to “Jenkins”
  • 76. Store secrets within Jenkins ● Choose “Secret text” as kind ● Fill Secret as your mongodb URL (from slide 7) ● Fill Description with your username (for easy identification) ● Click “Add”
  • 77. Store secrets within Jenkins ● In the “Execute Shell”, add a line under `docker run`: “--env MONGODB_CREDENTIALS=$mongodb ” MUST add the backslash “” at the end!
  • 78. Build and Run with Jenkins ● Click “Build Now” ● Under “Build History”, there should be a build number like “#1” or “#2” or…
  • 79. Build and Run with Jenkins ● Click on the arrow beside the build number (shown here) ● Click on “Console Output” to show the logs from the build
  • 80. Build and Run with Jenkins ● If all goes well, it should be pulling from your latest code commit, check the commit message. ○ It should be the same as the value in “git commit -m ‘remove secret’” ran earlier
  • 81. Build and Run with Jenkins ● If all goes well, it should look something like this ending with “Finished: SUCCESS” ● Note that the secret is also masked out. Good job Jenkins!
  • 82. Access your deployed app ● Append the port number you specified in jenkins to http://13.228.110.97:<specified_port> and go to this URL in your browser ● In my example, I go to http://13.228.110.97:9999 ● A simple app should display ● Interact with the app by adding quotes ● These quotes are stored in your mongodb in mlab. You can go back to mlab and check the changes in database
  • 83. ● Docker UI is at http://13.228.110.97:8100 ● Login with username and password “readonly” to view the state and logs of containers Debug your deployed app
  • 84. Congrats! You have just removed (and rotated) a shameful secret! But is this good enough?
  • 85. Solution 2 - Remove Secrets from App and Jenkins, using Vault and its App Role
  • 86. What is App Role? https://www.vaultproject.io/docs/auth/approle.html
  • 87. Access to Vault ● Membership in https://github.com/DevSecOpsSG allows access to Vault ● Generate a GitHub personal access token to login -> Follow Steps 1-9 on: https://help.github.com/articles/creating-a-personal-access-token-for-the-co mmand-line/ ● Scopes define the access for personal tokens: Check “read:org” only
  • 88. Access to Vault (GUI version) ● This is Vault’s UI (web container) Note: Vault UI runs on port 8300 While Vault Server runs on port 8200
  • 89. Access to Vault (CLI version) ● Download the vault binary https://www.vaultproject.io/downloads.html ● Replace the GitHub Personal Token with your own and run: $ export VAULT_ADDR=http://13.228.110.97:8200 $ vault auth -method=github token=<$YOUR_GITHUB_PERSONAL_TOKEN> Successfully authenticated! You are now logged in. The token below is already saved in the session. You do not need to "vault auth" again with the token. token: ************************ token_duration: 2764799 token_policies: [default]
  • 90. Access to Vault (CLI version) ● Replace the username and secret with your own and run: $ vault write secret/example/triplejhacker mongodb=<$MONGODB_URL_SECRET> Success! Data written to: secret/example/triplejhacker $ vault read secret/example/triplejhacker Key Value --- ----- refresh_interval 768h0m0s mongodb <$MONGODB_URL_SECRET> You can now skip slides for Access to Vault (GUI version) This command overwrites any existing values
  • 91. Access to Vault (GUI version) ● Go to http://13.228.110.97:8300 ● Paste the GitHub Personal Token and login ● If it is not showing this, then Click on settings and choose "GitHub" as Login Method. Do not change the Vault Server URL ● Click “OK” ● Paste the GitHub Personal Token and login
  • 92. Access to Vault (GUI version) ● Under Secret Backend, click “secret/” ● Click “example/” folder
  • 93. Access to Vault (GUI version) ● Click “test” item to view its key value ● Click “NEW SECRET” at the far right to create a new item
  • 94. Access to Vault (GUI version) ● Fill <Insert object key> as your username ● Click on the box icon (arrow pointing) and choose “Append”, “field:value” boxes will appear
  • 95. Access to Vault (GUI version) ● Fill “field” as ‘mongodb’ ● Fill “value” as the secret mongodb URL in your app from slide 7 ○ mongdb://... ● Click “Save”
  • 96. Access to Vault (GUI version) ● Your secret is created in Vault, click on it to view ● Note its path: i.e.secret/example/<username>
  • 97. Retrieve secret from Vault with Jenkins ● Navigate back to your Jenkins project, under “Configure” ● Uncheck previous “Use secret text(s) file(s)” box ● Check “Vault Plugin” box
  • 98. Retrieve secret from Vault with Jenkins ● Fill Vault URL as http://172.18.0.2:8200 ● Click “Add” -> “Jenkins”
  • 99. ● In the same terminal, run: $ vault token-lookup Key Value --- ----- accessor 4fb12012-fb92-8d84-a4ed-bdb820532739 creation_time 1519349293 creation_ttl 2764800 display_name github-triplejhacker entity_id ab3297fe-5fc2-5dca-f38e-c2716151774f expire_time 2018-03-27T01:28:13.581448089Z explicit_max_ttl 0 id ce38db15-****-524f-482c-************ issue_time 2018-02-23T01:28:13.581440761Z meta map[org:DevSecOpsSG username:triplejhacker] num_uses 0 orphan true path auth/github/login policies [default] renewable true ttl 2764132 Retrieve secret from Vault with Jenkins (CLI version) This is your vault token
  • 100. ● In the same terminal, run: $ vault read auth/approle/role/example/role-id Key Value --- ----- role_id e4964208-6fed-882b-7739-ace170ec5aba $ vault write -f auth/approle/role/example/secret-id Key Value --- ----- secret_id acb24ed4-1232-298a-abd4-4ad0ac77c461 secret_id_accessor b84b516e-eb53-c5ff-8b5c-************ You can now skip slides for Retrieve secret from Vault with Jenkins (GUI version) Retrieve secret from Vault with Jenkins (CLI version) Secret-id is uniquely generated each time this command is ran
  • 101. Retrieve secret from Vault with Jenkins (GUI version) ● Go to http://13.228.110.97:8300 ● Click on the top right corner and “Show token” ● Copy the vault token ● Note: This is generated by Vault and is different from the GitHub Token
  • 102. ● Sorry there’s no GUI for this! ● Paste your vault token from the previous slide ● Using curl, or https://www.getpostman.com/apps or any request tool, to GET request: curl --header "X-Vault-Token: <REPLACE WITH VAULT TOKEN>" http://13.228.110.97:8200/v1/auth/approle/role/example/role-id ● Copy the role-id ○ {"request_id":"8d789757-ab4a-de80-9783-0927ac926f35","lease_id":"","renewable":false,"leas e_duration":0,"data":{"role_id":"e4964208-6fed-882b-7739-ace170ec5aba"},"wrap_info":null,"w arnings":null,"auth":null} Retrieve secret from Vault with Jenkins (GUI version)
  • 103. ● Sorry there’s no GUI for this! ● Paste your vault token from the previous slide ● Using curl, or https://www.getpostman.com/apps or any request tool, to POST request: curl --header "X-Vault-Token: <REPLACE WITH VAULT TOKEN>" --request POST http://13.228.110.97:8200/v1/auth/approle/role/example/secret-id ● Copy the secret-id ○ {"request_id":"a2bdb1d5-28d9-d7c8-da4e-94800ba496e3","lease_id":"","renewable":false,"leas e_duration":0,"data":{"secret_id":"a6f53a92-96bd-9fc4-9d8a-**********","secret_id_accessor":"6 0e54752-c6d1-320f-574a-a1ee3f7a219b"},"wrap_info":null,"warnings":null,"auth":null} Retrieve secret from Vault with Jenkins (GUI version)
  • 104. Store secrets within Jenkins ● Choose “Vault App Role Credential” as kind ● Fill Role ID from previous, previous slide ● Fill Secret ID from previous slide ● Fill Description with your username (for easy identification) ● Click “Add”
  • 105. Store secrets within Jenkins ● Choose your newly created item as the Vault Credential i.e. “triplejhacker approle” ● Click “Add a vault secret”
  • 106. Store secrets within Jenkins ● Fill Environment Variable as “mongodb” (all small caps) ● Fill the rest as illustrated matching from the Vault UI ● Click “Save” Path (secret/example/triplejhacker) Key Name (mongodb)
  • 107. Build and Run with Jenkins ● Click “Build Now” ● Under “Build History”, there should be a build number like “#1” or “#2” or…
  • 108. Build and Run with Jenkins ● Click on the arrow beside the build number (shown here) ● Click on “Console Output” to show the logs from the build
  • 109. ● If all goes well, it should be pulling from your latest code commit, check the commit message. ○ It should be the same as the value in “git commit -m ‘remove secret’” ran earlier ● We didn’t push any code changes so this is correct. Build and Run with Jenkins
  • 110. Build and Run with Jenkins ● If all goes well, it should look something like this ending with “Finished: SUCCESS” ● Note that the secret is also masked out. Good job Jenkins!
  • 111. Access your deployed app ● Append the port number you specified in jenkins to http://13.228.110.97:<specified_port> and go to this URL in your browser ● In my example, I go to http://13.228.110.97:9999 ● A simple app should still display ● Interact with the app by adding quotes ● These quotes are stored in your mongodb in mlab. You can go back to mlab and check the changes in database
  • 112. ● Docker UI is at http://13.228.110.97:8100 ● Login with username and password “readonly” to view the state and logs of containers Debug your deployed app
  • 113. Congrats! You have just removed a shameful secret AND use App Role to control access to the secrets! But is this good enough?
  • 115. Solution 3 - Remove Secrets from App and Jenkins, using App Role and +++
  • 116. … until next time... https://www.vaultproject.io/docs/concepts/response-wrapping.html Or try https://medium.com/what-about-security/all-day-devops-2017-removing-dev elopers-shameful-secrets-f5aca3960316