-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(vm): add region
option to vm scan to be able to scan any region's ami and ebs snapshots
#3284
feat(vm): add region
option to vm scan to be able to scan any region's ami and ebs snapshots
#3284
Conversation
|
pkg/flag/vm_flags.go
Outdated
@@ -0,0 +1,38 @@ | |||
package flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use AWSFlagGroup instead?
Lines 36 to 42 in f369bd3
type AWSFlagGroup struct { | |
Region *Flag | |
Endpoint *Flag | |
Services *Flag | |
Account *Flag | |
ARN *Flag | |
} |
docs/docs/vm/aws.md
Outdated
If you want to scan a AMI of non-default setting region, you can set any region via `--region` option. | ||
|
||
```shell | ||
$ trivy vm --region ap-northeast-1 ami:ami-0123456789abcdefg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VM scanning is not dedicated to AWS. We will probably add support for GCP and Azure.
$ trivy vm --region ap-northeast-1 ami:ami-0123456789abcdefg | |
$ trivy vm --aws-region ap-northeast-1 ami:ami-0123456789abcdefg |
docs/docs/vm/aws.md
Outdated
@@ -52,6 +58,13 @@ $ trivy vm --security-checks vuln ebs:snap-0123456789abcdefg | |||
!!! tip | |||
The scanning could be faster if you enable only vulnerability scanning (`--security-checks vuln`) because Trivy tries to download only necessary blocks for vulnerability detection. | |||
|
|||
If you want to scan an EBS Snapshot of non-default setting region, you can set any region via `--region` option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
pkg/commands/app.go
Outdated
@@ -884,6 +884,7 @@ func NewVMCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command { | |||
ScanFlagGroup: flag.NewScanFlagGroup(), | |||
SecretFlagGroup: flag.NewSecretFlagGroup(), | |||
VulnerabilityFlagGroup: flag.NewVulnerabilityFlagGroup(), | |||
VMFlagGroups: flag.NewVMFlagGroup(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can define a custom flag as below.
awsFlagGroup := flag.AWSFlagGroup{
Region: flag.Flag{
Name: "aws-region",
ConfigName: "aws.region",
Value: "",
Usage: "AWS region to scan",
}
}
The following variable should be exported so it could be reused. I'll refactor that later.
Lines 4 to 9 in f369bd3
awsRegionFlag = Flag{ | |
Name: "region", | |
ConfigName: "cloud.aws.region", | |
Value: "", | |
Usage: "AWS Region to scan", | |
} |
@knqyf263 Thank you for reviewing! I've fixed those points. |
Thanks for your contribution! |
Description
Hi. Thank you for such a wonderful product!
VM scanning is performed in the current implementation using default region settings read from environment variables, etc. The only way to scan for EBS snapshots (or AMIs) in any region was probably to dynamically change the AWS_REGION environment variable.
Therefore, in this pr, I have implemented the
--region
option so that EBS snapshots and AMIs can be fetched by specifying any region.This is just a personal usage that I implemented on my own, so if you have a different idea, please close this pr!
Related issues
N/A
before
after
Checklist