question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

security-group ingress filters do not support both OnlyPorts and Cidr

See original GitHub issue

Here’s a sample policy that I’ve been fighting with for the past week with no success:

policies:
  - name: high-risk-security-groups-notify
    resource: security-group
    description: |
      Notifies if any rule from a security group that allows 0.0.0.0/0 
      ingress, not on ports 80 or 443, and notify the user who added the 
      violating rule.
    mode:
        type: cloudtrail
        role: arn:aws:iam::xxx:role/CloudCustodian
        events:
          - source: ec2.amazonaws.com
            event: AuthorizeSecurityGroupIngress
            ids: "requestParameters.groupId"
          - source: ec2.amazonaws.com
            event: AuthorizeSecurityGroupEgress
            ids: "requestParameters.groupId"
          - source: ec2.amazonaws.com
            event: RevokeSecurityGroupEgress
            ids: "requestParameters.groupId"
          - source: ec2.amazonaws.com
            event: RevokeSecurityGroupIngress
            ids: "requestParameters.groupId"
    filters:
        - type: ingress
          OnlyPorts: [80, 443]
          Cidr:
            value: "0.0.0.0/0"
    actions:
      - type: notify
        template: default.html
        priority_header: 1
        subject: "Open Security Group Rule Created-[custodian {{ account }} - {{ region }}]"
        violation_desc: "Security Group(s) Which Had Rules Open To The World:"
        action_desc: |
            "Actions Taken:  The Violating Security Group Rule Violates Our Company's 
            Cloud Policy.  Please Refer To The Cloud FAQ."
        to:
          - event-owner
        transport:
          type: sqs
          queue: https://sqs.us-east-1.amazonaws.com/xxx/cloud-custodian-mailer
          region: us-east-1

I’ve tried using -and when defining the filter conditions, but that didn’t seem to make a difference.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
thomasbiddlecommented, Oct 12, 2018

Notifies if any rule from a security group that allows 0.0.0.0/0 ingress, not on ports 80 or 443, and notify the user who added the violating rule.

So how would this work now after all the changes? Everything I’ve tried breaks in one manner or another.

0reactions
kapiltcommented, Jun 25, 2019

the and references in my comments earlier were specific to the internals of the implementation and are configured via match-operator… which defaults to and

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws.security-group — Cloud Custodian documentation
Filter for verifying security group ingress and egress permissions. All attributes of a security group permission are available as value filters.
Read more >
Restrict only Specific Ports in Specific Security Groups using ...
I want to restrict all of the ports exposed to public apart from a few security groups. For example for one of the...
Read more >
Control traffic to resources using security groups
Use security groups to control the inbound and outbound traffic for associated resources.
Read more >
Working with Security Groups — documentation
The rules within a security group may allow only a single IP address/port ... not defining any port range and using the CIDR...
Read more >
Dome9 - GSL Knowledge Base
Ensure no security groups allow ingress from 0.0.0.0/0 to SSH (TCP:22). Risk Level: High. AWS Security Group.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found