Skip to content

Container scanner image 6.6.0 is failing to get relative path

Summary

One of our customers (internal) reported that container scanning is no longer working. The main error is:

[ERROR] [2023-12-21 07:43:05 +0000] [container-scanning]  >  different prefix: "" and "/builds/SNIPPED/SNIPPED"
[ERROR] [2023-12-21 07:43:05 +0000] [container-scanning]  >  /usr/local/lib/ruby/3.1.0/pathname.rb:528:in `relative_path_from'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:112:in `diff_to_patch'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:104:in `create_patch'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:79:in `to_hash'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/collection.rb:19:in `map'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/collection.rb:19:in `to_hash'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/converter.rb:40:in `convert'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/plugin/container_scan.rb:10:in `convert'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/scan.rb:26:in `scan_image'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:16:in `block in scan'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:15:in `map'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:15:in `scan'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/base.rb:584:in `start'
/usr/local/bundle/gems/gcs-6.6.0/exe/gtcs:14:in `<top (required)>'
/usr/local/bundle/bin/gtcs:25:in `load'
/usr/local/bundle/bin/gtcs:25:in `<main>'

From the stacktrace, it appears this might have been introduced here: gitlab-org/security-products/analyzers/container-scanning!2944 (merged)

When we set the image back to use 6.5.1, scan succeeds.

Steps to reproduce

See thread gitlab-org/security-products/analyzers/container-scanning!2964 (62d6a504, comment 1710640622)

Example Project

What is the current bug behavior?

Scan fails with an error.

What is the expected correct behavior?

Scan succeeds.

Relevant logs and/or screenshots

[ERROR] [2023-12-21 07:43:05 +0000] [container-scanning]  >  different prefix: "" and "/builds/SNIPPED/SNIPPED"
[ERROR] [2023-12-21 07:43:05 +0000] [container-scanning]  >  /usr/local/lib/ruby/3.1.0/pathname.rb:528:in `relative_path_from'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:112:in `diff_to_patch'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:104:in `create_patch'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/remediation.rb:79:in `to_hash'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/collection.rb:19:in `map'
/usr/local/bundle/gems/gcs-6.6.0/ee/lib/gcs/remediations/collection.rb:19:in `to_hash'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/converter.rb:40:in `convert'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/plugin/container_scan.rb:10:in `convert'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/scan.rb:26:in `scan_image'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:16:in `block in scan'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:15:in `map'
/usr/local/bundle/gems/gcs-6.6.0/lib/gcs/cli.rb:15:in `scan'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/bundle/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
/usr/local/bundle/gems/thor-1.3.0/lib/thor/base.rb:584:in `start'
/usr/local/bundle/gems/gcs-6.6.0/exe/gtcs:14:in `<top (required)>'
/usr/local/bundle/bin/gtcs:25:in `load'
/usr/local/bundle/bin/gtcs:25:in `<main>'

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Thiago Figueiró