Skip to content

Commit 6a99a80

Browse files
PE-5714
1 parent 25ad70f commit 6a99a80

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

cis-harden/harden.sh

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77

88

9-
root_dir="$( cd "$( dirname $0 )" && pwd )"
10-
echo Root dir $root_dir
9+
root_dir="$( cd "$( dirname "$0" )" && pwd )"
10+
echo Root dir "$root_dir"
1111

1212

1313
##########################################################################
@@ -21,7 +21,7 @@ check_error()
2121

2222
if [[ ${status} -ne 0 ]]; then
2323
echo -e "\033[31m - ${msg} \033[0m"
24-
exit ${exit_status}
24+
exit "${exit_status}"
2525
fi
2626

2727
return 0
@@ -40,10 +40,10 @@ update_config_files() {
4040
check_error 1 "File ${config_file} not found"
4141
fi
4242

43-
sed -i "s/^\($search_str.*\)$/#\1/" ${config_file}
43+
sed -i "s/^\($search_str.*\)$/#\1/" "${config_file}"
4444
check_error $? "Failed commenting config value $search_str." 1
4545

46-
echo "$append_str" >> ${config_file}
46+
echo "$append_str" >> "${config_file}"
4747
check_error $? "Failed appending config value $append_str" 1
4848

4949
return 0
@@ -109,7 +109,7 @@ upgrade_packages() {
109109
apt-get -y upgrade
110110
check_error $? "Failed upgrading packages" 1
111111
apt-get install -y auditd apparmor-utils libpam-pwquality
112-
if [[ $? -ne 0 ]]; then
112+
if $? -ne 0 ; then
113113
echo 'deb http://archive.ubuntu.com/ubuntu focal main restricted' > /etc/apt/sources.list.d/repotmp.list
114114
apt-get update
115115
apt-get install -y auditd apparmor-utils libpam-pwquality
@@ -516,8 +516,8 @@ harden_system() {
516516

517517
echo "Error out if there are users with empty password"
518518
cat /etc/shadow |awk -F : '($2 == "" ){ exit 1}'
519-
if [[ $? -ne 0 ]]; then
520-
echo "Users present with empty password. Remove the user or set password for the users"
519+
if $? -ne 0 ; then
520+
echo "Users present with empty password. Remove the user or set pasword for the users"
521521
exit 1
522522
fi
523523

@@ -529,18 +529,18 @@ harden_system() {
529529
fi
530530

531531
echo "Fix permission of all cron files"
532-
for each in `echo /etc/cron.daily /etc/cron.hourly /etc/cron.d /etc/cron.monthly /etc/cron.weekly /etc/crontab`
532+
for each in echo /etc/cron.daily /etc/cron.hourly /etc/cron.d /etc/cron.monthly /etc/cron.weekly /etc/crontab
533533
do
534534
if [[ -e ${each} ]]; then
535-
stat -L -c "%a %u %g" ${each} | egrep ".00 0 0"
536-
if [[ $? -ne 0 ]]; then
537-
chown root:root ${each}
538-
chmod og-rwx ${each}
535+
stat -L -c "%a %u %g" "${each}" | grep -E".00 0 0"
536+
if $? -ne 0 ; then
537+
chown root:root "${each}"
538+
chmod og-rwx "${each}"
539539
fi
540540
fi
541541
done
542542

543-
echo "Remove cron and at deny files and have allow files in place"
543+
echo "Remove cron and at deny files anf have allow files in place"
544544
rm -f /etc/cron.deny
545545
rm -f /etc/at.deny
546546
touch /etc/cron.allow
@@ -821,12 +821,14 @@ harden_auth() {
821821
# Backup the original file
822822
cp /etc/pam.d/common-auth /etc/pam.d/common-auth.bak
823823

824-
echo "auth required pam_faillock.so preauth audit silent deny=4 fail_interval=900 unlock_time=600" > /etc/pam.d/common-auth
825-
echo "auth [success=1 default=ignore] pam_unix.so nullok" >> /etc/pam.d/common-auth
826-
echo "auth [default=die] pam_faillock.so authfail audit deny=4 fail_interval=900 unlock_time=600" >> /etc/pam.d/common-auth
827-
echo "auth sufficient pam_faillock.so authsucc audit deny=4 fail_interval=900 unlock_time=600" >> /etc/pam.d/common-auth
828-
echo "auth requisite pam_deny.so" >> /etc/pam.d/common-auth
829-
echo "auth required pam_permit.so" >> /etc/pam.d/common-auth
824+
{
825+
echo "auth required pam_faillock.so preauth audit silent deny=4 fail_interval=900 unlock_time=600"
826+
echo "auth [success=1;default=ignore] pam_unix.so nullok"
827+
echo "auth [default=die] pam_faillock.so authfail audit deny=4 fail_interval=900 unlock_time=600"
828+
echo "auth sufficient pam_faillock.so authsucc audit deny=4 fail_interval=900 unlock_time=600"
829+
echo "auth requisite pam_deny.so"
830+
echo "auth required pam_permit.so"
831+
} > /etc/pam.d/common-auth
830832

831833
# Backup the original file
832834
cp /etc/pam.d/common-account /etc/pam.d/common-account.bak
@@ -838,10 +840,12 @@ harden_auth() {
838840
# Backup the original file
839841
cp /etc/pam.d/common-password /etc/pam.d/common-password.bak
840842

841-
echo "password requisite pam_pwquality.so retry=3" > /etc/pam.d/common-password
842-
echo "password [success=1 default=ignore] pam_unix.so obscure use_authtok try_first_pass remember=5" >> /etc/pam.d/common-password
843-
echo "password requisite pam_deny.so" >> /etc/pam.d/common-password
844-
echo "password required pam_permit.so" >> /etc/pam.d/common-password
843+
{
844+
echo "password requisite pam_pwquality.so retry=3"
845+
echo "password [success=1 default=ignore] pam_unix.so obscure use_authtok try_first_pass remember=5"
846+
echo "password requisite pam_deny.so"
847+
echo "password required pam_permit.so"
848+
} > /etc/pam.d/common-password
845849

846850
#####################Password expiry policy#################
847851

earthly.sh

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ function build_with_proxy() {
1818
--rm -t \
1919
-e GLOBAL_CONFIG="$global_config" \
2020
-e BUILDKIT_TCP_TRANSPORT_ENABLED=true \
21-
-e http_proxy=$HTTP_PROXY \
22-
-e https_proxy=$HTTPS_PROXY \
23-
-e HTTPS_PROXY=$HTTPS_PROXY \
24-
-e HTTP_PROXY=$HTTP_PROXY \
25-
-e NO_PROXY=$NO_PROXY \
26-
-e no_proxy=$NO_PROXY \
27-
-e EARTHLY_GIT_CONFIG=$gitconfig \
28-
-v "$(pwd)/certs:/usr/local/share/ca-certificates:ro" \
21+
-e http_proxy="$HTTP_PROXY" \
22+
-e https_proxy="$HTTPS_PROXY" \
23+
-e HTTPS_PROXY="$HTTPS_PROXY" \
24+
-e HTTP_PROXY="$HTTP_PROXY" \
25+
-e NO_PROXY="$NO_PROXY" \
26+
-e no_proxy="$NO_PROXY" \
27+
-e EARTHLY_GIT_CONFIG="$gitconfig" \
28+
-v "$PROXY_CERT_PATH:/usr/local/share/ca-certificates/sc.crt:ro" \
2929
-v earthly-tmp:/tmp/earthly:rw \
3030
-p 8372:8372 \
31-
$SPECTRO_PUB_REPO/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION
31+
"$SPECTRO_PUB_REPO"/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION
3232
# Update the CA certificates in the container
3333
docker exec -it earthly-buildkitd update-ca-certificates
3434

@@ -40,21 +40,21 @@ function build_with_proxy() {
4040
-e GLOBAL_CONFIG="$global_config" \
4141
-e EARTHLY_BUILDKIT_HOST=tcp://0.0.0.0:8372 \
4242
-e BUILDKIT_TLS_ENABLED=false \
43-
-e http_proxy=$HTTP_PROXY \
44-
-e https_proxy=$HTTPS_PROXY \
45-
-e HTTPS_PROXY=$HTTPS_PROXY \
46-
-e HTTP_PROXY=$HTTP_PROXY \
47-
-e NO_PROXY=$NO_PROXY \
48-
-e no_proxy=$NO_PROXY \
43+
-e http_proxy="$HTTP_PROXY" \
44+
-e https_proxy="$HTTPS_PROXY" \
45+
-e HTTPS_PROXY="$HTTPS_PROXY" \
46+
-e HTTP_PROXY="$HTTP_PROXY" \
47+
-e NO_PROXY="$NO_PROXY" \
48+
-e no_proxy="$NO_PROXY" \
4949
-v "$(pwd)":/workspace \
50-
-v "$(pwd)/certs:/usr/local/share/ca-certificates:ro" \
50+
-v "$PROXY_CERT_PATH:/workspace/sc.crt:ro" \
5151
--entrypoint /workspace/earthly-entrypoint.sh \
52-
$SPECTRO_PUB_REPO/third-party/edge/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
52+
"$SPECTRO_PUB_REPO"/third-party/edge/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
5353
}
5454

5555
function build_without_proxy() {
5656
# Run Earthly in Docker to create artifacts Variables are passed from the .arg file
57-
docker run --privileged -v ~/.docker/config.json:/root/.docker/config.json -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -e GLOBAL_CONFIG="$global_config" -v "$(pwd)":/workspace $SPECTRO_PUB_REPO/third-party/edge/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
57+
docker run --privileged -v ~/.docker/config.json:/root/.docker/config.json -v /var/run/docker.sock:/var/run/docker.sock --rm --env EARTHLY_BUILD_ARGS -t -e GLOBAL_CONFIG="$global_config" -v "$(pwd)":/workspace "$SPECTRO_PUB_REPO"/third-party/edge/earthly/earthly:$EARTHLY_VERSION --allow-privileged "$@"
5858
}
5959

6060
function print_os_pack() {
@@ -94,14 +94,6 @@ PE_VERSION=$(git describe --abbrev=0 --tags)
9494
SPECTRO_PUB_REPO=us-docker.pkg.dev/palette-images
9595
EARTHLY_VERSION=v0.8.15
9696
source .arg
97-
98-
# Workaround to support deprecated field PROXY_CERT_PATH
99-
if [ -n "$PROXY_CERT_PATH" ]; then
100-
echo "PROXY_CERT_PATH is deprecated. Please place your certificates in the certs directory."
101-
echo "Copying the certificates from $PROXY_CERT_PATH to certs/"
102-
cp $PROXY_CERT_PATH certs/
103-
fi
104-
10597
ALPINE_IMG=$SPECTRO_PUB_REPO/edge/canvos/alpine:3.20
10698
### Verify Dependencies
10799
# Check if Docker is installed
@@ -111,28 +103,28 @@ else
111103
echo "Docker not found. Please use the guide for your platform located https://docs.docker.com/engine/install/ to install Docker."
112104
fi
113105
# Check if the current user has permission to run privileged containers
114-
if ! docker run --rm --privileged $ALPINE_IMG sh -c 'echo "Privileged container test"' &>/dev/null; then
106+
if ! docker run --rm --privileged "$ALPINE_IMG" sh -c 'echo "Privileged container test"' &>/dev/null; then
115107
echo "Privileged containers are not allowed for the current user."
116108
exit 1
117109
fi
118-
if [ -z "$HTTP_PROXY" ] && [ -z "$HTTPS_PROXY" ] && [ -z "$(find certs -type f ! -name '.*' -print -quit)" ]; then
110+
if [ -z "$HTTP_PROXY" ] && [ -z "$HTTPS_PROXY"]; then
119111
build_without_proxy "$@"
120112
else
121113
build_with_proxy "$@"
122114
fi
123115

124116
# Verify the command was successful
125-
if [ $? -ne 0 ]; then
117+
if $? -ne 0 ; then
126118
echo "An error occurred while running the command."
127119
exit 1
128120
fi
129121
# Cleanup builder helper images.
130-
docker rmi $SPECTRO_PUB_REPO/third-party/edge/earthly/earthly:$EARTHLY_VERSION
122+
docker rmi "$SPECTRO_PUB_REPO"/third-party/edge/earthly/earthly:$EARTHLY_VERSION
131123
if [ "$(docker container inspect -f '{{.State.Running}}' earthly-buildkitd)" = "true" ]; then
132124
docker stop earthly-buildkitd
133125
fi
134-
docker rmi $SPECTRO_PUB_REPO/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION 2>/dev/null
135-
docker rmi $ALPINE_IMG
126+
docker rmi "$SPECTRO_PUB_REPO"/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION 2>/dev/null
127+
docker rmi "$ALPINE_IMG"
136128

137129
if [[ "$1" == "+uki-genkey" ]]; then
138130
./keys.sh secure-boot/

hack/launch-qemu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ qemu-system-x86_64 \
1313
-cpu "${CPU:=host}" \
1414
-nographic \
1515
-spice port=9000,addr=127.0.0.1,disable-ticketing=yes \
16-
-m ${MEMORY:=10096} \
17-
-smp ${CORES:=5} \
16+
-m "${MEMORY:=10096}" \
17+
-smp "${CORES:=5}" \
1818
-monitor unix:/tmp/qemu-monitor.sock,server=on,wait=off \
1919
-serial mon:stdio \
2020
-rtc base=utc,clock=rt \

rhel-fips/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ PASSWORD=$2
66
BASE_IMAGE="${3:-rhel-byoi-fips}"
77

88
# Build the container image
9-
docker build --build-arg USERNAME=$USERNAME --build-arg PASSWORD=$PASSWORD -t $BASE_IMAGE .
9+
docker build --build-arg USERNAME="$USERNAME" --build-arg PASSWORD="$PASSWORD" -t "$BASE_IMAGE" .
1010

1111
docker run -v "$PWD"/build:/tmp/auroraboot \
1212
-v /var/run/docker.sock:/var/run/docker.sock \
1313
--rm quay.io/kairos/auroraboot \
14-
--set container_image=docker://$BASE_IMAGE \
14+
--set container_image=docker://"$BASE_IMAGE" \
1515
--set "disable_http_server=true" \
1616
--set "disable_netboot=true" \
1717
--set "state_dir=/tmp/auroraboot"

ubuntu-fips/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
BASE_IMAGE="${1:-ubuntu-focal-fips}"
22

3-
DOCKER_BUILDKIT=1 docker build . --secret id=pro-attach-config,src=pro-attach-config.yaml -t $BASE_IMAGE
4-
docker run -v "$PWD"/build:/tmp/auroraboot -v /var/run/docker.sock:/var/run/docker.sock --rm quay.io/kairos/auroraboot --set container_image=docker://$BASE_IMAGE --set "disable_http_server=true" --set "disable_netboot=true" --set "state_dir=/tmp/auroraboot"
3+
DOCKER_BUILDKIT=1 docker build . --secret id=pro-attach-config,src=pro-attach-config.yaml -t "BASE_IMAGE"
4+
docker run -v "$PWD"/build:/tmp/auroraboot -v /var/run/docker.sock:/var/run/docker.sock --rm quay.io/kairos/auroraboot --set container_image=docker://"BASE_IMAGE" --set "disable_http_server=true" --set "disable_netboot=true" --set "state_dir=/tmp/auroraboot"

0 commit comments

Comments
 (0)