Replace Excon with Faraday for requesting object storage
What does this MR do?
History
- The origin of this story is: "Triggering multiple dynamically generated child pipelines in a single phase causes all but one to fail".
- And this MR actually fixed that problem: "Fix triggering multiple children pipeline with the same artifact".
- at least for
GitLab.com
...
- at least for
- Some self-hosted users start to get errors after enabling/removing the feature flag: "Removal of :ci_new_artifact_file_reader feature flag causes child pipelines to break"
- Then, we added the feature flag again to prevent this: "Add ci_new_artifact_file_reader FF again".
- meanwhile,
GitLab.com
can still use the original fix.
- meanwhile,
Right now we have a new issue: #323920 (closed), self-hosted users also want to use that fix, so we need to fix that problem.
The reproduction steps are in the issue, you can also do that in your local gdk.
The error
For instances with object storage, this error raises;
Zip::Error
=> Zip end of central directory signature not found
in lib/gitlab/ci/artifact_file_reader.rb
:
zip_file = Zip::File.new(file, false, true)
It actually means that we don't have a Zip file there.
Why?
When requesting the remote artifact with Excon
, AWS returns this;
Excon.get(url)
=> <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>HIDDEN</AWSAccessKeyId><StringToSign>HIDDEN</StringToSign><SignatureProvided>HIDDEN</SignatureProvided>...
The problem with Excon
is the Host
header. Excon
sends Host: gitlab-local-artifacts.s3.amazonaws.com:443
in headers and S3 does not accept this. Faraday
sends Host: gitlab-local-artifacts.s3.amazonaws.com
and S3 accepts this.
Now...
We have 3 options;
- Overriding the
Host
header inExcon
# from
Excon.get(url, response_block: streamer)
# to
uri = URI(url)
Excon.get(url, headers: { 'Host' => uri.host }, response_block: streamer)
- Sending
omit_default_port
param toExcon
Excon
checks the omit_default_port
param before adding the port in the Host
header.
# from
Excon.get(url, response_block: streamer)
# to
Excon.get(url, omit_default_port: true, response_block: streamer)
- Replacing
Excon
withFaraday
.
# from
streamer = lambda { |chunk, _, _| file.write(chunk) }
Excon.get(url, response_block: streamer)
# to
Faraday.get(url) do |req|
req.options.on_data = proc { |chunk, _| file.write(chunk) }
end
We use Faraday
more than Excon
;
This MR simply replaces the usage of Excon
with Faraday
.
Using Faraday
was suggested in the original MR, but our Faraday
version did not support the usage of req.options.on_data
at that time. Then using Excon
was suggested.
Unfortunately, I couldn't find a proper test to add here...
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team