Skip to content

Commit 85355bf

Browse files
committed
chore: update marketplace scripts and dependencies
1 parent 91ebe1e commit 85355bf

File tree

6 files changed

+97
-36
lines changed

6 files changed

+97
-36
lines changed

ansible/tasks/setup-system.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
apt: update_cache=yes upgrade=yes
1313
# SEE http://archive.vn/DKJjs#parameter-upgrade
1414

15+
- name: Install required security updates
16+
become: yes
17+
apt:
18+
pkg:
19+
- tzdata
20+
- linux-libc-dev
1521

1622
- name: Install python
1723
become: yes

scripts/11-lemp.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# DigitalOcean Marketplace Image Validation Tool
4+
# © 2021 DigitalOcean LLC.
5+
# This code is licensed under Apache 2.0 license (see LICENSE.md for details)
6+
7+
rm -rvf /etc/nginx/sites-enabled/default
8+
9+
ln -s /etc/nginx/sites-available/digitalocean \
10+
/etc/nginx/sites-enabled/digitalocean
11+
12+
rm -rf /var/www/html/index*debian.html
13+
14+
chown -R www-data: /var/www

scripts/12-ufw-nginx.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# DigitalOcean Marketplace Image Validation Tool
4+
# © 2021 DigitalOcean LLC.
5+
# This code is licensed under Apache 2.0 license (see LICENSE.md for details)
6+
7+
ufw limit ssh
8+
ufw allow 'Nginx Full'
9+
10+
ufw --force enable

scripts/13-force-ssh-logout.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# DigitalOcean Marketplace Image Validation Tool
4+
# © 2021 DigitalOcean LLC.
5+
# This code is licensed under Apache 2.0 license (see LICENSE.md for details)
6+
7+
cat >> /etc/ssh/sshd_config <<EOM
8+
Match User root
9+
ForceCommand echo "Please wait while we get your droplet ready..."
10+
EOM

scripts/90-cleanup.sh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
#!/bin/bash
22

3-
apt-get -y update
4-
apt-get -y upgrade
3+
# DigitalOcean Marketplace Image Validation Tool
4+
# © 2021 DigitalOcean LLC.
5+
# This code is licensed under Apache 2.0 license (see LICENSE.md for details)
6+
7+
set -o errexit
8+
9+
# Ensure /tmp exists and has the proper permissions before
10+
# checking for security updates
11+
# https://github.com/digitalocean/marketplace-partners/issues/94
12+
if [[ ! -d /tmp ]]; then
13+
mkdir /tmp
14+
fi
15+
chmod 1777 /tmp
16+
17+
if [ -n "$(command -v yum)" ]; then
18+
yum update -y
19+
yum clean all
20+
elif [ -n "$(command -v apt-get)" ]; then
21+
apt-get -y update
22+
apt-get -y upgrade
23+
apt-get -y autoremove
24+
apt-get -y autoclean
25+
fi
26+
527
rm -rf /tmp/* /var/tmp/*
628
history -c
729
cat /dev/null > /root/.bash_history
830
unset HISTFILE
9-
apt-get -y autoremove
10-
apt-get -y autoclean
1131
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
1232
rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
1333
rm -rf /var/lib/cloud/instances/*
@@ -33,4 +53,4 @@ dd if=/dev/zero of=/zerofile &
3353
sleep 5
3454
done
3555
sync; rm /zerofile; sync
36-
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp
56+
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp

scripts/99-img_check.sh

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
2-
#
2+
33
# DigitalOcean Marketplace Image Validation Tool
4-
# © 2018 DigitalOcean LLC.
5-
# This code is licensed under MIT license (see LICENSE.txt for details)
6-
#
7-
VERSION="v. 1.2"
4+
# © 2021 DigitalOcean LLC.
5+
# This code is licensed under Apache 2.0 license (see LICENSE.md for details)
6+
7+
VERSION="v. 1.6"
88
RUNDATE=$( date )
99

1010
# Script should be run with SUDO
@@ -110,18 +110,12 @@ function checkLogs {
110110
[[ -e $f ]] || break
111111
if [[ "${f}" = '/var/log/lfd.log' && "$( cat "${f}" | egrep -v '/var/log/messages has been reset| Watching /var/log/messages' | wc -c)" -gt 50 ]]; then
112112
if [ $f != $cp_ignore ]; then
113-
echo -en "\e[93m[WARN]\e[0m un-cleared log file, ${f} found\n"
114-
((WARN++))
115-
if [[ $STATUS != 2 ]]; then
116-
STATUS=1
117-
fi
118-
fi
119-
elif [[ "${f}" == '/var/log/cloud-init-output.log' ]]; then
120-
if cat '/var/log/cloud-init-output.log' | grep -q SHA256; then
121-
echo -en "\e[41m[FAIL]\e[0m log containing SHA256 value found in log file ${f}\n"
122-
((FAIL++))
123-
STATUS=1
113+
echo -en "\e[93m[WARN]\e[0m un-cleared log file, ${f} found\n"
114+
((WARN++))
115+
if [[ $STATUS != 2 ]]; then
116+
STATUS=1
124117
fi
118+
fi
125119
elif [[ "${f}" != '/var/log/lfd.log' && "$( cat "${f}" | wc -c)" -gt 50 ]]; then
126120
if [ $f != $cp_ignore ]; then
127121
echo -en "\e[93m[WARN]\e[0m un-cleared log file, ${f} found\n"
@@ -252,7 +246,7 @@ function checkUsers {
252246
echo -en "\e[32m[PASS]\e[0m User ${user} has no password set.\n"
253247
((PASS++))
254248
else
255-
echo -en "\e[41m[FAIL]\e[0m User ${user} has a password set on their account.\n"
249+
echo -en "\e[41m[FAIL]\e[0m User ${user} has a password set on their account. Only system users are allowed on the image.\n"
256250
((FAIL++))
257251
STATUS=2
258252
fi
@@ -385,7 +379,7 @@ function checkFirewall {
385379
# we will check some of the most common
386380
if cmdExists 'ufw'; then
387381
fw="ufw"
388-
ufwa=$(ufw status | sed -e "s/^Status:\ //")
382+
ufwa=$(ufw status |head -1| sed -e "s/^Status:\ //")
389383
if [[ $ufwa == "active" ]]; then
390384
FW_VER="\e[32m[PASS]\e[0m Firewall service (${fw}) is active\n"
391385
((PASS++))
@@ -418,6 +412,14 @@ function checkFirewall {
418412
}
419413
function checkUpdates {
420414
if [[ $OS == "Ubuntu" ]] || [[ "$OS" =~ Debian.* ]]; then
415+
# Ensure /tmp exists and has the proper permissions before
416+
# checking for security updates
417+
# https://github.com/digitalocean/marketplace-partners/issues/94
418+
if [[ ! -d /tmp ]]; then
419+
mkdir /tmp
420+
fi
421+
chmod 1777 /tmp
422+
421423
echo -en "\nUpdating apt package database to check for security updates, this may take a minute...\n\n"
422424
apt-get -y update > /dev/null
423425

@@ -441,11 +443,11 @@ function checkUpdates {
441443
echo -en "\e[32m[PASS]\e[0m There are no pending security updates for this image.\n\n"
442444
fi
443445
elif [[ $OS == "CentOS Linux" ]]; then
444-
echo -en "\nChecking for available updates with yum, this may take a minute...\n\n"
446+
echo -en "\nChecking for available security updates, this may take a minute...\n\n"
445447

446-
update_count=$(yum list updates -q | grep -vc "Updated Packages")
448+
update_count=$(yum check-update --security --quiet | wc -l)
447449
if [[ $update_count -gt 0 ]]; then
448-
echo -en "\e[41m[FAIL]\e[0m There are ${update_count} updates available for this image that have not been installed.\n"
450+
echo -en "\e[41m[FAIL]\e[0m There are ${update_count} security updates available for this image that have not been installed.\n"
449451
((FAIL++))
450452
STATUS=2
451453
else
@@ -553,11 +555,6 @@ function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$
553555

554556

555557
clear
556-
557-
echo "Installing Security Update"
558-
sudo apt-get update
559-
sudo apt-get install libp11-kit0
560-
561558
echo "DigitalOcean Marketplace Image Validation Tool ${VERSION}"
562559
echo "Executed on: ${RUNDATE}"
563560
echo "Checking local system for Marketplace compatibility..."
@@ -572,7 +569,9 @@ osv=0
572569

573570
if [[ $OS == "Ubuntu" ]]; then
574571
ost=1
575-
if [[ $VER == "18.04" ]]; then
572+
if [[ $VER == "20.04" ]]; then
573+
osv=1
574+
elif [[ $VER == "18.04" ]]; then
576575
osv=1
577576
elif [[ $VER == "16.04" ]]; then
578577
osv=1
@@ -596,7 +595,9 @@ elif [[ "$OS" =~ Debian.* ]]; then
596595

597596
elif [[ $OS == "CentOS Linux" ]]; then
598597
ost=1
599-
if [[ $VER == "7" ]]; then
598+
if [[ $VER == "8" ]]; then
599+
osv=1
600+
elif [[ $VER == "7" ]]; then
600601
osv=1
601602
elif [[ $VER == "6" ]]; then
602603
osv=1
@@ -674,8 +675,8 @@ if [[ $STATUS == 0 ]]; then
674675
exit 0
675676
elif [[ $STATUS == 1 ]]; then
676677
echo -en "Please review all [WARN] items above and ensure they are intended or resolved. If you do not have a specific requirement, we recommend resolving these items before image submission\n\n"
677-
exit 1
678+
exit 0
678679
else
679-
echo -en "Some critical tests failed. These items must be resolved and this scan re-run before you submit your image to the marketplace.\n\n"
680+
echo -en "Some critical tests failed. These items must be resolved and this scan re-run before you submit your image to the DigitalOcean Marketplace.\n\n"
680681
exit 1
681-
fi
682+
fi

0 commit comments

Comments
 (0)