Commit 424187fa authored by Sean McGivern's avatar Sean McGivern

Merge branch '241130-vault-secrets-make-auth-path-configurable' into 'master'

Specify custom path for Vault auth method

Closes #241130

See merge request gitlab-org/gitlab!40366
parents c909c0ec 87377e92
...@@ -148,8 +148,8 @@ module EE ...@@ -148,8 +148,8 @@ module EE
variable_value('VAULT_SERVER_URL').present? variable_value('VAULT_SERVER_URL').present?
end end
def variable_value(key) def variable_value(key, default = nil)
variables_hash[key] variables_hash.fetch(key, default)
end end
private private
......
...@@ -19,7 +19,7 @@ module EE ...@@ -19,7 +19,7 @@ module EE
'url' => variable_value('VAULT_SERVER_URL'), 'url' => variable_value('VAULT_SERVER_URL'),
'auth' => { 'auth' => {
'name' => 'jwt', 'name' => 'jwt',
'path' => 'jwt', 'path' => variable_value('VAULT_AUTH_PATH', 'jwt'),
'data' => { 'data' => {
'jwt' => '${CI_JOB_JWT}', 'jwt' => '${CI_JOB_JWT}',
'role' => variable_value('VAULT_AUTH_ROLE') 'role' => variable_value('VAULT_AUTH_ROLE')
......
...@@ -63,6 +63,24 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -63,6 +63,24 @@ RSpec.describe Ci::BuildRunnerPresenter do
end end
end end
end end
context 'Vault auth path' do
let(:vault_auth) { presenter.secrets_configuration.dig('DATABASE_PASSWORD', 'vault', 'server', 'auth') }
context 'VAULT_AUTH_PATH CI variable is present' do
it 'contains user defined auth path' do
create(:ci_variable, project: ci_build.project, key: 'VAULT_AUTH_PATH', value: 'custom/path')
expect(vault_auth.fetch('path')).to eq('custom/path')
end
end
context 'VAULT_AUTH_PATH CI variable is not present' do
it 'contains the default auth path' do
expect(vault_auth.fetch('path')).to eq('jwt')
end
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment