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

fix(ownership): change Kong permissions to be kong:root #632

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions Dockerfile.apk
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ RUN set -ex; \
fi \
&& tar -C / -xzf /tmp/kong.apk.tar.gz \
&& apk add --no-cache libstdc++ libgcc perl tzdata libcap zlib zlib-dev bash \
&& adduser -S kong \
&& addgroup -S kong \
&& adduser -S -G kong kong \
&& mkdir -p "${KONG_PREFIX}" \
&& chown -R kong:0 ${KONG_PREFIX} \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R root:kong ${KONG_PREFIX} \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tieske Is there more context on the motivation for this change? IIRC, the owner of kong files was changed to kong fairly recently, so I am afraid of changing it back to root.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original pr by Colin; Changing the ownership to root but giving the Kong user access prevents the Kong user from modifying the files.

Copy link
Contributor

@fffonion fffonion Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally, everything under a common shared path like /usr/local/lib, /usr/local/share should always be owned by root:root because technically other packages will also write to it. this applies to also /etc/kong/kong.conf; only
/usr/local/kong (and /usr/local/openresty, if we mark our package a conflict with openresty) should be owned by
kong:kong. (well, technically, even under /usr/local/kong, subdirs like /usr/local/kong/lib, /usr/local/kong/include` should be owned by root:root as well)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The course of action is IMO:

  • Consolidate what the permissions should be (I tend to agree with most of what @fffonion said)
  • Move permission-related code to post-install scripts (alpine is an exception since it's not really a distro package) as suggested by Wangchong. I cannot remember of any particular issues around this explaining why they were placed in the docker images only.

&& chown -R root:kong /usr/local/lib/lua \
&& chown -R root:kong /usr/local/lib/luarocks \
&& chown -R root:kong /usr/local/share/lua \
&& chown root:kong /usr/local/bin/kong \
&& chmod -R g=u ${KONG_PREFIX} \
&& rm -rf /tmp/kong.apk.tar.gz \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile.deb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ RUN set -ex; \
&& apt-get install --yes /tmp/kong.deb \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/kong.deb \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R kong:0 ${KONG_PREFIX} \
&& chown -R root:kong ${KONG_PREFIX} \
&& chown -R root:kong /usr/local/lib/lua \
&& chown -R root:kong /usr/local/lib/luarocks \
&& chown -R root:kong /usr/local/share/lua \
&& chown root:kong /usr/local/bin/kong \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
Expand Down
9 changes: 7 additions & 2 deletions Dockerfile.rpm
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ RUN set -ex; \
&& rpm -iv /tmp/kong.rpm \
&& microdnf -y clean all \
&& rm /tmp/kong.rpm \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R kong:0 ${KONG_PREFIX} \
&& echo "addgroup -S kong" \
&& echo "adduser -S -G kong kong" \
&& chown -R root:kong ${KONG_PREFIX} \
&& chown -R root:kong /usr/local/lib/lua \
&& chown -R root:kong /usr/local/lib/luarocks \
&& chown -R root:kong /usr/local/share/lua \
&& chown root:kong /usr/local/bin/kong \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
Expand Down
37 changes: 37 additions & 0 deletions tests/05-ownership.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

function run_test {
# the suite name below will only be used when running this file directly, when
# running through "test.sh" it must be provided using the "--suite" option.
tinitialize "Docker-Kong test suite" "${BASH_SOURCE[0]}"

tchapter "ownership is root:kong"


for filename in \
/usr/local/share/lua/5.1/ \
/usr/local/share/lua/5.1/kong/plugins/ \
/usr/local/lib/lua/5.1/ \
/usr/local/lib/luarocks/rocks-5.1/
do
ttest "owenership $filename"
local USR
local GRP
USR=$(docker run -ti --rm "kong-$BASE" ls -ld $filename | awk '{print $3}')
GRP=$(docker run -ti --rm "kong-$BASE" ls -ld $filename | awk '{print $4}')
if [ "$USR:$GRP" == "root:kong" ]; then
tsuccess
else
tmessage "user and group found to be $USR:$GRP"
tfailure
fi
done

tfinish
}

# No need to modify anything below this comment

# shellcheck disable=SC1090 # do not follow source
[[ "$T_PROJECT_NAME" == "" ]] && set -e && if [[ -f "${1:-$(dirname "$(realpath "$0")")/test.sh}" ]]; then source "${1:-$(dirname "$(realpath "$0")")/test.sh}"; else source "${1:-$(dirname "$(realpath "$0")")/run.sh}"; fi && set +e
run_test
7 changes: 5 additions & 2 deletions ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ RUN set -ex; \
&& apt install --yes /tmp/kong.deb \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/kong.deb \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R kong:0 /usr/local/kong \
&& chown -R root:kong /usr/local/kong \
&& chown -R root:kong /usr/local/lib/lua \
&& chown -R root:kong /usr/local/lib/luarocks \
&& chown -R root:kong /usr/local/share/lua \
&& chown root:kong /usr/local/bin/kong \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
&& ln -sf /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
Expand Down