Skip to content

Replace Excon with Faraday for requesting object storage

Furkan Ayhan requested to merge 323920-artifacts-object-storage into master

What does this MR do?

History

  1. The origin of this story is: "Triggering multiple dynamically generated child pipelines in a single phase causes all but one to fail".
  2. And this MR actually fixed that problem: "Fix triggering multiple children pipeline with the same artifact".
    • at least for GitLab.com...
  3. 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"
  4. 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.

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;

  1. Overriding the Host header in Excon
# from
Excon.get(url, response_block: streamer)

# to
uri = URI(url)
Excon.get(url, headers: { 'Host' => uri.host }, response_block: streamer)
  1. Sending omit_default_port param to Excon

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)
  1. Replacing Excon with Faraday.
# 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;

Screen_Shot_2021-06-18_at_15.54.04

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

Availability and Testing

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
Edited by Furkan Ayhan

Merge request reports

Loading