Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatcar-tmpfiles: Always copy missing entries over to the database #26

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions scripts/flatcar-tmpfiles
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ mkdir -p "${ROOT}/etc"

# readable files
umask 022
if [[ ! -e "${ROOT}/etc/passwd" ]]; then
grep -E -e "^(${COPY_USERS}):" "${BASE}/passwd" > "${ROOT}/etc/passwd"
fi
if [[ ! -e "${ROOT}/etc/group" ]]; then
grep -E -e "^(${COPY_GROUPS}):" "${BASE}/group" > "${ROOT}/etc/group"
fi
# Output those lines in BASE/passwd (that are to be copied) when their user/group names are not in /etc/passwd already,
# and append the entries from BASE/passwd to /etc/passwd.
# But since we don't want lines/half lines being added also be used as patterns, we first read the file and in a second
# step write to it. (We are fine if /etc/passwd doesn't exist as this will result in no patterns. As patterns have the
# filtering out function, no patterns means that every line will match.)
PATTERNS=$(cut -s -d ":" -f 1 "${ROOT}/etc/passwd" | sed 's/^/\^/' | sed 's/$/:.*$/')
grep -v -x -f <(echo "${PATTERNS}") <(grep -E -e "^(${COPY_USERS}):" "${BASE}/passwd") >> "${ROOT}/etc/passwd"
PATTERNS=$(cut -s -d ":" -f 1 "${ROOT}/etc/group" | sed 's/^/\^/' | sed 's/$/:.*$/')
grep -v -x -f <(echo "${PATTERNS}") <(grep -E -e "^(${COPY_GROUPS}):" "${BASE}/group") >> "${ROOT}/etc/group"

# secure files
umask 027
if [[ ! -e "${ROOT}/etc/shadow" ]]; then
grep -E -e "^(${COPY_USERS}):" "${BASE}/shadow" > "${ROOT}/etc/shadow"
fi
if [[ ! -e "${ROOT}/etc/gshadow" ]]; then
grep -E -e "^(${COPY_GROUPS}):" "${BASE}/gshadow" > "${ROOT}/etc/gshadow"
fi
PATTERNS=$(cut -s -d ":" -f 1 "${ROOT}/etc/shadow" | sed 's/^/\^/' | sed 's/$/:.*$/')
grep -v -x -f <(echo "${PATTERNS}") <(grep -E -e "^(${COPY_USERS}):" "${BASE}/shadow") >> "${ROOT}/etc/shadow"
PATTERNS=$(cut -s -d ":" -f 1 "${ROOT}/etc/gshadow" | sed 's/^/\^/' | sed 's/$/:.*$/')
grep -v -x -f <(echo "${PATTERNS}") <(grep -E -e "^(${COPY_GROUPS}):" "${BASE}/gshadow") >> "${ROOT}/etc/gshadow"

# The script runs without set -euo pipefail and allows grep to return 1, thus the last statement must not be grep
# because it would propagate the exit code 1 and let the systemd unit fail.
exit 0