Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scanner/redhat): do not make cache when offline of redhat fast #1814

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

MaineK00n
Copy link
Collaborator

@MaineK00n MaineK00n commented Dec 16, 2023

What did you implement:

If you try to create a cache while offline or in redhat fast mode, the execution will fail due to an inability to connect to the network or insufficient privileges to the subscription manager.
Also, if a cache has been created in advance, even if cache creation fails, it will not affect subsequent commands, so it will be treated as a warning rather than an error.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

redhat fast(no cache

before

  • have sudo privilege
$ vuls scan
[Dec 17 05:02:17]  INFO [localhost] vuls-v0.24.7-build-20231217_045258_b2c9117
[Dec 17 05:02:17]  INFO [localhost] Start scanning
[Dec 17 05:02:17]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:02:17]  INFO [localhost] Validating config...
[Dec 17 05:02:17]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:02:17]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:02:17]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:02:17]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:02:17]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:02:17]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:02:19]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:02:19]  INFO [vagrant] Scanning OS pkg in fast mode


Scan Summary
================
vagrant	redhat9.0	496 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.
  • no sudo privilege
$ vuls scan
[Dec 17 05:02:38]  INFO [localhost] vuls-v0.24.7-build-20231217_045258_b2c9117
[Dec 17 05:02:38]  INFO [localhost] Start scanning
[Dec 17 05:02:38]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:02:38]  INFO [localhost] Validating config...
[Dec 17 05:02:38]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:02:38]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:02:38]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:02:38]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:02:38]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:02:38]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:02:40]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:02:40]  INFO [vagrant] Scanning OS pkg in fast mode
[Dec 17 05:02:42] ERROR [localhost] Error on vagrant, err: [Failed to detect installed dnf modules:
    github.com/future-architect/vuls/scanner.(*redhatBase).scanPackages
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:428
  - Failed to dnf module list: execResult: servername: vagrant
      cmd: /usr/bin/ssh -o StrictHostKeyChecking=yes -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/home/mainek00n/.vuls/cm-c4bea344-%C -o Controlpersist=10m -l vuls -p 2222 -i /home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa -o PasswordAuthentication=no 127.0.0.1
      exitstatus: 1
      stdout: 
      stderr: stty: 'standard input': Inappropriate ioctl for device
    Error: Cache-only enabled but no cache for 'epel'
    
      err: %!s(<nil>):
    github.com/future-architect/vuls/scanner.(*redhatBase).detectEnabledDnfModules
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:949]


Scan Summary
================
vagrant	Error		Use configtest subcommand or scan with --debug to view the details


[Dec 17 05:02:42] ERROR [localhost] Failed to scan: Failed to scan. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/scanner.go:110
  - An error occurred on [vagrant]

after(not bug, When using redhat fast, it is necessary to create a cache before scanning.

  • have sudo privilege
$ vuls scan
[Dec 17 05:07:13]  INFO [localhost] vuls-v0.24.7-build-20231217_050633_5b8a536
[Dec 17 05:07:13]  INFO [localhost] Start scanning
[Dec 17 05:07:13]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:07:13]  INFO [localhost] Validating config...
[Dec 17 05:07:13]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:07:13]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:07:13]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:07:13]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:07:13]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:07:13]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:07:15]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:07:15]  INFO [vagrant] Scanning OS pkg in fast mode
[Dec 17 05:07:16] ERROR [localhost] Error on vagrant, err: [Failed to detect installed dnf modules:
    github.com/future-architect/vuls/scanner.(*redhatBase).scanPackages
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:433
  - Failed to dnf module list: execResult: servername: vagrant
      cmd: /usr/bin/ssh -o StrictHostKeyChecking=yes -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/home/mainek00n/.vuls/cm-c4bea344-%C -o Controlpersist=10m -l vagrant -p 2222 -i /home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa -o PasswordAuthentication=no 127.0.0.1
      exitstatus: 1
      stdout: 
      stderr: stty: 'standard input': Inappropriate ioctl for device
    Error: Cache-only enabled but no cache for 'epel'
    
      err: %!s(<nil>):
    github.com/future-architect/vuls/scanner.(*redhatBase).detectEnabledDnfModules
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:950]


Scan Summary
================
vagrant	Error		Use configtest subcommand or scan with --debug to view the details


[Dec 17 05:07:16] ERROR [localhost] Failed to scan: Failed to scan. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/scanner.go:110
  - An error occurred on [vagrant]
  • no sudo privilege
