Commit bbab7fd9 authored by Stan Hu's avatar Stan Hu

Coerce string object storage options to booleans

Admins that accidentally configure `use_iam_profile` or `path_style`
with string values (e.g. `"true"`) instead of boolean values would see
obscure unmarshaling errors in Workhorse. To avoid this trouble, coerce
these string values o boolean values.

Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/5588
parent 0d661320
---
title: Coerce string object storage options to booleans
merge_request: 39901
author:
type: fixed
...@@ -34,11 +34,11 @@ module ObjectStorage ...@@ -34,11 +34,11 @@ module ObjectStorage
end end
def use_iam_profile? def use_iam_profile?
credentials.fetch(:use_iam_profile, false) Gitlab::Utils.to_boolean(credentials[:use_iam_profile], default: false)
end end
def use_path_style? def use_path_style?
credentials.fetch(:path_style, false) Gitlab::Utils.to_boolean(credentials[:path_style], default: false)
end end
def server_side_encryption def server_side_encryption
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'fast_spec_helper'
require 'rspec-parameterized'
RSpec.describe ObjectStorage::Config do RSpec.describe ObjectStorage::Config do
using RSpec::Parameterized::TableSyntax
let(:region) { 'us-east-1' } let(:region) { 'us-east-1' }
let(:bucket_name) { 'test-bucket' } let(:bucket_name) { 'test-bucket' }
let(:path_style) { false }
let(:use_iam_profile) { false }
let(:credentials) do let(:credentials) do
{ {
provider: 'AWS', provider: 'AWS',
aws_access_key_id: 'AWS_ACCESS_KEY_ID', aws_access_key_id: 'AWS_ACCESS_KEY_ID',
aws_secret_access_key: 'AWS_SECRET_ACCESS_KEY', aws_secret_access_key: 'AWS_SECRET_ACCESS_KEY',
region: region, region: region
path_style: path_style,
use_iam_profile: use_iam_profile
} }
end end
...@@ -52,6 +51,14 @@ RSpec.describe ObjectStorage::Config do ...@@ -52,6 +51,14 @@ RSpec.describe ObjectStorage::Config do
it { expect(subject.bucket).to eq(bucket_name) } it { expect(subject.bucket).to eq(bucket_name) }
end end
describe '#use_iam_profile' do
it { expect(subject.use_iam_profile?).to be false }
end
describe '#use_path_style' do
it { expect(subject.use_path_style?).to be false }
end
context 'with unconsolidated settings' do context 'with unconsolidated settings' do
describe 'consolidated_settings? returns false' do describe 'consolidated_settings? returns false' do
it { expect(subject.consolidated_settings?).to be false } it { expect(subject.consolidated_settings?).to be false }
...@@ -68,25 +75,47 @@ RSpec.describe ObjectStorage::Config do ...@@ -68,25 +75,47 @@ RSpec.describe ObjectStorage::Config do
end end
end end
context 'with IAM profile in use' do context 'with IAM profile configured' do
let(:use_iam_profile) { true } where(:value, :expected) do
true | true
"true" | true
"yes" | true
false | false
"false" | false
"no" | false
nil | false
end
with_them do
before do
credentials[:use_iam_profile] = value
end
it '#use_iam_profile? returns true' do it 'coerces the value to a boolean' do
expect(subject.use_iam_profile?).to be true expect(subject.use_iam_profile?).to be expected
end
end end
end end
context 'with IAM profile not in use' do context 'with path style configured' do
it '#use_iam_profile? returns false' do where(:value, :expected) do
expect(subject.use_iam_profile?).to be false true | true
"true" | true
"yes" | true
false | false
"false" | false
"no" | false
nil | false
end end
end
context 'with path style' do with_them do
let(:path_style) { true } before do
credentials[:path_style] = value
end
it '#use_path_style? returns true' do it 'coerces the value to a boolean' do
expect(subject.use_path_style?).to be true expect(subject.use_path_style?).to be expected
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