diff --git a/common/documentserver/bin/documentserver-generate-allfonts.sh.m4 b/common/documentserver/bin/documentserver-generate-allfonts.sh.m4 index ddfae94..94153cb 100644 --- a/common/documentserver/bin/documentserver-generate-allfonts.sh.m4 +++ b/common/documentserver/bin/documentserver-generate-allfonts.sh.m4 @@ -57,10 +57,19 @@ echo -n Generating js caches, please wait... echo Done -# Setting user rights for files created in the previous steps +# Setting user rights for files created in the previous steps. +# Only the generated ones, by name: the converters in this directory belong to +# root, because the scripts in /usr/bin run them, and this script is one of +# those. Handing the directory over to ds here would put back what the packages +# take away, and a program root runs must not be one ds can rewrite. -h keeps +# chown on a symlink in place of one of these names, as chown -R did before, +# instead of handing ds whatever file the link points at. if [ "${ONLYOFFICE_K8S_CONTAINER}" != "true" ]; then chown -R ds:ds "$DIR/sdkjs" - chown -R ds:ds "$DIR/server/FileConverter/bin" + chown -h ds:ds \ + "$DIR/server/FileConverter/bin/AllFonts.js" \ + "$DIR/server/FileConverter/bin/font_selection.bin" \ + "$DIR/server/FileConverter/bin/fonts.log" 2>/dev/null chown -R ds:ds "$DIR/fonts" fi diff --git a/deb/template/postinst.m4 b/deb/template/postinst.m4 index 8816f0b..7db4cab 100644 --- a/deb/template/postinst.m4 +++ b/deb/template/postinst.m4 @@ -366,6 +366,20 @@ ifelse('M4_DS_ADMINPANEL_ENABLE','1',`mkdir -p "$LOG_DIR/adminpanel" chown ds:ds -R "$DIR"* # set up read-only access to prevent modification ds's home directory chmod a-w -R "$DIR"* + # what the root owned scripts in /usr/bin run stays owned by root: the + # blanket chown above hands everything under here to ds, and the owner of + # a program is one chmod away from replacing what root will execute. The + # directories count as much as the files: chmod a-w does not hold against + # the owner of a directory, who can make it writable again, and a ds + # writable directory lets ds swap out x2t no matter who owns the file in it. + # That goes for every directory on the way down, not only the last one: + # in a ds owned server/ ds can rename the root owned tools/ aside and put + # its own in its place. Only the directories themselves change owner, what + # is in them keeps its owner. + for f in "$DIR" "$DIR"*/server "$DIR"*/server/FileConverter "$DIR"*/npm "$DIR"*/server/tools "$DIR"*/server/tools/* "$DIR"*/server/FileConverter/bin "$DIR"*/server/FileConverter/bin/x2t "$DIR"*/server/FileConverter/bin/*.so* "$DIR"*/npm/json + do + if [ -e "$f" ]; then chown root:root "$f"; fi + done chown ds:ds "$CONF_DIR"/*.json getent group onlyoffice >/dev/null && { DATA_OWNER="onlyoffice:onlyoffice"; usermod -aG onlyoffice ds; } || DATA_OWNER="ds:ds" diff --git a/rpm/common.spec b/rpm/common.spec index 5334ceb..4ac0255 100644 --- a/rpm/common.spec +++ b/rpm/common.spec @@ -156,14 +156,12 @@ rm -rf "%{buildroot}" %defattr(440, ds, ds, 555) %{_localstatedir}/www/%{_ds_prefix}*/* -%attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/npm/json +%attr(550, root, root) %{_localstatedir}/www/%{_ds_prefix}/npm/json %attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/DocService/docservice %attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/converter %attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/bin/docbuilder -%attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/bin/x2t %attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/Metrics/metrics %{?adminpanel:%attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/AdminPanel/server/adminpanel} -%attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}/server/tools/* %if %{defined example} %attr(550, ds, ds) %{_localstatedir}/www/%{_ds_prefix}-example/example %endif @@ -180,6 +178,18 @@ rm -rf "%{buildroot}" %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/bin/*.so* %attr(744, root, root) %{_bindir}/documentserver-*.sh +# The scripts installed into /usr/bin are owned by root and run these programs, +# so the programs and every directory on the way down to them are root owned +# too: ds may execute them but neither rewrite them nor rename them, or a +# directory holding them, aside from a writable parent. +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix} +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/npm +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/tools +%dir %attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/bin +%attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/tools/* +%attr(755, root, root) %{_localstatedir}/www/%{_ds_prefix}/server/FileConverter/bin/x2t %attr(-, root, root) %{_sysconfdir}/logrotate.d/* %attr(-, root, root) %{_sysconfdir}/nginx/%{nginx_conf_d}/* %attr(-, root, root) %{_sysconfdir}/nginx/includes/*