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

Add set_unix_permissions and syno_user_add_to_legacy_group #3161

Merged
merged 4 commits into from
Feb 23, 2018

Conversation

Safihre
Copy link
Contributor

@Safihre Safihre commented Feb 21, 2018

Support functions needed to:

  • Correct permissions on folders during upgrade in Linux mode.
  • For transfer for download-related packages from 'sc-media' to 'sc-download'

@ymartin59 This separate PR to keep package PR's clean. But all my other PR's kind of depend on it.
After this is merged, I can rebase #3092 #3153 #3053 on master after that so they are package-only.

@Safihre Safihre requested a review from ymartin59 February 21, 2018 12:29
@Safihre Safihre force-pushed the generic-service-fixes branch 2 times, most recently from 6253204 to a79e9a2 Compare February 21, 2018 16:33
Copy link
Contributor

@ymartin59 ymartin59 left a comment

Choose a reason for hiding this comment

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

Definitely that is the right way to do it. And I guess it will probably fix troubles I saw with set_syno_permissions.
Still to confirm it properly works as expected on DSM 5.2

# Set read/write permissions for GROUP for folder and subfolders
if [ ! "`synoacltool -get \"${DIRNAME}\"| grep \"group:${GROUP}:allow:rwxpdDaARWcC-:fd--\"`" ]; then
# First Unix permissions, but only if it's in Linux mode
if [ ! "`synoacltool -get \"${DIRNAME}\"| grep \"Linux mocde\"`" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a typo: "mocde" !


# Check if user in old group
MEMBERS="$(synogroup --get $LEGACY_GROUP | grep '^[0-9]' | sed 's/.*\[\([^]]*\)].*/\1/' | tr '\n' ' ')"
if [[ $MEMBERS = *"$LEGACY_USER"* && $MEMBERS != *"$NEW_USER"* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Hum. I would take care about such expression which may only run on bash... so only on DSM 6. I would check against on DSM 5.2 which runs busybox as default shell.

Copy link
Contributor Author

@Safihre Safihre Feb 22, 2018

Choose a reason for hiding this comment

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

So I came to this, because (at least on DSM61) this if statement in postinst always returns true and the user always gets added even if already present:~~

if ! synogroup --get "$GROUP" | grep '^[0-9]:\[${EFF_USER}\]' &> /dev/null; then

So something is wrong with this syntax, but I couldn't figure out what.~~

I just tested and indeed seems busybox does not support this syntax.. Will come up with a new one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aah, my bash/shell-noobness that it took me an hour to figure out. It should be of course:

grep "^[0-9]:\[${EFF_USER}\]"

and not

grep '^[0-9]:\[${EFF_USER}\]'

In both commands.

if [[ $MEMBERS = *"$LEGACY_USER"* && $MEMBERS != *"$NEW_USER"* ]]; then
# Add new user and remove old one
echo "Adding '${NEW_USER}' to '${LEGACY_GROUP}' for backwards compatibility" >> ${INST_LOG}
MEMBERS=${MEMBERS//$LEGACY_USER}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here again, probably requires bash too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one does seem to work:
image

Support functions needed to:
- Correct permissions on folders during upgrade in Linux mode.
- For transfer for download-related packages from 'sc-media' to 'sc-download'
@Safihre Safihre force-pushed the generic-service-fixes branch from a79e9a2 to 323f639 Compare February 22, 2018 10:40
@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

Now it is working as expected.
Before it would add svc-download twice and not detect legacy membership correctly, now it does:

Step postinst. USER=nzbdrone GROUP=sc-download SHARE_PATH=
Installing service configuration /var/packages/nzbdrone/conf/nzbdrone.sc
Creating group sc-download
Group Name: [sc-download]
Group Type: [AUTH_LOCAL]
Group ID:   [65537]
Group Members:
0:[svc-nzbdrone]
Invoke service_postinst
Granting 'svc-nzbdrone' unix permissions on /volume1/@appstore/nzbdrone/var/.config
Adding 'svc-nzbdrone' to 'sc-media' for backwards compatibility
Group Name: [sc-media]
Group Type: [AUTH_LOCAL]
Group ID:   [65536]
Group Members:
0:[svc-nzbdrone]
Thr Feb 22 09:56:18 CET 2018

@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

Just found out that grep on DSM 5.2 doesn't support the -P. Have to update all packages to some fancy sed. 😢

@Safihre Safihre force-pushed the generic-service-fixes branch from 250f5af to 0aea8ee Compare February 22, 2018 13:35
@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

Removed Sonarr/Radarr specific things from this PR, creating separate one.

@Safihre Safihre mentioned this pull request Feb 22, 2018
3 tasks
@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

Another small bug: all code assumes EFF_USER is set. But for packages like Python it's not set since they don't need a user.
Introduced checks to all functions to only be performed if there actually is EFF_USER.

@Safihre Safihre force-pushed the generic-service-fixes branch from b9f0e30 to 3a9e320 Compare February 22, 2018 15:10
@ymartin59
Copy link
Contributor

OK. Do you consider it as ready to merge ?

@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

I would say so yes.
Have been testing all day today on the 3 systems (Xpenology 5.2, Xpenology 6.1 and real 6.1 NAS) and also the "old style" package to "new style" upgrade paths.
That revealed all these problems that I fixed today also in the other PR's.
What a hassle these packages are :|
Never imagined it to be so complex..

@Safihre
Copy link
Contributor Author

Safihre commented Feb 22, 2018

If this is merged I'll do a proper rebuild of all the testing packages and test it again on all 3 systems.

@m4tt075
Copy link
Contributor

m4tt075 commented Feb 22, 2018

@ymartin59 @Diaoul Thanks a lot for inviting me to this elect club. More than happy to join, although I will consider myself as a "junior" member for the time being. @Safihre I have been on a business trip the last couple of days and am amazed about the progress you have made in the meantime. This is great, great work. Thanks so much! Looking forward to review "my" packages as well once this is in!

@ymartin59 ymartin59 merged commit 005677a into SynoCommunity:master Feb 23, 2018
@Safihre Safihre deleted the generic-service-fixes branch February 23, 2018 07:31
if [ -n "${EFF_USER}" ]; then
echo "Granting '${EFF_USER}' unix permissions on ${DIRNAME}" >> ${INST_LOG}
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ]; then
chown -R ${EFF_USER}:root "${DIRNAME}" >> $INST_LOG 2>&1
Copy link
Contributor

Choose a reason for hiding this comment

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

@Safihre @ymartin59 I have continued to debug the upgrade problems on DSM5.2 systems that I ran into yesterday (packages did not start anymore after upgrade due to permission issues). I suspect the culprit is that the group is set to root here rather than users for DSM lt 6. Do you agree? If so, we probaby have to re-build all packages which were built since.

Copy link
Contributor

Choose a reason for hiding this comment

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

Most test packages have only built for DSM 6... Group "users" is used for share folders accessible from other processes. For a package specific folder, group "root" should be far enough as owner matches service user.

Copy link
Contributor Author

@Safihre Safihre Feb 28, 2018

Choose a reason for hiding this comment

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

Agreed with @ymartin59, but unfortunately in the case of Tvheaded everything is mixed. Package and "user" folders blend together.

But @m4tt075, do you need to use set_syno_permmissions at all in your case? Since everything stays in the Package directory, do you need to call any permissions command at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't really impossible to configure TVH download location to a share folder as other applications ? I think that may be the key. If download locations are "hardcoded", it is still possible to create symbolic link from expected/original locations to DSM share folder(s)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks for clarifying. @Safihre I agree with you. Unix permissions need to be sufficient for all folders within @appstore. I have been able to implement that approach successfully for DSM6.1 now. I have tested clean installs, upgrading by itself and upgrading from the currently published package. But it does not work on DSM 5.2, when upgrading from the currently published package. In that version, ACL permissions were still set on the target and traversal folders. Is there a way to "remove" those ACL permissions again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@m4tt075 Why are ACL permissions applied? Only if set_syno_permissions is called this happens, but that shouldn't be needed at all, right?

stefaang pushed a commit to stefaang/spksrc that referenced this pull request Jan 21, 2019
…nity#3161)

* Add set_unix_permissions and syno_user_add_to_legacy_group

Support functions needed to:
- Correct permissions on folders during upgrade in Linux mode.
- For transfer for download-related packages from 'sc-media' to 'sc-download'

* Highlight logging of Generic Service to identify steps easier

* Create INST_VAR before calling service_postinst

So that service_postinst can assume the var directory is available.

* Do not assume that EFF_USER exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants