-
Notifications
You must be signed in to change notification settings - Fork 16
add customprecompare to normalize policy #75
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
Conversation
a-hilaly
left a comment
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.
Thanks @rushmash91 !
pkg/resource/queue/hooks.go
Outdated
| var policyDoc policy.Policy | ||
|
|
||
| decoder := json.NewDecoder(bytes.NewBufferString(jsonStr)) | ||
| decoder.DisallowUnknownFields() |
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'm curious, why DisallowUnknownFields ? AFAIK iam-controller doesn't use this approach
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.
DisallowUnknownFields will catch unknown fields in the policy.
Readme:
https://github.com/micahhausler/aws-iam-policy
invalidPolicyJSON := []byte(`{
"Id": "CloudTrailBucketPolicy",
"Foo": "hypothetical new field",
"Statement": [
{
"Sid": "AWSCloudTrailWrite20150319",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::examplebucket/AWSLogs/123456789012/*"
}
]
}`)
var p policy.Policy
decoder := json.NewDecoder(bytes.NewBuffer(invalidPolicyJSON))
decoder.DisallowUnknownFields()
err := decoder.Decode(&p)
if err != nil {
fmt.Println(err)
}
// Output:
// json: unknown field "Foo"
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 use this in the iam controller as well?
pkg/resource/queue/hooks.go
Outdated
| // normalizeRedrivePolicyString takes an SQS RedrivePolicy JSON string, unmarshals | ||
| // it into an interface{}, and then marshals it back into a compact JSON string. | ||
| // This normalizes whitespace and key order using a generic approach. | ||
| // https://go.dev/play/p/YtzsxG0l9ze | ||
| func normalizeRedrivePolicyString(jsonStr string) (string, error) { |
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.
why isn't this one using a custom decoder w/ DisallowUnknownFields
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.
RedrivePolicy is not an iam policy, so cant use it.
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html
so using an interface: https://go.dev/play/p/PSV7ZxUQykg
took the string from the issue: aws-controllers-k8s/community#2421
9097fad to
b60ef36
Compare
michaelhtm
left a comment
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.
Thank you @rushmash91 👍
left a few comments below
| decoderB.DisallowUnknownFields() | ||
| errB := decoderB.Decode(&policyB) | ||
|
|
||
| if errA != nil || errB != nil || !reflect.DeepEqual(policyA, policyB) { |
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.
should this be && instead?
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.
Depends do we want a diff if the unmarshal fails? I think it might be better for it to show up..
michaelhtm
left a comment
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.
Thank you @rushmash91
left a few more comments
|
@rushmash91: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
Nice 👍 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: michaelhtm, rushmash91 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
fixes aws-controllers-k8s/community#2421
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.