salt icon indicating copy to clipboard operation
salt copied to clipboard

iptables module not working?

Open mkoistinen opened this issue 13 years ago • 8 comments

Attempting to do this in an sls file using salt v 0.17.1:

  iptables.append:
    - table: filter
    - chain: INPUT
    - proto: tcp
    - match: tcp
    - source: 10.0.0.0/24
    - destination: {{ private_ip }}
    - destination-port: 3306
    - jump: ACCEPT

Using salt-call on the minion (Ubuntu 12.04.3 LTS) shows:

[INFO    ] Executing state iptables.append for mysql-server
[INFO    ] Executing command 'iptables -t filter -C INPUT -m tcp --destination-port 3306 --proto tcp --destination 10.xxx.xxx.xxx --jump ACCEPT --source 10.0.0.0/24 --__env__ base --__sls__ mysql-server --order 10002 ' in directory '/root'
[INFO    ] Executing command 'iptables -t filter -A INPUT -m tcp --destination-port 3306 --proto tcp --destination 10.xxx.xxx.xxx --jump ACCEPT --source 10.0.0.0/24 --__env__ base --__sls__ mysql-server --order 10002 ' in directory '/root'
[ERROR   ] Failed to set iptables rule for mysql-server

Manually running the rules generated:

iptables -t filter -C INPUT -m tcp --destination-port 3306 --proto tcp --destination 10.xxx.xxx.xxx --jump ACCEPT --source 10.0.0.0/24 --__env__ base --__sls__ mysql-server --order 10002

iptables v1.4.12: unknown option "--__env__"
Try `iptables -h' or 'iptables --help' for more information.

Am I doing it wrong?

mkoistinen avatar Nov 12 '13 00:11 mkoistinen

I think this is a duplicate, there was a bug in the order in which we pass args to iptables. Can you test on develop?

basepi avatar Nov 12 '13 22:11 basepi

I'm having a similar issue, running salt 0.17.2 with iptables 1.4.12 (Ubuntu 12.04's version).

Was this fixed in the .2 release? I couldn't see anything covering it.

[INFO    ] Executing command 'iptables -t filter -A INPUT -m state --jump ACCEPT --state ESTABLISHED
,RELATED --__env__ base --__sls__ firewall --order 10002 ' in directory '/home/vagrant'
[DEBUG   ] output: iptables v1.4.12: unknown option "--__env__"
[INFO    ] Executing state iptables.append for http-in
[INFO    ] Executing command 'iptables -t filter -C INPUT -m state --sport 1025:65535 --proto tcp --
jump ACCEPT --dport 80 --state NEW --__env__ base --__sls__ firewall --order 10004 ' in directory '/
home/vagrant'
[DEBUG   ] output: iptables v1.4.12: unknown option "--sport"

elithrar avatar Dec 20 '13 03:12 elithrar

This has been fixed in develop.

techhat avatar Dec 20 '13 03:12 techhat

@techhat Thanks - for some reason the bootstrap script is still installing 0.17.2 (and Vagrant & Packer use this to bootstrap salt-masterless). I've posted about it on the mailing list too: https://groups.google.com/forum/#!topic/salt-users/ym1OSmdCP1o

I should note that the second error (output: iptables v1.4.12: unknown option "--sport") I'm having appears to be an ordering issue. If I change the order of the arguments (when runinng it manually) so that --proto tcp comes before --sport 1025:65535 there's no issue. Let me know if I should submit a new issue for this.

On Fri, Dec 20, 2013 at 11:09 AM, Joseph Hall [email protected]:

This has been fixed in develop.

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/8419#issuecomment-30986103 .

elithrar avatar Dec 20 '13 04:12 elithrar

@elithrar and @mkoistinen, see #8237 which resolves the __env__, etc issues. Also, I haven't been able to find the pull request for it, but you can see that the develop branch does explicitly handle ordering for proto, dport and sport:

https://github.com/saltstack/salt/blob/develop/salt/modules/iptables.py#L111-L121

Also, referencing #7995.

techhat avatar Dec 20 '13 12:12 techhat

Because of the amount of recent churn in the iptables module, many of the bugfixes didn't make it into 0.17.4, and won't be in until the next release (hopefully in RC at the first of the year)

basepi avatar Dec 20 '13 23:12 basepi

@techhat @basepi Thanks for the updates: appreciated. Will use file.managed for the moment until the bugfixes make it into a release and refactor from there.

Cheers!

elithrar avatar Dec 21 '13 01:12 elithrar

Closing as this is a duplicate and the other bug seems to have been resolved last year.

ssgward avatar Nov 10 '14 22:11 ssgward