+ - 0:00:00
Notes for current slide
Notes for next slide

Managing Secrets with Vault

vault logo


Presented by Michael Herman
1 / 64

Agenda

2 / 64

Agenda

(1) Intro
  1. About Me
  2. Objectives
3 / 64

Agenda

(1) Intro
  1. About Me
  2. Objectives
(2) Theory
  1. What is Vault?
  2. Why Vault?
  3. Using Vault
4 / 64

Agenda

(1) Intro
  1. About Me
  2. Objectives
(2) Theory
  1. What is Vault?
  2. Why Vault?
  3. Using Vault
(3) Practice
  1. Project Overview
  2. Storage Backends
  3. Init, Unseal, and Authenticate
  4. Auditing
  5. Static Secrets
  6. Dynamic Secrets
  7. Encryption as a Service
5 / 64

Agenda

(1) Intro
  1. About Me
  2. Objectives
(2) Theory
  1. What is Vault?
  2. Why Vault?
  3. Using Vault
(3) Practice
  1. Project Overview
  2. Storage Backends
  3. Init, Unseal, and Authenticate
  4. Auditing
  5. Static Secrets
  6. Dynamic Secrets
  7. Encryption as a Service
(4) Next Steps
6 / 64

Intro

7 / 64

About Michael

$ whoami
michael.herman

me

8 / 64

About Michael

$ whoami
michael.herman

me

Day Job

Software Engineer at ClickFox.   clickfox logo

9 / 64

About Michael

$ whoami
michael.herman

me

Day Job

Software Engineer at ClickFox.   clickfox logo

Also

  1. Co-founder/author of Real Python
  2. 😍 - tech writing/education, open source, financial models, radiohead

testdriven.io

10 / 64

Objectives

By the end of this talk, you should be able to...

11 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it
12 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

13 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

14 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

  4. Init and unseal Vault

15 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

  4. Init and unseal Vault

  5. Authenticate against Vault

16 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

  4. Init and unseal Vault

  5. Authenticate against Vault

  6. Configure an Audit backend

17 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

  4. Init and unseal Vault

  5. Authenticate against Vault

  6. Configure an Audit backend

  7. Work with static and dynamic secrets

18 / 64

Objectives

By the end of this talk, you should be able to...

  1. Explain what Vault is and why you may want to use it

  2. Describe the basic Vault architecture along with dynamic and static secrets, the various backends (storage, secret, auth, audit), and how Vault can be used as an "encryption as a service"

  3. Spin up Vault with the Filesystem backend

  4. Init and unseal Vault

  5. Authenticate against Vault

  6. Configure an Audit backend

  7. Work with static and dynamic secrets

  8. Use the Transit backend as an "encryption as a service"

19 / 64

Theory

20 / 64

What is Vault?

21 / 64

What is Vault?

Vault is an open-source tool used for securely storing and managing secrets.

vault logo

22 / 64

What is Vault?

Vault is an open-source tool used for securely storing and managing secrets.

vault logo

Secrets?

23 / 64

What is Vault?

Vault is an open-source tool used for securely storing and managing secrets.

vault logo

Secrets?

Secrets are securely-sensitive or personally identifiable info like database credentials, SSH keys, usernames/passwords, AWS IAM credentials, API tokens, SSNs, credit card numbers.

24 / 64

What is Vault?

Vault is an open-source tool used for securely storing and managing secrets.

vault logo

Secrets?

Secrets are securely-sensitive or personally identifiable info like database credentials, SSH keys, usernames/passwords, AWS IAM credentials, API tokens, SSNs, credit card numbers.

Distributing secrets

  1. Who has access to them?
  2. Who manages them?
  3. How do you control who has access to them?
  4. How do your apps get them?
  5. How are they updated?
  6. How are they revoked?
25 / 64

Why Vault?

26 / 64

Why Vault?

Vault provides answers to the questions on the previous slide and helps to solve the following problems with secret management:

Current problems Vault's Goals
Secrets are everywhere. Vault is the single source of truth for all secrets.
They are generally unencrypted. Vault manages encryption (during transit and at rest) out of the box.
It's difficult to dynamically generate them. Secrets can be dynamically generated.
It's even more difficult to lease and revoke them. Secrets can be leased and revoked.
There's no audit trail. There's an audit trail for generating and using secrets.

https://www.vaultproject.io/intro/index.html

hashicorp logo

27 / 64

Using Vault (1)

28 / 64

Using Vault (1)

Secret Management

Vault has two types of secrets:

  1. Static secrets (think encrypted Redis or Memcached) have refresh intervals but they do not expire unless explicitly revoked. They are defined ahead of time and then shared.

    secure secret storage

  2. Dynamic secrets have enforced leases and generally expire after a short period of time. Since they don’t exist until they are accessed, there’s less exposure - so dynamic secrets are much more secure.

29 / 64

Using Vault (1)

Secret Management

Vault has two types of secrets:

  1. Static secrets (think encrypted Redis or Memcached) have refresh intervals but they do not expire unless explicitly revoked. They are defined ahead of time and then shared.

    secure secret storage

  2. Dynamic secrets have enforced leases and generally expire after a short period of time. Since they don’t exist until they are accessed, there’s less exposure - so dynamic secrets are much more secure.

Encryption as a Service

The Transit backend can be used as an "encryption as a service":

  1. Encrypt and decrypt data "in-transit" without storing it
  2. Easily integrate encryption into your application workflow
30 / 64

Using Vault (2)

31 / 64

Using Vault (2)

Backends are everywhere!

Backend Use Examples
Storage Where secrets are stored Consul, Filesystem*, In-Memory, PostgreSQL, S3
Secret Handles static or dynamic secrets AWS*, Databases, Key/Value*, RabbitMQ, SSH
Auth Handles authentication and authorization AWS, Azure, Google Cloud, GitHub, Tokens*, Username & Password
Audit Logs all requests and responses File*, Syslog, Socket

* used in this presentation

32 / 64

Using Vault (2)

Backends are everywhere!

Backend Use Examples
Storage Where secrets are stored Consul, Filesystem*, In-Memory, PostgreSQL, S3
Secret Handles static or dynamic secrets AWS*, Databases, Key/Value*, RabbitMQ, SSH
Auth Handles authentication and authorization AWS, Azure, Google Cloud, GitHub, Tokens*, Username & Password
Audit Logs all requests and responses File*, Syslog, Socket

* used in this presentation

vault-architecture.png

https://www.vaultproject.io/docs/internals/architecture.html

33 / 64

Practice

34 / 64

Project Overview

https://github.com/testdrivenio/vault-consul-docker

├── docker-compose.yml
└─ vault
├── Dockerfile
├── config
│ └── vault-config.json
├── data
├── logs
└── policies
└── app-policy.json
35 / 64

Project Overview

https://github.com/testdrivenio/vault-consul-docker

├── docker-compose.yml
└─ vault
├── Dockerfile
├── config
│ └── vault-config.json
├── data
├── logs
└── policies
└── app-policy.json

Build the image and run the container:

$ docker-compose up -d --build
36 / 64

Project Overview

https://github.com/testdrivenio/vault-consul-docker

├── docker-compose.yml
└─ vault
├── Dockerfile
├── config
│ └── vault-config.json
├── data
├── logs
└── policies
└── app-policy.json

Build the image and run the container:

$ docker-compose up -d --build

Start a bash session within the running container:

$ docker-compose exec vault bash
37 / 64

Storage Backends

38 / 64

Storage Backends

Vault works with a number of storage backends that are used for storing the secrets - in-memory, files, various SQL and NoSQL databases, Consul, S3, etc.

https://www.vaultproject.io/docs/configuration/storage/index.html

39 / 64

Storage Backends

Vault works with a number of storage backends that are used for storing the secrets - in-memory, files, various SQL and NoSQL databases, Consul, S3, etc.

https://www.vaultproject.io/docs/configuration/storage/index.html

To keep things simple, the examples in this presentation use the Filesystem backend:

{
"backend": {
"file": {
"path": "vault/data"
}
},
"listener": {
"tcp":{
"address": "0.0.0.0:8200",
"tls_disable": 1
}
},
"ui": true
}
40 / 64

Init, Unseal, and Authenticate

41 / 64

Init, Unseal, and Authenticate

Initialize Vault:

$ vault operator init

Take note of the unseal keys and the initial root token. You will need to provide 3 of the unseal keys every time the Vault server is re-sealed.

(Why 3 keys? https://en.wikipedia.org/wiki/Shamir's_Secret_Sharing)

42 / 64

Init, Unseal, and Authenticate

Initialize Vault:

$ vault operator init

Take note of the unseal keys and the initial root token. You will need to provide 3 of the unseal keys every time the Vault server is re-sealed.

(Why 3 keys? https://en.wikipedia.org/wiki/Shamir's_Secret_Sharing)

Now you can unseal the Vault using 3 of the keys:

$ vault operator unseal

Authenticate:

$ vault login
Token (will be hidden):

This uses the root policy. In production you'll want to set up policies with different levels of access.

https://www.vaultproject.io/docs/concepts/policies.html

43 / 64

Auditing

44 / 64

Auditing

Before we test out the functionality, let’s enable an Audit Device:

$ vault audit enable file file_path=/vault/logs/audit.log
Success! Enabled the file audit device at: file/
45 / 64

Auditing

Before we test out the functionality, let’s enable an Audit Device:

$ vault audit enable file file_path=/vault/logs/audit.log
Success! Enabled the file audit device at: file/

To test, run the following command to view all enabled Audit Devices:

$ vault audit list
Path Type Description
---- ---- -----------
file/ file n/a

This request should be logged in vault/logs/audit.log.

46 / 64

Static Secrets

47 / 64

Static Secrets

Vault can be managed through the CLI, HTTP API, or UI.

48 / 64

Static Secrets

Vault can be managed through the CLI, HTTP API, or UI.

CLI Examples

https://www.vaultproject.io/docs/secrets/kv/index.html

Create:

$ vault kv put secret/foo bar=precious
Success! Data written to: secret/foo

Read:

$ vault kv get secret/foo

Delete:

$ vault kv delete secret/foo
49 / 64

Static Secrets

Vault can be managed through the CLI, HTTP API, or UI.

CLI Examples

https://www.vaultproject.io/docs/secrets/kv/index.html

Create:

$ vault kv put secret/foo bar=precious
Success! Data written to: secret/foo

Read:

$ vault kv get secret/foo

Delete:

$ vault kv delete secret/foo


Take note of the audit log. Each of the above requests were logged!

50 / 64

Dynamic Secrets (1)

51 / 64

Dynamic Secrets (1)

Vault supports a number of dynamic secret backends for generating secrets dynamically when needed.

For example, with the AWS and Google Cloud backends, you can create access credentials based on IAM policies. The databases backend, meanwhile, generates database credentials based on configured roles.

52 / 64

Dynamic Secrets (1)

Vault supports a number of dynamic secret backends for generating secrets dynamically when needed.

For example, with the AWS and Google Cloud backends, you can create access credentials based on IAM policies. The databases backend, meanwhile, generates database credentials based on configured roles.

Dynamic Secrets:

  • are generated on demand
  • have limited access based on role
  • are "leased"
  • can be revoked
  • come with an audit trail
53 / 64

Dynamic Secrets (2)

54 / 64

Dynamic Secrets (2)

Generate dynamic, on-demand AWS access credentials

Enable:

$ vault secrets enable -path=aws aws
Success! Enabled the aws secrets engine at: aws/

Authenticate:

$ vault write aws/config/root access_key=foo secret_key=bar
Success! Data written to: aws/config/root

Create role and credentials:

$ vault write aws/roles/ec2-read \
arn=arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
$ vault read aws/creds/ec2-read
55 / 64

Dynamic Secrets (2)

Generate dynamic, on-demand AWS access credentials

Enable:

$ vault secrets enable -path=aws aws
Success! Enabled the aws secrets engine at: aws/

Authenticate:

$ vault write aws/config/root access_key=foo secret_key=bar
Success! Data written to: aws/config/root

Create role and credentials:

$ vault write aws/roles/ec2-read \
arn=arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
$ vault read aws/creds/ec2-read

Secrets are generated when they are requested (i.e., a web app requests access to S3). They are not available in the store before this.

https://www.vaultproject.io/intro/getting-started/dynamic-secrets.html

56 / 64

Encryption as a Service

57 / 64

Encryption as a Service

Enable transit:

$ vault secrets enable transit
Success! Enabled the transit secrets engine at: transit/
58 / 64

Encryption as a Service

Enable transit:

$ vault secrets enable transit
Success! Enabled the transit secrets engine at: transit/

Configure named encryption key:

$ vault write -f transit/keys/foo
Success! Data written to: transit/keys/foo
59 / 64

Encryption as a Service

Enable transit:

$ vault secrets enable transit
Success! Enabled the transit secrets engine at: transit/

Configure named encryption key:

$ vault write -f transit/keys/foo
Success! Data written to: transit/keys/foo

Encrypt and decrypt:

$ vault write transit/encrypt/foo plaintext=$(base64 <<< "my precious")
Key Value
--- -----
ciphertext vault:v1:/Tun95IT+dVTvDfYiCHdI5rGPSAxgvPcFaDDtneRorQCyBOgv9mPKw==
$ vault write transit/decrypt/foo ciphertext=vault:v1:/Tun95IT+dVTvDfYiCHdI5rGPSAxgvPcFaDDtneRorQCyBOgv9mPKw==
Key Value
--- -----
plaintext bXkgcHJlY2lvdXMK
$ base64 -d <<< "bXkgcHJlY2lvdXMK"
my precious
60 / 64

That's it!

What's next?

61 / 64

That's it!

What's next?

What has not been covered?
  1. Leases and revocation
  2. Setting up new policies
  3. Deployment
  4. Configuring TLS
  5. High availability
62 / 64

That's it!

What's next?

What has not been covered?
  1. Leases and revocation
  2. Setting up new policies
  3. Deployment
  4. Configuring TLS
  5. High availability
Resources
  1. Full blog post - https://testdriven.io/managing-secrets-with-vault-and-consul
  2. Slides - http://mherman.org/presentations/vault
  3. Repo - https://github.com/testdrivenio/vault-docker-example
  4. Why We Need Dynamic Secrets - https://www.hashicorp.com/blog/why-we-need-dynamic-secrets (advantages of using dynamic secrets)
63 / 64

That's it!

What's next?

What has not been covered?
  1. Leases and revocation
  2. Setting up new policies
  3. Deployment
  4. Configuring TLS
  5. High availability
Resources
  1. Full blog post - https://testdriven.io/managing-secrets-with-vault-and-consul
  2. Slides - http://mherman.org/presentations/vault
  3. Repo - https://github.com/testdrivenio/vault-docker-example
  4. Why We Need Dynamic Secrets - https://www.hashicorp.com/blog/why-we-need-dynamic-secrets (advantages of using dynamic secrets)
Questions?

✌️

64 / 64

Agenda

2 / 64
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow