Skip to content
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

aws - elastic-ip - used-by filter #9958

Merged
merged 6 commits into from
Jan 30, 2025

Conversation

naohito-intuit
Copy link
Contributor

@naohito-intuit naohito-intuit commented Jan 25, 2025

Add a new used-by filter to the elastic-ip (network-addr) resource to help identify the type of service that the Elastic IP is associated with. It utilizes the get_eni_resource_type utility function contributed in #8028. It will make one API call to get a list of network interfaces that are associated with EIPs.

Initially I was going to add a used filter, but we can check the usage simply by checking the AssociationId attribute using the value filter. The used-by filter returns the resource type that the ENI which EIP is associated with, is attached to.

Background

The Amazon EC2 and NLBs are the only resources that can be protected by AWS Shield Advanced by attaching EIPs. Other resources such as NAT Gateway, Transit Gateway, VPC Endpoint, or AWS Lambda don't need AWS Shield Advanced. Thus, we need a way to filter them out.

Available Types

  • ec2
  • elb-app
  • elb-net
  • elb-gwy
  • elb
  • apigw
  • dax
  • dir
  • dms
  • ecs
  • fsmt
  • elasticache
  • emr
  • hsm
  • hsmv2
  • lambda
  • nat
  • rds
  • redshift
  • tgw
  • vpce
  • eks
  • unknown

Example

policies:
  - name: eip-shield-advanced-enable
    resource: elastic-ip
    description: |
      Enables AWS Shield Advanced for Elastic IPs that are used by EC2 instances or Network Load Balancers
    filters:
      - or:
        # Associated with EC2
        - type: value
          key: InstanceId
          value: present
        # Associated with NLB
        - type: used-by
          resource-type: elb-net
      # No Shield Advanced Protection
      - type: shield-enabled
        state: false
    actions:
      - type: set-shield
        state: true

c7n/resources/vpc.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@kapilt kapilt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the changes, lgtm

@kapilt kapilt merged commit 496eeed into cloud-custodian:main Jan 30, 2025
22 checks passed
@naohito-intuit naohito-intuit deleted the CLOP-25043 branch January 30, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants