Skip to content

Commit e1fe334

Browse files
fix(trivy): handle plugin install for non-root user
1 parent 396b463 commit e1fe334

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/trivy/install.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,24 @@ trivy --version
9191
# of how trivy is invoked (login shell, non-interactive sh -c, etc.).
9292
mkdir -p "${TRIVY_HOME}"
9393
mv /usr/local/bin/trivy /usr/local/bin/trivy-real
94-
cat > /usr/local/bin/trivy << WRAPPER
94+
cat > /usr/local/bin/trivy << 'WRAPPER'
9595
#!/bin/sh
96-
export TRIVY_HOME="\${TRIVY_HOME:-${TRIVY_HOME}}"
97-
exec /usr/local/bin/trivy-real "\$@"
96+
TRIVY_HOME="${TRIVY_HOME:-/usr/local/share/trivy}"
97+
export TRIVY_HOME
98+
# Ensure the current user's .trivy points to the shared TRIVY_HOME
99+
# so plugins installed at build time are available to all users.
100+
if [ ! -e "$HOME/.trivy" ]; then
101+
ln -sf "$TRIVY_HOME" "$HOME/.trivy" 2>/dev/null || true
102+
fi
103+
exec /usr/local/bin/trivy-real "$@"
98104
WRAPPER
99105
chmod +x /usr/local/bin/trivy
100106
export TRIVY_HOME
101107

108+
# Symlink root's .trivy to TRIVY_HOME so that plugin installs during
109+
# the build are written to the shared location.
110+
ln -sf "${TRIVY_HOME}" /root/.trivy
111+
102112
# Install plugins if specified
103113
if [ -n "${TRIVY_PLUGINS}" ]; then
104114
echo "Installing Trivy plugins..."

0 commit comments

Comments
 (0)