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_waf_web_acl failing when configuring rules of type rate_based #1510

Open
1 task done
MrBones757 opened this issue Sep 21, 2022 · 1 comment
Open
1 task done
Labels
bug This issue/PR relates to a bug needs_triage python3 traceback

Comments

@MrBones757
Copy link

MrBones757 commented Sep 21, 2022

Summary

When running the aws_waf_web_acl module with a list of rules that contain a mix of regular and rate_based rules, an error is returned when looking up the name of a rate_based rule.

Issue Type

Bug Report

Component Name

aws_waf_web_acl

Ansible Version

2.9.x, 2.12.x

Collection Versions

amazon.aws - 4.2.0
community.aws - 4.2.0

amazon.aws - 2.2.0
community.aws - 2.2.0

AWS SDK versions

botocore-1.27.77
boto3-1.24.77

Configuration

OS / Environment

N/A

Steps to Reproduce

# anonomised
- name: "Change Web ACL"
  community.aws.aws_waf_web_acl:
    aws_access_key: "some-key"
    aws_secret_key: "some-secret-key"
    security_token: "some-session-token"
    region: "some-region"
    name: "some-waf-classic-name"
    default_action: block
    purge_rules: true
    rules:
      - name: "rule-1"
        priority: 1
        action: allow
        type: "regular"
      - name: "rule-2"
        priority: 2
        action: block
        type: "regular"
      - name: "rule-3"
        priority: 3
        action: block
        type: "regular"
      - name: "rule-4"
        priority: 4
        action: allow
        type: "regular"
      - name: "rule-5"
        priority: 5
        action: block
        type: "regular"
      - name: "rule-6"
        priority: 6
        action: block
        type: "regular"
      - name: "rule-7"
        priority: 7
        action: block
        type: "regular"
      - name: "rule-8"
        priority: 8
        action: allow
        type: "regular"
      - name: "rule-9"
        priority: 9
        action: count
        type: "rate_based"
      - name: "rule-10"
        priority: 10
        action: block
        type: "regular"

Expected Results

Rules are updated as per config

Actual Results

A stack trace is returned, stating that the key is not found.

I believe the root cause of the stack trace below is that this module consumes
https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/waf_web_acl.py#L176

Which in the amazon.aws collection, calls list_web_acls:
https://github.com/ansible-collections/amazon.aws/blob/main/plugins/module_utils/waf.py#L182

I believe something needs to be changed here to call list_rate_based_rules in addition:

@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def list_rate_based_rules_with_backoff(client):
    paginator = client.get_paginator('list_rate_based_rules')
    return paginator.paginate().build_full_result()['Rules']

in this modle, this would be consumed here:
https://github.com/ansible-collections/community.aws/blob/main/plugins/modules/waf_web_acl.py#L193
where the two dictionaries would need to be merged, before being returned

# anonomised
Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1663744496.6413488-455-280617290021228/AnsiballZ_aws_waf_web_acl.py\", line 107, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1663744496.6413488-455-280617290021228/AnsiballZ_aws_waf_web_acl.py\", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1663744496.6413488-455-280617290021228/AnsiballZ_aws_waf_web_acl.py\", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.aws_waf_web_acl', init_globals=dict(_module_fqn='ansible_collections.community.aws.plugins.modules.aws_waf_web_acl', _modlib_path=modlib_path),
  File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.aws.aws_waf_web_acl_payload_57rh61yt/ansible_community.aws.aws_waf_web_acl_payload.zip/ansible_collections/community/aws/plugins/modules/aws_waf_web_acl.py\", line 361, in <module>
  File \"/tmp/ansible_community.aws.aws_waf_web_acl_payload_57rh61yt/ansible_community.aws.aws_waf_web_acl_payload.zip/ansible_collections/community/aws/plugins/modules/aws_waf_web_acl.py\", line 353, in main
  File \"/tmp/ansible_community.aws.aws_waf_web_acl_payload_57rh61yt/ansible_community.aws.aws_waf_web_acl_payload.zip/ansible_collections/community/aws/plugins/modules/aws_waf_web_acl.py\", line 307, in ensure_web_acl_present
  File \"/tmp/ansible_community.aws.aws_waf_web_acl_payload_57rh61yt/ansible_community.aws.aws_waf_web_acl_payload.zip/ansible_collections/community/aws/plugins/modules/aws_waf_web_acl.py\", line 226, in find_and_update_web_acl
  File \"/tmp/ansible_community.aws.aws_waf_web_acl_payload_57rh61yt/ansible_community.aws.aws_waf_web_acl_payload.zip/ansible_collections/community/aws/plugins/modules/aws_waf_web_acl.py\", line 226, in <listcomp>
KeyError: 'rule-9'

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@MrBones757
Copy link
Author

I can submit a PR for this, if the above fix / method is desired, though im not sure if the new list_rate_based_rules_with_backoff belongs here or in amazon.aws

@ansibullbot ansibullbot added bug This issue/PR relates to a bug needs_triage python3 traceback labels Sep 21, 2022
abikouo pushed a commit to abikouo/community.aws that referenced this issue Oct 24, 2023
…tions#1563)

elb_application_lb - fix missing attributes on create

SUMMARY
The create_or_update_alb() function didn't include all attributes when creating a new ALB. This fix just adds a call to the existing update_elb_attributes() and modify_elb_attributes() methods to ensure ALB attributes match supplied params after creating the new ALB.
Fixes ansible-collections#1510
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
elb_application_lb

Reviewed-by: Mark Chappell
Reviewed-by: Helen Bailey <hebailey@redhat.com>
Reviewed-by: Alina Buzachis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug needs_triage python3 traceback
Projects
None yet
Development

No branches or pull requests

2 participants