Skip to content

Commit 98b5b1d

Browse files
[universal] Jekyll feature: Fix permissions for ruby version manager folder (devcontainers#554)
* [universal/jekyll] Fix permissions for ruby version manager folder - Change the setting up permission logic to be compatible with ruby feature * Empty-Commit * Revert "[universal/jekyll] Fix permissions for ruby version manager folder" This reverts commit 66486ef. * [universal] Jekyll feature: Rework the fix - Rework the fix to sync permissions for the ruby version manager gem folder only * Add directory ownership check - Add function to check directory ownership - Add test to ensure that `codespace` user has ownership over `extension` directory * Rework test to use IDs instead of names * Restart CI checks * Temp: Add diagnostics * Rework test
1 parent 3e64ffb commit 98b5b1d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/universal/.devcontainer/local-features/jekyll/install.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ if ! jekyll --version > /dev/null ; then
3030
chown -R "${USERNAME}:rvm" "${GEMS_DIR}/"
3131
chmod -R g+r+w "${GEMS_DIR}/"
3232
find "${GEMS_DIR}" -type d | xargs -n 1 chmod g+s
33+
34+
# Make sure the user has the necessary permissions to install the gems
35+
RVM_GEMS_DIR=/usr/local/rvm/gems/default/extensions
36+
37+
chown -R "${USERNAME}:rvm" "${RVM_GEMS_DIR}/"
38+
chmod -R g+r+w "${RVM_GEMS_DIR}/"
39+
find "${RVM_GEMS_DIR}" -type d | xargs -n 1 chmod g+s
3340
fi

src/universal/test-project/test-utils.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,41 @@ checkVersionCount() {
179179
return 1
180180
fi
181181
}
182+
183+
checkDirectoryOwnership() {
184+
LABEL=$1
185+
targetDirectory=$2
186+
expectedUser=$3
187+
expectedGroup=$4
188+
189+
echo -e "\n🧪 Testing $LABEL"
190+
191+
# Get group metadata
192+
groupMetadata=$(getent group ${expectedGroup})
193+
194+
# Extract group id and group members
195+
targetGroupId=$(echo $groupMetadata | cut -d: -f3)
196+
targetGroupMembers=$(echo $groupMetadata | cut -d: -f4)
197+
198+
# Get directory ownership metadata
199+
# Note: "stat" returns the string "UNKNOWN" for %U and %G if it's not defined in the system files.
200+
# So it's better to work with UID (%u) and GID (%g) numbers from "stat".
201+
directoryOwnershipGroupId=$(stat -c "%g" ${targetDirectory})
202+
203+
# Check that group has ownership over directory and user belong to the group
204+
if [ "$targetGroupId" == "$directoryOwnershipGroupId" ] && [[ "$targetGroupMembers" == *"$expectedUser"* ]]; then
205+
echo "✅ Passed!"
206+
return 0
207+
else
208+
expected="Expected: Group - $expectedGroup ($targetGroupId), User - $expectedUser"
209+
got="Got: $(stat -c "Group - %G (%g), User - %U (%u)" ${targetDirectory})"
210+
echoStderr "$LABEL check failed. $expected $got"
211+
212+
# Provide more context on test failure
213+
stat ${targetDirectory}
214+
215+
FAILED+=("$LABEL")
216+
217+
return 1
218+
fi
219+
}

src/universal/test-project/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ count=$(ls /usr/local/rvm/gems | wc -l)
8484
expectedCount=6 # 2 version folders + 2 global folders for each version + 1 default folder which links to either one of the version + 1 cache folder
8585
checkVersionCount "two versions of ruby are present" $count $expectedCount
8686
echo $(echo "ruby versions" && ls -a /usr/local/rvm/rubies)
87+
rvmExtensions="/usr/local/rvm/gems/default/extensions"
88+
rvmPlatform=$(rvm info default ruby | grep -w "platform" | cut -d'"' -f 2)
89+
checkDirectoryOwnership "codespace user has ownership over extension directory" "$rvmExtensions/$rvmPlatform" "codespace" "rvm"
8790

8891
# Node.js
8992
check "node" node --version

0 commit comments

Comments
 (0)