Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion bosh-stemcell/spec/support/os_image_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
end
end

context "installed by bosh_sudoers" do
context "installed by bosh_sudoers (CIS-5.2.2, CIS-5.2.3)" do
describe file("/etc/sudoers") do
it { should be_file }
its(:content) { should match(/%bosh_sudoers ALL=\(ALL\) NOPASSWD: ALL/m) }
its(:content) { should match "#includedir /etc/sudoers.d" }
its(:content) { should match(/^Defaults\s+use_pty$/) }
its(:content) { should match(%r{^Defaults\s+logfile=/var/log/sudo\.log$}) }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
end

describe command("egrep -sh '!use_pty' /etc/sudoers /etc/sudoers.d/* | egrep -v '^[[:space:]]*#' --") do
its(:stdout) { should eq("") }
end
Comment thread
karthickaliappa marked this conversation as resolved.
end

Expand Down Expand Up @@ -69,6 +75,17 @@
it { should be_file }
end

context "idle session timeout (CIS-5.4.3.2)" do
describe file("/etc/profile.d/01-tmout.sh") do
it { should be_file }
it { should be_mode(0o644) }
it { should be_owned_by("root") }
its(:group) { should eq("root") }
its(:content) { should match(/^readonly TMOUT=900$/) }
its(:content) { should match(/^export TMOUT$/) }
end
end

describe command("grep -q .bashrc /root/.profile") do
it("has exit status of 0") { expect(subject.exit_status).to eq 0 }
end
Expand Down Expand Up @@ -229,6 +246,10 @@
expect(sshd_config.content).to match(/^MaxAuthTries 3$/)
end

it "sets MaxStartups to 10:30:60 (CIS-5.1.18)" do
expect(sshd_config.content.scan(/^[ \t]*MaxStartups\s+\S+$/).map(&:strip)).to contain_exactly("MaxStartups 10:30:60")
end

it "sets PermitEmptyPasswords to no (stig: V-38614)" do
expect(sshd_config.content).to match(/^PermitEmptyPasswords no$/)
end
Expand Down
3 changes: 3 additions & 0 deletions stemcell_builder/stages/base_ssh/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ echo 'X11Forwarding no' >> $chroot/etc/ssh/sshd_config
sed "/^ *MaxAuthTries/d" -i $chroot/etc/ssh/sshd_config
echo 'MaxAuthTries 3' >> $chroot/etc/ssh/sshd_config

sed "/^[ \t]*MaxStartups/d" -i "$chroot/etc/ssh/sshd_config"
echo 'MaxStartups 10:30:60' >> "$chroot/etc/ssh/sshd_config"

sed "/^ *PermitEmptyPasswords/d" -i $chroot/etc/ssh/sshd_config
echo 'PermitEmptyPasswords no' >> $chroot/etc/ssh/sshd_config

Expand Down
7 changes: 7 additions & 0 deletions stemcell_builder/stages/bosh_users/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ cp $assets_dir/ps1.sh $chroot/etc/profile.d/00-bosh-ps1
echo "source /etc/profile.d/00-bosh-ps1" >> $chroot/root/.bashrc
echo "source /etc/profile.d/00-bosh-ps1" >> $chroot/home/vcap/.bashrc
echo "source /etc/profile.d/00-bosh-ps1" >> $chroot/etc/skel/.bashrc

# configure idle session shell timeout
cat << 'EOF' > "$chroot/etc/profile.d/01-tmout.sh"
readonly TMOUT=900
export TMOUT
EOF
chmod 0644 "$chroot/etc/profile.d/01-tmout.sh"
4 changes: 4 additions & 0 deletions stemcell_builder/stages/bosh_users/assets/sudoers
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# Defaults

Defaults !lecture,tty_tickets,!fqdn
# Run sudo commands in a dedicated pseudo-terminal
Defaults use_pty
# Log sudo activity to a dedicated log file
Defaults logfile=/var/log/sudo.log
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# Uncomment to allow members of group sudo to not need a password
# %sudo ALL=NOPASSWD: ALL
Expand Down