-
Notifications
You must be signed in to change notification settings - Fork 24
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 aws.s3.bucket.policy
resource
#5228
Conversation
This change allows running `aws.s3.bucket.policy` when in discovery mode. ``` cnspec shell aws --discover s3-buckets ``` Also, fixes the issue discovered at #5218 where we noticed that the policy resource doesn't implement the `id()` func properly. Closes #5169 Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
// Name for the policy | ||
name string | ||
// Bucket name that this policy belongs | ||
bucketName string |
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.
This might be a breaking change, but a bucket policy doesn't have a name. It belongs to a bucket and, to calculate the bucket policy ID we need the bucket name, so I re purpose this field.
If this is not acceptable, I am ok creating an internal struct to pass the bucket name but, we need to do something about this name
field that says it is the name of the policy, but it's not.
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.
we don't know whether this is used by someone or not. Perhaps keep both for a while and add a comment to name
that it's deprecated. We can remove it in next major release
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.
If someone is using it, they are using it incorrectly but I agree, I'll put it back with a deprecation.
providers/aws/resources/aws.lr
Outdated
// Document for the policy | ||
document string | ||
// Version of the policy | ||
version() string | ||
// List of statements for the policy | ||
statements() []dict | ||
// Whether the bucket policy exists | ||
exists bool |
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.
Buckets can have a policy, but not all of them has it. This is very helpful, I think.
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.
I don't understand why this is needed. If there is no bucket policy then that resource shouldn't be created, right? Do we have some specific requirement to have the MQL object even when such resource in AWS doesn't exist?
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.
we should be able to use null comparisons if we need to check that a policy exists or does not exist on a bucket. like aws.s3.bucket.policy != null -- does that not work?
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.
It sounds it is possible! 🙌🏽 Thank you both for the correction 💯
Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
i'm hitting a panic when i try to test this
|
providers/aws/resources/aws_s3.go
Outdated
if isNotFoundForS3(err) { | ||
return emptyAwsS3BucketPolicy(a.MqlRuntime) | ||
} | ||
if err != nil && !isNotFoundForS3(err) { |
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.
perhaps it would be useful to set the plugin state here? plugin.StateIsNull | plugin.StateIsSet
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.
Nice, I learned something new today. Thanks @vjeffrey 👍🏽
Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
hmm. the other panic is gone:
but i'm seeing this:
|
Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
@@ -133,6 +158,9 @@ func initAwsS3Bucket(runtime *plugin.Runtime, args map[string]*llx.RawData) (map | |||
var arn string | |||
if args["arn"] != nil { | |||
arn = args["arn"].Value.(string) | |||
if !strings.HasPrefix(arn, "arn:aws:s3:") { | |||
return nil, nil, errors.Newf("not a valid bucket ARN '%s'", arn) |
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.
During testing I detected that, if you are NOT in discovery and, you try to access aws.s3.bucket
then we try to "create a bucket resource" of the AWS account, which is incorrect.
Now, we will exit with helpful error message:
cnquery> aws.s3.bucket
not a valid bucket ARN 'arn:aws:sts::123456789012'
aws.s3.bucket: no data available
providers/aws/resources/aws.lr
Outdated
// Unique ID for the policy | ||
id string | ||
// Name for the policy | ||
// Deprecated |
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.
nit: can you add "use bucketName instead" so that the deprecation reason is clear?
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.
Done
This change allows running
aws.s3.bucket.policy
when in discovery mode.Also, fixes the issue discovered at #5218
where we noticed that the policy resource doesn't implement the
id()
func properly.Closes #5169