Skip to content

Firewalld open sshd port #2285

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

Merged
merged 17 commits into from
Sep 13, 2017

Conversation

yuumasato
Copy link
Member

Select Rule firewalld_sshd_port_enabled in Profiles that

  • set default zone drop for firewalld and
  • allows sshd to be enabled
    Except for stig-rhel7-disa Profile.

Add remediation for configure_firewalld_ports, used only by stig-rhel7-disa Profile.

Add OVAL definition to check if current default zone allows ssh. The check fetches current set default zone from /etc/firewalld/firewalld.conf and verifies if it allows ssh service.

Issue: Above check will lead us to a situation where we will need two runs of scans and remediation.
During first scan, all zones, and current zone will allow service ssh. But then remediation will change default zone to drop. And default zone drop is not customized to allow ssh, and a second run of remediation will be needed.
Question: Can we compromise on this check and always check for /etc/firewalld/zones/drop.xml?

@jan-cerny
Copy link
Collaborator

Regarding your new issue: Can we simply allow ssh in remediation script that sets the default firewall zone? shared/templates/static/bash/set_firewalld_default_zone.sh


. /usr/share/scap-security-guide/remediation_functions

package_command install firewalld
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it was already there, but I wonder. I thought that there is a separate rule checking if package firewalld is installed? There could be also a separate remediation that just installs the package.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is separate Rule for firewalld installed with its own fix, but it is not selected anywhere.
Installing the package we are configuring during remediation is the way we are dealing with dependency on package_foo_installed Rules.
Not ideal, but this works around need of XCCDF requires.

@redhatrises
Copy link
Contributor

configure_firewalld_ports.sh should not have a remediation script associated with it. Those should come from the <extended_definition /> scripts. These type of issues make me think that the order with which we scan and remediate rules is wrong. I wonder if we check for services first we would avoid these issues. Although, I guess not as if you don't select the correct service rule it wouldn't remediate correctly.

We should check that SSH is enabled in one of the zones but not necessarily the default zone. We should never check the drop zone for ssh enabled. In addition, the default zone may not be the zone in which the nic that SSH is enabled on is actually listening.

@yuumasato
Copy link
Member Author

configure_firewalld_ports.sh should not have a remediation script associated with it. Those should come from the <extended_definition /> scripts.

The check comes from OVAL extend_definition elements, but the fixes comes from XCCDF, and it is picked automatically by build system by looking at Rule ID.
Moreover, what is checked in configure_firewalld_ports may change in the future, enabling other ports, right? So an appropriate remediation script be might be needed anyway.

These type of issues make me think that the order with which we scan and remediate rules is wrong. I wonder if we check for services first we would avoid these issues. Although, I guess not as if you don't select the correct service rule it wouldn't remediate correctly.

Evaluation of Rules occurs according to their order in the Benchmark, scanner should go from top to bottom. (Note that order of selectors in Profile doesn't affect order of evaluation of Rules, this bit me while writing test for XCCDF requires PR for OpenSCAP).
I see in the benchmark that for firewalld, package installed is before configure_firewalld_ports.
And for sshd, firt is package installed, then service enabled, and then other Rules.

The problem I see is that scanner first evaluates all Rules, then remediates all Rules.
Does specification allow scanner to have a mode in which a Rule evaluated as false is remediated before moving to evaluating next Rule?

We should check that SSH is enabled in one of the zones but not necessarily the default zone. We should never check the drop zone for ssh enabled. In addition, the default zone may not be the zone in which the nic that SSH is enabled on is actually listening.

So we should check if there is at least one NIC assigned to a zone which allows SSH.
As for the remediation for firewalld_sshd_port_enabled, as it is now, it allows service ssh to current default zone, be it drop or other. We should specify a zone, and have a variable for user to customize it.

@yuumasato yuumasato force-pushed the firewalld_open_sshd_port branch from 195ac52 to f170ad3 Compare September 6, 2017 13:09
@yuumasato
Copy link
Member Author

I have changed check to verify if there is any NIC assigned to a zone which allows service SSH.
We still miss remediation.
I'm not sure what values to use fore remediation.
Defaulting to first Ethernet interface found is ok?
And what zone to assign the NIC to?

@yuumasato
Copy link
Member Author

@openscap-ci test this please

There was error during fetch of repository:
https://jenkins.open-scap.org/job/scap-security-guide-pull-requests/311/label=ssg_new/console

@yuumasato
Copy link
Member Author

@openscap-ci test this please

@shawndwells
Copy link
Member

WRT NIC assignments: How does Anaconda open up the ports? Is it anything more than
firewall-cmd --zone=public --add-port=22/tcp --permanent ?

@yuumasato
Copy link
Member Author

@openscap-ci test this please

@yuumasato
Copy link
Member Author

@shawndwells In witch context? We don't have remediation for Anaconda for firewalld.

@redhatrises
Copy link
Contributor

@shawndwells In witch context? We don't have remediation for Anaconda for firewalld.

Which I would argue more and more that we need to have.

I'm not sure what values to use fore remediation.
Defaulting to first Ethernet interface found is ok?
And what zone to assign the NIC to?

I would do the following:

  1. Check if ssh is enabled in a zone. If not, fix.
  2. Check if nic is assigned to a zone. If not fix.
  3. If nic is assigned to zone, and ssh is enabled, do nothing. This should account for custom zone and nic settings.

@shawndwells
Copy link
Member

shawndwells commented Sep 6, 2017 via email

@redhatrises
Copy link
Contributor

@yuumasato I wonder if we could create some sort of way to extend remediation scripts to follow their extended definitions so that we don't have to duplicate scripts. Might not be in this PR, but it could be beneficial to prevent script duplication as well as allow us to extend scripts easier?

@yuumasato
Copy link
Member Author

yuumasato commented Sep 7, 2017

@redhatrises What would be the benefits of an Anaconda remediation? OAA will run the post install scan and remediation.

What we will need is a bash remediation that doesn't depend on firewall-cmd command. As we are in chrooted environment firewall-cmd will probably not be available.

So, for the remediation of this rule I will default to adding the first ethernet interface found to the public zone.

About extending remediations, that could be helpful. But I'm not sure if automatically mimicking the extends done in OVAL is a good idea.

@redhatrises
Copy link
Contributor

redhatrises commented Sep 7, 2017

@redhatrises What would be the benefits of an Anaconda remediation? OAA will run the post install scan and remediation.

Not true with anaconda scripts which are supposed to be evaluated pre-install using python kickstart functionality. If the anaconda scripts are not evaluated before the system acutally installs, this is a serious bug as the kickstart and build is supposed to be modified to fix packages, services, etc. By adding the kickstart firewall command functionality to OAA, this should handle setting firewall settings, and we don't have to worry about firewall-cmd as that is handled for us.

For post-install, these remediation scripts are still needed hence what you are doing in this PR.

About extending remediations, that could be helpful. But I'm not sure if automatically mimicking the extends done in OVAL is a good idea.

True. Just a thought. It does seem weird to me that any remediation script associated with <extend_definition/> is not run as part of the remediation. But I guess the issue lies with the fact that <fixtext/> is in XCCDF and not OVAL.

For all Profiles, except stig-rhel7-disa, select firewalld_sshd_port_enabled
Rule in Profiles that select Rule set_firewalld_default_zone.
Add OVAL definition that checks if there exists a NIC assigned to a
firewalld zone with service sshd enabled.
Do not evalute to true if no config that allows sshd port exists.
Fedora is not fetching Rules from shared directory.
Decouple fix for listening port from fix of SSH enabled zone.
They are not mutualy exclusive.

Plus, do not add SSH service to current firewalld default zone, add it
to public zone.
Add iteractively tailorable value to specify which firewalld zone will
have SSH service enabled by remediation.
Be sure only port in SSH service is the one configured through Value
sshd_listening_port.
Check if there is a ethernet NIC bounded to a SSH enabled zone.
If not, add first ethernet NIC to the SSH enabled zone.
@yuumasato
Copy link
Member Author

I'll add some tests for this remediation.

Ethernet interfaces can be named with previx 'en' or 'eth'.
combine-remediations.py handle fixparts in pairs.
If two function calls are put after each other, the second call of the
function will not be expanded, just appended as pure text.

By adding newlines we workaround this issue, the newline is the
second element in the pair, and is just fine being appended.
Tested scenarios:
- There is no NIC assigned to a ssh enabled zone
- There is no zone with ssh service enabled
- There is only one zone with ssh service enabled, and NIC is assigned
to zone with ssh service disabled
@yuumasato yuumasato force-pushed the firewalld_open_sshd_port branch from 274eb86 to 7262205 Compare September 12, 2017 15:30
@yuumasato
Copy link
Member Author

Regarding Anaconda scenario, OAA doesn't support kickstart firewall option.
So, the way to go for now is to have bash remediation based on sed/grep functions.

Reduce dependency of firewalld_sshd_port_enabled remediation on
firewall-cmd command.
Manipulate configuration files whenever possible.

Also do the similar changes for configure_firewalld_ports remediation.

These remediations are now suitable for chrooted and non-chrooted
environments.
Add all pre-defined zones of firewalld to Value firewalld_sshd_zone.
Do no allow interactive change of firewalld_sshd_zone Value.
@yuumasato
Copy link
Member Author

This should be complete now. Summary for reviewer:

  • Rule 'firewalld_sshd_port_enabled' selected in Profiles that set drop as default zone
  • OVAL definition updated to check that there is a NIC assigned to a zone with SSH enabled
  • Remediation that can add SSH service to a zone and bind a NIC to it
    • Defaults to public zone and first ethernet interface found
    • Works in chrooted and non-chrooted environments
  • Tests scenarios for remediation added

Log of SSG TestSuite:

Setting console output to log level INFO
INFO - Logging into /home/wsato/git/scap-security-guide/tests/logs/rule-custom-2017-09-13-1514/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_firewalld_sshd_port_enabled
INFO - Script no_nic_in_ssh_zone.fail.sh using profile xccdf_org.ssgproject.content_profile_ospp-rhel7 OK
INFO - Script ssh_zone_nic_bounded.pass.sh using profile xccdf_org.ssgproject.content_profile_ospp-rhel7 OK
INFO - Script ssh_zone_and_nic_mismatch.fail.sh using profile xccdf_org.ssgproject.content_profile_ospp-rhel7 OK
INFO - Script no_ssh_zone.fail.sh using profile xccdf_org.ssgproject.content_profile_ospp-rhel7 OK
INFO - All snapshots reverted successfully

@mpreisler mpreisler added this to the 0.1.36 milestone Sep 13, 2017
@mpreisler mpreisler self-assigned this Sep 13, 2017
@mpreisler mpreisler added the bugfix Fixes to reported bugs. label Sep 13, 2017
@mpreisler
Copy link
Member

ACK. Awesome stuff.

@mpreisler mpreisler merged commit 460c629 into ComplianceAsCode:master Sep 13, 2017
@dahaic
Copy link
Contributor

dahaic commented Sep 13, 2017

Thank you, great PR!

I have one possible issue with that - in real scenarios, it's more than likely that multiple network interfaces are present on the machine, and a specific one (it might be even a bond or VPN connection, not the low-level stuff) is supposed to have ssh allowed.

Can you alter the code once again to have network interface in the value? (With possible default behaviour not touching interfaces at all?). Thanks!

@yuumasato yuumasato deleted the firewalld_open_sshd_port branch September 14, 2017 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes to reported bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants