Skip to content

Commit

Permalink
[universal] Jekyll feature: Fix permissions for ruby version manager …
Browse files Browse the repository at this point in the history
…folder (#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
  • Loading branch information
alexander-smolyakov committed May 11, 2023
1 parent 3e64ffb commit 98b5b1d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/universal/.devcontainer/local-features/jekyll/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ if ! jekyll --version > /dev/null ; then
chown -R "${USERNAME}:rvm" "${GEMS_DIR}/"
chmod -R g+r+w "${GEMS_DIR}/"
find "${GEMS_DIR}" -type d | xargs -n 1 chmod g+s

# Make sure the user has the necessary permissions to install the gems
RVM_GEMS_DIR=/usr/local/rvm/gems/default/extensions

chown -R "${USERNAME}:rvm" "${RVM_GEMS_DIR}/"
chmod -R g+r+w "${RVM_GEMS_DIR}/"
find "${RVM_GEMS_DIR}" -type d | xargs -n 1 chmod g+s
fi
38 changes: 38 additions & 0 deletions src/universal/test-project/test-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,41 @@ checkVersionCount() {
return 1
fi
}

checkDirectoryOwnership() {
LABEL=$1
targetDirectory=$2
expectedUser=$3
expectedGroup=$4

echo -e "\n🧪 Testing $LABEL"

# Get group metadata
groupMetadata=$(getent group ${expectedGroup})

# Extract group id and group members
targetGroupId=$(echo $groupMetadata | cut -d: -f3)
targetGroupMembers=$(echo $groupMetadata | cut -d: -f4)

# Get directory ownership metadata
# Note: "stat" returns the string "UNKNOWN" for %U and %G if it's not defined in the system files.
# So it's better to work with UID (%u) and GID (%g) numbers from "stat".
directoryOwnershipGroupId=$(stat -c "%g" ${targetDirectory})

# Check that group has ownership over directory and user belong to the group
if [ "$targetGroupId" == "$directoryOwnershipGroupId" ] && [[ "$targetGroupMembers" == *"$expectedUser"* ]]; then
echo "✅ Passed!"
return 0
else
expected="Expected: Group - $expectedGroup ($targetGroupId), User - $expectedUser"
got="Got: $(stat -c "Group - %G (%g), User - %U (%u)" ${targetDirectory})"
echoStderr "$LABEL check failed. $expected $got"

# Provide more context on test failure
stat ${targetDirectory}

FAILED+=("$LABEL")

return 1
fi
}
3 changes: 3 additions & 0 deletions src/universal/test-project/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ count=$(ls /usr/local/rvm/gems | wc -l)
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
checkVersionCount "two versions of ruby are present" $count $expectedCount
echo $(echo "ruby versions" && ls -a /usr/local/rvm/rubies)
rvmExtensions="/usr/local/rvm/gems/default/extensions"
rvmPlatform=$(rvm info default ruby | grep -w "platform" | cut -d'"' -f 2)
checkDirectoryOwnership "codespace user has ownership over extension directory" "$rvmExtensions/$rvmPlatform" "codespace" "rvm"

# Node.js
check "node" node --version
Expand Down

0 comments on commit 98b5b1d

Please sign in to comment.