Skip to content

Commit cd8f0cf

Browse files
PE5714
1 parent 7b871fe commit cd8f0cf

File tree

7 files changed

+55
-51
lines changed

7 files changed

+55
-51
lines changed

cis-harden/harden.sh

Lines changed: 26 additions & 22 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,7 +516,7 @@ 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
519+
if $? -ne 0 ; then
520520
echo "Users present with empty password. Remove the user or set password for the users"
521521
exit 1
522522
fi
@@ -529,13 +529,13 @@ 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
@@ -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: 21 additions & 21 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 \
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" \
2828
-v "$(pwd)/certs:/usr/local/share/ca-certificates: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 \
5050
-v "$(pwd)/certs:/usr/local/share/ca-certificates: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() {
@@ -111,7 +111,7 @@ else
111111
echo "Docker not found. Please use the guide for your platform located https://docs.docker.com/engine/install/ to install Docker."
112112
fi
113113
# 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
114+
if ! docker run --rm --privileged "$ALPINE_IMG" sh -c 'echo "Privileged container test"' &>/dev/null; then
115115
echo "Privileged containers are not allowed for the current user."
116116
exit 1
117117
fi
@@ -122,17 +122,17 @@ else
122122
fi
123123

124124
# Verify the command was successful
125-
if [ $? -ne 0 ]; then
125+
if $? -ne 0 ; then
126126
echo "An error occurred while running the command."
127127
exit 1
128128
fi
129129
# Cleanup builder helper images.
130-
docker rmi $SPECTRO_PUB_REPO/third-party/edge/earthly/earthly:$EARTHLY_VERSION
130+
docker rmi "$SPECTRO_PUB_REPO"/third-party/edge/earthly/earthly:$EARTHLY_VERSION
131131
if [ "$(docker container inspect -f '{{.State.Running}}' earthly-buildkitd)" = "true" ]; then
132132
docker stop earthly-buildkitd
133133
fi
134-
docker rmi $SPECTRO_PUB_REPO/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION 2>/dev/null
135-
docker rmi $ALPINE_IMG
134+
docker rmi "$SPECTRO_PUB_REPO"/third-party/edge/earthly/buildkitd:$EARTHLY_VERSION 2>/dev/null
135+
docker rmi "$ALPINE_IMG"
136136

137137
if [[ "$1" == "+uki-genkey" ]]; then
138138
./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 \

overlay/files/opt/spectrocloud/bin/check-disk-size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ REQUIRED_FREE_DISK=$1
66

77
FREE=$(df -h --output=pcent /var/ | tail -n 1 | tr -d '\% ')
88

9-
if (( $FREE < $REQUIRED_FREE_DISK )); then
9+
if (( FREE < REQUIRED_FREE_DISK )); then
1010
echo "Not enough free disk, required: $1. Free: $FREE"
1111
exit 1
1212
fi

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"

test/test-two-node.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function init_globals() {
4848

4949
if [ -n "$REPLACEMENT_HOST" ]; then
5050
export HOST_3="tn3-$HOST_SUFFIX"
51-
vm_array+=($HOST_3)
51+
vm_array+=("$HOST_3")
5252
echo "Added replacement VM: $HOST_3"
5353
fi
5454
}

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)