BastilleBSD / bastille

Bastille is an open-source system for automating deployment and management of containerized applications on FreeBSD.
https://bastillebsd.org
BSD 3-Clause "New" or "Revised" License
860 stars 140 forks source link

[BUG] Ignoring blank lines and comments kills multiple consecutive spaces #400

Open michael-o opened 3 years ago

michael-o commented 3 years ago

[MANDATORY] Describe the bug [MANDATORY] If your Bastillefile contains more than one space in one line this block: https://github.com/BastilleBSD/bastille/blob/b85d6347dee44c943819c2d7b4eee9c5a30535b5/usr/local/share/bastille/template.sh#L267-L268 kills it.

[MANDATORY] Bastille and FreeBSD version (paste bastille -v && freebsd-version -kru output) 0.8.20210115 12.2-STABLE 12.2-STABLE 12.2-STABLE

[MANDATORY] How did you install bastille? (port/pkg/git) ports

[optional] Steps to reproduce? Add this to your Bastillefile:

sed -i "" -e 's/# Host \*/Host \*/' -e 's/#   GSSAPIAuthentication no/  GSSAPIAuthentication yes/' /etc/ssh/ssh_config

Run the following:

# grep -v '^[[:blank:]]*$' "/usr/local/bastille/templates/lda/base/Bastillefile" | grep -v '^[[:blank:]]*#'
ARG HOST_RESOLV_CONF=/etc/resolv.conf
ARG DOMAIN_NAME=ad001.siemens.net
CMD touch /etc/rc.conf
SYSRC syslogd_flags="-N -ss"
SYSRC sendmail_enable="NO"
SYSRC clear_tmp_enable="YES"
SYSRC cron_flags="-J 60"
CP "${HOST_RESOLV_CONF}" etc/resolv.conf
OVERLAY etc
RENDER etc/hosts
CMD sed -i "" -e 's/#PermitRootLogin no/PermitRootLogin yes/' -e 's/#GSSAPIAuthentication no/GSSAPIAuthentication yes/'  /etc/ssh/sshd_config
CMD sed -i "" -e 's/# Host \*/Host \*/' -e 's/#   GSSAPIAuthentication no/  GSSAPIAuthentication yes/' /etc/ssh/ssh_config
SYSRC sshd_enable="YES"

Looks good. Now do this:

# SCIRPT="$(grep -v '^[[:blank:]]*$' "/usr/local/bastille/templates/lda/base/Bastillefile" | grep -v '^[[:blank:]]*#')"
# echo $SCIRPT
ARG HOST_RESOLV_CONF=/etc/resolv.conf ARG DOMAIN_NAME=ad001.siemens.net CMD touch /etc/rc.conf SYSRC syslogd_flags="-N -ss" SYSRC sendmail_enable="NO" SYSRC clear_tmp_enable="YES" SYSRC cron_flags="-J 60" CP "${HOST_RESOLV_CONF}" etc/resolv.conf OVERLAY etc RENDER etc/hosts CMD sed -i "" -e 's/#PermitRootLogin no/PermitRootLogin yes/' -e 's/#GSSAPIAuthentication no/GSSAPIAuthentication yes/' /etc/ssh/sshd_config CMD sed -i "" -e 's/# Host \*/Host \*/' -e 's/# GSSAPIAuthentication no/ GSSAPIAuthentication yes/' /etc/ssh/ssh_config SYSRC sshd_enable="YES"

My spaces are now gone and ssh_config cannot be modified by sed.

[optional] Expected behavior No mangling is multiple consecutive spaces

[optional] Additional context I guess a while loop would be much better here. A workaround is to write instead of a space a \.

bmac2 commented 1 year ago

@michael-o so if I am understanding this, it is the sed statement that is messing up the spaces? Only that line??? Your last statement makes me ask is this an issue with how that sed line is escaped for spaces and NOT an actual Bastillefile error. Am I reading this wrong???

michael-o commented 1 year ago

@michael-o so if I am understanding this, it is the sed statement that is messing up the spaces? Only that line??? Your last statement makes me ask is this an issue with how that sed line is escaped for spaces and NOT an actual Bastillefile error. Am I reading this wrong???

IIRC, the sed statement isn't a problem, but the preprocessing shreds it, not putting in-line spaces into account. The combination of SCRIPT and the subshell.