Skip to content

ENT-13766: Fixes / improvements / security hardning#2131

Open
larsewi wants to merge 5 commits intocfengine:masterfrom
larsewi:provision
Open

ENT-13766: Fixes / improvements / security hardning#2131
larsewi wants to merge 5 commits intocfengine:masterfrom
larsewi:provision

Conversation

@larsewi
Copy link
Contributor

@larsewi larsewi commented Mar 5, 2026

  • Suppress cleanup() errors for missing files
  • Export NO_CONFIGURE so it propagates to autogen.sh subprocesses
  • Harden SSH on build hosts: disable root login and password auth
  • Install epel-release on all RHEL/CentOS versions
  • Install and configure fail2ban on all build hosts

@larsewi larsewi changed the title Suppress cleanup() errors for missing files More fixes / improvements to buildscripts and build machine provisioning Mar 5, 2026
@larsewi larsewi changed the title More fixes / improvements to buildscripts and build machine provisioning More fixes / improvements to buildscripts and buildmachine provisioning Mar 5, 2026
@larsewi larsewi changed the title More fixes / improvements to buildscripts and buildmachine provisioning ENT-13766: Fixes / improvements / security hardning Mar 5, 2026
larsewi and others added 5 commits March 5, 2026 16:38
The mv commands in cleanup() print confusing "cannot stat" errors when
files don't exist, which is expected on first provisioning runs.

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Disable PermitRootLogin, PasswordAuthentication, and
KbdInteractiveAuthentication in sshd_config to enforce key-only SSH
access. This prevents brute force attacks on VMs exposed via autossh
tunnels through the SSH bridge.

Ticket: ENT-13766
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Broaden epel-release from redhat_7/centos_7 only to all redhat/centos
platforms. This is needed to install fail2ban (and potentially other
EPEL packages) on RHEL 8/9/10.

Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Install fail2ban on Debian/Ubuntu and RHEL/CentOS platforms to ban IPs
with repeated failed SSH auth attempts. Configures sshd jail with
5 max retries, 1 hour ban time, and 10 minute find window.

Ticket: ENT-13766
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines -64 to +65
NO_CONFIGURE=1 run_and_print_on_failure ./autogen.sh
export NO_CONFIGURE=1
run_and_print_on_failure ./autogen.sh
Copy link
Member

Choose a reason for hiding this comment

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

@larsewi isn't this exactly the same?

Copy link
Member

@olehermanse olehermanse Mar 6, 2026

Choose a reason for hiding this comment

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

echo 'echo "  In child script:       NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"' > autogen.sh

run_and_print_on_failure() {
    echo "  Inside function:       NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"
    bash -c 'echo "  In child process:      NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"'
    bash $1
}

echo "=== Test 1: prefix assignment ==="
(
    NO_CONFIGURE=1 run_and_print_on_failure autogen.sh
)

echo ""
echo "=== Test 2: export ==="
(
    export NO_CONFIGURE=1
    run_and_print_on_failure autogen.sh
)
$ bash test.sh
=== Test 1: prefix assignment ===
  Inside function:       NO_CONFIGURE=1
  In child process:      NO_CONFIGURE=1
  In child script:       NO_CONFIGURE=1

=== Test 2: export ===
  Inside function:       NO_CONFIGURE=1
  In child process:      NO_CONFIGURE=1
  In child script:       NO_CONFIGURE=1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true for bash, but not dash. So it fails on the Debian 9 bootstrap host.

When a shell function is executed, the variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to the values given. Linux Man Pages

The key phrase is "local to the function" — dash makes them local, not exported. That means child processes spawned within the function don't inherit them.

Copy link
Member

@olehermanse olehermanse Mar 6, 2026

Choose a reason for hiding this comment

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

The key phrase is "local to the function" — dash makes them local, not exported. That means child processes spawned within the function don't inherit them.

I think that's ambiguous, exactly what "local to the function" means here. My interpretation, which seems to align with all the shells I tested on is that "local to the function" means it will be unset after the function, but it will be set for subprocesses spawned inside the function. This also makes it so functions work "the same" / similarily as commands which start binaries / spawn subprocesses.

I tested in dash with Debian 12, exactly the same result - maybe a bug in debian 9 version of dash?

Copy link
Member

Choose a reason for hiding this comment

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

Interesting - tested with Craig and it does make a difference on Debian 9, but looks like a bug IMO:

echo 'echo "  In child script:       NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"' > autogen.sh

in_sub_function() {
    echo "  Inside subfunction:    NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"
}

run_and_print_on_failure() {
    echo "  Inside function:       NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"
    dash -c 'echo "  In child process:      NO_CONFIGURE=${NO_CONFIGURE:-<unset>}"'
    dash $1
    in_sub_function
}

echo "=== Test 1: prefix assignment ==="
(
    NO_CONFIGURE=1 run_and_print_on_failure autogen.sh
)

echo ""
echo "=== Test 2: export ==="
(
    export NO_CONFIGURE=1
    run_and_print_on_failure autogen.sh
)
$ dash test.sh
=== Test 1: prefix assignment ===
  Inside function:       NO_CONFIGURE=1
  In child process:      NO_CONFIGURE=<unset>
  In child script:       NO_CONFIGURE=<unset>
  Inside subfunction:    NO_CONFIGURE=1

=== Test 2: export ===
  Inside function:       NO_CONFIGURE=1
  In child process:      NO_CONFIGURE=1
  In child script:       NO_CONFIGURE=1
  Inside subfunction:    NO_CONFIGURE=1

Copy link
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

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

yes, I really think we need a refined sshd config module though... as still managing just sshd_config is not really sufficient. If some of these options are present in sshd_config.d they may come in first and "win". So we need to compare the RESULTING configuration aka ssh -G output which shows the resulting configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants