Skip to content

iptables and match-set with two parameters #29423

Closed

Description

@l13t

I have such configuration:

iptables_outsideIn_rule11:
  iptables.append:
    - table: filter
    - match:
      - comment
      - set
    - chain: outsideIn
    - jump: ACCEPT
    - proto: 
    - match-set:
      - WWW-VIP dst
      - CL_WWW-DEWLT-STAGING src
    - comment: outsideIn_11 dewlt-staging HTTP/HTTPS access to WWW-VIP

When I run salt-call with debug option, i'm getting next output for this rule:

/sbin/iptables -t filter -C outsideIn -m comment -m set --comment "outsideIn_11 dewlt-staging HTTP/HTTPS access to WWW-VIP" --match-set [\'WWW-VIP dst\', \'CL_WWW-DEWLT-STAGING src\'] --jump ACCEPT

As I can see iptables state and module doesn't proceed match-set with multiple parameters. Any ideas or proposals how it can be fixed?

Activity

  1. l13t commented on Dec 4, 2015

    @l13t
    ContributorAuthor

    Update:
    I thought about appending string with variables.
    For such configuration:

    iptables_outsideIn_rule11:
      iptables.append:
        - table: filter
        - match:
          - comment
          - set
        - chain: outsideIn
        - jump: ACCEPT
        - proto: 
        - match-set: WWW-VIP dst
        - match-set: CL_WWW-DEWLT-STAGING src
        - comment: outsideIn_11 dewlt-staging HTTP/HTTPS access to WWW-VIP

    I got such string generated:

    /sbin/iptables -t filter -C outsideIn -m comment -m set --comment "outsideIn_11 dewlt-staging HTTP/HTTPS access to WWW-VIP" --match-set CL_WWW-DEWLT-STAGING src --jump ACCEPT

    For some reason it doesn't proceed inserted twice option and gets only last one.

  2. l13t commented on Dec 4, 2015

    @l13t
    ContributorAuthor

    One variant:
    In /usr/lib/python2.7/dist-packages/salt/modules/iptables.py insert into build_rule funnction after proceeding match with if next code:

        if 'match-set' in kwargs:
            if not isinstance(kwargs['match-set'], list):
                kwargs['match-set'] = kwargs['match-set'].split(',')
            for match_s in kwargs['match-set']:
                rule += '-m set --match-set {0} '.format(match_s)
            del kwargs['match-set']
  3. added
    bug
    severity-medium
    P3
    Platform
    on Dec 4, 2015
  4. added this to the Approved milestone on Dec 4, 2015
  5. jfindlay commented on Dec 4, 2015

    @jfindlay
    Contributor

    @l13t, thanks for working on this. You are welcome to submit a pull request for this against 2015.8. @thusoy, please also review.

  6. thusoy commented on Dec 4, 2015

    @thusoy
    Contributor

    Some thoughts:

    • -m set only needs to be added to the rule once (right?), thus can be pulled out of the loop
    • rule is a list, thus appending needs to be done using rule.append.
    • Splitting on comma as a fallback is probably not too wise, as commas can be used in the flag spec to seperate flags (see docs)

    Put it next to and integrate with the deprecated set handling in build_rule and I'm happy.

  7. l13t commented on Dec 4, 2015

    @l13t
    ContributorAuthor

    My current formula in result has next code:

    iptables_outsideIn_rule11:
      iptables.append:
        - table: filter
        - match:
          - comment
          - set
        - chain: outsideIn
        - jump: ACCEPT
        - proto: 
        - match-set: 
          - WWW-VIP dst
          - CL_WWW-DEWLT-STAGING src
        - comment: outsideIn_11 dewlt-staging HTTP/HTTPS access to WWW-VIP

    But it would be better if match-set in result would have next structure:

    match-set:
      src:
        - src_set_1
        - src_set_2
      dst:
        - dst_set_1
        - dst_set_2

    And then result of proceeding such configuration would be:

    iptables -<some option list> -m set --match-set src_set_1,src_set_2 src -m set --match-set dst_set_1,dst_set_2 dst

    If I clearly understand iptables man pages it should work.

  8. thusoy commented on Dec 7, 2015

    @thusoy
    Contributor

    Cool, learned something new today about -m set.

    Why exactly is the latter example you posted better? I haven't used ipset much myself, but from reading the manpages the format of the argument is --match-set setname flag[,flag], to which I think your first example maps cleaner, and is easier to reason about and implement.

  9. l13t commented on Dec 7, 2015

    @l13t
    ContributorAuthor

    About last example.
    I think it's better for visual understanding. Cause we can specify several ipset lists per one of directions (src and dst).
    I saw your reply to pull request. I agree that my "patch" is not so good and I didn't checked variant with negotiations. I can try to fix this and create new pull request.

  10. l13t commented on Dec 7, 2015

    @l13t
    ContributorAuthor

    @thusoy
    I thought about your proposal one more time. I think it would be really better to have next structure for match-set option:

        - match-set: 
          - WWW-VIP dst
          - CL_WWW-DEWLT_1-STAGING src
          - CL_WWW-DEWLT_2-STAGING src

    It would prevent issue with negotiation of all list. Anyway it works if we're specifying set's one-by-one.
    And it should be documented as well ((:

  11. l13t commented on Dec 9, 2015

    @l13t
    ContributorAuthor

    I updated iptables module. It now includes check for negotiation.
    While I was working on my iptables formula for linux firewall I got that we should manually specify next thing:

    - match:
      -iprange
    - dst-range: 10.0.0.2-10.0.0.5

    But i saw a ticket there with proposal totally rewrite this module. Hope this also would be fiixed in future.

  12. added a commit that references this issue on Dec 16, 2015
    387ac2c
  13. added a commit that references this issue on Feb 12, 2016
    ceae2a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Execution-ModuleP3Platformbugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions