-
Notifications
You must be signed in to change notification settings - Fork 31
Intial commit of secrets management CB #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paul1994
wants to merge
2
commits into
main
Choose a base branch
from
pb_vault_example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
examples/cookbooks/secrets_management/.delivery/project.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Delivery for Local Phases Execution | ||
| # | ||
| # This file allows you to execute test phases locally on a workstation or | ||
| # in a CI pipeline. The delivery-cli will read this file and execute the | ||
| # command(s) that are configured for each phase. You can customize them | ||
| # by just modifying the phase key on this file. | ||
| # | ||
| # By default these phases are configured for Cookbook Workflow only | ||
| # | ||
|
|
||
| [local_phases] | ||
| unit = "chef exec rspec spec/" | ||
| lint = "chef exec cookstyle" | ||
| # foodcritic has been deprecated in favor of cookstyle so we skip the syntax | ||
| # phase now. | ||
| syntax = "echo skipping syntax phase. Use lint phase instead." | ||
| provision = "chef exec kitchen create" | ||
| deploy = "chef exec kitchen converge" | ||
| smoke = "chef exec kitchen verify" | ||
| # The functional phase is optional, you can define it by uncommenting | ||
| # the line below and running the command: `delivery local functional` | ||
| # functional = "" | ||
| cleanup = "chef exec kitchen destroy" | ||
|
|
||
| # Remote project.toml file | ||
| # | ||
| # Instead of the local phases above, you may specify a remote URI location for | ||
| # the `project.toml` file. This is useful for teams that wish to centrally | ||
| # manage the behavior of the `delivery local` command across many different | ||
| # projects. | ||
| # | ||
| # remote_file = "https://url/project.toml" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| .vagrant | ||
| *~ | ||
| *# | ||
| .#* | ||
| \#*# | ||
| .*.sw[a-z] | ||
| *.un~ | ||
|
|
||
| # Bundler | ||
| Gemfile.lock | ||
| gems.locked | ||
| bin/* | ||
| .bundle/* | ||
|
|
||
| # test kitchen | ||
| .kitchen/ | ||
| kitchen.local.yml | ||
| .kitchen* | ||
|
|
||
| # Chef | ||
| Berksfile.lock | ||
| .zero-knife.rb | ||
| Policyfile.lock.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # secrets_management CHANGELOG | ||
|
|
||
| This file is used to list changes made in each version of the secrets_management cookbook. | ||
|
|
||
| ## 0.1.0 | ||
|
|
||
| Initial release. | ||
|
|
||
| - change 0 | ||
| - change 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Copyright 2020 The Authors | ||
|
|
||
| All rights reserved, do not redistribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Policyfile.rb - Describe how you want Chef Infra Client to build your system. | ||
| # | ||
| # For more information on the Policyfile feature, visit | ||
| # https://docs.chef.io/policyfile/ | ||
|
|
||
| # A name that describes what the system you're building with Chef does. | ||
| name 'secrets_management' | ||
|
|
||
| # Where to find external cookbooks: | ||
| default_source :supermarket | ||
|
|
||
| # run_list: chef-client will run these recipes in the order specified. | ||
| run_list 'secrets_management::default' | ||
| named_run_list :hashi_vault, 'secrets_management::hashi_vault' | ||
|
|
||
| # Specify a custom source for a single cookbook: | ||
| cookbook 'secrets_management', path: '.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # HowTo: Retrieving secrets from a secrets management tool | ||
| This cookbook will store examples on how to grab secrets from tools like Hashicorp Vault. In the future I would like to include examples for Akeyless.io/Aws KMS/Azure | ||
|
|
||
| ## Before you start | ||
| ### Assumptions | ||
| * This guide assumes that you have a working Vault solution up and running that you can interact with | ||
|
|
||
| **Note:** The way that the vault token is used in this cookbook is not the way we recommended to store the vault_token. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's expand upon this:
|
||
| This is just an example on how to communicate with the sercrets management platform. Please consider using encrypted databags or some other means to protect the vault token. | ||
|
|
||
| ### Tested on chef client version 16+ | ||
|
|
||
| ### Cookbook | ||
|
|
||
| #### recipes | ||
|
|
||
| * hashi_vault : This is the main recipe that shows how to interact with a vault instance. | ||
|
|
||
| #### libraries | ||
|
|
||
| * hashi_vault | ||
|
|
||
| #### Attributes | ||
|
|
||
| * hashi_vault | ||
|
|
||
| `default['secrets_managment']['hashi']['vault_address']` | ||
|
|
||
| The address to the hashi corp vault *Example*: | ||
| default['secrets_managment']['hashi']['vault_address'] = 'https://myvault.chefsuccess.io:8200' | ||
|
|
||
| `default['secrets_managment']['hashi']['vault_token']` | ||
|
|
||
| The Vault token of the AppRole or Root(not suggested but used to for demo purposes) Example: | ||
| default['secrets_managment']['hashi']['vault_token'] = 's.xfffffff6666666777777hhh' | ||
|
|
||
| `default['secrets_managment']['hashi']['vault_path']` | ||
|
|
||
| The path to the secrets Example: | ||
| default['secrets_managment']['hashi']['vault_path'] = 'secret/my-app' | ||
|
|
||
| `default['secrets_managment']['hashi']['vault_role']` | ||
|
|
||
| The name of the app role is used. Leave an empty string if a app role is not used Example: | ||
| default['secrets_managment']['hashi']['vault_role'] = 'web' | ||
4 changes: 4 additions & 0 deletions
4
examples/cookbooks/secrets_management/attributes/hashi_vault.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| default['secrets_managment']['hashi']['vault_address'] = 'https://myvault:8200' | ||
| default['secrets_managment']['hashi']['vault_token'] = 's.5GM4NeJmbdfe34refUNWHaNriZ' | ||
| default['secrets_managment']['hashi']['vault_path'] = 'secret/myapp' | ||
| default['secrets_managment']['hashi']['vault_role'] = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Put files/directories that should be ignored in this file when uploading | ||
| # to a Chef Infra Server or Supermarket. | ||
| # Lines that start with '# ' are comments. | ||
|
|
||
| # OS generated files # | ||
| ###################### | ||
| .DS_Store | ||
| ehthumbs.db | ||
| Icon? | ||
| nohup.out | ||
| Thumbs.db | ||
| .envrc | ||
|
|
||
| # EDITORS # | ||
| ########### | ||
| .#* | ||
| .project | ||
| .settings | ||
| *_flymake | ||
| *_flymake.* | ||
| *.bak | ||
| *.sw[a-z] | ||
| *.tmproj | ||
| *~ | ||
| \#* | ||
| REVISION | ||
| TAGS* | ||
| tmtags | ||
| .vscode | ||
| .editorconfig | ||
|
|
||
| ## COMPILED ## | ||
| ############## | ||
| *.class | ||
| *.com | ||
| *.dll | ||
| *.exe | ||
| *.o | ||
| *.pyc | ||
| *.so | ||
| */rdoc/ | ||
| a.out | ||
| mkmf.log | ||
|
|
||
| # Testing # | ||
| ########### | ||
| .circleci/* | ||
| .codeclimate.yml | ||
| .delivery/* | ||
| .foodcritic | ||
| .kitchen* | ||
| .mdlrc | ||
| .overcommit.yml | ||
| .rspec | ||
| .rubocop.yml | ||
| .travis.yml | ||
| .watchr | ||
| .yamllint | ||
| azure-pipelines.yml | ||
| Dangerfile | ||
| examples/* | ||
| features/* | ||
| Guardfile | ||
| kitchen.yml* | ||
| mlc_config.json | ||
| Procfile | ||
| Rakefile | ||
| spec/* | ||
| test/* | ||
|
|
||
| # SCM # | ||
| ####### | ||
| .git | ||
| .gitattributes | ||
| .gitconfig | ||
| .github/* | ||
| .gitignore | ||
| .gitkeep | ||
| .gitmodules | ||
| .svn | ||
| */.bzr/* | ||
| */.git | ||
| */.hg/* | ||
| */.svn/* | ||
|
|
||
| # Berkshelf # | ||
| ############# | ||
| Berksfile | ||
| Berksfile.lock | ||
| cookbooks/* | ||
| tmp | ||
|
|
||
| # Bundler # | ||
| ########### | ||
| vendor/* | ||
| Gemfile | ||
| Gemfile.lock | ||
|
|
||
| # Policyfile # | ||
| ############## | ||
| Policyfile.rb | ||
| Policyfile.lock.json | ||
|
|
||
| # Documentation # | ||
| ############# | ||
| CODE_OF_CONDUCT* | ||
| CONTRIBUTING* | ||
| documentation/* | ||
| TESTING* | ||
| UPGRADING* | ||
|
|
||
| # Vagrant # | ||
| ########### | ||
| .vagrant | ||
| Vagrantfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| driver: | ||
| name: vagrant | ||
|
|
||
| ## The forwarded_port port feature lets you connect to ports on the VM guest via | ||
| ## localhost on the host. | ||
| ## see also: https://www.vagrantup.com/docs/networking/forwarded_ports.html | ||
|
|
||
| # network: | ||
| # - ["forwarded_port", {guest: 80, host: 8080}] | ||
|
|
||
| provisioner: | ||
| name: chef_zero | ||
|
|
||
| ## product_name and product_version specifies a specific Chef product and version to install. | ||
| ## see the Chef documentation for more details: https://docs.chef.io/workstation/config_yml_kitchen/ | ||
| # product_name: chef | ||
| # product_version: 16 | ||
|
|
||
| verifier: | ||
| name: inspec | ||
| chef_license: accept | ||
|
|
||
| platforms: | ||
| - name: ubuntu-16.04 | ||
|
|
||
| suites: | ||
| - name: hashi_vault | ||
| provisioner: | ||
| named_run_list: hashi_vault | ||
| verifier: | ||
| inspec_tests: | ||
| - test/integration/default | ||
| attributes: |
37 changes: 37 additions & 0 deletions
37
examples/cookbooks/secrets_management/libraries/hashi_vault.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # | ||
| # Chef Infra Documentation | ||
| # https://docs.chef.io/libraries/ | ||
| # | ||
|
|
||
| # | ||
| # This module name was auto-generated from the cookbook name. This name is a | ||
| # single word that starts with a capital letter and then continues to use | ||
| # camel-casing throughout the remainder of the name. | ||
| # | ||
| require 'vault' | ||
| module SecretsManagement | ||
| module HashiVaultObjectHelpers | ||
| def get_hashi_vault_object(vault_path, vault_address, vault_token, vault_role = nil) | ||
| # Setting the vault address | ||
| Vault.address = vault_address | ||
| # Authenticate with the token | ||
| Vault.token = vault_token | ||
| Vault.ssl_verify = false | ||
| if vault_role # Authenticate to Vault using the role_id | ||
| approle_id = Vault.approle.role_id(vault_role) | ||
| secret_id = Vault.approle.create_secret_id(vault_role).data[:secret_id] | ||
| Vault.auth.approle(approle_id, secret_id) | ||
| end | ||
| # Attempt to read the secret | ||
| secret = Vault.logical.read(vault_path) | ||
| if secret.nil? | ||
| raise "Could not read secret '#{vault_path}'!" | ||
| else | ||
| secret.data | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Chef::Resource.include ::SecretsManagement::HashiVaultObjectHelpers | ||
| Chef::Recipe.include ::SecretsManagement::HashiVaultObjectHelpers | ||
| Chef::Node.include ::SecretsManagement::HashiVaultObjectHelpers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name 'secrets_management' | ||
| maintainer 'Chef Examples' | ||
| maintainer_email 'pbradford@chef.io' | ||
| license 'All Rights Reserved' | ||
| description 'Installs/Configures secrets_management' | ||
| version '0.1.0' | ||
| chef_version '>= 15.0' | ||
|
|
||
| gem 'vault' | ||
|
|
||
| # The `issues_url` points to the location where issues for this cookbook are | ||
| # tracked. A `View Issues` link will be displayed on this cookbook's page when | ||
| # uploaded to a Supermarket. | ||
| # | ||
| # issues_url 'https://github.com/<insert_org_here>/secrets_management/issues' | ||
|
|
||
| # The `source_url` points to the development repository for this cookbook. A | ||
| # `View Source` link will be displayed on this cookbook's page when uploaded to | ||
| # a Supermarket. | ||
| # | ||
| # source_url 'https://github.com/<insert_org_here>/secrets_management' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # | ||
| # Cookbook:: secrets_management | ||
| # Recipe:: default | ||
| # | ||
| # Copyright:: 2020, The Authors, All Rights Reserved. |
22 changes: 22 additions & 0 deletions
22
examples/cookbooks/secrets_management/recipes/hashi_vault.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # | ||
| # Cookbook:: secrets_management | ||
| # Recipe:: hashi_vault | ||
| # | ||
| # Copyright:: 2020, The Authors, All Rights Reserved. | ||
|
|
||
| # Hashi_vault library. This was written so the out could be used during the converge stage | ||
| vault_data = get_hashi_vault_object(node['secrets_managment']['hashi']['vault_path'], node['secrets_managment']['hashi']['vault_address'], node['secrets_managment']['hashi']['vault_token']) | ||
|
|
||
| template '/tmp/config.conf' do | ||
| source 'app.conf.erb' | ||
| sensitive true | ||
| variables(username: vault_data[:username], | ||
| password: vault_data[:password]) | ||
| end | ||
|
|
||
| file '/tmp/vault.txt' do | ||
| content "This is a test and the password is: #{vault_data[:password]}" | ||
| mode '0755' | ||
| action :create | ||
| sensitive true | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| require 'chefspec' | ||
| require 'chefspec/policyfile' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably explain what the .delivery stuff is for in the README.