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

Add support for stopping Scans to Orchestrator #218

Merged
merged 26 commits into from
Apr 24, 2023
Merged

Add support for stopping Scans to Orchestrator #218

merged 26 commits into from
Apr 24, 2023

Conversation

chrisgacsal
Copy link
Contributor

@chrisgacsal chrisgacsal commented Mar 31, 2023

Description

  • Add ScanWatcher to look up for Scans which status has changed to Aborted and updated all the corresponding ScanResult status to ABORTED so the Scanner Worker and the CLI could detect cancellation events.
  • Update Scanner Worker to detect if the ScanResult state is changed to Aborted.

Type of Change

[ ] Bug Fix
[x] New Feature
[ ] Breaking Change
[ ] Refactor
[ ] Documentation
[ ] Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

Test Plan

Manual steps to test aborting ongoing scans in live environment.

Expand

Scan configuration

Create Scan Configuration file

cat <<EOF > scanconfig.json
{
  "name": "test",
  "scanFamiliesConfig": {
     "sbom": {
       "enabled": true
     },
     "vulnerabilities": {
       "enabled": true
     },
     "exploits": {
       "enabled": true
     }
  },
  "scheduled": {
    "cronLine": "0 */4 * * *",
    "operationTime": "2023-01-20T15:46:18+00:00"
  },
  "scope": {
    "allRegions": true,
    "objectType": "AwsScanScope",
    "instanceTagSelector": [
      {
        "key": "ScanConfig",
        "value": "test"
      }
    ]
  }
}
EOF

Apply Scan Configuration to API

curl -sSf -X POST 'http://localhost:8888/api/scanConfigs' -H 'Content-Type: application/json' \
  -d @scanconfig.json \
| jq -r -e '.id' > scanconfig.id

Get Scan Configuration object from API

curl -sSf -X GET 'http://localhost:8888/api/scanConfigs/'"$(cat scanconfig.id)"'' \
| jq -r -e '.' > scanconfig.api.json

Start Scan

Start Scan using Scan Config

jq -r -e '{maxParallelScanners, name, scanFamiliesConfig, scheduled, scope} | .scheduled.operationTime = (now|todate)' \
  scanconfig.api.json \
| curl -sSf -X PUT -H 'Content-Type: application/json' 'http://localhost:8888/api/scanConfigs/'"$(cat scanconfig.id)"'' \
  -d @-

Get ongoing Scan from API using ScanConfig id

curl -sSf -G 'http://localhost:8888/api/scans' \
  --data-urlencode "\$filter=scanConfig/id eq '$(cat scanconfig.id)' and state ne 'Done' and state ne 'Failed'" \
| jq -r -e '.items[] | first' > scan.api.json

Abort Scan in progress

cat <<EOF > scan-aborted.json
{
  "state": "Aborted"
}
EOF
jq -r -e '.id' scan.api.json > scan.id \
&& curl -sSf -X PATCH -H 'Content-Type: application/json' \
  "http://localhost:8888/api/scans/$(cat scan.id)" \
  -d @scan-aborted.json \
| jq -r -e '.' > scan-aborted.api.json

@chrisgacsal chrisgacsal force-pushed the stop-scan branch 3 times, most recently from f04e658 to 416bedd Compare March 31, 2023 19:20
@chrisgacsal chrisgacsal force-pushed the stop-scan branch 3 times, most recently from 461fc76 to a326e35 Compare April 3, 2023 12:45
@chrisgacsal chrisgacsal force-pushed the stop-scan branch 4 times, most recently from 4fe5cb4 to 2bc98cf Compare April 11, 2023 17:04
@chrisgacsal chrisgacsal requested a review from a user April 12, 2023 16:09
cli/cmd/root.go Outdated Show resolved Hide resolved
runtime_scan/pkg/orchestrator/scanwatcher/watcher.go Outdated Show resolved Hide resolved
runtime_scan/pkg/orchestrator/scanwatcher/watcher.go Outdated Show resolved Hide resolved
runtime_scan/pkg/orchestrator/scanwatcher/watcher.go Outdated Show resolved Hide resolved
runtime_scan/pkg/scanner/job_managment.go Outdated Show resolved Hide resolved
shared/pkg/families/manager.go Show resolved Hide resolved
shared/pkg/families/manager.go Show resolved Hide resolved
shared/pkg/families/manager.go Outdated Show resolved Hide resolved
@chrisgacsal chrisgacsal force-pushed the stop-scan branch 2 times, most recently from 355b6e9 to 29edd4d Compare April 18, 2023 08:56
@chrisgacsal chrisgacsal marked this pull request as ready for review April 18, 2023 08:57
@chrisgacsal chrisgacsal requested a review from a team as a code owner April 18, 2023 08:57
@chrisgacsal chrisgacsal requested a review from a user April 18, 2023 08:57
@chrisgacsal
Copy link
Contributor Author

The PR is ready for review. I have added a test plan with manual steps to verify the functionality to abort running scans.

@chrisgacsal chrisgacsal force-pushed the stop-scan branch 3 times, most recently from 9aff99b to 8ef78dc Compare April 18, 2023 14:13
ghost
ghost previously approved these changes Apr 19, 2023
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking great, I've got a couple of suggestions, happy to punt them to later.

cli/pkg/state/local.go Outdated Show resolved Hide resolved
cli/cmd/root.go Outdated Show resolved Hide resolved
shared/pkg/families/manager.go Show resolved Hide resolved
shared/pkg/families/manager.go Outdated Show resolved Hide resolved
cli/pkg/cli/cli.go Outdated Show resolved Hide resolved
@akpsgit akpsgit enabled auto-merge (squash) April 24, 2023 07:09
@akpsgit akpsgit merged commit 4e25247 into main Apr 24, 2023
@akpsgit akpsgit deleted the stop-scan branch April 24, 2023 09:24
@ghost ghost mentioned this pull request Apr 26, 2023
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

3 participants