Commit c50776b6 authored by Stan Hu's avatar Stan Hu

Merge branch '231528-conditionally-fetching-aws-creds' into 'master'

Only send AWS Credentials ENV to indexer when AWS config is enabled

Closes #231528

See merge request gitlab-org/gitlab!37865
parents 217af8aa 68ee6948
---
title: Only send AWS Credentials ENV to indexer when AWS config is enabled
merge_request: 37865
author:
type: fixed
......@@ -110,7 +110,9 @@ module Gitlab
}
# Set AWS environment variables for IAM role authentication if present
vars = build_aws_credentials_env(vars)
if Gitlab::CurrentSettings.elasticsearch_config[:aws]
vars = build_aws_credentials_env(vars)
end
# Users can override default SSL certificate path via SSL_CERT_FILE SSL_CERT_DIR
vars.merge(ENV.slice('SSL_CERT_FILE', 'SSL_CERT_DIR'))
......
......@@ -345,12 +345,26 @@ RSpec.describe Gitlab::Elastic::Indexer do
allow(Gitlab::Elastic::Client).to receive(:aws_credential_provider).and_return(credentials)
end
it 'credentials env vars will be included' do
expect(subject).to include({
'AWS_ACCESS_KEY_ID' => access_key_id,
'AWS_SECRET_ACCESS_KEY' => secret_access_key,
'AWS_SESSION_TOKEN' => session_token
})
context 'when AWS config is not enabled' do
it 'credentials env vars will not be included' do
expect(subject).not_to include('AWS_ACCESS_KEY_ID')
expect(subject).not_to include('AWS_SECRET_ACCESS_KEY')
expect(subject).not_to include('AWS_SESSION_TOKEN')
end
end
context 'when AWS config is enabled' do
before do
stub_application_setting(elasticsearch_aws: true)
end
it 'credentials env vars will be included' do
expect(subject).to include({
'AWS_ACCESS_KEY_ID' => access_key_id,
'AWS_SECRET_ACCESS_KEY' => secret_access_key,
'AWS_SESSION_TOKEN' => session_token
})
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