-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added harden_sshd job to disable ssh port forwarding [fixes #174089050]
- Loading branch information
1 parent
2481332
commit ae8025a
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
name: harden_sshd | ||
|
||
templates: | ||
pre-start.sh.erb: bin/pre-start | ||
|
||
properties: | ||
allow_tcp_forwarding: | ||
description: Specifies whether TCP forwarding is permitted | ||
default: false | ||
allow_stream_local_forwarding: | ||
description: Specifies whether forwarding Unix domain sockets is permitted | ||
default: false | ||
gateway_ports: | ||
description: Specifies whether remote hosts are allowed to connect to ports forwarded for the client | ||
default: false | ||
permit_tunnel: | ||
description: Specifies whether tun(4) device forwarding is allowed | ||
default: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
<% unless p('allow_tcp_forwarding') %> | ||
sed "/^ *AllowTcpForwarding/d" -i /etc/ssh/sshd_config | ||
echo 'AllowTcpForwarding no' >> /etc/ssh/sshd_config | ||
<% end %> | ||
|
||
<% unless p('allow_stream_local_forwarding') %> | ||
sed "/^ *AllowStreamLocalForwarding/d" -i /etc/ssh/sshd_config | ||
echo 'AllowStreamLocalForwarding no' >> /etc/ssh/sshd_config | ||
<% end %> | ||
|
||
<% unless p('gateway_ports') %> | ||
sed "/^ *GatewayPorts/d" -i /etc/ssh/sshd_config | ||
echo 'GatewayPorts no' >> /etc/ssh/sshd_config | ||
<% end %> | ||
|
||
<% unless p('permit_tunnel') %> | ||
sed "/^ *PermitTunnel/d" -i /etc/ssh/sshd_config | ||
echo 'PermitTunnel no' >> /etc/ssh/sshd_config | ||
<% end %> | ||
|
||
systemctl restart sshd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package os_conf_acceptance_tests_test | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gbytes" | ||
"github.com/onsi/gomega/gexec" | ||
) | ||
|
||
var _ = Describe("HardenSshd", func() { | ||
It("hardens the sshd", func() { | ||
By("disabeling port forwarding", func() { | ||
session := boshSSH("os-conf/0", "sudo sshd -T | sort") | ||
Eventually(session, 30*time.Second).Should(gbytes.Say("allowstreamlocalforwarding no")) | ||
Eventually(session, 30*time.Second).Should(gbytes.Say("allowtcpforwarding no")) | ||
Eventually(session, 30*time.Second).Should(gbytes.Say("gatewayports no")) | ||
Eventually(session, 30*time.Second).Should(gbytes.Say("permittunnel no")) | ||
Eventually(session, 30*time.Second).Should(gexec.Exit(0)) | ||
}) | ||
}) | ||
}) |