Skip to content

Commit

Permalink
Merge pull request #20 from Roblox/update_license_installation
Browse files Browse the repository at this point in the history
Enable enterprise Vault upgrades
  • Loading branch information
roberteckert authored Dec 14, 2023
2 parents 5f2135b + e0dfa26 commit bfbe395
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 10 deletions.
23 changes: 22 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ suites:
<<: *default-provisioner
attributes:
hashicorp-vault:
version: 1.8.4
config:
unauthenticated_metrics_access: true
- name: test_license
provisioner:
<<: *default-provisioner
attributes:
hashicorp-vault:
license_content: <%= ENV['VAULT_LICENSE'] %>
- name: test_license_external_ent
provisioner:
<<: *default-provisioner
attributes:
hashicorp-vault:
enterprise: true
license_content: <%= ENV['VAULT_LICENSE'] %>
- name: test_license_internal_ent
provisioner:
<<: *default-provisioner
attributes:
hashicorp-vault:
archive_url_root: "cdn.aws.robloxlabs.com"
enterprise: true
use_internal_repos: true
license_content: <%= ENV['VAULT_LICENSE'] %>
4 changes: 3 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
default['hashicorp-vault']['service_user'] = 'vault'
default['hashicorp-vault']['service_group'] = 'vault'

default['hashicorp-vault']['version'] = '1.6.1'
default['hashicorp-vault']['version'] = '1.8.5'

default['hashicorp-vault']['archive_url_root'] = 'releases.hashicorp.com'

default['hashicorp-vault']['enterprise'] = false
default['hashicorp-vault']['use_internal_repos'] = false

default['hashicorp-vault']['config']['path'] = '/etc/vault/vault.json'
default['hashicorp-vault']['config']['license_path'] = '/etc/vault/vault_license.hclic'
default['hashicorp-vault']['config']['address'] = '127.0.0.1:8200'
default['hashicorp-vault']['config']['log_level'] = 'info'
default['hashicorp-vault']['config']['tls_cert_file'] = '/etc/vault/ssl/certs/vault.crt'
Expand Down
5 changes: 5 additions & 0 deletions libraries/vault_installation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class VaultInstallation < Chef::Resource
# @return [boolean]
attribute(:enterprise, equal_to: [true, false])

# @!attribute use_internal_repos
# Install using internal repos or not
# @return [boolean]
attribute(:use_internal_repos, equal_to: [true, false])

def vault_program
@program ||= provider_for_action(:vault_program).vault_program
end
Expand Down
24 changes: 19 additions & 5 deletions libraries/vault_installation_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def self.default_inversion_options(node, new_resource)
archive_basename = binary_basename(node, new_resource)
super.merge(
version: new_resource.version,
archive_url: format(default_archive_url, archive_url_root: node['hashicorp-vault']['archive_url_root'], version: new_resource.version, basename: archive_basename),
archive_url: format(
default_archive_url,
archive_url_root: node['hashicorp-vault']['archive_url_root'],
version: new_resource.version,
ent_terminal: new_resource.enterprise ? !new_resource.use_internal_repos ? "%%2bent": "" : "",
basename: archive_basename
),
archive_basename: archive_basename,
archive_checksum: binary_checksum(node, new_resource),
extract_to: '/opt/vault'
Expand Down Expand Up @@ -82,13 +88,21 @@ def vault_program
end

def self.default_archive_url
"https://%{archive_url_root}/vault/%{version}/%{basename}" # rubocop:disable Style/StringLiterals
"https://%{archive_url_root}/vault/%{version}%{ent_terminal}/%{basename}" # rubocop:disable Style/StringLiterals
end

def self.binary_basename(node, resource)
filename = resource.enterprise ? 'vault-enterprise' : 'vault'
# %2b is +, and %% is required because of call to format()
version = resource.enterprise ? "#{resource.version}%%2bprem" : resource.version
filename = 'vault'
version = resource.version
if resource.enterprise
if resource.use_internal_repos
filename = 'vault-enterprise'
# %2b is +, and %% is required because of call to format()
version = "#{resource.version}%%2bprem"
else
version = "#{resource.version}%%2bent"
end
end

case node['kernel']['machine']
when 'x86_64', 'amd64' then [filename, version, node['os'], 'amd64'].join('_')
Expand Down
21 changes: 20 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,37 @@
node['hashicorp-vault']['installation'].each_pair { |k, v| r.send(k, v) }
end
r.send('enterprise', node['hashicorp-vault']['enterprise'])
r.send('use_internal_repos', node['hashicorp-vault']['use_internal_repos'])
end

config = vault_config node['hashicorp-vault']['config']['path'] do |r|
owner node['hashicorp-vault']['service_user']
group node['hashicorp-vault']['service_group']

if node['hashicorp-vault']['config']
node['hashicorp-vault']['config'].each_pair { |k, v| r.send(k, v) }
node['hashicorp-vault']['config'].each_pair do |k, v|
if k == "license_path" and !node['hashicorp-vault']['license_content']
next
end
r.send(k, v)
end
end

notifies :reload, "vault_service[#{node['hashicorp-vault']['service_name']}]", :delayed
end

if node['hashicorp-vault']['license_content']
file node['hashicorp-vault']['config']['license_path'] do
content node['hashicorp-vault']['license_content']
owner node['hashicorp-vault']['service_user']
group node['hashicorp-vault']['service_group']
sensitive true
notifies :reload, "vault_service[#{node['hashicorp-vault']['service_name']}]", :delayed
end
else
node.default['hashicorp-vault']['config'].delete('license_path')
end

vault_service node['hashicorp-vault']['service_name'] do |r|
user node['hashicorp-vault']['service_user']
group node['hashicorp-vault']['service_group']
Expand Down
2 changes: 1 addition & 1 deletion test/integration/default/inspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe file('/opt/vault/1.6.1/vault') do
describe file('/opt/vault/1.8.5/vault') do
it { should be_file }
it { should be_executable }
end
Expand Down
34 changes: 34 additions & 0 deletions test/integration/test_license/inspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe file('/opt/vault/1.8.5/vault') do
it { should be_file }
it { should be_executable }
end

describe group('vault') do
it { should exist }
end

describe user('vault') do
it { should exist }
end

describe file('/etc/vault/vault.json') do
its('mode') { should eq 0640 }
it { should be_file }
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
its('content') { should match /.*log_level.*/ }
its('content') { should match /.*license_path.*/}
end

describe file('/etc/vault/vault_license.hclic') do
it {should exist}
it {should be_file}
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
end

describe service('vault') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
34 changes: 34 additions & 0 deletions test/integration/test_license_external_ent/inspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe file('/opt/vault/1.8.5/vault') do
it { should be_file }
it { should be_executable }
end

describe group('vault') do
it { should exist }
end

describe user('vault') do
it { should exist }
end

describe file('/etc/vault/vault.json') do
its('mode') { should eq 0640 }
it { should be_file }
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
its('content') { should match /.*log_level.*/ }
its('content') { should match /.*license_path.*/}
end

describe file('/etc/vault/vault_license.hclic') do
it {should exist}
it {should be_file}
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
end

describe service('vault') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
34 changes: 34 additions & 0 deletions test/integration/test_license_internal_ent/inspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe file('/opt/vault/1.8.5/vault') do
it { should be_file }
it { should be_executable }
end

describe group('vault') do
it { should exist }
end

describe user('vault') do
it { should exist }
end

describe file('/etc/vault/vault.json') do
its('mode') { should eq 0640 }
it { should be_file }
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
its('content') { should match /.*log_level.*/ }
its('content') { should match /.*license_path.*/}
end

describe file('/etc/vault/vault_license.hclic') do
it {should exist}
it {should be_file}
it { should be_owned_by 'vault' }
it { should be_grouped_into 'vault' }
end

describe service('vault') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe file('/opt/vault/1.8.4/vault') do
describe file('/opt/vault/1.8.5/vault') do
it { should be_file }
it { should be_executable }
end
Expand Down

0 comments on commit bfbe395

Please sign in to comment.