Open ZenoRewn opened 1 year ago
Resource: security-group CATEGORY: Filter Item: PrefixListIds
---above can work to filter prefix list--- But When you are allow all traffic policy with prefixlist, it can't work properly Still finding workaround or how to filter all traffic with prefixlistid.
policies:
- name: prefix
resource: security-group
description: This works for filter prefix list. But not on all traffic.
filters:
- type: ingress
PrefixListIds: [PrefixListId: "pl-0bb6fa005053d29a9"]
If your existing policy works for finding the prefix lists, you should be able to add an IpProtocol
key to catch the 'all traffic' case:
policies:
- name: prefix
resource: security-group
filters:
- type: ingress
IpProtocol: '-1'
PrefixListIds: [PrefixListId: "pl-0bb6fa005053d29a9"]
Note that you do need '-1'
in quotes since the API response is a string. Without quotes it'll treat -1
as an integer and fail to match.
While testing this locally, I did notice that the fanciness of the ingress
filter won't match a policy like yours if there's a description on the security group rule that has the prefix list association. One way to work around that is by using a value filter instead, so your policy would become:
policies:
- name: prefix
resource: security-group
filters:
- type: value
key: |
IpPermissions[?
IpProtocol == '-1'
&& PrefixListIds[?PrefixListId == 'pl-0bb6fa005053d29a9']
]
value: not-null
That's unfortunately an uglier policy, but it does seem to more reliably capture your intent.
Hi ajkerrigan@,
Thanks for your supporting. And Happy 2023 New Year~
I tried your policy and it's worked. If I need to filter the ingress all traffic, seems like value filter is the only option. Correct? If I don't add 'IpProtocol' then the policy can't filter ingress all traffic security group rules.
Describe the bug
We had multi accounts. And I tried to enhanced our security group policy by aws prefix-list.
With the same custodian env, my account can return the expect result. Like Match SG who is using the prefix-list. But other accounts can't return the expect result.
What did you expect to happen?
Policy-A and Policy-B just prefix id is different. And I'm sure about those prefix id existed on corresponding account.
Policy-A:
Policy-B:
---custodian run--- Account-A returns as below:
Cloud Provider
Amazon Web Services (AWS)
Cloud Custodian version and dependency information
Policy
Relevant log/traceback output
---metadata---