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

[PR #5203/4c52fdb9 backport][stable-5] seport: add local argument #5218

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Sep 3, 2022

This is a backport of PR #5203 as merged into main (4c52fdb).

Using local: true users can enforce to work only with local policy
modifications. i.e.

# Without `local`, no new modification is added when port already exists
$ sudo ansible -m seport -a 'ports=22 state=present setype=ssh_port_t proto=tcp' localhost

localhost | SUCCESS => {
    "changed": false,
    "ports": [
        "22"
    ],
    "proto": "tcp",
    "setype": "ssh_port_t",
    "state": "present"
}

$ sudo semanage port -l -C

# With `local`, a port is always added/changed in local modification list
$ sudo ansible -m seport -a 'ports=22 state=present setype=ssh_port_t proto=tcp local=true' localhost

localhost | CHANGED => {
    "changed": true,
    "ports": [
        "22"
    ],
    "proto": "tcp",
    "setype": "ssh_port_t",
    "state": "present"
}

$ sudo semanage port -l -C
SELinux Port Type              Proto    Port Number

ssh_port_t                     tcp      22

# With `local`, seport removes the port only from local modifications
$ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp local=true' localhost

localhost | CHANGED => {
    "changed": true,
    "ports": [
        "22"
    ],
    "proto": "tcp",
    "setype": "ssh_port_t",
    "state": "absent"
}

$ sudo semanage port -l -C

# Even though the port is still defined in system policy, the module
# result is success as there's no port local modification
$ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp local=true' localhost

localhost | SUCCESS => {
    "changed": false,
    "ports": [
        "22"
    ],
    "proto": "tcp",
    "setype": "ssh_port_t",
    "state": "absent"
}

# But it fails without `local` as it tries to remove port defined in
# system policy
$ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp' localhost

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: Port tcp/22 is defined in policy, cannot be deleted
localhost | FAILED! => {
    "changed": false,
    "msg": "ValueError: Port tcp/22 is defined in policy, cannot be deleted\n"
}

Signed-off-by: Petr Lautrbach [email protected]

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
  • New Module Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION

Using `local: true` users can enforce to work only with local policy
modifications. i.e.

    # Without `local`, no new modification is added when port already exists
    $ sudo ansible -m seport -a 'ports=22 state=present setype=ssh_port_t proto=tcp' localhost

    localhost | SUCCESS => {
        "changed": false,
        "ports": [
            "22"
        ],
        "proto": "tcp",
        "setype": "ssh_port_t",
        "state": "present"
    }

    $ sudo semanage port -l -C

    # With `local`, a port is always added/changed in local modification list
    $ sudo ansible -m seport -a 'ports=22 state=present setype=ssh_port_t proto=tcp local=true' localhost

    localhost | CHANGED => {
        "changed": true,
        "ports": [
            "22"
        ],
        "proto": "tcp",
        "setype": "ssh_port_t",
        "state": "present"
    }

    $ sudo semanage port -l -C
    SELinux Port Type              Proto    Port Number

    ssh_port_t                     tcp      22

    # With `local`, seport removes the port only from local modifications
    $ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp local=true' localhost

    localhost | CHANGED => {
        "changed": true,
        "ports": [
            "22"
        ],
        "proto": "tcp",
        "setype": "ssh_port_t",
        "state": "absent"
    }

    $ sudo semanage port -l -C

    # Even though the port is still defined in system policy, the module
    # result is success as there's no port local modification
    $ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp local=true' localhost

    localhost | SUCCESS => {
        "changed": false,
        "ports": [
            "22"
        ],
        "proto": "tcp",
        "setype": "ssh_port_t",
        "state": "absent"
    }

    # But it fails without `local` as it tries to remove port defined in
    # system policy
    $ sudo ansible -m seport -a 'ports=22 state=absent setype=ssh_port_t proto=tcp' localhost

    An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: Port tcp/22 is defined in policy, cannot be deleted
    localhost | FAILED! => {
        "changed": false,
        "msg": "ValueError: Port tcp/22 is defined in policy, cannot be deleted\n"
    }

Signed-off-by: Petr Lautrbach <[email protected]>

Signed-off-by: Petr Lautrbach <[email protected]>
(cherry picked from commit 4c52fdb)
@patchback patchback bot mentioned this pull request Sep 3, 2022
@felixfontein felixfontein merged commit e646d21 into stable-5 Sep 3, 2022
@felixfontein felixfontein deleted the patchback/backports/stable-5/4c52fdb9d91bc4b6293fcf6273d38f24e3b886aa/pr-5203 branch September 3, 2022 09:58
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