Skip to content

Commit fa7c094

Browse files
committed
fix(local-mounts): 🐛 improve username resolution and config validation
1 parent deb9a1a commit fa7c094

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/local-mounts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
set -e
1212

13-
USERNAME="${USERNAME:-"${_BUILD_ARG_USERNAME:-"node"}"}"
13+
USERNAME="${_BUILD_ARG_USERNAME:-"${USERNAME:-"node"}"}"
1414
SOURCE_HOME="/tmp/local-mounts"
1515

1616
# Resolve target home robustly

src/local-mounts/sync-files.sh

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@
1111
# No set -e: sync as much as possible even if one part fails.
1212

1313
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
14+
CONFIG_FILE="${SCRIPT_DIR}/config"
15+
16+
if [ ! -r "${CONFIG_FILE}" ]; then
17+
echo "❌ local-mounts: config file ${CONFIG_FILE} not found or not readable, aborting sync"
18+
exit 1
19+
fi
20+
1421
# shellcheck source=/dev/null
15-
. "${SCRIPT_DIR}/config"
22+
. "${CONFIG_FILE}"
1623

1724
USERNAME="${LOCAL_MOUNTS_USERNAME}"
1825
SOURCE_HOME="${LOCAL_MOUNTS_SOURCE}"
1926
TARGET_HOME="${LOCAL_MOUNTS_TARGET}"
2027

28+
if [ -z "${USERNAME}" ] || [ -z "${SOURCE_HOME}" ] || [ -z "${TARGET_HOME}" ]; then
29+
echo "❌ local-mounts: config is missing required values, aborting sync"
30+
exit 1
31+
fi
32+
2133
# Check staging directory exists (bind mounts active?)
2234
if [ ! -d "${SOURCE_HOME}" ]; then
2335
echo "ℹ️ local-mounts: staging directory ${SOURCE_HOME} not found, skipping sync"
@@ -28,8 +40,11 @@ echo "🔧 local-mounts: syncing files from ${SOURCE_HOME} to ${TARGET_HOME}..."
2840

2941
# ── Sync .gitconfig ──────────────────────────────────────────────────────────
3042

31-
if [ -f "${SOURCE_HOME}/.gitconfig" ] && [ -s "${SOURCE_HOME}/.gitconfig" ]; then
43+
if [ -L "${SOURCE_HOME}/.gitconfig" ]; then
44+
echo " ⚠️ .gitconfig is a symlink, skipping for security"
45+
elif [ -f "${SOURCE_HOME}/.gitconfig" ] && [ -s "${SOURCE_HOME}/.gitconfig" ]; then
3246
cp -f "${SOURCE_HOME}/.gitconfig" "${TARGET_HOME}/.gitconfig"
47+
chmod 600 "${TARGET_HOME}/.gitconfig"
3348
echo " ✅ .gitconfig"
3449
elif [ -f "${SOURCE_HOME}/.gitconfig" ]; then
3550
echo " ⚠️ .gitconfig exists but is empty"
@@ -39,8 +54,11 @@ fi
3954

4055
# ── Sync .npmrc ──────────────────────────────────────────────────────────────
4156

42-
if [ -f "${SOURCE_HOME}/.npmrc" ] && [ -s "${SOURCE_HOME}/.npmrc" ]; then
57+
if [ -L "${SOURCE_HOME}/.npmrc" ]; then
58+
echo " ⚠️ .npmrc is a symlink, skipping for security"
59+
elif [ -f "${SOURCE_HOME}/.npmrc" ] && [ -s "${SOURCE_HOME}/.npmrc" ]; then
4360
cp -f "${SOURCE_HOME}/.npmrc" "${TARGET_HOME}/.npmrc"
61+
chmod 600 "${TARGET_HOME}/.npmrc"
4462
echo " ✅ .npmrc"
4563
elif [ -f "${SOURCE_HOME}/.npmrc" ]; then
4664
echo " ⚠️ .npmrc exists but is empty"
@@ -53,8 +71,8 @@ fi
5371
if [ -d "${SOURCE_HOME}/.ssh" ]; then
5472
mkdir -p "${TARGET_HOME}/.ssh"
5573

56-
# Copy all regular files (keys, config, known_hosts, etc.)
57-
find "${SOURCE_HOME}/.ssh" -maxdepth 1 -type f -exec cp -f {} "${TARGET_HOME}/.ssh/" \;
74+
# Copy all regular files, skip symlinks for security
75+
find "${SOURCE_HOME}/.ssh" -maxdepth 1 -type f ! -type l -exec cp -f {} "${TARGET_HOME}/.ssh/" \;
5876

5977
# Fix permissions
6078
chmod 700 "${TARGET_HOME}/.ssh"
@@ -75,30 +93,16 @@ fi
7593
if [ -d "${SOURCE_HOME}/.gnupg" ]; then
7694
mkdir -p "${TARGET_HOME}/.gnupg"
7795

78-
# Copy top-level files (pubring, trustdb, gpg.conf, etc.)
79-
find "${SOURCE_HOME}/.gnupg" -maxdepth 1 -type f -exec cp -f {} "${TARGET_HOME}/.gnupg/" \;
80-
81-
# Copy private keys subdirectory
82-
if [ -d "${SOURCE_HOME}/.gnupg/private-keys-v1.d" ]; then
83-
mkdir -p "${TARGET_HOME}/.gnupg/private-keys-v1.d"
84-
find "${SOURCE_HOME}/.gnupg/private-keys-v1.d" -maxdepth 1 -type f \
85-
-exec cp -f {} "${TARGET_HOME}/.gnupg/private-keys-v1.d/" \;
86-
chmod 700 "${TARGET_HOME}/.gnupg/private-keys-v1.d"
87-
find "${TARGET_HOME}/.gnupg/private-keys-v1.d" -type f -exec chmod 600 {} \;
88-
fi
89-
90-
# Copy openpgp-revocs subdirectory
91-
if [ -d "${SOURCE_HOME}/.gnupg/openpgp-revocs.d" ]; then
92-
mkdir -p "${TARGET_HOME}/.gnupg/openpgp-revocs.d"
93-
find "${SOURCE_HOME}/.gnupg/openpgp-revocs.d" -maxdepth 1 -type f \
94-
-exec cp -f {} "${TARGET_HOME}/.gnupg/openpgp-revocs.d/" \;
95-
chmod 700 "${TARGET_HOME}/.gnupg/openpgp-revocs.d"
96-
find "${TARGET_HOME}/.gnupg/openpgp-revocs.d" -type f -exec chmod 600 {} \;
97-
fi
98-
99-
# Fix top-level permissions
100-
chmod 700 "${TARGET_HOME}/.gnupg"
101-
find "${TARGET_HOME}/.gnupg" -maxdepth 1 -type f -exec chmod 600 {} \;
96+
# Recursively mirror directories and regular files, skip sockets/symlinks
97+
(
98+
cd "${SOURCE_HOME}/.gnupg" || exit 1
99+
find . -type d -exec mkdir -p "${TARGET_HOME}/.gnupg/{}" \;
100+
find . -type f ! -type l -exec cp -f "{}" "${TARGET_HOME}/.gnupg/{}" \;
101+
)
102+
103+
# Fix permissions recursively
104+
find "${TARGET_HOME}/.gnupg" -type d -exec chmod 700 {} \;
105+
find "${TARGET_HOME}/.gnupg" -type f -exec chmod 600 {} \;
102106

103107
echo " ✅ .gnupg"
104108
else

0 commit comments

Comments
 (0)