$ vuls scan
[Dec 17 05:06:51]  INFO [localhost] vuls-v0.24.7-build-20231217_050633_5b8a536
[Dec 17 05:06:51]  INFO [localhost] Start scanning
[Dec 17 05:06:51]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:06:51]  INFO [localhost] Validating config...
[Dec 17 05:06:51]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:06:51]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:06:52]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:06:52]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:06:52]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:06:52]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:06:54]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:06:54]  INFO [vagrant] Scanning OS pkg in fast mode
[Dec 17 05:06:54] ERROR [localhost] Error on vagrant, err: [Failed to detect installed dnf modules:
    github.com/future-architect/vuls/scanner.(*redhatBase).scanPackages
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:433
  - Failed to dnf module list: execResult: servername: vagrant
      cmd: /usr/bin/ssh -o StrictHostKeyChecking=yes -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/home/mainek00n/.vuls/cm-c4bea344-%C -o Controlpersist=10m -l vuls -p 2222 -i /home/mainek00n/github/github.com/MaineK00n/vuls-targets-docker/.ssh/id_rsa -o PasswordAuthentication=no 127.0.0.1
      exitstatus: 1
      stdout: 
      stderr: stty: 'standard input': Inappropriate ioctl for device
    Error: Cache-only enabled but no cache for 'epel'
    
      err: %!s(<nil>):
    github.com/future-architect/vuls/scanner.(*redhatBase).detectEnabledDnfModules
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/redhatbase.go:950]


Scan Summary
================
vagrant	Error		Use configtest subcommand or scan with --debug to view the details


[Dec 17 05:06:54] ERROR [localhost] Failed to scan: Failed to scan. err:
    github.com/future-architect/vuls/scanner.Scanner.Scan
        /home/mainek00n/github/github.com/MaineK00n/vuls/scanner/scanner.go:110
  - An error occurred on [vagrant]

redhat fast(have cache

before

  • have sudo privilege
$ vuls scan
[Dec 17 05:12:01]  INFO [localhost] vuls-v0.24.7-build-20231217_051053_b2c9117
[Dec 17 05:12:01]  INFO [localhost] Start scanning
[Dec 17 05:12:01]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:12:01]  INFO [localhost] Validating config...
[Dec 17 05:12:01]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:12:01]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:12:01]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:12:01]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:12:01]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:12:01]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:12:03]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:12:03]  INFO [vagrant] Scanning OS pkg in fast mode


Scan Summary
================
vagrant	redhat9.0	496 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.
  • no sudo privilege
$ vuls scan
[Dec 17 05:11:38]  INFO [localhost] vuls-v0.24.7-build-20231217_051053_b2c9117
[Dec 17 05:11:38]  INFO [localhost] Start scanning
[Dec 17 05:11:38]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:11:38]  INFO [localhost] Validating config...
[Dec 17 05:11:38]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:11:38]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:11:39]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:11:39]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:11:39]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:11:39]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:11:41]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:11:41]  INFO [vagrant] Scanning OS pkg in fast mode


Scan Summary
================
vagrant	redhat9.0	496 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.

after

  • have sudo privilege
$ vuls scan
[Dec 17 05:14:34]  INFO [localhost] vuls-v0.24.7-build-20231217_051402_5b8a536
[Dec 17 05:14:34]  INFO [localhost] Start scanning
[Dec 17 05:14:34]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:14:34]  INFO [localhost] Validating config...
[Dec 17 05:14:34]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:14:34]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:14:34]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:14:34]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:14:34]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:14:34]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:14:37]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:14:37]  INFO [vagrant] Scanning OS pkg in fast mode


Scan Summary
================
vagrant	redhat9.0	496 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.
  • no sudo privilege
$ vuls scan
[Dec 17 05:14:59]  INFO [localhost] vuls-v0.24.7-build-20231217_051402_5b8a536
[Dec 17 05:14:59]  INFO [localhost] Start scanning
[Dec 17 05:14:59]  INFO [localhost] config: /home/mainek00n/github/github.com/MaineK00n/vuls/config.toml
[Dec 17 05:14:59]  INFO [localhost] Validating config...
[Dec 17 05:14:59]  INFO [localhost] Detecting Server/Container OS... 
[Dec 17 05:14:59]  INFO [localhost] Detecting OS of servers... 
[Dec 17 05:14:59]  INFO [localhost] (1/1) Detected: vagrant: redhat 9.0
[Dec 17 05:14:59]  INFO [localhost] Detecting OS of containers... 
[Dec 17 05:14:59]  INFO [localhost] Checking Scan Modes... 
[Dec 17 05:14:59]  INFO [localhost] Detecting Platforms... 
[Dec 17 05:15:02]  INFO [localhost] (1/1) vagrant is running on other
[Dec 17 05:15:02]  INFO [vagrant] Scanning OS pkg in fast mode


Scan Summary
================
vagrant	redhat9.0	496 installed





To view the detail, vuls tui is useful.
To send a report, run vuls report -h.

offline

before

Screenshot from 2023-12-17 04-42-25

after

  • have cache
    Screenshot from 2023-12-17 04-43-31

  • no cache(not bug, When using offline, it is necessary to create a cache before scanning.
    image

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@MaineK00n MaineK00n self-assigned this Dec 16, 2023
@MaineK00n MaineK00n marked this pull request as ready for review December 16, 2023 20:19
@MaineK00n MaineK00n merged commit 8e497bb into master Dec 16, 2023
4 checks passed
@MaineK00n MaineK00n deleted the MaineK00n/patch-1 branch December 16, 2023 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant