Skip to content

Commit 259e0ee

Browse files
committed
feat: use ubuntu minimal
1 parent cbd74ea commit 259e0ee

File tree

3 files changed

+29
-95
lines changed

3 files changed

+29
-95
lines changed

amazon-arm64-nix.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variable "ami" {
22
type = string
3-
default = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-*"
3+
default = "ubuntu-minimal/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-minimal-*"
44
}
55

66
variable "profile" {

ansible/tasks/clean-build-dependencies.yml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,34 @@
66
ansible.builtin.apt:
77
autoremove: false
88
pkg:
9+
# Build tools installed by Ansible tasks
910
- bison
1011
- build-essential
1112
- clang-11
1213
- cmake
1314
- cpp
1415
- flex
1516
- g++
16-
- g++-10
1717
- g++-9
18+
- g++-10
1819
- gcc-10
1920
- make
20-
- manpages
21-
- manpages-dev
2221
- ninja-build
2322
- patch
2423
- python2
25-
state: 'absent'
26-
27-
# Security hardening: remove packages that increase attack surface
28-
# - Compiler toolchain enables local exploit compilation
29-
# - Dev packages provide headers for building exploits
30-
# - salt-minion is a remote management agent (large attack surface)
31-
# - sshpass stores credentials in plaintext
32-
- name: Remove high-security-risk packages
33-
ansible.builtin.apt:
34-
autoremove: false
35-
pkg:
36-
# Compiler toolchain (gcc-14-base kept - libgcc-s1 runtime depends on it)
37-
- binutils
38-
- binutils-aarch64-linux-gnu
39-
- binutils-common
40-
# Dev/header packages
24+
# Dev headers installed for compilation
4125
- libc6-dev
4226
- libcrypt-dev
4327
- libevent-dev
4428
- libpcre3-dev
4529
- libssl-dev
46-
- libsystemd-dev
4730
- linux-headers-aws
4831
- linux-libc-dev
4932
- pkg-config
5033
- pkgconf
5134
- pkgconf-bin
52-
- rpcsvc-proto
53-
- systemd-dev
5435
- zlib1g-dev
55-
# Remote management (if not used)
56-
- salt-minion
57-
- salt-common
58-
# Credential handling
36+
# Security: credential handling
5937
- sshpass
6038
# Build tool leftovers
6139
- ansible-core

scripts/90-cleanup.sh

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,45 @@
11
#!/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-
72
set -o errexit
83

9-
# Ensure /tmp exists and has the proper permissions before
10-
# checking for security updates
11-
# https://github.com/digitalocean/marketplace-partners/issues/94
4+
# Ensure /tmp exists and has proper permissions
125
if [[ ! -d /tmp ]]; then
136
mkdir /tmp
147
fi
158
chmod 1777 /tmp
169

17-
if [ -n "$(command -v yum)" ]; then
18-
yum update -y
19-
yum clean all
20-
elif [ -n "$(command -v apt-get)" ]; then
21-
# Cleanup more packages
22-
apt-get -y remove --purge \
23-
automake \
24-
autoconf \
25-
autotools-dev \
26-
cmake-data \
27-
cpp-9 \
28-
cpp-10 \
29-
gcc-9 \
30-
gcc-10 \
31-
git \
32-
git-man \
33-
ansible \
34-
libicu-dev \
35-
libcgal-dev \
36-
libgcc-9-dev \
37-
ansible
38-
10+
# Update system
11+
if [ -n "$(command -v apt-get)" ]; then
3912
# Remove ansible PPA directly (software-properties-common may not be installed)
4013
rm -f /etc/apt/sources.list.d/ansible-ubuntu-ansible-*.list \
4114
/etc/apt/sources.list.d/ansible-ubuntu-ansible-*.sources 2>/dev/null || true
4215

43-
source /etc/os-release
44-
45-
# Protect critical runtime packages from autoremove
46-
apt-mark manual libevent-2.1-7t64
47-
48-
# Ensure cloud-init and openssh-server are installed
49-
# They may have been removed as dependencies during package cleanup
50-
apt-get -y install --no-install-recommends cloud-init openssh-server
51-
52-
# Ensure cloud-init and SSH services are enabled (may not be re-enabled on reinstall)
53-
# systemctl enable can fail silently in chroot - create symlinks manually
54-
mkdir -p /etc/systemd/system/cloud-init.target.wants
55-
mkdir -p /etc/systemd/system/multi-user.target.wants
56-
ln -sf /usr/lib/systemd/system/cloud-init-local.service /etc/systemd/system/cloud-init.target.wants/ || true
57-
ln -sf /usr/lib/systemd/system/cloud-init.service /etc/systemd/system/cloud-init.target.wants/ || true
58-
ln -sf /usr/lib/systemd/system/cloud-config.service /etc/systemd/system/cloud-init.target.wants/ || true
59-
ln -sf /usr/lib/systemd/system/cloud-final.service /etc/systemd/system/cloud-init.target.wants/ || true
60-
ln -sf /usr/lib/systemd/system/cloud-init.target /etc/systemd/system/multi-user.target.wants/ || true
61-
ln -sf /usr/lib/systemd/system/ssh.service /etc/systemd/system/multi-user.target.wants/ || true
62-
echo "Created cloud-init and SSH service symlinks"
63-
64-
# Protect SSH and cloud-init dependencies from autoremove
65-
# Without these, the AMI won't be accessible via SSH after boot
66-
apt-mark manual openssh-server cloud-init python3-systemd python3-jinja2 \
67-
python3-yaml python3-oauthlib python3-configobj python3-requests \
68-
python3-urllib3 python3-certifi python3-chardet python3-idna || true
69-
70-
apt-get -y autoremove
71-
apt-get -y autoclean
72-
7316
apt-get -y update
7417
apt-get -y upgrade
18+
apt-get -y autoremove
19+
apt-get -y autoclean
7520
fi
21+
22+
# Clean temp files
7623
rm -rf /tmp/* /var/tmp/*
24+
25+
# Clear history
7726
history -c
7827
cat /dev/null > /root/.bash_history
7928
unset HISTFILE
29+
30+
# Clean logs
8031
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
8132
rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
33+
34+
# Clean cloud-init for fresh start
8235
rm -rf /var/lib/cloud/instances/*
36+
37+
# Remove SSH keys (cloud-init regenerates on boot)
8338
rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
8439
touch /etc/ssh/revoked_keys
8540
chmod 600 /etc/ssh/revoked_keys
8641

87-
# Securely erase the unused portion of the filesystem
42+
# Securely erase unused disk space
8843
GREEN='\033[0;32m'
8944
NC='\033[0m'
9045
printf "\n${GREEN}Writing zeros to the remaining disk space to securely
@@ -95,11 +50,12 @@ The secure erase will complete successfully when you see:${NC}
9550
Beginning secure erase now\n"
9651

9752
dd if=/dev/zero of=/zerofile &
98-
PID=$!
99-
while [ -d /proc/$PID ]
100-
do
101-
printf "."
102-
sleep 5
103-
done
53+
PID=$!
54+
while [ -d /proc/$PID ]; do
55+
printf "."
56+
sleep 5
57+
done
10458
sync; rm /zerofile; sync
105-
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp
59+
60+
cat /dev/null > /var/log/lastlog
61+
cat /dev/null > /var/log/wtmp

0 commit comments

Comments
 (0)