├── CONTRIBUTORS ├── .yardopts ├── .rspec ├── spec ├── classes │ ├── coverage_spec.rb │ └── vault_spec.rb ├── default_facts.yml ├── acceptance │ ├── nodesets │ │ ├── ubuntu-16.04-x86_64-docker.yml │ │ ├── ubuntu-18.04-x86_64-docker.yml │ │ ├── centos-6-x86_64-docker.yml │ │ ├── ubuntu-14.04-x86_64-docker.yml │ │ └── centos-7-x86_64-docker.yml │ └── class_spec.rb ├── spec_helper_acceptance.rb └── spec_helper.rb ├── .gitattributes ├── Guardfile ├── manifests ├── service.pp ├── install.pp ├── params.pp ├── config.pp └── init.pp ├── .gitignore ├── .pdkignore ├── tests └── init.pp ├── .fixtures.yml ├── .github └── PULL_REQUEST_TEMPLATE.md ├── templates ├── vault.upstart.erb ├── vault.systemd.erb └── vault.initd.erb ├── Rakefile ├── .travis.yml ├── metadata.json ├── Gemfile ├── CHANGELOG.md ├── README.md ├── .rubocop.yml └── LICENSE /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | jsok 2 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format documentation 3 | -------------------------------------------------------------------------------- /spec/classes/coverage_spec.rb: -------------------------------------------------------------------------------- 1 | at_exit { RSpec::Puppet::Coverage.report! } 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.rb eol=lf 2 | *.erb eol=lf 3 | *.pp eol=lf 4 | *.sh eol=lf 5 | *.epp eol=lf 6 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | notification :off 2 | 3 | guard 'rake', :task => 'test' do 4 | watch(%r{^manifests\/(.+)\.pp$}) 5 | end 6 | -------------------------------------------------------------------------------- /spec/default_facts.yml: -------------------------------------------------------------------------------- 1 | # Use default_module_facts.yml for module specific facts. 2 | # 3 | # Facts specified here will override the values provided by rspec-puppet-facts. 4 | --- 5 | ipaddress: "172.16.254.254" 6 | is_pe: false 7 | macaddress: "AA:AA:AA:AA:AA:AA" 8 | -------------------------------------------------------------------------------- /manifests/service.pp: -------------------------------------------------------------------------------- 1 | # == Class vault::service 2 | class vault::service { 3 | if $::vault::manage_service { 4 | service { $::vault::service_name: 5 | ensure => $::vault::service_ensure, 6 | enable => $::vault::service_enable, 7 | provider => $::vault::service_provider, 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | .*.sw[op] 3 | .metadata 4 | .yardoc 5 | .yardwarns 6 | *.iml 7 | /.bundle/ 8 | /.idea/ 9 | /.vagrant/ 10 | /coverage/ 11 | /bin/ 12 | /doc/ 13 | /Gemfile.local 14 | /Gemfile.lock 15 | /junit/ 16 | /log/ 17 | /pkg/ 18 | /spec/fixtures/manifests/ 19 | /spec/fixtures/modules/ 20 | /tmp/ 21 | /vendor/ 22 | /convert_report.txt 23 | /update_report.txt 24 | .DS_Store 25 | -------------------------------------------------------------------------------- /.pdkignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | .*.sw[op] 3 | .metadata 4 | .yardoc 5 | .yardwarns 6 | *.iml 7 | /.bundle/ 8 | /.idea/ 9 | /.vagrant/ 10 | /coverage/ 11 | /bin/ 12 | /doc/ 13 | /Gemfile.local 14 | /Gemfile.lock 15 | /junit/ 16 | /log/ 17 | /pkg/ 18 | /spec/fixtures/manifests/ 19 | /spec/fixtures/modules/ 20 | /tmp/ 21 | /vendor/ 22 | /convert_report.txt 23 | /update_report.txt 24 | .DS_Store 25 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-16.04-x86_64-docker.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-1604-x64: 3 | default_apply_opts: 4 | order: random 5 | strict_variables: 6 | platform: ubuntu-16.04-amd64 7 | hypervisor : docker 8 | image: ubuntu:16.04 9 | docker_cmd: '["/sbin/init"]' 10 | docker_preserve_image: true 11 | docker_image_commands: 12 | - 'apt-get install -y curl unzip' 13 | CONFIG: 14 | type: foss 15 | log_level: debug 16 | docker_options: 17 | ssl_verify_peer: false 18 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-18.04-x86_64-docker.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-1804-x64: 3 | default_apply_opts: 4 | order: random 5 | strict_variables: 6 | platform: ubuntu-18.04-amd64 7 | hypervisor : docker 8 | image: ubuntu:18.04 9 | docker_cmd: '["/sbin/init"]' 10 | docker_preserve_image: true 11 | docker_image_commands: 12 | - 'apt-get install -y curl iproute2 libcap2-bin unzip' 13 | CONFIG: 14 | type: foss 15 | log_level: debug 16 | docker_options: 17 | ssl_verify_peer: false 18 | -------------------------------------------------------------------------------- /spec/spec_helper_acceptance.rb: -------------------------------------------------------------------------------- 1 | require 'beaker-rspec' 2 | require 'beaker/puppet_install_helper' 3 | require 'beaker/module_install_helper' 4 | 5 | run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' 6 | install_module 7 | install_module_dependencies 8 | 9 | RSpec.configure do |c| 10 | # Readable test descriptions 11 | c.formatter = :documentation 12 | hosts.each do |host| 13 | if host[:platform] =~ %r{el-7-x86_64} && host[:hypervisor] =~ %r{docker} 14 | on(host, "sed -i '/nodocs/d' /etc/yum.conf") 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /tests/init.pp: -------------------------------------------------------------------------------- 1 | # The baseline for module testing used by Puppet Labs is that each manifest 2 | # should have a corresponding test manifest that declares that class or defined 3 | # type. 4 | # 5 | # Tests are then run by using puppet apply --noop (to check for compilation 6 | # errors and view a log of events) or by fully applying the test in a virtual 7 | # environment (to compare the resulting system state to the desired state). 8 | # 9 | # Learn more about module testing here: 10 | # http://docs.puppetlabs.com/guides/tests_smoke.html 11 | # 12 | include ::vault 13 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/centos-6-x86_64-docker.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | centos-6-x64: 3 | default_apply_opts: 4 | order: random 5 | strict_variables: 6 | platform: el-6-x86_64 7 | hypervisor : docker 8 | # Need upstart to tests services 9 | image: centos:6 10 | # This stops the image from being deleted on completion, speeding up the process. 11 | docker_preserve_image: true 12 | docker_cmd: '["/sbin/init"]' 13 | docker_image_commands: 14 | - 'yum install -y unzip' 15 | CONFIG: 16 | type: foss 17 | log_level: debug 18 | docker_options: 19 | ssl_verify_peer: false 20 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-1404-x64: 3 | default_apply_opts: 4 | order: random 5 | strict_variables: 6 | platform: ubuntu-14.04-amd64 7 | hypervisor : docker 8 | # Need upstart to tests services 9 | image: ubuntu-upstart:14.04 10 | docker_cmd: '["/sbin/init"]' 11 | # This stops the image from being deleted on completion, speeding up the process. 12 | docker_preserve_image: true 13 | docker_image_commands: 14 | - 'apt-get install -y curl unzip' 15 | CONFIG: 16 | type: foss 17 | log_level: debug 18 | docker_options: 19 | ssl_verify_peer: false 20 | -------------------------------------------------------------------------------- /.fixtures.yml: -------------------------------------------------------------------------------- 1 | fixtures: 2 | repositories: 3 | stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" 4 | archive: "git://github.com/voxpupuli/puppet-archive.git" 5 | hashi_stack: "https://github.com/voxpupuli/puppet-hashi_stack.git" 6 | systemd: "git://github.com/camptocamp/puppet-systemd.git" 7 | file_capability: "git://github.com/smoeding/puppet-file_capability.git" 8 | apt: "https://github.com/puppetlabs/puppetlabs-apt.git" 9 | yum: "https://github.com/voxpupuli/puppet-yum.git" 10 | yumrepo_core: 11 | repo: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git" 12 | puppet_version: ">= 6.0.0" 13 | symlinks: 14 | vault: "#{source_dir}" 15 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/centos-7-x86_64-docker.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | centos-7-x64: 3 | default_apply_opts: 4 | order: random 5 | strict_variables: 6 | platform: el-7-x86_64 7 | hypervisor : docker 8 | # Need upstart to tests services 9 | image: centos:7 10 | # This stops the image from being deleted on completion, speeding up the process. 11 | docker_preserve_image: true 12 | docker_cmd: '["/sbin/init"]' 13 | # we need iproute because ServerSpec on CentOS 7 uses the ``ss`` command 14 | docker_image_commands: 15 | - 'yum install -y unzip iproute' 16 | CONFIG: 17 | type: foss 18 | log_level: debug 19 | docker_options: 20 | ssl_verify_peer: false 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ##### SUMMARY 2 | 3 | 4 | 9 | 10 | ##### TESTS/SPECS 11 | 12 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /templates/vault.upstart.erb: -------------------------------------------------------------------------------- 1 | # vault Agent (Upstart unit) 2 | ########################################################################################################### 3 | # this file has been put in place by the jsok/vault Puppet module (https://forge.puppetlabs.com/jsok/vault) 4 | # any changes will be overwritten if Puppet is run again 5 | ########################################################################################################### 6 | description "vault server" 7 | start on (local-filesystems and net-device-up IFACE!=lo) 8 | stop on runlevel [06] 9 | 10 | env VAULT=<%= scope['vault::bin_dir'] %>/vault 11 | env CONFIG=<%= scope['vault::config_dir'] %>/config.json 12 | env USER=<%= scope['vault::user'] %> 13 | env GROUP=<%= scope['vault::group'] %> 14 | env PID_FILE=/var/run/vault.pid 15 | env LOG_FILE=/var/log/vault.log 16 | 17 | script 18 | export GOMAXPROCS=${GOMAXPROCS:-<%= scope['vault::num_procs'] %>} 19 | [ -e /etc/default/$UPSTART_JOB ] && . /etc/default/$UPSTART_JOB 20 | exec >> $LOG_FILE 2>&1 21 | exec start-stop-daemon -u $USER -g $GROUP -p $PID_FILE -x $VAULT -S -- server -config=$CONFIG <%= scope['vault::service_options'] %> 22 | end script 23 | 24 | respawn 25 | respawn limit 10 10 26 | kill timeout 10 27 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | require 'rspec-puppet-facts' 3 | require 'rspec/json_expectations' 4 | 5 | require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) 6 | 7 | include RspecPuppetFacts 8 | 9 | default_facts = { 10 | puppetversion: Puppet.version, 11 | facterversion: Facter.version, 12 | } 13 | 14 | default_fact_files = [ 15 | File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), 16 | File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), 17 | ] 18 | 19 | default_fact_files.each do |f| 20 | next unless File.exist?(f) && File.readable?(f) && File.size?(f) 21 | 22 | begin 23 | default_facts.merge!(YAML.safe_load(File.read(f))) 24 | rescue => e 25 | RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" 26 | end 27 | end 28 | 29 | RSpec.configure do |c| 30 | c.default_facts = default_facts 31 | c.before :each do 32 | # set to strictest setting for testing 33 | # by default Puppet runs at warning level 34 | Puppet.settings[:strict] = :warning 35 | end 36 | end 37 | 38 | def ensure_module_defined(module_name) 39 | module_name.split('::').reduce(Object) do |last_module, next_module| 40 | last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) 41 | last_module.const_get(next_module, false) 42 | end 43 | end 44 | 45 | # 'spec_overrides' from sync.yml will appear below this line 46 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/rake_tasks' 2 | require 'puppet/version' 3 | require 'puppet-lint/tasks/puppet-lint' 4 | require 'puppet-syntax/tasks/puppet-syntax' 5 | require 'rubocop/rake_task' 6 | 7 | ENV['STRICT_VARIABLES'] = "yes" 8 | 9 | # These gems aren't always present, for instance 10 | # on Travis with --without development 11 | begin 12 | require 'puppet_blacksmith/rake_tasks' 13 | rescue LoadError 14 | end 15 | 16 | RuboCop::RakeTask.new 17 | 18 | Rake::Task[:lint].clear 19 | 20 | PuppetLint.configuration.relative = true 21 | PuppetLint.configuration.send("disable_80chars") 22 | PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" 23 | PuppetLint.configuration.fail_on_warnings = true 24 | 25 | # Forsake support for Puppet 2.6.2 for the benefit of cleaner code. 26 | # http://puppet-lint.com/checks/class_parameter_defaults/ 27 | PuppetLint.configuration.send('disable_class_parameter_defaults') 28 | # http://puppet-lint.com/checks/class_inherits_from_params_class/ 29 | PuppetLint.configuration.send('disable_class_inherits_from_params_class') 30 | 31 | exclude_paths = [ 32 | "bundle/**/*", 33 | "pkg/**/*", 34 | "vendor/**/*", 35 | "spec/**/*", 36 | ] 37 | PuppetLint.configuration.ignore_paths = exclude_paths 38 | PuppetSyntax.exclude_paths = exclude_paths 39 | 40 | desc "Run acceptance tests" 41 | RSpec::Core::RakeTask.new(:acceptance) do |t| 42 | t.pattern = 'spec/acceptance' 43 | end 44 | 45 | desc "Populate CONTRIBUTORS file" 46 | task :contributors do 47 | system("git log --format='%aN' | sort -u > CONTRIBUTORS") 48 | end 49 | 50 | desc "Run syntax, lint, and spec tests." 51 | task :test => [ 52 | :syntax, 53 | :lint, 54 | :rubocop, 55 | :spec, 56 | :metadata_lint, 57 | ] 58 | -------------------------------------------------------------------------------- /templates/vault.systemd.erb: -------------------------------------------------------------------------------- 1 | # vault systemd unit file 2 | ########################################################################################################### 3 | # this file has been put in place by the jsok/vault Puppet module (https://forge.puppetlabs.com/jsok/vault) 4 | # any changes will be overwritten if Puppet is run again 5 | # This script is originally from: 6 | # https://learn.hashicorp.com/vault/operations/ops-deployment-guide#step-3-configure-systemd 7 | ########################################################################################################### 8 | 9 | [Unit] 10 | Description="HashiCorp Vault - A tool for managing secrets" 11 | Documentation=https://www.vaultproject.io/docs/ 12 | Requires=network-online.target 13 | After=network-online.target 14 | ConditionFileNotEmpty=<%= scope['vault::config_dir'] %>/config.json 15 | 16 | [Service] 17 | User=<%= scope['vault::user'] %> 18 | Group=<%= scope['vault::group'] %> 19 | PrivateDevices=yes 20 | PrivateTmp=yes 21 | ProtectSystem=full 22 | ProtectHome=read-only 23 | <% # Still require check for :undef for Puppet 3.x -%> 24 | <% if scope['vault::disable_mlock'] && scope['vault::disable_mlock'] != :undef -%> 25 | CapabilityBoundingSet=CAP_SYSLOG 26 | <% else -%> 27 | SecureBits=keep-caps 28 | Capabilities=CAP_IPC_LOCK+ep 29 | CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK 30 | <% end -%> 31 | NoNewPrivileges=yes 32 | Environment=GOMAXPROCS=<%= scope['vault::num_procs'] %> 33 | ExecStart=<%= scope['vault::bin_dir'] %>/vault server -config=<%= scope['vault::config_dir'] %>/config.json <%= scope['vault::service_options'] %> 34 | KillSignal=SIGINT 35 | TimeoutStopSec=30s 36 | Restart=on-failure 37 | StartLimitInterval=60s 38 | StartLimitBurst=3 39 | AmbientCapabilities=CAP_IPC_LOCK 40 | ExecReload=/bin/kill --signal HUP $MAINPID 41 | KillMode=process 42 | RestartSec=5 43 | LimitNOFILE=65536 44 | 45 | [Install] 46 | WantedBy=multi-user.target 47 | -------------------------------------------------------------------------------- /manifests/install.pp: -------------------------------------------------------------------------------- 1 | # == Class vault::install 2 | # 3 | class vault::install { 4 | $vault_bin = "${::vault::bin_dir}/vault" 5 | 6 | case $::vault::install_method { 7 | 'archive': { 8 | if $::vault::manage_download_dir { 9 | file { $::vault::download_dir: 10 | ensure => directory, 11 | } 12 | } 13 | 14 | archive { "${::vault::download_dir}/${::vault::download_filename}": 15 | ensure => present, 16 | extract => true, 17 | extract_path => $::vault::bin_dir, 18 | source => $::vault::real_download_url, 19 | cleanup => true, 20 | creates => $vault_bin, 21 | before => File['vault_binary'], 22 | } 23 | 24 | $_manage_file_capabilities = true 25 | } 26 | 27 | 'repo': { 28 | if $vault::manage_repo{ 29 | include hashi_stack::repo 30 | Class['hashi_stack::repo'] -> Package[$::vault::package_name] 31 | } 32 | package { $::vault::package_name: 33 | ensure => $::vault::package_ensure, 34 | } 35 | $_manage_file_capabilities = false 36 | } 37 | 38 | default: { 39 | fail("Installation method ${::vault::install_method} not supported") 40 | } 41 | } 42 | 43 | file { 'vault_binary': 44 | path => $vault_bin, 45 | owner => 'root', 46 | group => 'root', 47 | mode => '0755', 48 | } 49 | 50 | if !$::vault::disable_mlock and pick($::vault::manage_file_capabilities, $_manage_file_capabilities) { 51 | file_capability { 'vault_binary_capability': 52 | ensure => present, 53 | file => $vault_bin, 54 | capability => 'cap_ipc_lock=ep', 55 | subscribe => File['vault_binary'], 56 | } 57 | 58 | if $::vault::install_method == 'repo' { 59 | Package['vault'] ~> File_capability['vault_binary_capability'] 60 | } 61 | } 62 | 63 | if $vault::manage_user { 64 | user { $::vault::user: 65 | ensure => present, 66 | } 67 | if $vault::manage_group { 68 | Group[$vault::group] -> User[$vault::user] 69 | } 70 | } 71 | if $vault::manage_group { 72 | group { $::vault::group: 73 | ensure => present, 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: false 3 | language: ruby 4 | bundler_args: --without development system_tests 5 | before_install: rm -f Gemfile.lock 6 | script: bundle exec rake test 7 | matrix: 8 | include: 9 | # RSpec tests 10 | - rvm: 2.4.5 11 | env: PUPPET_GEM_VERSION="~> 5" 12 | - rvm: 2.5.5 13 | env: PUPPET_GEM_VERSION="~> 6" DEPLOY_CANDIDATE=yes 14 | 15 | # Beaker tests 16 | - sudo: required 17 | services: docker 18 | rvm: 2.5.5 19 | env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set="centos-6-x86_64-docker" 20 | script: bundle exec rake acceptance 21 | bundler_args: --without development 22 | - sudo: required 23 | services: docker 24 | rvm: 2.5.5 25 | env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set="centos-7-x86_64-docker" 26 | script: bundle exec rake acceptance 27 | bundler_args: --without development 28 | - sudo: required 29 | services: docker 30 | rvm: 2.5.5 31 | env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set="ubuntu-16.04-x86_64-docker" 32 | script: bundle exec rake acceptance 33 | bundler_args: --without development 34 | - sudo: required 35 | services: docker 36 | rvm: 2.5.5 37 | env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_set="ubuntu-18.04-x86_64-docker" 38 | script: bundle exec rake acceptance 39 | bundler_args: --without development 40 | deploy: 41 | provider: puppetforge 42 | user: jsok 43 | password: 44 | secure: Fpvb/pZBy+FBpcXkQua6eEWN/4/klJjgFvBzDocrEa8ud5MGs8YuERKENoZ16bFzCtnyytRGZbiXJtqo4+IkxY0EFuCWgw1BH0ekljXWsuTi0ZCrYgedjy0Tykj6cgPkLecBzqtPe5b1gXwmIamlYQkVdnyglZEkSKvo9GqYX/VYSs7cc5mJ5bP5zgAr7U1jBQCKxD95kSt28NwIliekX1KoUqEVhxsHW5fzQa+4eS8vz7HUBppkJoUpHJfjXuoZKWXR4lQka4VgIZXflHno6OH908B0JiFoZI6klOInrn6eZbpF10CmjbK7ZCMIKdiPiVqzDQJgsSqg2n+9fA6TGbEj5A3K8VZtqp7MGd3b5HBfeVNPTPEAFGi4SkWPGwb2l53fUxP7T/NQUQ130GGNKdJdFmVW6Y6i2q9zrWWYZB1zbHRac/lY3uDd6qRxmbDYJzzTqMUPpl5eyBtRbg0XWuxTR1R9yhSwNw+N1sz1CaqT27MvgHqNRrISPSAXRfA+KP5mV8n+gInZVKiXf1BkNtPZJ+t2WO7jhKkC05WRGy0HAi2jaZiSL39bBMQOuoTCGlgo3h146PE27dJ2E4Yd3OBPn3vV/FrU8zuRFt77kOlffCq7yL7zv4OORfIgUql2RvEJ0aLA3jIxrKve8uQZFQ6Y7NjuFMQnKpG+lntW5xw= 45 | on: 46 | tags: true 47 | condition: "$DEPLOY_CANDIDATE = yes" 48 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsok-vault", 3 | "version": "2.3.0", 4 | "author": "jsok", 5 | "summary": "Puppet module to manage Vault (https://vaultproject.io)", 6 | "license": "Apache-2.0", 7 | "source": "https://github.com/jsok/puppet-vault.git", 8 | "project_page": "https://github.com/jsok/puppet-vault", 9 | "issues_url": "https://github.com/jsok/puppet-vault/issues", 10 | "tags": [ 11 | "vault", 12 | "hashicorp", 13 | "secrets" 14 | ], 15 | "dependencies": [ 16 | { 17 | "name": "puppetlabs-stdlib", 18 | "version_requirement": ">= 4.24.0 < 7.0.0" 19 | }, 20 | { 21 | "name": "puppet-archive", 22 | "version_requirement": ">= 2.0.0 < 5.0.0" 23 | }, 24 | { 25 | "name": "puppet/hashi_stack", 26 | "version_requirement": ">=1.0.0 <2.0.0" 27 | }, 28 | { 29 | "name": "camptocamp-systemd", 30 | "version_requirement": ">= 1.1.1 < 3.0.0" 31 | }, 32 | { 33 | "name": "stm-file_capability", 34 | "version_requirement": ">= 1.0.1 < 5.0.0" 35 | } 36 | ], 37 | "operatingsystem_support": [ 38 | { 39 | "operatingsystem": "Ubuntu", 40 | "operatingsystemrelease": [ 41 | "14.04", 42 | "16.04", 43 | "18.04" 44 | ] 45 | }, 46 | { 47 | "operatingsystem": "Debian", 48 | "operatingsystemrelease": [ 49 | "8", 50 | "9" 51 | ] 52 | }, 53 | { 54 | "operatingsystem": "RedHat", 55 | "operatingsystemrelease": [ 56 | "6.0", 57 | "7.0" 58 | ] 59 | }, 60 | { 61 | "operatingsystem": "CentOS", 62 | "operatingsystemrelease": [ 63 | "6.0", 64 | "7.0" 65 | ] 66 | }, 67 | { 68 | "operatingsystem": "Amazon", 69 | "operatingsystemrelease": [ 70 | "2016.03" 71 | ] 72 | }, 73 | { 74 | "operatingsystem": "Fedora", 75 | "operatingsystemrelease": [ 76 | "25", 77 | "26", 78 | "27" 79 | ] 80 | }, 81 | { 82 | "operatingsystem": "Archlinux" 83 | } 84 | ], 85 | "requirements": [ 86 | { 87 | "name": "puppet", 88 | "version_requirement": ">= 4.0.0 < 7.0.0" 89 | } 90 | ], 91 | "tags": [ 92 | "vault", 93 | "hashicorp", 94 | "secrets" 95 | ], 96 | "pdk-version": "1.8.0", 97 | "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", 98 | "template-ref": "1.8.0-0-g0d9da00" 99 | } 100 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source ENV['GEM_SOURCE'] || "https://rubygems.org" 2 | 3 | group :test do 4 | gem 'puppetlabs_spec_helper', '~> 2.15.0', :require => false 5 | gem 'rspec-puppet', '~> 2.5', :require => false 6 | gem 'rspec-puppet-facts', :require => false 7 | gem 'rspec-puppet-utils', :require => false 8 | gem 'rspec-json_expectations', :require => false 9 | gem 'puppet-lint-leading_zero-check', :require => false 10 | gem 'puppet-lint-trailing_comma-check', :require => false 11 | gem 'puppet-lint-version_comparison-check', :require => false 12 | gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false 13 | gem 'puppet-lint-unquoted_string-check', :require => false 14 | gem 'puppet-lint-variable_contains_upcase', :require => false 15 | gem 'semantic_puppet', :require => false 16 | gem 'metadata-json-lint', :require => false 17 | gem 'redcarpet', :require => false 18 | gem 'rubocop', '~> 0.51', :require => false 19 | gem 'rubocop-rspec', '~> 1.20', :require => false 20 | gem 'mocha', '>= 1.2.1', :require => false 21 | gem 'coveralls', :require => false 22 | gem 'simplecov-console', :require => false 23 | gem 'parallel_tests', :require => false 24 | gem 'fakefs', :require => false 25 | end 26 | 27 | group :development do 28 | gem 'puppet-blacksmith' 29 | gem 'travis' 30 | end 31 | 32 | group :system_tests do 33 | gem "beaker", '~> 4', :require => false 34 | gem 'beaker-puppet', '~>1.0', :require => false 35 | gem "beaker-docker", :require => false 36 | gem "beaker-rspec", :require => false 37 | gem 'beaker-puppet_install_helper', :require => false 38 | gem 'beaker-module_install_helper', :require => false 39 | end 40 | 41 | ENV['PUPPET_GEM_VERSION'].nil? ? puppetversion = '~> 6' : puppetversion = ENV['PUPPET_GEM_VERSION'].to_s 42 | gem 'puppet', puppetversion, :require => false, :groups => [:test] 43 | 44 | # vim: syntax=ruby 45 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # == Class vault::params 2 | # 3 | # This class is meant to be called from vault. 4 | # It sets variables according to platform. 5 | # 6 | class vault::params { 7 | $user = 'vault' 8 | $manage_user = true 9 | $group = 'vault' 10 | $manage_group = true 11 | $config_dir = '/etc/vault' 12 | $config_mode = '0750' 13 | $manage_config_file = true 14 | $download_url = undef 15 | $download_url_base = 'https://releases.hashicorp.com/vault/' 16 | $download_extension = 'zip' 17 | $version = '1.4.2' 18 | $service_name = 'vault' 19 | $num_procs = $facts['processorcount'] 20 | $package_name = 'vault' 21 | $package_ensure = 'installed' 22 | 23 | $download_dir = '/tmp' 24 | $manage_download_dir = false 25 | $download_filename = 'vault.zip' 26 | 27 | # storage and listener are mandatory, we provide some sensible 28 | # defaults here 29 | $storage = { 'file' => { 'path' => '/var/lib/vault' }} 30 | $manage_storage_dir = false 31 | $listener = { 32 | 'tcp' => { 33 | 'address' => '127.0.0.1:8200', 34 | 'tls_disable' => 1, 35 | }, 36 | } 37 | 38 | $enable_ui = undef 39 | 40 | # These should always be undef as they are optional settings that 41 | # should not be configured unless explicitly declared. 42 | $ha_storage = undef 43 | $seal = undef 44 | $disable_cache = undef 45 | $telemetry = undef 46 | $default_lease_ttl = undef 47 | $max_lease_ttl = undef 48 | $disable_mlock = undef 49 | 50 | $manage_file_capabilities = undef 51 | 52 | $manage_service = true 53 | 54 | $service_enable = true 55 | $service_ensure = 'running' 56 | 57 | $service_provider = $facts['service_provider'] 58 | 59 | case $facts['architecture'] { 60 | 'aarch64': { $arch = 'arm64' } 61 | /(x86_64|amd64)/: { $arch = 'amd64' } 62 | 'i386': { $arch = '386' } 63 | /^arm.*/: { $arch = 'arm' } 64 | default: { fail("Unsupported kernel architecture: ${facts['architecture']}") } 65 | } 66 | 67 | case $facts['os']['family'] { 68 | 'Archlinux': { 69 | $install_method = 'repo' 70 | $bin_dir = '/bin' 71 | $manage_service_file = true 72 | $manage_repo = false 73 | } 74 | default: { 75 | $install_method = 'archive' 76 | $bin_dir = '/usr/local/bin' 77 | $manage_service_file = undef 78 | $manage_repo = true 79 | } 80 | } 81 | $os = downcase($facts['kernel']) 82 | } 83 | -------------------------------------------------------------------------------- /templates/vault.initd.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # vault - this script manages the vault server 4 | # 5 | # chkconfig: 3 85 15 6 | # processname: vault 7 | # description: Init.d script for Vault Project Server 8 | # pidfile: /var/run/vault.pid 9 | # config: <%= scope['vault::config_dir'] %>/config.json 10 | ########################################################################################################### 11 | # this file has been put in place by the jsok/vault Puppet module (https://forge.puppetlabs.com/jsok/vault) 12 | # any changes will be overwritten if Puppet is run again 13 | ########################################################################################################### 14 | 15 | ### BEGIN INIT INFO 16 | # Provides: vault 17 | # Required-Start: $local_fs $network 18 | # Required-Stop: $local_fs $network 19 | # Default-Start: 3 4 5 20 | # Default-Stop: 0 1 2 6 21 | # Short-Description: Manage the vault server 22 | ### END INIT INFO 23 | 24 | # Source function library. 25 | . /etc/rc.d/init.d/functions 26 | 27 | # Source networking configuration. 28 | . /etc/sysconfig/network 29 | 30 | # Check that networking is up. 31 | [ "$NETWORKING" = "no" ] && exit 0 32 | 33 | exec="<%= scope['vault::bin_dir'] %>/vault" 34 | prog=${exec##*/} 35 | 36 | lockfile="/var/lock/subsys/$prog" 37 | pidfile="/var/run/${prog}.pid" 38 | logfile="/var/log/${prog}.log" 39 | sysconfig="/etc/sysconfig/$prog" 40 | conffile="<%= scope['vault::config_dir'] %>/config.json" 41 | 42 | [ -f $sysconfig ] && . $sysconfig 43 | 44 | OPTIONS=$OPTIONS:-"<%= scope['vault::service_options'] %>" 45 | 46 | start() { 47 | [ -x $exec ] || exit 5 48 | [ -f $conffile ] || exit 6 49 | 50 | echo -n $"Starting $prog: " 51 | touch $logfile $pidfile 52 | chown <%= scope['vault::user'] %> $logfile $pidfile 53 | export GOMAXPROCS=${GOMAXPROCS:-<%= scope['vault::num_procs'] %>} 54 | daemon --user <%= scope['vault::user'] %> "{ $exec server -config=$conffile $OPTIONS &>> $logfile & }; echo \$! >| $pidfile" 55 | 56 | RETVAL=$? 57 | if [ $RETVAL -eq 0 ]; then 58 | touch $lockfile 59 | fi 60 | echo 61 | return $RETVAL 62 | } 63 | 64 | stop() { 65 | echo -n $"Stopping $prog: " 66 | killproc -p $pidfile $exec 2>> $logfile 67 | RETVAL=$? 68 | [ $RETVAL -eq 0 ] && rm -f $lockfile 69 | echo 70 | return $RETVAL 71 | } 72 | 73 | restart() { 74 | stop 75 | start 76 | } 77 | 78 | reload() { 79 | echo -n $"Reloading $prog: " 80 | killproc -p $pidfile $exec -HUP 81 | echo 82 | } 83 | 84 | force_reload() { 85 | restart 86 | } 87 | 88 | rh_status() { 89 | status $prog 90 | } 91 | 92 | rh_status_q() { 93 | rh_status >/dev/null 2>&1 94 | } 95 | 96 | case "$1" in 97 | start) 98 | rh_status_q && exit 0 99 | $1 100 | ;; 101 | stop) 102 | rh_status_q || exit 0 103 | $1 104 | ;; 105 | restart) 106 | $1 107 | ;; 108 | status) 109 | rh_status 110 | ;; 111 | condrestart|try-restart) 112 | rh_status_q || exit 7 113 | restart 114 | ;; 115 | *) 116 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" 117 | exit 2 118 | esac 119 | 120 | exit $? 121 | -------------------------------------------------------------------------------- /manifests/config.pp: -------------------------------------------------------------------------------- 1 | # == Class vault::config 2 | # 3 | # This class is called from vault for service config. 4 | # 5 | class vault::config { 6 | 7 | file { $::vault::config_dir: 8 | ensure => directory, 9 | purge => $::vault::purge_config_dir, 10 | recurse => $::vault::purge_config_dir, 11 | owner => $::vault::user, 12 | group => $::vault::group, 13 | } 14 | 15 | if $::vault::manage_config_file { 16 | 17 | $_config_hash = delete_undef_values({ 18 | 'listener' => $::vault::listener, 19 | 'storage' => $::vault::storage, 20 | 'ha_storage' => $::vault::ha_storage, 21 | 'seal' => $::vault::seal, 22 | 'telemetry' => $::vault::telemetry, 23 | 'disable_cache' => $::vault::disable_cache, 24 | 'default_lease_ttl' => $::vault::default_lease_ttl, 25 | 'max_lease_ttl' => $::vault::max_lease_ttl, 26 | 'disable_mlock' => $::vault::disable_mlock, 27 | 'ui' => $::vault::enable_ui, 28 | 'api_addr' => $::vault::api_addr, 29 | }) 30 | 31 | $config_hash = merge($_config_hash, $::vault::extra_config) 32 | 33 | file { "${::vault::config_dir}/config.json": 34 | content => to_json_pretty($config_hash), 35 | owner => $::vault::user, 36 | group => $::vault::group, 37 | mode => $::vault::config_mode, 38 | } 39 | 40 | # If manage_storage_dir is true and a file or raft storage backend is 41 | # configured, we create the directory configured in that backend. 42 | # 43 | if $::vault::manage_storage_dir { 44 | 45 | if $::vault::storage['file'] { 46 | $_storage_backend = 'file' 47 | } elsif $::vault::storage['raft'] { 48 | $_storage_backend = 'raft' 49 | } else { 50 | fail('Must provide a valid storage backend: file or raft') 51 | } 52 | 53 | if $::vault::storage[$_storage_backend]['path'] { 54 | file { $::vault::storage[$_storage_backend]['path']: 55 | ensure => directory, 56 | owner => $::vault::user, 57 | group => $::vault::group, 58 | } 59 | } else { 60 | fail("Must provide a path attribute to storage ${_storage_backend}") 61 | } 62 | 63 | } 64 | } 65 | 66 | # If nothing is specified for manage_service_file, defaults will be used 67 | # depending on the install_method. 68 | # If a value is passed, it will be interpretted as a boolean. 69 | if $::vault::manage_service_file == undef { 70 | case $::vault::install_method { 71 | 'archive': { $real_manage_service_file = true } 72 | 'repo': { $real_manage_service_file = false } 73 | default: { $real_manage_service_file = false } 74 | } 75 | } else { 76 | validate_bool($::vault::manage_service_file) 77 | $real_manage_service_file = $::vault::manage_service_file 78 | } 79 | 80 | if $real_manage_service_file { 81 | case $::vault::service_provider { 82 | 'upstart': { 83 | file { '/etc/init/vault.conf': 84 | ensure => file, 85 | mode => '0444', 86 | owner => 'root', 87 | group => 'root', 88 | content => template('vault/vault.upstart.erb'), 89 | } 90 | file { '/etc/init.d/vault': 91 | ensure => link, 92 | target => '/lib/init/upstart-job', 93 | owner => 'root', 94 | group => 'root', 95 | mode => '0755', 96 | } 97 | } 98 | 'systemd': { 99 | ::systemd::unit_file{'vault.service': 100 | content => template('vault/vault.systemd.erb'), 101 | } 102 | } 103 | /(redhat|sysv|init)/: { 104 | file { '/etc/init.d/vault': 105 | ensure => file, 106 | owner => 'root', 107 | group => 'root', 108 | mode => '0755', 109 | content => template('vault/vault.initd.erb'), 110 | } 111 | } 112 | default: { 113 | fail("vault::service_provider '${::vault::service_provider}' is not valid") 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 2020-05-27 2.3.0 2 | - Add `manage_config_file` option 3 | - Update stm/file_capability dependency 4 | - Update to vault 1.4.2 5 | 6 | ## 2020-02-01 2.2.0 7 | - Add support for `api_addr` stanza 8 | - Update to vault 1.3.2 9 | 10 | ## 2019-08-19 2.1.0 11 | - Add support for `seal` stanza 12 | - Remove duplicate TimeoutStopSec in systemd unit file 13 | - Update to vault 1.2.2 14 | 15 | ## 2019-06-01 2.0.1 16 | - Allow puppetlabs/stdlib 6.x 17 | - Allow stm/file_capability 2.x 18 | - Allow puppet/archive 4.x 19 | 20 | ## 2019-03-17 2.0.0 21 | - Drop Puppet 3 support 22 | - Add Puppet 6 support 23 | - Allow specifying `$listener` as an array of listener hashes 24 | - Add `config_mode` parameter 25 | - Update systemd unit file 26 | - Support Ubuntu 18.04 27 | - Support enabling Web UI 28 | - Update to vault 1.0.3 29 | - Use stm/file_capability to manage file capabilities 30 | - Use camptocamp/systemd to manage systemd unit file 31 | 32 | ## 2017-10-16 1.2.8 33 | - Update to vault 0.8.3 34 | 35 | ## 2017-08-18 1.2.7 36 | - Update to vault 0.8.1 37 | 38 | ## 2017-08-10 1.2.6 39 | - Update to vault 0.8.0 40 | 41 | ## 2017-07-15 1.2.5 42 | - Added `manage_service_file` option 43 | 44 | ## 2017-07-10 1.2.4 45 | - Fix and update beaker tests 46 | - Update to vault 0.7.3 47 | 48 | ## 2017-05-09 1.2.3 49 | - Update to vault 0.7.2 50 | 51 | ## 2017-05-08 1.2.2 52 | - Update to vault 0.7.1 53 | 54 | ## 2017-04-22 1.2.1 55 | - Update to rspec 3.5 56 | - Ruby 2.4 Fixnum deprecation 57 | - Correctly set config dir owner and group as vault user 58 | 59 | ## 2017-03-27 v1.2.0 60 | - Support Debian 7 and 8 61 | - Update to vault 0.7.0 62 | 63 | ## 2017-03-13 v1.1.9 64 | - Make download URL configuration more fine-grained 65 | - Support upgrading when `version` changes and installing via `archive` method 66 | 67 | ## 2017-02-13 v1.1.8 68 | - Test with Puppet 4.9 by default 69 | - Test with bleeding edge Puppet 4 70 | - Allow legacy Puppet 3 builds to fail in CI 71 | - Add `manage_service` option 72 | 73 | ## 2017-02-09 v1.1.7 74 | - Update to vault 0.6.5 75 | 76 | ## 2017-01-21 v1.1.6 77 | - Fix regression in vault_sorted_json 78 | 79 | ## 2017-01-10 v1.1.5 80 | - Update to vault 0.6.4 81 | 82 | ## 2016-12-07 v1.1.4 83 | - Update to vault 0.6.3 84 | 85 | ## 2016-11-04 v1.1.3 86 | - Fix `cap_ipc_lock` for Debian/Ubuntu 87 | - Bump Puppet and Ruby versions used in CI 88 | 89 | ## 2016-11-03 v1.1.2 90 | - Better code to ensure `cap_ipc_lock` is set 91 | 92 | ## 2016-10-10 v1.1.1 93 | - Documentation fixes 94 | 95 | ## 2016-10-07 v1.1.0 96 | - Update to vault 0.6.2 97 | - Add `manage_backend_dir` option 98 | 99 | ## 2016-09-29 v1.0.0 100 | - Replaced `config_hash` parameter for more fine grained controls 101 | - Replaced nanliu/staging for puppet/archive 102 | - Allow for package-based install method 103 | - Generate pretty JSON configs 104 | 105 | ## 2016-08-27 v0.4.0 106 | - Update to vault 0.6.1 107 | - Add Amazon OS support 108 | 109 | ## 2016-07-19 v0.3.0 110 | - Ensure config.json has correct user/group 111 | 112 | ## 2016-06-01 v0.2.3 113 | - Configure log file for upstart 114 | - Update to vault 0.6.0 115 | - Deploy to PuppetForge via TravisCI 116 | 117 | ## 2016-06-01 v0.2.2 118 | - Update to vault 0.5.3 119 | 120 | ## 2016-03-17 v0.2.1 121 | - Update to vault 0.5.2 122 | 123 | ## 2016-03-17 v0.2.0 124 | - Add RedHat7/CentOS7 support (including `systemd` support) 125 | - Add `num_procs` option to control `GOMAXPROCS` in init scripts 126 | - RedHat6 SysV init script improvements 127 | - Improved beaker acceptance tests 128 | 129 | ## 2016-03-15 v0.1.9 130 | - Update to vault 0.5.1 131 | - Add `manage_user` and `manage_group` params 132 | 133 | ## 2016-02-11 v0.1.8 134 | - Update to vault 0.5.0 135 | 136 | ## 2016-01-14 v0.1.7 137 | - Update to vault 0.4.1 138 | 139 | ## 2016-01-05 v0.1.6 140 | - Update to vault 0.4.0 141 | 142 | ## 2016-01-05 v0.1.5 143 | - Add CentOS 6 support 144 | 145 | ## 2015-10-14 v0.1.4 146 | - Fixes syntax error in bad release v0.1.3 147 | 148 | ## 2015-10-14 v0.1.3 149 | - Use new Fastly CDN for default `download_url` parameter 150 | 151 | ## 2015-10-14 v0.1.2 152 | - Support specifying `service_provider` 153 | 154 | ## 2015-10-06 v0.1.1 155 | - Fixed issue #1, containment bug 156 | 157 | ## 2015-07-28 v0.1.0 158 | - Initial relase 159 | - Add support exclusively for Ubuntu 14.04 160 | -------------------------------------------------------------------------------- /spec/acceptance/class_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | describe 'vault class' do 4 | context 'default parameters' do 5 | # Using puppet_apply as a helper 6 | it 'works idempotently with no errors' do 7 | pp = <<-MANIFEST 8 | class { '::vault': 9 | storage => { 10 | file => { 11 | path => '/tmp', 12 | } 13 | }, 14 | listener => [{ 15 | tcp => { 16 | address => '127.0.0.1:8200', 17 | tls_disable => 1, 18 | } 19 | }] 20 | } 21 | MANIFEST 22 | # Run it twice and test for idempotency 23 | apply_manifest(pp, catch_failures: true) 24 | apply_manifest(pp, catch_changes: true) 25 | end 26 | 27 | describe user('vault') do 28 | it { is_expected.to exist } 29 | end 30 | 31 | describe group('vault') do 32 | it { is_expected.to exist } 33 | end 34 | 35 | describe command('getcap /usr/local/bin/vault') do 36 | its(:exit_status) { is_expected.to eq 0 } 37 | its(:stdout) { is_expected.to include '/usr/local/bin/vault = cap_ipc_lock+ep' } 38 | end 39 | 40 | describe file('/usr/local/bin/vault') do 41 | it { is_expected.to exist } 42 | it { is_expected.to be_mode 755 } 43 | it { is_expected.to be_owned_by 'root' } 44 | it { is_expected.to be_grouped_into 'root' } 45 | end 46 | 47 | if fact('service_provider') == 'upstart' 48 | describe file('/etc/init/vault.conf') do 49 | it { is_expected.to be_file } 50 | it { is_expected.to be_mode 444 } 51 | it { is_expected.to be_owned_by 'root' } 52 | it { is_expected.to be_grouped_into 'root' } 53 | its(:content) { is_expected.to include 'env VAULT=/usr/local/bin/vault' } 54 | its(:content) { is_expected.to include 'env CONFIG=/etc/vault/config.json' } 55 | its(:content) { is_expected.to include 'env USER=vault' } 56 | its(:content) { is_expected.to include 'env GROUP=vault' } 57 | its(:content) { is_expected.to include 'exec start-stop-daemon -u $USER -g $GROUP -p $PID_FILE -x $VAULT -S -- server -config=$CONFIG ' } 58 | its(:content) { is_expected.to match %r{export GOMAXPROCS=\${GOMAXPROCS:-\d+}} } 59 | end 60 | describe file('/etc/init.d/vault') do 61 | it { is_expected.to be_symlink } 62 | it { is_expected.to be_linked_to '/lib/init/upstart-job' } 63 | end 64 | elsif fact('service_provider') == 'systemd' 65 | describe file('/etc/systemd/system/vault.service') do 66 | it { is_expected.to be_file } 67 | it { is_expected.to be_mode 644 } 68 | it { is_expected.to be_owned_by 'root' } 69 | it { is_expected.to be_grouped_into 'root' } 70 | its(:content) { is_expected.to include 'User=vault' } 71 | its(:content) { is_expected.to include 'Group=vault' } 72 | its(:content) { is_expected.to include 'ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json ' } 73 | its(:content) { is_expected.to match %r{Environment=GOMAXPROCS=\d+} } 74 | end 75 | describe command('systemctl list-units') do 76 | its(:stdout) { is_expected.to include 'vault.service' } 77 | end 78 | elsif fact('osfamily') == 'RedHat' 79 | if fact('operatingsystemmajrelease') == '6' 80 | describe file('/etc/init.d/vault') do 81 | it { is_expected.to be_file } 82 | it { is_expected.to be_mode 755 } 83 | it { is_expected.to be_owned_by 'root' } 84 | it { is_expected.to be_grouped_into 'root' } 85 | its(:content) { is_expected.to include 'daemon --user vault "{ $exec server -config=$conffile $OPTIONS &>> $logfile & }; echo \$! >| $pidfile"' } 86 | its(:content) { is_expected.to include 'conffile="/etc/vault/config.json"' } 87 | its(:content) { is_expected.to include 'exec="/usr/local/bin/vault"' } 88 | its(:content) { is_expected.to match %r{export GOMAXPROCS=\${GOMAXPROCS:-\d+}} } 89 | end 90 | end 91 | end 92 | 93 | describe file('/etc/vault') do 94 | it { is_expected.to be_directory } 95 | end 96 | 97 | describe file('/etc/vault/config.json') do 98 | it { is_expected.to be_file } 99 | its(:content) { is_expected.to include('"address": "127.0.0.1:8200"') } 100 | end 101 | 102 | describe service('vault') do 103 | it { is_expected.to be_enabled } 104 | it { is_expected.to be_running } 105 | end 106 | 107 | describe port(8200) do 108 | it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } 109 | end 110 | end 111 | end 112 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # Class: vault 2 | # =========================== 3 | # 4 | # Full description of class vault here. 5 | # 6 | # Parameters 7 | # ---------- 8 | # 9 | # * `user` 10 | # Customise the user vault runs as, will also create the user unless `manage_user` is false. 11 | # 12 | # * `manage_user` 13 | # Whether or not the module should create the user. 14 | # 15 | # * `group` 16 | # Customise the group vault runs as, will also create the user unless `manage_group` is false. 17 | # 18 | # * `manage_group` 19 | # Whether or not the module should create the group. 20 | # 21 | # * `bin_dir` 22 | # Directory the vault executable will be installed in. 23 | # 24 | # * `config_dir` 25 | # Directory the vault configuration will be kept in. 26 | # 27 | # * `config_mode` 28 | # Mode of the configuration file (config.json). Defaults to '0750' 29 | # 30 | # * `purge_config_dir` 31 | # Whether the `config_dir` should be purged before installing the 32 | # generated config. 33 | # 34 | # * `download_url` 35 | # Manual URL to download the vault zip distribution from. 36 | # 37 | # * `download_url_base` 38 | # Hashicorp base URL to download vault zip distribution from. 39 | # 40 | # * `download_extension` 41 | # The extension of the vault download 42 | # 43 | # * `service_name` 44 | # Customise the name of the system service 45 | # 46 | # * `service_provider` 47 | # Customise the name of the system service provider; this 48 | # also controls the init configuration files that are installed. 49 | # 50 | # * `service_options` 51 | # Extra argument to pass to `vault server`, as per: 52 | # `vault server --help` 53 | # 54 | # * `manage_repo` 55 | # Configure the upstream HashiCorp repository. Only relevant when $nomad::install_method = 'repo'. 56 | # 57 | # * `manage_service` 58 | # Instruct puppet to manage service or not 59 | # 60 | # * `num_procs` 61 | # Sets the GOMAXPROCS environment variable, to determine how many CPUs Vault 62 | # can use. The official Vault Terraform install.sh script sets this to the 63 | # output of ``nprocs``, with the comment, "Make sure to use all our CPUs, 64 | # because Vault can block a scheduler thread". Default: number of CPUs 65 | # on the system, retrieved from the ``processorcount`` Fact. 66 | # 67 | # * `api_addr` 68 | # Specifies the address (full URL) to advertise to other Vault servers in the 69 | # cluster for client redirection. This value is also used for plugin backends. 70 | # This can also be provided via the environment variable VAULT_API_ADDR. In 71 | # general this should be set as a full URL that points to the value of the 72 | # listener address 73 | # 74 | # * `version` 75 | # The version of Vault to install 76 | # 77 | class vault ( 78 | $user = $::vault::params::user, 79 | $manage_user = $::vault::params::manage_user, 80 | $group = $::vault::params::group, 81 | $manage_group = $::vault::params::manage_group, 82 | $bin_dir = $::vault::params::bin_dir, 83 | $config_dir = $::vault::params::config_dir, 84 | $manage_config_file = $::vault::params::manage_config_file, 85 | $config_mode = $::vault::params::config_mode, 86 | $purge_config_dir = true, 87 | $download_url = $::vault::params::download_url, 88 | $download_url_base = $::vault::params::download_url_base, 89 | $download_extension = $::vault::params::download_extension, 90 | $service_name = $::vault::params::service_name, 91 | $service_enable = $::vault::params::service_enable, 92 | $service_ensure = $::vault::params::service_ensure, 93 | $service_provider = $::vault::params::service_provider, 94 | Boolean $manage_repo = $::vault::params::manage_repo, 95 | $manage_service = $::vault::params::manage_service, 96 | $manage_service_file = $::vault::params::manage_service_file, 97 | Hash $storage = $::vault::params::storage, 98 | $manage_storage_dir = $::vault::params::manage_storage_dir, 99 | Variant[Hash, Array[Hash]] $listener = $::vault::params::listener, 100 | Optional[Hash] $ha_storage = $::vault::params::ha_storage, 101 | Optional[Hash] $seal = $::vault::params::seal, 102 | Optional[Boolean] $disable_cache = $::vault::params::disable_cache, 103 | Optional[Hash] $telemetry = $::vault::params::telemetry, 104 | Optional[String] $default_lease_ttl = $::vault::params::default_lease_ttl, 105 | Optional[String] $max_lease_ttl = $::vault::params::max_lease_ttl, 106 | $disable_mlock = $::vault::params::disable_mlock, 107 | $manage_file_capabilities = $::vault::params::manage_file_capabilities, 108 | $service_options = '', 109 | $num_procs = $::vault::params::num_procs, 110 | $install_method = $::vault::params::install_method, 111 | $package_name = $::vault::params::package_name, 112 | $package_ensure = $::vault::params::package_ensure, 113 | $download_dir = $::vault::params::download_dir, 114 | $manage_download_dir = $::vault::params::manage_download_dir, 115 | $download_filename = $::vault::params::download_filename, 116 | $version = $::vault::params::version, 117 | $os = $::vault::params::os, 118 | $arch = $::vault::params::arch, 119 | Optional[Boolean] $enable_ui = $::vault::params::enable_ui, 120 | Optional[String] $api_addr = undef, 121 | Hash $extra_config = {}, 122 | ) inherits ::vault::params { 123 | 124 | # lint:ignore:140chars 125 | $real_download_url = pick($download_url, "${download_url_base}${version}/${package_name}_${version}_${os}_${arch}.${download_extension}") 126 | # lint:endignore 127 | 128 | contain ::vault::install 129 | contain ::vault::config 130 | contain ::vault::service 131 | 132 | Class['vault::install'] -> Class['vault::config'] 133 | Class['vault::config'] ~> Class['vault::service'] 134 | 135 | } 136 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Puppet Forge](https://img.shields.io/puppetforge/v/jsok/vault.svg)](https://forge.puppetlabs.com/jsok/vault) 2 | [![Puppet Forge Downloads](https://img.shields.io/puppetforge/dt/jsok/vault.svg)](https://forge.puppetlabs.com/jsok/vault) 3 | 4 | # NOTICE 5 | 6 | :warning: This module is no longer maintained :warning: 7 | 8 | Users are encouraged to switch to the fork at https://github.com/voxpupuli/puppet-vault. 9 | 10 | # puppet-vault 11 | 12 | Puppet module to install and run [Hashicorp Vault](https://vaultproject.io). 13 | 14 | ## Support 15 | 16 | This module is currently only tested on: 17 | 18 | * Ubuntu 16.04 19 | * Ubuntu 18.04 20 | * CentOS/RedHat 6 21 | * CentOS/RedHat 7 22 | 23 | ## Usage 24 | 25 | ```puppet 26 | include vault 27 | ``` 28 | 29 | By default, with no parameters the module will configure vault with some sensible defaults to get you running, the following parameters may be specified to configure Vault. 30 | Please see [The official documentation](https://www.vaultproject.io/docs/configuration/index.html) for further details of acceptable parameter values. 31 | 32 | ## Parameters 33 | 34 | ### Setup parameters 35 | 36 | * `user`: Customise the user vault runs as, will also create the user unless `manage_user` is false. 37 | 38 | * `manage_user`: Whether or not the module should create the user. 39 | 40 | * `group`: Customise the group vault runs as, will also create the user unless `manage_group` is false. 41 | 42 | * `manage_group`: Whether or not the module should create the group. 43 | 44 | * `bin_dir`: Directory the vault executable will be installed in. 45 | 46 | * `config_dir`: Directory the vault configuration will be kept in. 47 | 48 | * `config_mode`: Mode of the configuration file (config.json). Defaults to '0750' 49 | 50 | * `purge_config_dir`: Whether the `config_dir` should be purged before installing the generated config. 51 | 52 | * `install_method`: Supports the values `repo` or `archive`. See [Installation parameters](#installation-parameters). 53 | 54 | * `service_name`: Customise the name of the system service 55 | 56 | * `service_enable`: Tell the OS to enable or disable the service at system startup 57 | 58 | * `service_ensure`: Tell the OS whether the service should be running or stopped 59 | 60 | * `service_provider`: Customise the name of the system service provider; this also controls the init configuration files that are installed. 61 | 62 | * `service_options`: Extra argument to pass to `vault server`, as per: `vault server --help` 63 | 64 | * `num_procs`: Sets the `GOMAXPROCS` environment variable, to determine how many CPUs Vault can use. The official Vault Terraform install.sh script sets this to the output of ``nprocs``, with the comment, "Make sure to use all our CPUs, because Vault can block a scheduler thread". Default: number of CPUs on the system, retrieved from the ``processorcount`` fact. 65 | 66 | * `manage_storage_dir`: When using the file storage, this boolean determines whether or not the path (as specified in the `['file']['path']` section of the storage config) is created, and the owner and group set to the vault user. Default: `false` 67 | 68 | * `manage_service_file`: Manages the service file regardless of the defaults. Default: See [Installation parameters](#installation-parameters). 69 | 70 | * `manage_config_file`: Manages the configuration file. When set to false, `config.json` will not be generated. `manag_storage_dir` is ignored. Default: `true` 71 | 72 | ### Installation parameters 73 | 74 | #### When `install_method` is `repo` 75 | 76 | When `repo` is set the module will attempt to install a package corresponding with the value of `package_name`. 77 | 78 | * `package_name`: Name of the package to install, default: `vault` 79 | * `package_ensure`: Desired state of the package, default: `installed` 80 | * `bin_dir`: Set to the path where the package will install the Vault binary, this is necessary to correctly manage the [`disable_mlock`](#mlock) option. 81 | * `manage_service_file`: Will manage the service file in case it's not included in the package, default: false 82 | * `manage_file_capabilities`: Will manage file capabilities of the vault binary. default: `false` 83 | 84 | #### When `install_method` is `archive` 85 | 86 | When `archive` the module will attempt to download and extract a zip file from the `download_url`, the extracted file will be placed in the `bin_dir` folder. 87 | The module will **not** manage any required packages to un-archive, e.g. `unzip`. See [`puppet-archive` setup](https://github.com/voxpupuli/puppet-archive#setup) documentation for more details. 88 | 89 | * `download_url`: Optional manual URL to download the vault zip distribution from. You can specify a local file on the server with a fully qualified pathname, or use `http`, `https`, `ftp` or `s3` based URI's. default: `undef` 90 | * `download_url_base`: This is the base URL for the hashicorp releases. If no manual `download_url` is specified, the module will download from hashicorp. default: `https://releases.hashicorp.com/vault/` 91 | * `download_extension`: The extension of the vault download when using hashicorp releases. default: `zip` 92 | * `download_dir`: Path to download the zip file to, default: `/tmp` 93 | * `manage_download_dir`: Boolean, whether or not to create the download directory, default: `false` 94 | * `download_filename`: Filename to (temporarily) save the downloaded zip file, default: `vault.zip` 95 | * `version`: The Version of vault to download. default: `1.4.2` 96 | * `manage_service_file`: Will manage the service file. default: true 97 | * `manage_file_capabilities`: Will manage file capabilities of the vault binary. default: `true` 98 | 99 | ### Configuration parameters 100 | 101 | By default, with no parameters the module will configure vault with some sensible defaults to get you running, the following parameters may be specified to configure Vault. Please see [The official documentation](https://www.vaultproject.io/docs/configuration/index.html) for further details of acceptable parameter values. 102 | 103 | * `storage`: A hash containing the Vault storage configuration. File and raft storage backends are supported. In the examples section you can find an example for raft. The file backend is the default: 104 | ``` 105 | { 'file' => { 'path' => '/var/lib/vault' }} 106 | ``` 107 | 108 | * `listener`: A hash or array of hashes containing the listener configuration(s), default: 109 | 110 | ``` 111 | { 112 | 'tcp' => { 113 | 'address' => '127.0.0.1:8200', 114 | 'tls_disable' => 1, 115 | } 116 | } 117 | ``` 118 | 119 | * `ha_storage`: An optional hash containing the `ha_storage` configuration 120 | 121 | * `seal`: An optional hash containing the `seal` configuration 122 | 123 | * `telemetry`: An optional hash containing the `telemetry` configuration 124 | 125 | * `disable_cache`: A boolean to disable or enable the cache (default: `undef`) 126 | 127 | * `disable_mlock`: A boolean to disable or enable mlock [See below](#mlock) (default: `undef`) 128 | 129 | * `default_lease_ttl`: A string containing the default lease TTL (default: `undef`) 130 | 131 | * `max_lease_ttl`: A string containing the max lease TTL (default: `undef`) 132 | 133 | * `enable_ui`: Enable the vault UI (requires vault 0.10.0+ or Enterprise) (default: `undef`) 134 | 135 | * `api_addr`: Specifies the address (full URL) to advertise to other Vault servers in the cluster for client redirection. This value is also used for plugin backends. This can also be provided via the environment variable VAULT_API_ADDR. In general this should be set as a full URL that points to the value of the listener address (default: `undef`) 136 | 137 | * `extra_config`: A hash containing extra configuration, intended for newly released configuration not yet supported by the module. This hash will get merged with other configuration attributes into the JSON config file. 138 | 139 | ## Examples 140 | 141 | ```puppet 142 | class { '::vault': 143 | storage => { 144 | file => { 145 | path => '/tmp', 146 | } 147 | }, 148 | listener => [ 149 | { 150 | tcp => { 151 | address => '127.0.0.1:8200', 152 | tls_disable => 0, 153 | } 154 | }, 155 | { 156 | tcp => { 157 | address => '10.0.0.10:8200', 158 | } 159 | } 160 | ] 161 | } 162 | ``` 163 | 164 | or alternatively using Hiera: 165 | 166 | ```yaml 167 | --- 168 | vault::storage: 169 | file: 170 | path: /tmp 171 | 172 | vault::listener: 173 | - tcp: 174 | address: 127.0.0.1:8200 175 | tls_disable: 1 176 | - tcp: 177 | address: 10.0.0.10:8200 178 | 179 | vault::default_lease_ttl: 720h 180 | ``` 181 | 182 | Configuring raft storage engine using Hiera: 183 | ```yaml 184 | vault::storage: 185 | raft: 186 | node_id: '%{facts.networking.hostname}' 187 | path: /var/lib/vault 188 | retry_join: 189 | - leader_api_addr: https://vault1:8200 190 | - leader_api_addr: https://vault2:8200 191 | - leader_api_addr: https://vault3:8200 192 | ``` 193 | 194 | ## mlock 195 | 196 | By default vault will use the `mlock` system call, therefore the executable will need the corresponding capability. 197 | 198 | In production, you should only consider setting the `disable_mlock` option on Linux systems that only use encrypted swap or do not use swap at all. 199 | 200 | The module will use `setcap` on the vault binary to enable this. 201 | If you do not wish to use `mlock`, set the `disable_mlock` attribute to `true` 202 | 203 | ```puppet 204 | class { '::vault': 205 | disable_mlock => true 206 | } 207 | ``` 208 | 209 | ## Testing 210 | 211 | First, ``bundle install`` 212 | 213 | To run RSpec unit tests: ``bundle exec rake spec`` 214 | 215 | To run RSpec unit tests, puppet-lint, syntax checks and metadata lint: ``bundle exec rake test`` 216 | 217 | To run Beaker acceptance tests: ``BEAKER_set= BEAKER_PUPPET_COLLECTION=puppet5 bundle exec rake acceptance`` 218 | where ```` is one of the filenames in ``spec/acceptance/nodesets`` without the trailing ``.yml``, 219 | e.g. `ubuntu-18.04-x86_64-docker`. 220 | 221 | ## Related Projects 222 | 223 | * [`hiera-vault`](https://github.com/jsok/hiera-vault): A Hiera storage backend to retrieve secrets from Hashicorp's Vault 224 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: rubocop-rspec 2 | AllCops: 3 | TargetRubyVersion: 2.5 4 | Include: 5 | - ./**/*.rb 6 | Exclude: 7 | - files/**/* 8 | - vendor/**/* 9 | - .vendor/**/* 10 | - pkg/**/* 11 | - spec/fixtures/**/* 12 | - Gemfile 13 | - Rakefile 14 | - Guardfile 15 | - Vagrantfile 16 | 17 | Layout/ConditionPosition: 18 | Enabled: True 19 | 20 | Lint/ElseLayout: 21 | Enabled: True 22 | 23 | Lint/UnreachableCode: 24 | Enabled: True 25 | 26 | Lint/UselessComparison: 27 | Enabled: True 28 | 29 | Lint/EnsureReturn: 30 | Enabled: True 31 | 32 | Lint/SuppressedException: 33 | Enabled: True 34 | 35 | Lint/ShadowingOuterLocalVariable: 36 | Enabled: True 37 | 38 | Lint/LiteralInInterpolation: 39 | Enabled: True 40 | 41 | Style/HashSyntax: 42 | Enabled: True 43 | 44 | Style/RedundantReturn: 45 | Enabled: True 46 | 47 | Layout/EndOfLine: 48 | Enabled: False 49 | 50 | Lint/AmbiguousOperator: 51 | Enabled: True 52 | 53 | Lint/AssignmentInCondition: 54 | Enabled: True 55 | 56 | Layout/SpaceBeforeComment: 57 | Enabled: True 58 | 59 | Style/AndOr: 60 | Enabled: True 61 | 62 | Style/RedundantSelf: 63 | Enabled: True 64 | 65 | Metrics/BlockLength: 66 | Enabled: False 67 | 68 | # Method length is not necessarily an indicator of code quality 69 | Metrics/MethodLength: 70 | Enabled: False 71 | 72 | # Module length is not necessarily an indicator of code quality 73 | Metrics/ModuleLength: 74 | Enabled: False 75 | 76 | Style/WhileUntilModifier: 77 | Enabled: True 78 | 79 | Lint/AmbiguousRegexpLiteral: 80 | Enabled: True 81 | 82 | Security/Eval: 83 | Enabled: True 84 | 85 | Layout/BlockAlignment: 86 | Enabled: True 87 | 88 | Layout/DefEndAlignment: 89 | Enabled: True 90 | 91 | Layout/EndAlignment: 92 | Enabled: True 93 | 94 | Lint/DeprecatedClassMethods: 95 | Enabled: True 96 | 97 | Lint/Loop: 98 | Enabled: True 99 | 100 | Lint/ParenthesesAsGroupedExpression: 101 | Enabled: True 102 | 103 | Lint/RescueException: 104 | Enabled: True 105 | 106 | Lint/RedundantStringCoercion: 107 | Enabled: True 108 | 109 | Lint/UnusedBlockArgument: 110 | Enabled: True 111 | 112 | Lint/UnusedMethodArgument: 113 | Enabled: True 114 | 115 | Lint/UselessAccessModifier: 116 | Enabled: True 117 | 118 | Lint/UselessAssignment: 119 | Enabled: True 120 | 121 | Lint/Void: 122 | Enabled: True 123 | 124 | Layout/AccessModifierIndentation: 125 | Enabled: True 126 | 127 | Naming/AccessorMethodName: 128 | Enabled: True 129 | 130 | Style/Alias: 131 | Enabled: True 132 | 133 | Layout/ArrayAlignment: 134 | Enabled: True 135 | 136 | Layout/HashAlignment: 137 | Enabled: True 138 | 139 | Layout/ParameterAlignment: 140 | Enabled: True 141 | 142 | Metrics/BlockNesting: 143 | Enabled: True 144 | 145 | Style/AsciiComments: 146 | Enabled: True 147 | 148 | Style/Attr: 149 | Enabled: True 150 | 151 | Style/CaseEquality: 152 | Enabled: True 153 | 154 | Layout/CaseIndentation: 155 | Enabled: True 156 | 157 | Style/CharacterLiteral: 158 | Enabled: True 159 | 160 | Naming/ClassAndModuleCamelCase: 161 | Enabled: True 162 | 163 | Style/ClassAndModuleChildren: 164 | Enabled: False 165 | 166 | Style/ClassCheck: 167 | Enabled: True 168 | 169 | # Class length is not necessarily an indicator of code quality 170 | Metrics/ClassLength: 171 | Enabled: False 172 | 173 | Style/ClassMethods: 174 | Enabled: True 175 | 176 | Style/ClassVars: 177 | Enabled: True 178 | 179 | Style/MixinUsage: 180 | Enabled: False 181 | 182 | Style/WhenThen: 183 | Enabled: True 184 | 185 | Style/WordArray: 186 | Enabled: True 187 | 188 | Style/RedundantPercentQ: 189 | Enabled: True 190 | 191 | Layout/IndentationStyle: 192 | Enabled: True 193 | 194 | Layout/SpaceBeforeSemicolon: 195 | Enabled: True 196 | 197 | Layout/TrailingEmptyLines: 198 | Enabled: True 199 | 200 | Layout/LeadingCommentSpace: 201 | Enabled: True 202 | 203 | Layout/SpaceBeforeFirstArg: 204 | Enabled: True 205 | 206 | Layout/SpaceAfterColon: 207 | Enabled: True 208 | 209 | Layout/SpaceAfterComma: 210 | Enabled: True 211 | 212 | Layout/SpaceAfterMethodName: 213 | Enabled: True 214 | 215 | Layout/SpaceAfterNot: 216 | Enabled: True 217 | 218 | Layout/SpaceAfterSemicolon: 219 | Enabled: True 220 | 221 | Layout/SpaceAroundEqualsInParameterDefault: 222 | Enabled: True 223 | 224 | Layout/SpaceAroundOperators: 225 | Enabled: True 226 | 227 | Layout/SpaceBeforeBlockBraces: 228 | Enabled: True 229 | 230 | Layout/SpaceBeforeComma: 231 | Enabled: True 232 | 233 | Style/CollectionMethods: 234 | Enabled: True 235 | 236 | Layout/CommentIndentation: 237 | Enabled: True 238 | 239 | Style/ColonMethodCall: 240 | Enabled: True 241 | 242 | Style/CommentAnnotation: 243 | Enabled: True 244 | 245 | # 'Complexity' is very relative 246 | Metrics/CyclomaticComplexity: 247 | Enabled: False 248 | 249 | Naming/ConstantName: 250 | Enabled: True 251 | 252 | Style/Documentation: 253 | Enabled: False 254 | 255 | Style/DefWithParentheses: 256 | Enabled: True 257 | 258 | Style/PreferredHashMethods: 259 | Enabled: True 260 | 261 | Layout/DotPosition: 262 | EnforcedStyle: trailing 263 | 264 | Style/DoubleNegation: 265 | Enabled: True 266 | 267 | Style/EachWithObject: 268 | Enabled: True 269 | 270 | Layout/EmptyLineBetweenDefs: 271 | Enabled: True 272 | 273 | Layout/FirstArrayElementIndentation: 274 | Enabled: True 275 | 276 | Layout/FirstHashElementIndentation: 277 | Enabled: True 278 | 279 | Layout/IndentationConsistency: 280 | Enabled: True 281 | 282 | Layout/IndentationWidth: 283 | Enabled: True 284 | 285 | Layout/EmptyLines: 286 | Enabled: True 287 | 288 | Layout/EmptyLinesAroundAccessModifier: 289 | Enabled: True 290 | 291 | Style/EmptyLiteral: 292 | Enabled: True 293 | 294 | # Configuration parameters: AllowURI, URISchemes. 295 | Metrics/LineLength: 296 | Enabled: False 297 | 298 | Style/MethodCallWithoutArgsParentheses: 299 | Enabled: True 300 | 301 | Style/MethodDefParentheses: 302 | Enabled: True 303 | 304 | Style/LineEndConcatenation: 305 | Enabled: True 306 | 307 | Layout/TrailingWhitespace: 308 | Enabled: True 309 | 310 | Style/StringLiterals: 311 | Enabled: True 312 | 313 | Style/TrailingCommaInArguments: 314 | Enabled: True 315 | 316 | Style/TrailingCommaInArrayLiteral: 317 | Enabled: True 318 | 319 | Style/TrailingCommaInHashLiteral: 320 | Enabled: True 321 | 322 | Style/GlobalVars: 323 | Enabled: True 324 | 325 | Style/GuardClause: 326 | Enabled: True 327 | 328 | Style/IfUnlessModifier: 329 | Enabled: True 330 | 331 | Style/MultilineIfThen: 332 | Enabled: True 333 | 334 | Style/NegatedIf: 335 | Enabled: True 336 | 337 | Style/NegatedWhile: 338 | Enabled: True 339 | 340 | Style/Next: 341 | Enabled: True 342 | 343 | Style/SingleLineBlockParams: 344 | Enabled: True 345 | 346 | Style/SingleLineMethods: 347 | Enabled: True 348 | 349 | Style/SpecialGlobalVars: 350 | Enabled: True 351 | 352 | Style/TrivialAccessors: 353 | Enabled: True 354 | 355 | Style/UnlessElse: 356 | Enabled: True 357 | 358 | Style/VariableInterpolation: 359 | Enabled: True 360 | 361 | Naming/VariableName: 362 | Enabled: True 363 | 364 | Style/WhileUntilDo: 365 | Enabled: True 366 | 367 | Style/EvenOdd: 368 | Enabled: True 369 | 370 | Naming/FileName: 371 | Enabled: True 372 | 373 | Style/For: 374 | Enabled: True 375 | 376 | Style/Lambda: 377 | Enabled: True 378 | 379 | Naming/MethodName: 380 | Enabled: True 381 | 382 | Style/MultilineTernaryOperator: 383 | Enabled: True 384 | 385 | Style/NestedTernaryOperator: 386 | Enabled: True 387 | 388 | Style/NilComparison: 389 | Enabled: True 390 | 391 | Style/FormatString: 392 | Enabled: True 393 | 394 | Style/MultilineBlockChain: 395 | Enabled: True 396 | 397 | Style/Semicolon: 398 | Enabled: True 399 | 400 | Style/SignalException: 401 | Enabled: True 402 | 403 | Style/NonNilCheck: 404 | Enabled: True 405 | 406 | Style/Not: 407 | Enabled: True 408 | 409 | Style/NumericLiterals: 410 | Enabled: True 411 | 412 | Style/OneLineConditional: 413 | Enabled: True 414 | 415 | Naming/BinaryOperatorParameterName: 416 | Enabled: True 417 | 418 | Style/ParenthesesAroundCondition: 419 | Enabled: True 420 | 421 | Style/PercentLiteralDelimiters: 422 | Enabled: True 423 | 424 | Style/PerlBackrefs: 425 | Enabled: True 426 | 427 | Naming/PredicateName: 428 | Enabled: True 429 | 430 | Style/RedundantException: 431 | Enabled: True 432 | 433 | Style/SelfAssignment: 434 | Enabled: True 435 | 436 | Style/Proc: 437 | Enabled: True 438 | 439 | Style/RaiseArgs: 440 | Enabled: True 441 | 442 | Style/RedundantBegin: 443 | Enabled: True 444 | 445 | Style/RescueModifier: 446 | Enabled: True 447 | 448 | # based on https://github.com/voxpupuli/modulesync_config/issues/168 449 | Style/RegexpLiteral: 450 | EnforcedStyle: percent_r 451 | Enabled: True 452 | 453 | Lint/UnderscorePrefixedVariableName: 454 | Enabled: True 455 | 456 | Metrics/ParameterLists: 457 | Enabled: False 458 | 459 | Lint/RequireParentheses: 460 | Enabled: True 461 | 462 | Style/ModuleFunction: 463 | Enabled: True 464 | 465 | Lint/Debugger: 466 | Enabled: True 467 | 468 | Style/IfWithSemicolon: 469 | Enabled: True 470 | 471 | Style/Encoding: 472 | Enabled: True 473 | 474 | Style/BlockDelimiters: 475 | Enabled: True 476 | 477 | Layout/MultilineBlockLayout: 478 | Enabled: True 479 | 480 | # 'Complexity' is very relative 481 | Metrics/AbcSize: 482 | Enabled: False 483 | 484 | # 'Complexity' is very relative 485 | Metrics/PerceivedComplexity: 486 | Enabled: False 487 | 488 | Layout/ClosingParenthesisIndentation: 489 | Enabled: True 490 | 491 | # RSpec 492 | 493 | RSpec/BeforeAfterAll: 494 | Exclude: 495 | - spec/acceptance/**/* 496 | 497 | # We don't use rspec in this way 498 | RSpec/DescribeClass: 499 | Enabled: False 500 | 501 | # Example length is not necessarily an indicator of code quality 502 | RSpec/ExampleLength: 503 | Enabled: False 504 | 505 | RSpec/NamedSubject: 506 | Enabled: False 507 | 508 | # disabled for now since they cause a lot of issues 509 | # these issues aren't easy to fix 510 | RSpec/RepeatedDescription: 511 | Enabled: False 512 | 513 | RSpec/NestedGroups: 514 | Enabled: False 515 | 516 | RSpec/ContextWording: 517 | Enabled: False 518 | 519 | # this is broken on ruby1.9 520 | Layout/HeredocIndentation: 521 | Enabled: False 522 | 523 | # disable Yaml safe_load. This is needed to support ruby2.0.0 development envs 524 | Security/YAMLLoad: 525 | Enabled: false 526 | 527 | # This affects hiera interpolation, as well as some configs that we push. 528 | Style/FormatStringToken: 529 | Enabled: false 530 | 531 | # This is useful, but sometimes a little too picky about where unit tests files 532 | # are located. 533 | RSpec/FilePath: 534 | Enabled: false 535 | 536 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /spec/classes/vault_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'vault' do 4 | let :node do 5 | 'agent.example.com' 6 | end 7 | 8 | on_supported_os.each do |os, facts| 9 | context "on #{os} " do 10 | let :facts do 11 | facts.merge(service_provider: 'init', processorcount: 3) 12 | end 13 | 14 | context 'vault class with simple configuration' do 15 | let(:params) do 16 | { 17 | storage: { 18 | 'file' => { 19 | 'path' => '/data/vault' 20 | } 21 | }, 22 | listener: { 23 | 'tcp' => { 24 | 'address' => '127.0.0.1:8200', 25 | 'tls_disable' => 1 26 | } 27 | } 28 | } 29 | end 30 | 31 | it { is_expected.to compile.with_all_deps } 32 | it { is_expected.to contain_class('vault') } 33 | 34 | it { is_expected.to contain_class('vault::params') } 35 | it { is_expected.to contain_class('vault::install').that_comes_before('Class[vault::config]') } 36 | it { is_expected.to contain_class('vault::config') } 37 | it { is_expected.to contain_class('vault::service').that_subscribes_to('Class[vault::config]') } 38 | 39 | it { 40 | is_expected.to contain_service('vault'). 41 | with_ensure('running'). 42 | with_enable(true) 43 | } 44 | it { is_expected.to contain_user('vault') } 45 | it { is_expected.to contain_group('vault') } 46 | it { is_expected.not_to contain_file('/data/vault') } 47 | 48 | context 'when not managing user and group' do 49 | let(:params) do 50 | { 51 | manage_user: false, 52 | manage_group: false 53 | } 54 | end 55 | 56 | it { is_expected.not_to contain_user('vault') } 57 | it { is_expected.not_to contain_group('vault') } 58 | end 59 | 60 | it { 61 | is_expected.to contain_file('/etc/vault'). 62 | with_ensure('directory'). 63 | with_purge('true'). 64 | with_recurse('true'). 65 | with_owner('vault'). 66 | with_group('vault') 67 | } 68 | it { 69 | is_expected.to contain_file('/etc/vault/config.json'). 70 | with_owner('vault'). 71 | with_group('vault') 72 | } 73 | 74 | context 'vault JSON config' do 75 | subject { param_value(catalogue, 'File', '/etc/vault/config.json', 'content') } 76 | 77 | it { 78 | is_expected.to include_json( 79 | storage: { 80 | file: { 81 | path: '/data/vault' 82 | } 83 | } 84 | ) 85 | } 86 | it { 87 | is_expected.to include_json( 88 | listener: { 89 | tcp: { 90 | address: '127.0.0.1:8200', 91 | tls_disable: 1 92 | } 93 | } 94 | ) 95 | } 96 | it 'excludes unconfigured config options' do 97 | expect(subject).not_to include_json( 98 | ha_storage: exist, 99 | seal: exist, 100 | disable_cache: exist, 101 | telemetry: exist, 102 | default_lease_ttl: exist, 103 | max_lease_ttl: exist, 104 | disable_mlock: exist, 105 | ui: exist, 106 | api_addr: exist 107 | ) 108 | end 109 | end 110 | 111 | it { is_expected.to contain_file('vault_binary').with_mode('0755') } 112 | 113 | context 'when disable mlock' do 114 | let(:params) do 115 | { 116 | disable_mlock: true 117 | } 118 | end 119 | 120 | it { is_expected.not_to contain_file_capability('vault_binary_capability') } 121 | 122 | it { 123 | expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json( 124 | disable_mlock: true 125 | ) 126 | } 127 | end 128 | 129 | context 'when api address is set' do 130 | let(:params) do 131 | { 132 | api_addr: 'something' 133 | } 134 | end 135 | 136 | 137 | it { 138 | expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json( 139 | api_addr: 'something' 140 | ) 141 | } 142 | end 143 | 144 | context 'when installed from archive' do 145 | let(:params) { { install_method: 'archive' } } 146 | 147 | it { 148 | is_expected.to contain_archive('/tmp/vault.zip'). 149 | that_comes_before('File[vault_binary]') 150 | } 151 | 152 | context 'when installed with default download options' do 153 | let(:params) do 154 | super().merge(version: '0.7.0') 155 | end 156 | 157 | it { 158 | is_expected.to contain_archive('/tmp/vault.zip'). 159 | with_source('https://releases.hashicorp.com/vault/0.7.0/vault_0.7.0_linux_amd64.zip') 160 | } 161 | end 162 | 163 | context 'when specifying a custom download params' do 164 | let(:params) do 165 | super().merge( 166 | version: '0.6.0', 167 | download_url_base: 'http://my_site.example.com/vault/', 168 | package_name: 'vaultbinary', 169 | download_extension: 'tar.gz' 170 | ) 171 | end 172 | 173 | it { 174 | is_expected.to contain_archive('/tmp/vault.zip'). 175 | with_source('http://my_site.example.com/vault/0.6.0/vaultbinary_0.6.0_linux_amd64.tar.gz') 176 | } 177 | end 178 | 179 | context 'when installed from download url' do 180 | let(:params) do 181 | super().merge(download_url: 'http://example.com/vault.zip') 182 | end 183 | 184 | it { 185 | is_expected.to contain_archive('/tmp/vault.zip'). 186 | with_source('http://example.com/vault.zip') 187 | } 188 | end 189 | 190 | it { 191 | is_expected.to contain_file_capability('vault_binary_capability'). 192 | with_ensure('present'). 193 | with_capability('cap_ipc_lock=ep'). 194 | that_subscribes_to('File[vault_binary]') 195 | } 196 | 197 | context 'when not managing file capabilities' do 198 | let(:params) { { manage_file_capabilities: false } } 199 | 200 | it { is_expected.not_to contain_file_capability('vault_binary_capability') } 201 | end 202 | end 203 | 204 | context "When asked not to manage the repo" do 205 | let(:params) {{ 206 | :manage_repo => false 207 | }} 208 | 209 | case facts[:os]['family'] 210 | when 'Debian' 211 | it { should_not contain_apt__source('HashiCorp') } 212 | when 'RedHat' 213 | it { should_not contain_yumrepo('HashiCorp') } 214 | end 215 | end 216 | 217 | context "When asked to manage the repo but not to install using repo" do 218 | let(:params) {{ 219 | :install_method => 'archive', 220 | :manage_repo => true 221 | }} 222 | 223 | case facts[:os]['family'] 224 | when 'Debian' 225 | it { should_not contain_apt__source('HashiCorp') } 226 | when 'RedHat' 227 | it { should_not contain_yumrepo('HashiCorp') } 228 | end 229 | end 230 | 231 | context "When asked to manage the repo and to install as repo" do 232 | let(:params) {{ 233 | :install_method => 'repo', 234 | :manage_repo => true 235 | }} 236 | 237 | case facts[:os]['family'] 238 | when 'Debian' 239 | it { should contain_apt__source('HashiCorp') } 240 | when 'RedHat' 241 | it { should contain_yumrepo('HashiCorp') } 242 | end 243 | end 244 | 245 | context 'when installed from package repository' do 246 | let(:params) do 247 | { 248 | install_method: 'repo', 249 | package_name: 'vault', 250 | package_ensure: 'installed' 251 | } 252 | end 253 | 254 | it { is_expected.to contain_package('vault') } 255 | it { is_expected.not_to contain_file_capability('vault_binary_capability') } 256 | 257 | context 'when managing file capabilities' do 258 | let(:params) do 259 | super().merge( 260 | manage_file_capabilities: true, 261 | ) 262 | end 263 | 264 | it { is_expected.to contain_file_capability('vault_binary_capability') } 265 | it { is_expected.to contain_package('vault').that_notifies(['File_capability[vault_binary_capability]']) } 266 | end 267 | end 268 | end 269 | 270 | context 'when specifying ui to be true' do 271 | let(:params) do 272 | { 273 | enable_ui: true 274 | } 275 | end 276 | 277 | it { 278 | expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json( 279 | ui: true 280 | ) 281 | } 282 | end 283 | 284 | context 'when specifying config mode' do 285 | let(:params) do 286 | { 287 | config_mode: '0700' 288 | } 289 | end 290 | 291 | it { is_expected.to contain_file('/etc/vault/config.json').with_mode('0700') } 292 | end 293 | 294 | context 'when specifying an array of listeners' do 295 | let(:params) do 296 | { 297 | listener: [ 298 | { 'tcp' => { 'address' => '127.0.0.1:8200' } }, 299 | { 'tcp' => { 'address' => '0.0.0.0:8200' } } 300 | ] 301 | } 302 | end 303 | 304 | it { 305 | expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json( 306 | listener: [ 307 | { 308 | tcp: { 309 | address: '127.0.0.1:8200' 310 | } 311 | }, 312 | { 313 | tcp: { 314 | address: '0.0.0.0:8200' 315 | } 316 | } 317 | ] 318 | ) 319 | } 320 | end 321 | 322 | context 'when specifying manage_service' do 323 | let(:params) do 324 | { 325 | manage_service: false, 326 | storage: { 327 | 'file' => { 328 | 'path' => '/data/vault' 329 | } 330 | } 331 | } 332 | end 333 | 334 | it { 335 | is_expected.not_to contain_service('vault'). 336 | with_ensure('running'). 337 | with_enable(true) 338 | } 339 | end 340 | 341 | context 'when specifying manage_storage_dir and file storage backend' do 342 | let(:params) do 343 | { 344 | manage_storage_dir: true, 345 | storage: { 346 | 'file' => { 347 | 'path' => '/data/vault' 348 | } 349 | } 350 | } 351 | end 352 | 353 | it { 354 | is_expected.to contain_file('/data/vault'). 355 | with_ensure('directory'). 356 | with_owner('vault'). 357 | with_group('vault') 358 | } 359 | end 360 | 361 | context 'when specifying manage_storage_dir and raft storage backend' do 362 | let(:params) do 363 | { 364 | manage_storage_dir: true, 365 | storage: { 366 | 'raft' => { 367 | 'path' => '/data/vault' 368 | } 369 | } 370 | } 371 | end 372 | 373 | it { 374 | is_expected.to contain_file('/data/vault'). 375 | with_ensure('directory'). 376 | with_owner('vault'). 377 | with_group('vault') 378 | } 379 | end 380 | 381 | context 'when specifying manage_config_file = false' do 382 | let(:params) do 383 | { 384 | manage_config_file: false, 385 | } 386 | end 387 | 388 | it { 389 | is_expected.not_to contain_file ('/etc/vault/config.json') 390 | } 391 | end 392 | 393 | context 'when ensuring the service is disabled' do 394 | let(:params) do 395 | { 396 | service_enable: false, 397 | service_ensure: 'stopped' 398 | } 399 | end 400 | 401 | it { 402 | is_expected.to contain_service('vault'). 403 | with_ensure('stopped'). 404 | with_enable(false) 405 | } 406 | end 407 | 408 | case facts[:os]['family'] 409 | when 'RedHat' 410 | case facts[:os]['release']['major'].to_i 411 | when 2017 412 | context 'RedHat 7 Amazon Linux specific' do 413 | let facts do 414 | facts.merge(service_provider: 'sysv', grocessorcount: 3) 415 | end 416 | 417 | context 'includes SysV init script' do 418 | it { 419 | is_expected.to contain_file('/etc/init.d/vault'). 420 | with_mode('0755'). 421 | with_ensure('file'). 422 | with_owner('root'). 423 | with_group('root'). 424 | with_content(%r{^#!/bin/sh}). 425 | with_content(%r{export GOMAXPROCS=\${GOMAXPROCS:-3}}). 426 | with_content(%r{OPTIONS=\$OPTIONS:-""}). 427 | with_content(%r{exec="/usr/local/bin/vault"}). 428 | with_content(%r{conffile="/etc/vault/config.json"}). 429 | with_content(%r{chown vault \$logfile \$pidfile}) 430 | } 431 | end 432 | context 'service with non-default options' do 433 | let(:params) do 434 | { 435 | bin_dir: '/opt/bin', 436 | config_dir: '/opt/etc/vault', 437 | service_options: '-log-level=info', 438 | user: 'root', 439 | group: 'admin', 440 | num_procs: '5' 441 | } 442 | end 443 | 444 | it { 445 | is_expected.to contain_file('/etc/init.d/vault'). 446 | with_mode('0755'). 447 | with_ensure('file'). 448 | with_owner('root'). 449 | with_group('root'). 450 | with_content(%r{^#!/bin/sh}). 451 | with_content(%r{export GOMAXPROCS=\${GOMAXPROCS:-5}}). 452 | with_content(%r{OPTIONS=\$OPTIONS:-"-log-level=info"}). 453 | with_content(%r{exec="/opt/bin/vault"}). 454 | with_content(%r{conffile="/opt/etc/vault/config.json"}). 455 | with_content(%r{chown root \$logfile \$pidfile}) 456 | } 457 | end 458 | context 'does not include systemd magic' do 459 | it { is_expected.not_to contain_class('systemd') } 460 | end 461 | context 'install through repo with default service management' do 462 | let(:params) do 463 | { 464 | install_method: 'repo', 465 | manage_service_file: :undef 466 | } 467 | end 468 | 469 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 470 | end 471 | context 'install through repo without service management' do 472 | let(:params) do 473 | { 474 | install_method: 'repo', 475 | manage_service_file: false 476 | } 477 | end 478 | 479 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 480 | end 481 | context 'install through repo with service management' do 482 | let(:params) do 483 | { 484 | install_method: 'repo', 485 | manage_service_file: true 486 | } 487 | end 488 | 489 | it { is_expected.to contain_file('/etc/init.d/vault') } 490 | end 491 | 492 | context 'install through archive with default service management' do 493 | let(:params) do 494 | { 495 | install_method: 'archive', 496 | manage_service_file: :undef 497 | } 498 | end 499 | 500 | it { is_expected.to contain_file('/etc/init.d/vault') } 501 | end 502 | context 'install through archive without service management' do 503 | let(:params) do 504 | { 505 | install_method: 'archive', 506 | manage_service_file: false 507 | } 508 | end 509 | 510 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 511 | end 512 | context 'install through archive with service management' do 513 | let(:params) do 514 | { 515 | install_method: 'archive', 516 | manage_service_file: true 517 | } 518 | end 519 | 520 | it { is_expected.to contain_file('/etc/init.d/vault') } 521 | end 522 | end 523 | when 6 524 | context 'RedHat 6 specific' do 525 | let :facts do 526 | facts.merge(service_provider: 'sysv', processorcount: 3) 527 | end 528 | 529 | context 'includes SysV init script' do 530 | it { 531 | is_expected.to contain_file('/etc/init.d/vault'). 532 | with_mode('0755'). 533 | with_ensure('file'). 534 | with_owner('root'). 535 | with_group('root'). 536 | with_content(%r{^#!/bin/sh}). 537 | with_content(%r{export GOMAXPROCS=\${GOMAXPROCS:-3}}). 538 | with_content(%r{OPTIONS=\$OPTIONS:-""}). 539 | with_content(%r{exec="/usr/local/bin/vault"}). 540 | with_content(%r{conffile="/etc/vault/config.json"}). 541 | with_content(%r{chown vault \$logfile \$pidfile}) 542 | } 543 | end 544 | context 'service with non-default options' do 545 | let(:params) do 546 | { 547 | bin_dir: '/opt/bin', 548 | config_dir: '/opt/etc/vault', 549 | service_options: '-log-level=info', 550 | user: 'root', 551 | group: 'admin', 552 | num_procs: '5' 553 | } 554 | end 555 | 556 | it { 557 | is_expected.to contain_file('/etc/init.d/vault'). 558 | with_mode('0755'). 559 | with_ensure('file'). 560 | with_owner('root'). 561 | with_group('root'). 562 | with_content(%r{^#!/bin/sh}). 563 | with_content(%r{export GOMAXPROCS=\${GOMAXPROCS:-5}}). 564 | with_content(%r{OPTIONS=\$OPTIONS:-"-log-level=info"}). 565 | with_content(%r{exec="/opt/bin/vault"}). 566 | with_content(%r{conffile="/opt/etc/vault/config.json"}). 567 | with_content(%r{chown root \$logfile \$pidfile}) 568 | } 569 | end 570 | context 'does not include systemd magic' do 571 | it { is_expected.not_to contain_class('systemd') } 572 | end 573 | context 'install through repo with default service management' do 574 | let(:params) do 575 | { 576 | install_method: 'repo', 577 | manage_service_file: :undef 578 | } 579 | end 580 | 581 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 582 | end 583 | context 'install through repo without service management' do 584 | let(:params) do 585 | { 586 | install_method: 'repo', 587 | manage_service_file: false 588 | } 589 | end 590 | 591 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 592 | end 593 | context 'install through repo with service management' do 594 | let(:params) do 595 | { 596 | install_method: 'repo', 597 | manage_service_file: true 598 | } 599 | end 600 | 601 | it { is_expected.to contain_file('/etc/init.d/vault') } 602 | end 603 | 604 | context 'install through archive with default service management' do 605 | let(:params) do 606 | { 607 | install_method: 'archive', 608 | manage_service_file: :undef 609 | } 610 | end 611 | 612 | it { is_expected.to contain_file('/etc/init.d/vault') } 613 | end 614 | context 'install through archive without service management' do 615 | let(:params) do 616 | { 617 | install_method: 'archive', 618 | manage_service_file: false 619 | } 620 | end 621 | 622 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 623 | end 624 | context 'install through archive with service management' do 625 | let(:params) do 626 | { 627 | install_method: 'archive', 628 | manage_service_file: true 629 | } 630 | end 631 | 632 | it { is_expected.to contain_file('/etc/init.d/vault') } 633 | end 634 | end 635 | when 7 636 | context 'RedHat >=7 specific' do 637 | let :facts do 638 | facts.merge(service_provider: 'systemd', processorcount: 3) 639 | end 640 | 641 | context 'includes systemd init script' do 642 | it { 643 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 644 | with_mode('0444'). 645 | with_ensure('file'). 646 | with_owner('root'). 647 | with_group('root'). 648 | with_content(%r{^# vault systemd unit file}). 649 | with_content(%r{^User=vault$}). 650 | with_content(%r{^Group=vault$}). 651 | with_content(%r{Environment=GOMAXPROCS=3}). 652 | with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $}). 653 | with_content(%r{SecureBits=keep-caps}). 654 | with_content(%r{Capabilities=CAP_IPC_LOCK\+ep}). 655 | with_content(%r{CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK}). 656 | with_content(%r{NoNewPrivileges=yes}) 657 | } 658 | end 659 | context 'service with non-default options' do 660 | let(:params) do 661 | { 662 | bin_dir: '/opt/bin', 663 | config_dir: '/opt/etc/vault', 664 | service_options: '-log-level=info', 665 | user: 'root', 666 | group: 'admin', 667 | num_procs: 8 668 | } 669 | end 670 | 671 | it { 672 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 673 | with_mode('0444'). 674 | with_ensure('file'). 675 | with_owner('root'). 676 | with_group('root'). 677 | with_content(%r{^# vault systemd unit file}). 678 | with_content(%r{^User=root$}). 679 | with_content(%r{^Group=admin$}). 680 | with_content(%r{Environment=GOMAXPROCS=8}). 681 | with_content(%r{^ExecStart=/opt/bin/vault server -config=/opt/etc/vault/config.json -log-level=info$}) 682 | } 683 | end 684 | context 'with mlock disabled' do 685 | let(:params) do 686 | { disable_mlock: true } 687 | end 688 | 689 | it { 690 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 691 | with_mode('0444'). 692 | with_ensure('file'). 693 | with_owner('root'). 694 | with_group('root'). 695 | with_content(%r{^# vault systemd unit file}). 696 | with_content(%r{^User=vault$}). 697 | with_content(%r{^Group=vault$}). 698 | with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $}). 699 | without_content(%r{SecureBits=keep-caps}). 700 | without_content(%r{Capabilities=CAP_IPC_LOCK\+ep}). 701 | with_content(%r{CapabilityBoundingSet=CAP_SYSLOG}). 702 | with_content(%r{NoNewPrivileges=yes}) 703 | } 704 | end 705 | context 'includes systemd magic' do 706 | it { is_expected.to contain_class('systemd') } 707 | end 708 | context 'install through repo with default service management' do 709 | let(:params) do 710 | { 711 | install_method: 'repo', 712 | manage_service_file: :undef 713 | } 714 | end 715 | 716 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 717 | end 718 | context 'install through repo without service management' do 719 | let(:params) do 720 | { 721 | install_method: 'repo', 722 | manage_service_file: false 723 | } 724 | end 725 | 726 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 727 | end 728 | context 'install through repo with service management' do 729 | let(:params) do 730 | { 731 | install_method: 'repo', 732 | manage_service_file: true 733 | } 734 | end 735 | 736 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 737 | end 738 | 739 | context 'install through archive with default service management' do 740 | let(:params) do 741 | { 742 | install_method: 'archive', 743 | manage_service_file: :undef 744 | } 745 | end 746 | 747 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 748 | end 749 | context 'install through archive without service management' do 750 | let(:params) do 751 | { 752 | install_method: 'archive', 753 | manage_service_file: false 754 | } 755 | end 756 | 757 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 758 | end 759 | context 'install through archive with service management' do 760 | let(:params) do 761 | { 762 | install_method: 'archive', 763 | manage_service_file: true 764 | } 765 | end 766 | 767 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 768 | end 769 | end 770 | end 771 | when 'Debian' 772 | context 'on Debian OS family' do 773 | context 'with upstart' do 774 | let :facts do 775 | facts.merge(service_provider: 'upstart', processorcount: 3) 776 | end 777 | 778 | context 'includes init link to upstart-job' do 779 | it { 780 | is_expected.to contain_file('/etc/init.d/vault'). 781 | with_ensure('link'). 782 | with_target('/lib/init/upstart-job'). 783 | with_mode('0755') 784 | } 785 | end 786 | context 'contains /etc/init/vault.conf' do 787 | it { 788 | is_expected.to contain_file('/etc/init/vault.conf'). 789 | with_mode('0444'). 790 | with_ensure('file'). 791 | with_owner('root'). 792 | with_group('root'). 793 | with_content(%r{^# vault Agent \(Upstart unit\)}). 794 | with_content(%r{env USER=vault}). 795 | with_content(%r{env GROUP=vault}). 796 | with_content(%r{env CONFIG=\/etc\/vault\/config.json}). 797 | with_content(%r{env VAULT=\/usr\/local\/bin\/vault}). 798 | with_content(%r{exec start-stop-daemon -u \$USER -g \$GROUP -p \$PID_FILE -x \$VAULT -S -- server -config=\$CONFIG $}). 799 | with_content(%r{export GOMAXPROCS=\${GOMAXPROCS:-3}}) 800 | } 801 | end 802 | end 803 | context 'service with modified options and sysv init' do 804 | let :facts do 805 | facts.merge(service_provider: 'init') 806 | end 807 | let(:params) do 808 | { 809 | bin_dir: '/opt/bin', 810 | config_dir: '/opt/etc/vault', 811 | service_options: '-log-level=info', 812 | user: 'root', 813 | group: 'admin' 814 | } 815 | end 816 | 817 | it { is_expected.to contain_file('vault_binary').with_path('/opt/bin/vault') } 818 | it { 819 | is_expected.to contain_file_capability('vault_binary_capability'). 820 | with_file('/opt/bin/vault') 821 | } 822 | 823 | it { is_expected.to contain_file('/opt/etc/vault/config.json') } 824 | 825 | it { 826 | is_expected.to contain_file('/opt/etc/vault'). 827 | with_ensure('directory'). 828 | with_purge('true'). \ 829 | with_recurse('true') 830 | } 831 | it { is_expected.to contain_user('root') } 832 | it { is_expected.to contain_group('admin') } 833 | end 834 | context 'install through repo with default service management' do 835 | let(:params) do 836 | { 837 | install_method: 'repo', 838 | manage_service_file: :undef 839 | } 840 | end 841 | 842 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 843 | end 844 | context 'install through repo without service management' do 845 | let(:params) do 846 | { 847 | install_method: 'repo', 848 | manage_service_file: false 849 | } 850 | end 851 | 852 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 853 | end 854 | context 'install through repo with service management' do 855 | let(:params) do 856 | { 857 | install_method: 'repo', 858 | manage_service_file: true 859 | } 860 | end 861 | 862 | it { is_expected.to contain_file('/etc/init.d/vault') } 863 | end 864 | 865 | context 'install through archive with default service management' do 866 | let(:params) do 867 | { 868 | install_method: 'archive', 869 | manage_service_file: :undef 870 | } 871 | end 872 | 873 | it { is_expected.to contain_file('/etc/init.d/vault') } 874 | end 875 | context 'install through archive without service management' do 876 | let(:params) do 877 | { 878 | install_method: 'archive', 879 | manage_service_file: false 880 | } 881 | end 882 | 883 | it { is_expected.not_to contain_file('/etc/init.d/vault') } 884 | end 885 | context 'install through archive with service management' do 886 | let(:params) do 887 | { 888 | install_method: 'archive', 889 | manage_service_file: true 890 | } 891 | end 892 | 893 | it { is_expected.to contain_file('/etc/init.d/vault') } 894 | end 895 | context 'on Debian based with systemd' do 896 | let :facts do 897 | facts.merge(service_provider: 'systemd', processorcount: 3) 898 | end 899 | 900 | context 'includes systemd init script' do 901 | it { 902 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 903 | with_mode('0444'). 904 | with_ensure('file'). 905 | with_owner('root'). 906 | with_group('root'). 907 | with_content(%r{^# vault systemd unit file}). 908 | with_content(%r{^User=vault$}). 909 | with_content(%r{^Group=vault$}). 910 | with_content(%r{Environment=GOMAXPROCS=3}). 911 | with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $}). 912 | with_content(%r{SecureBits=keep-caps}). 913 | with_content(%r{Capabilities=CAP_IPC_LOCK\+ep}). 914 | with_content(%r{CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK}). 915 | with_content(%r{NoNewPrivileges=yes}) 916 | } 917 | end 918 | context 'service with non-default options' do 919 | let(:params) do 920 | { 921 | bin_dir: '/opt/bin', 922 | config_dir: '/opt/etc/vault', 923 | service_options: '-log-level=info', 924 | user: 'root', 925 | group: 'admin', 926 | num_procs: 8 927 | } 928 | end 929 | 930 | it { 931 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 932 | with_mode('0444'). 933 | with_ensure('file'). 934 | with_owner('root'). 935 | with_group('root'). 936 | with_content(%r{^# vault systemd unit file}). 937 | with_content(%r{^User=root$}). 938 | with_content(%r{^Group=admin$}). 939 | with_content(%r{Environment=GOMAXPROCS=8}). 940 | with_content(%r{^ExecStart=/opt/bin/vault server -config=/opt/etc/vault/config.json -log-level=info$}) 941 | } 942 | end 943 | context 'with mlock disabled' do 944 | let(:params) do 945 | { disable_mlock: true } 946 | end 947 | 948 | it { 949 | is_expected.to contain_file('/etc/systemd/system/vault.service'). 950 | with_mode('0444'). 951 | with_ensure('file'). 952 | with_owner('root'). 953 | with_group('root'). 954 | with_content(%r{^# vault systemd unit file}). 955 | with_content(%r{^User=vault$}). 956 | with_content(%r{^Group=vault$}). 957 | with_content(%r{^ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json $}). 958 | without_content(%r{SecureBits=keep-caps}). 959 | without_content(%r{Capabilities=CAP_IPC_LOCK\+ep}). 960 | with_content(%r{CapabilityBoundingSet=CAP_SYSLOG}). 961 | with_content(%r{NoNewPrivileges=yes}) 962 | } 963 | end 964 | it { is_expected.to contain_systemd__unit_file('vault.service') } 965 | 966 | context 'install through repo with default service management' do 967 | let(:params) do 968 | { 969 | install_method: 'repo', 970 | manage_service_file: :undef 971 | } 972 | end 973 | 974 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 975 | end 976 | context 'install through repo without service management' do 977 | let(:params) do 978 | { 979 | install_method: 'repo', 980 | manage_service_file: false 981 | } 982 | end 983 | 984 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 985 | end 986 | context 'install through repo with service management' do 987 | let(:params) do 988 | { 989 | install_method: 'repo', 990 | manage_service_file: true 991 | } 992 | end 993 | 994 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 995 | end 996 | 997 | context 'install through archive with default service management' do 998 | let(:params) do 999 | { 1000 | install_method: 'archive', 1001 | manage_service_file: :undef 1002 | } 1003 | end 1004 | 1005 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 1006 | end 1007 | context 'install through archive without service management' do 1008 | let(:params) do 1009 | { 1010 | install_method: 'archive', 1011 | manage_service_file: false 1012 | } 1013 | end 1014 | 1015 | it { is_expected.not_to contain_file('/etc/systemd/system/vault.service') } 1016 | end 1017 | context 'install through archive with service management' do 1018 | let(:params) do 1019 | { 1020 | install_method: 'archive', 1021 | manage_service_file: true 1022 | } 1023 | end 1024 | 1025 | it { is_expected.to contain_file('/etc/systemd/system/vault.service') } 1026 | end 1027 | end 1028 | end 1029 | when 'Archlinux' 1030 | context 'defaults to repo install' do 1031 | it { is_expected.to contain_file('vault_binary').with_path('/bin/vault') } 1032 | it { is_expected.not_to contain_file_capability('vault_binary_capability') } 1033 | end 1034 | end 1035 | end 1036 | end 1037 | end 1038 | --------------------------------------------------------------------------------