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

Add rule revocation capabilities to ec2_group #23619

Closed
wants to merge 1 commit into from

Conversation

Sodki
Copy link
Contributor

@Sodki Sodki commented Apr 14, 2017

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_group

ANSIBLE VERSION
ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12+ (default, Sep 17 2016, 12:08:02) [GCC 6.2.0 20160914]
SUMMARY

ec2_group allows us to create security groups, to remove security groups and to add new rules to security groups. What it doesn't allow us to do is to remove rules, so we can't easily revoke rules that have been set. With this change we can.

Fixes #20456

@ansibot
Copy link
Contributor

ansibot commented Apr 14, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 aws cloud committer_review In order to be merged, this PR must follow the certified review workflow. feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Apr 14, 2017
@ansibot
Copy link
Contributor

ansibot commented Apr 14, 2017

The test ansible-test sanity --test pep8 failed with the following error:

lib/ansible/modules/cloud/amazon/ec2_group.py:643:8: E114 indentation is not a multiple of four (comment)

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed committer_review In order to be merged, this PR must follow the certified review workflow. labels Apr 14, 2017
@ansibot ansibot added committer_review In order to be merged, this PR must follow the certified review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 14, 2017
Copy link
Contributor

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

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

The code/documentation looks good. I guess using the option to purge rules isn't working well for your use cases?

@Sodki
Copy link
Contributor Author

Sodki commented Apr 18, 2017

The problem with purging rules is that you need to calculate the difference between the current rules and the rules that you want to remove, which is a bit daunting, specially if you're using it extensively.

Revocation capabilities are already present in AWS's API and Boto, this PR just makes Ansible aware of them.

@s-hertel
Copy link
Contributor

@Sodki Makes sense, it sounds tedious until it's automated. Hm. What is your process for adding rules/egress rules? How do you get the ips and ports?

@Sodki
Copy link
Contributor Author

Sodki commented Apr 18, 2017

We mostly deal with security groups. Let's say that a service is responsible for making itself work, so when it comes alive it will open the necessary ports on the services it needs. When it's time to destroy that service, it cleans itself up by revoking the access it initially created.

@Sodki
Copy link
Contributor Author

Sodki commented Apr 18, 2017

I just hit a wall and realised this alone isn't necessarily idempotent when using group names. Group ids should work just fine.

If we do the revocation over and over again, it is idempotent, but as soon as the group is removed, this module will fail because ec2_group will try to create a group from a revocation rule and fail because no description was given.

@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Apr 19, 2017
@shaunbrady
Copy link
Contributor

This type of feature would be excellent.

@captainkerk
Copy link
Contributor

It looks like these changes were approved... is this going to be merged soon?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 3, 2017
@s-hertel
Copy link
Contributor

s-hertel commented May 5, 2017

@captainkerk Hopefully!

@Sodki Can you document the lack of idempotence when using group names for this? And can you fix this to exit gracefully if the group doesn't exist instead of failing?

@captainkerk
Copy link
Contributor

@Sodki If i understand correctly: when revoking a rule referencing a source security group by name, if the name is not found, the module attempts to create the security group to satisfy the condition? But it fails because it tries to create it without having a description?

@s-hertel It seems like you are advocating for the module to fail silently. If the example that @Sodki gave happens, I think the module should fail with a helpful message. This will cause the user to fix the problem (remove the now defunct security group reference from the revocation list) rather than thinking the security group being managed is configured as defined.

@s-hertel
Copy link
Contributor

s-hertel commented May 5, 2017

@captainkerk I'm definitely not advocating for it to fail silently! I haven't run this using group name, but it sounded like it might be raising an exception. If that is the case, it needs to be caught and handled. Regardless though, this needs to be added to the documentation.

@wimnat
Copy link
Contributor

wimnat commented May 14, 2017

I do not think this change should be made in ec2_group.

I think you're better off having a separate module ec2_group_rule that allows the addition and removal of individual rules to a group. If the group didn't exist then the module you just report changed=False and, if you like, an additional message saying the group didn't exist.

It's similar to how the elb classic modules work - one for managing an elb and one for managing the instances attached to that elb. Something similar coming for target groups too.

@ryansb
Copy link
Contributor

ryansb commented May 15, 2017

I think if the idea is to be able to force rules not to exist, a new state parameter would be a better fit, if not a new module for just the rules. How about something like this instead:

- ec2_group:
    name: foobar
    description: Group rules so Foo can access the Bar service
    rules:
      - to_port: 443
        from_port: 443
        proto: tcp
        cidr_ip: 0.0.0.0/0
- ec2_group:
    name: foobar
    state: denied
    rules:
      - to_port: 80
        from_port: 80
        proto: tcp
        cidr_ip: 0.0.0.0/0

So for rules to revoke/deny, you'd have a separate task that would use the same code paths to get info about what rules are in a group, but without adding a parallel set of options (and the confusion of purge vs. revoke option sets). That way, you don't have weird questions like "if someone specifies a rule in both rules and revoke_rules what happens?"

So instead of adding a new parameter, how do you feel about a state instead? @wimnat @Sodki

@wimnat
Copy link
Contributor

wimnat commented May 16, 2017

I still prefer the new module option to be honest.

The beauty of Ansible and desired state config in general is the simplicity. I like simple state is present or state is absent options. Whenever I see more state options I start to worry about code complexity.

# I know absolutely that this is going to try and leave me with an ec2 security group
ec2_group:
  state: present

# I know absolutely that this is going to try and leave me without the ec2 security group rule
ec2_group_rule:
  state: absent

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. support:curated and removed committer_review In order to be merged, this PR must follow the certified review workflow. labels Jun 27, 2017
@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2017

cc @adq
click here for bot help

@ansibot ansibot added the support:certified This issue/PR relates to certified code. label Aug 16, 2017
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:certified This issue/PR relates to certified code. labels Sep 9, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 2, 2018
@s-hertel
Copy link
Contributor

s-hertel commented Nov 30, 2018

This will probably not rebase cleanly since ec2_group has been refactored for boto3. If you're still interested in this, an ec2_group_rule module as wimnat suggested would probably be a better approach than overload this module.

@s-hertel s-hertel closed this Nov 30, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 aws cloud feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2_group should allow for security group revocations
8 participants