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

DSM 7 support framework design #4215

Closed
ymartin59 opened this issue Oct 12, 2020 · 77 comments · Fixed by #4395
Closed

DSM 7 support framework design #4215

ymartin59 opened this issue Oct 12, 2020 · 77 comments · Fixed by #4395
Labels

Comments

@ymartin59
Copy link
Contributor

ymartin59 commented Oct 12, 2020

I propose to collaboratively edit this issue description (with comments for discussions about points) so that to prepare how framework has to evolve.

Objectives:

  • if possible, package should run seamlessly on both DSM 6 and DSM 7
    • this is not possible, packages for DSM 6 and DSM 7 are not compatible
    • packages for DSM 7 need at least os_min_ver="7.0-40000"
  • reduce as much as possible package maintenance: implement support in framework make files and generated/embedded scripts

Design proposals:

  • ✔️ At upgrade "var" content is restored as "home" in both DSM 6 and DSM 7
  • Migrate to the new resource/permission file/specification which help implement common uses cases that otherwise required root Privileges (may not be required see comment, but is something we are working towards)
    • ✔️ SPK_COMMANDS and SPK_LINKS have to generate resource file for links
    • ✔️ installer has to generate database resource file from wizard for concerned application
    • ❌ Use privilege file to add package to a group e.g. sc-media
    • ✔️ Use privilege file to add create shared folder

To investigate

  • Privileges: what should be done?
  • ❌ Verify that adding package to a group e.g. sc-media still works from the install script.

Minimal requirements for DSM7

  • os_min_ver= must be present and the value at least "7.0-40000"
  • A conf/privilege file must exist (and have "defaults": { "run-as": "package" } [other values not validated yet])
@ymartin59 ymartin59 pinned this issue Oct 12, 2020
@publicarray
Copy link
Member

publicarray commented Oct 12, 2020

I've played around a little in my own fork, just to see what breaks and I think I got the minimal requirements done so packages can be "installed" but probably won't work. And binary packages can now be linked to /usr/local using Synology's resource file.

@th0ma7
Copy link
Contributor

th0ma7 commented Oct 12, 2020

OPTIONAL: There are a few changes I'd like to complete on the framework before jumping on the dsm7 bang-wagon:

  1. Review the DSM vs SRM management by using the new TC_TYPE variable now in place in the toolchain
  2. Review toolchains naming to be singular and use long naming for mk/spksrc.tc*.mk for mk/spksrc.toolchain*.mk
  3. Review the ARM7 exception used for some packages such as with go dependencies in order to have a a generic approach such as ARCH_NO_DUPE or FORCE_ARCHS (help on naming appreciated) pointing towards default available arches allowing to remove dupes for other arches as well as needed and also allow forcing specific sub-arches. This would also allow eliminating newly added syno-apollolake-6.2 in the all-supported builds.
  4. Last but not least, a little more far-stretched, review PLIST management not following regular cookie building makefile layout.

And forgot to mention meson/ninja build support as many packages cannot be further updated anymore...

@hgy59
Copy link
Contributor

hgy59 commented Oct 13, 2020

synology has published a beta release of the Development documentation DSM_Developer_Guide_7_0_Beta.pdf.
It is newer than the preview version.

One interesting difference I found is for 3rdparty developers:

1. Force lower privilege for package

All packages should provide conf/privilege with package in run-as explicitly. Any privileged operation should be
accomplished via resource worker.
But if you are 3rdparty developer, you can still use root privilege.

@publicarray
Copy link
Member

publicarray commented Oct 13, 2020

@ymartin59 Thanks, but why not link to the file? https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/7.0/enu/DSM_Developer_Guide_7_0_Beta.pdf
I don't know but with the current build, when I make a package that asks for root "run-as": "root" I get this:

Failed to install. The package should run with a lower privilege level. Please contact the package developer to modify the privilege settings.

@hgy59
Copy link
Contributor

hgy59 commented Oct 13, 2020

@publicarray thanks for the link (comment updated).
I think that this will work with DSM 7 beta (we are still on DSM 7 preview).

@publicarray
Copy link
Member

That may be true. but I think sooner or later permissions will be more restricted over time, maybe at DSM version 24 ;)
Still think it's worth to migrate some of the shell scripts to their resource file equivalent. What do you think?

@hgy59
Copy link
Contributor

hgy59 commented Oct 13, 2020

Yes, agree. We should use the official kind of resource scripts whereever provided.

EDIT:
the following is proposed already

We should use resource scripts for creating links too.
As I introduced SPK_COMMANDS and SPK_LINKS for commandline tools, it would be worth to create the resource scripts based on these (or slightly adjusted) variables.

@publicarray
Copy link
Member

publicarray commented Oct 13, 2020

resource scripts for creating links too.

Yeah I've worked on that in my dsm7 branch. You can see the result in the synocli-disk GitHub release here. https://github.com/publicarray/spksrc/releases

Agreed. Currently I assume SPK_ COMMANDS are binaries so for other resource types new variables need to be made. Using SPK_COMMANDS would seamlessly work on existing scripts.

I think I'll create PRs once Synology releases the beta and once I'm more confident that it works correctly.

@publicarray
Copy link
Member

publicarray commented Oct 18, 2020

To maniuplate json I would like to jq as a dependecy to the docker image and spksrc. Why is sed not enough? Once arrays are used it makes code hard to read and error prone, jq ensures that we generate valid json.

e.g. To add a package to the sc-media and sc-example group in the privilege file:

$ jq --arg packagename sc-media '."join-pkg-groupnames" += [{$packagename}]' privilege | jq --arg packagename sc-example '."join-pkg-groupnames" += [{$packagename}]'
{
  "defaults": {
    "run-as": "package"
  },
  "join-pkg-groupnames": [
    {
      "packagename": "sc-media"
    },
    {
      "packagename": "sc-example"
    }
  ]
}

Edit: there are other ways to do this (see below) but the above is easy to use in a loop.

$ jq --arg pkg1 sc-media --arg pkg2 sc-example '."join-pkg-groupnames"+=[{packagename: $pkg1},{packagename: $pkg2}]' privilege
{
  "defaults": {
    "run-as": "package"
  },
  "join-pkg-groupnames": [
    {
      "packagename": "sc-media"
    },
    {
      "packagename": "sc-example"
    }
  ]
}

Edit2: Create the minium needed for a privilege file

$ echo '{}' | jq --arg run_as package '.defaults = {"run-as": $run_as}'
# or
$ echo '{}' | jq --arg key run-as --arg value package '.defaults[$key] = $value'

{
  "defaults": {
    "run-as": "package"
  }
}

I'm happy to work with alterntives too :) Just please don't make use sed for json manipulation 😆

@hgy59
Copy link
Contributor

hgy59 commented Nov 29, 2020

@publicarray may you please rebase the dsm7 branch to current head@master?
I would like to build some current packages (like ntopng) for my DS218+ that has installed DSM7 preview.

@publicarray
Copy link
Member

@hgy59

Yup. It's Done 👍

@publicarray
Copy link
Member

DSM7 is now in Beta https://www.synology.com/en-global/beta/DSM70Beta

@kalatos86
Copy link

Is there any information when the community packages might have update to be compatible with DSM 7?

@publicarray
Copy link
Member

@kalatos86 Since this is an open source project where people donate their time to contribute I can't give you an ETA. But you are more than welcome to build packages / contribute on the dsm7 branch

@publicarray
Copy link
Member

publicarray commented Dec 22, 2020

DSM7 and Logs

I propose to change logging in DSM7, if we do nothing some logs will be lost between, package upgrades and install because the target/var folder is not permanent storage. (not a huge issue) Using var aka ${SYNOPKG_PKGVAR}/${SYNOPKG_PKGNAME}.log" fixes the above problem but turns out that the $SYNOPKG_PKGVAR variable does not exist in every stage of the installation cycle thus attempting to write the log file in /${SYNOPKG_PKGNAME}.log which fails in those stages. I think writing to stderr fixes these issues because now Synology is responsible for logging and log rotation (which it does on package reinstall) It also frees up some code in our scripts. Please let me know what you think. @ymartin59 @hgy59 @th0ma7

# /var/package/{package}/target/var/{package.log}.log (Current, main branch)
LOGFILE="${SYNOPKG_PKGDEST}/var/${SYNOPKG_PKGNAME}.log"

# /var/package/{package}/var/{package.log}.log (permanent storage, is in dsm7 branch)
LOGFILE="${SYNOPKG_PKGVAR}/${SYNOPKG_PKGNAME}.log"

# /tmp/synopkgmgr.log-{package} # I no idea how/where to retrieve it, since the file disappears immediately after install.
LOGFILE= ${SYNOPKG_TEMP_LOGFILE}

# /var/log/packages/{package}.log (I think that this is the best option)
echo "$1" 1>&2 #  stderr

# for completeness: show the message to the user
echo "$1" # (during install only, /var/log/packages/{package}.log when service is running)

 # /var/log/messages
logger -p 3 "$1"

@th0ma7
Copy link
Contributor

th0ma7 commented Dec 26, 2020

Sounds like a good idea but I haven't looked much on that part of the code, neither on the dsm7 update yet. @ymartin59 and @hgy59 might have more to say on this.

@publicarray
Copy link
Member

Thanks @th0ma7

While I was looking through some code I found a few packages uses busybox to delete users/groups from what I assume a migration from around DSM5 to DSM6? (can someone confirm that that is the intent?) Since I expect it already hard to migrate settings from DSM6 I want to drop busybox completely in DSM7 and not support package migration from DSM5 to DSM7, (IMHO It doesn't make sense to do so anyway)

@publicarray
Copy link
Member

@ymartin59 @hgy59 What arches should we build for DSM7.0? I think this should cover everything:

make -j`nproc` arch-x64-7.0 arch-armv7-7.0 arch-aarch64-7.0 arch-evansport-7.0

@hgy59 hgy59 mentioned this issue Jan 2, 2021
@publicarray
Copy link
Member

publicarray commented Jan 19, 2021

@hgy59 I've added SPK_DEPENDS to avoid confusion: https://seby.io/download/synology-7.0/adminer_noarch-dsm7_4.7.6-3.spk
publicarray@3dfb3d4

Yea it works on my machine:tm: The new folder should have been /var/services/web_packages/adminer maybe the migration is broken.

If you continue to have problems can I suggest reinstalling web station?

Was there a reason packages still use Apache 2.2? I'm actually surprised Synology still ships it. From apache's website:

The Apache HTTP Server Project had long committed to provide maintenance releases of the 2.2.x flavor through June of 2017. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases.

FYI same for php 5.6, 7.0 and 7.2: https://www.php.net/supported-versions.php (7.4 is the only realistic version to support right now)

@hgy59
Copy link
Contributor

hgy59 commented Jan 19, 2021

You cannot uninstall apache 2.2 without accepting the following warning in DSM7:

Uninstalling this package will cause abnormalities in the following functions. 
Do you mant to continue?
Some of the Web Stations's services will not be able to function properly, including default
back-end, personal website, and Virtual Host.

Hopefully apache 2.2 (and other outdated packages) will be removed in the final DSM7...

@publicarray
Copy link
Member

Does the warning show up even when you have both apache versions installed? I don't use those functions but I can confirm that the default server works with just apache2.4 installed.

@publicarray
Copy link
Member

Oh in DSM6 the checkbox for personal website is disabled until I install old versions of php and apache. DSM7 allows you to mix and match php/apache versions

@hgy59
Copy link
Contributor

hgy59 commented Jan 19, 2021

Does the warning show up even when you have both apache versions installed? I don't use those functions but I can confirm that the default server works with just apache2.4 installed.

Yes, I have both versions (2.2 and 2.4 installed) and you can uninstall apache2.4 without warning.

@publicarray
Copy link
Member

I think that warning only shows up if you have a 'personal website or Virtual Host' setup from DSM6. I accepted the warning once but it no longer shows up when I uninstall 2.2.

@publicarray
Copy link
Member

What is configured for your default server?
Screenshot from 2021-01-19 19-35-12
Screenshot from 2021-01-19 19-35-43

@publicarray
Copy link
Member

publicarray commented Jan 19, 2021

If I install 2.2 and set the default server to 2.2 I get the warning. If I set it to 2.4 and uninstall 2.4 I also get the warning. On Nginx I don't. I guess it's to prevent unexpected errors. I which the warning was clearer though.

To sum up just update the setting for your default server to 2.4 or nginx (unless you explicitly require 2.2 for some reason).

@hgy59
Copy link
Contributor

hgy59 commented Jan 19, 2021

Yes you have to remove/update all the Web Service Portal configurations and Script Language Settings referencing outdated apache and php versions. Then you can uninstall the appropriate packages without warnings.

publicarray added a commit to publicarray/spksrc that referenced this issue Jan 30, 2021
simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

SynoCommunity#4215 (comment)
@publicarray publicarray linked a pull request Jan 31, 2021 that will close this issue
publicarray added a commit to publicarray/spksrc that referenced this issue Feb 1, 2021
simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

SynoCommunity#4215 (comment)
@digitalbox94
Copy link

Another interesting source of information regarding DSM7 package : https://github.com/SynologyOpenSource/ExamplePackages

@publicarray
Copy link
Member

Thanks @digitalbox94 but unfortunately it's no very useful. It only demonstrates the new /usr/local/bin/ linking. We already implemented it on the dsm7 branch.

@digitalbox94
Copy link

Ok I've played a little bit with the Icecast package and DSM7 and here are my findings :

  • Cross compile is successful for braswell DSM 7
  • Installation on DSM 7 is OK (no error raised)
  • Running is not OK by default because the folder /usr/local/icecast is not created during installation (to be investigated)

By doing some manual tricks directly on the NAS (configuration files & directory creation) I've got Icecast server running fine on my DS716+II with an ezstream flow (ezstream is also embedded in this package).
It means it's a good starting point before having a package 100% DSM 7 compatible.

I will continue my investigation but I you have any comments/advice to share for this DSM 7 topic they are welcome.

@publicarray
Copy link
Member

publicarray commented Feb 4, 2021

Thanks @DigitalBox98, fixed in 9dd89e3

Most packages have old assumptions on the file layout and permissions so most will need to be manually migrated.

@digitalbox94
Copy link

Many thanks, the start of the server now works without any manual fix on DSM 7 ! :)

Regarding the "service-setup" file, I have identified an issue to fix regarding the "ice cast.xml" CFG-FILE where the correct line is :
CFG_FILE="${SYNOPKG_PKGDEST}/var/icecast.xml"
It will help to have correct login/password for the admin part

icecast

publicarray added a commit to publicarray/spksrc that referenced this issue Feb 6, 2021
simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

SynoCommunity#4215 (comment)
publicarray added a commit to publicarray/spksrc that referenced this issue Feb 20, 2021
simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

SynoCommunity#4215 (comment)
publicarray added a commit to publicarray/spksrc that referenced this issue Feb 21, 2021
simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

SynoCommunity#4215 (comment)
@DigitalBox98
Copy link
Contributor

I would like to test the below "proof-of-concept" for DSM7 (but also for DSM6) :

  • Propose a basic ImageMagick admin page (HTML/PHP) to have image conversion available directly in DSM
  • Protect pages via Syno AUTH webapi (working fine on DSM7)

I'm actually fine tuning the solution on DSM7 because sometime the admin page is not available via DSM7 (access to /var/services/web_packages/imagemagick), and sometime it works (need to investigate further).
Putting the HTML/PHP pages on another directory (like previous method on DSM6 ie /var/services/web/imagemagick resolve 100% the previous issue on DSM7.

If I would like to propose a PR for this for DSM7, but what is the best below :

  • Send this PR to a branch "imagemagick" created from master branch ?
  • Send this PR to a branch "imagemagick" created from DSM7 branch ?

Another point : actually I have created & tested it on DSM7 with a branch created from DSM7 branch
Does it make senses to propose it for DSM6 with a branch "imagemagick" created from master branch ? (ie would the framework will generate the correct version for DSM6)

Let me know if you are interested to test this (at least the Syno AUTH webapi can be useful for other packages).

publicarray added a commit that referenced this issue Mar 11, 2021
* prepare for dsm7

* Add 7.0 toolchain for testing

* Add x64-7.0 to CI

* start on dsm7 install/service script

* fix DSM_APP_NAME in dsm7

* remove tools that require root permissions:
  (synouser, synogroup, synoshare)
* remove tool that fail to modify permissions (synoacltool)
* remove tool that fail to apply configuration (servicetool)

servicetool, synouser, synogroup and synoshare have alternative
 ways to do the same thing using resource configuration

* fix username, keep DSM6 name convention sc-packagename

* Issue user facing warning on unsupported functions

* change package icon size

- change icon size from 72x72 to 64x64 for DSM 7

* cleanup

* Store log files, pid and other files in permanent storage
fixes missing log entries on reinstall

* Migrate some JSON processing to jq

TODO add moreutils package, use sponge to prevent overriding file with 0 content
- 1<> $@
+ | sponge $@

* fix adding GROUPs DSM7

* join-pkg-groupnames Creates group but is different from the groups the user can create, they are invisible in the UI an are only useful to access another packages permissions (ffmpeg comes to mind)
For DSM7 I recommend setting permissions for individual packages (System Internal User)
or use the shared folder resource worker to add permissions. We can ask the user from the wizard the folder name

"join-groupname": "http" is for system groups, mainly for the web service ("root" don't work but "system" does)

* DSM6->DSM7 move target/var to var/

* Added dsm7 preview toolchain for syno-armada38x-7.0

* Add DSM7.0 toolchains

* Add v1000 to generic x64-7.0

* Add evansport DSM 7.0 Toolkit

* fix builds for dsm versions < 7

* DSM7 Log install script to /var/log/packages/{package}.log

Remove some more statements that modify files in places where we don't have permissions or is just unnecessary in DSM7

* add back firewall install/removal

* Acquire Shared folder resource/permissions

set using SERVICE_WIZARD_SHARE

only disadvantage is that this does not support sub-folders currently

* Only migrate /var directory to permanent storage when destination is empty

* set SYNOPKG_PKGVAR for DSM versions less than 7.0

* Add uninstaller that can optionally remove all package files

Includes files in the new permanent storage (/var) and home folder

* uninstaller: also remove /etc

* fix noarch in dsm7

simple hack to set os_min_ver to 7.0-4000

build using: make noarch-7.0 or make noarch-6.1
build must be clean between builds

#4215 (comment)

* fix missing files on clean install
Copy config files on first install from "target/var" to "/var"

* Error on dropped support for busybox start-stop-daemon aka SERVICE_EXE

* fix don't override old configurations

* Add ability for packages to join a SYSTEM_GROUP and cleanup

Available options are: http and system

* fix DSM6 regression and code review

* fix regression: backwards compatibility with DSM6

* for DSM6 don't set "groupname". fixes permission issues with sc-{groups}

Add SPK_GROUP variable to override "groupname", default is sc-{packagename}

* fix noarch for dsm7

- use noarch-dsm7 to distinguish from noach-all
- use different work dirs for all and dsm7
- incorporate #4392
- followup of 05c2383 to avoid to clean between builds

* update github action to build noarch-7.0 packages

* fix github build action for noarch-7.0

* another fix for noarch build action

* fix DSM7 running with su command:
#4395 (comment)

* Toolchains: Update DSM7 hashes and fix typos

* Add supported DSM 7 archs to CI/GH Actions

* fix os_min_vers for DSM 7 noarch

- update min. build from 4000 to 40000

* regenerated digests of dsm7 toolchains

* Add sha256 digest to evansport toolkit

* fix TC_BUILD for DSM7.0

* Apply new version comparison function

Fixes wrong comparisons e.g. where 3.10 was erroneously less than 3.2

Thanks @th0ma7

* framework, resource: simplify jq command

* framework: code review

* Add linking support for /usr/local/lib and /usr/local/etc

depreciate SPK_LINKS and add new make variable: SPK_USR_LOCAL_LINKS

* fix SPK_USR_LOCAL_LINKS

* Fix comments being output to command line

* Framework: DSM7 Make sure folder exists before migrating files

* Framework: Fix unable to override uninstall wizard

* Update mk/spksrc.service.start-stop-status

Co-authored-by: hgy59 <hpgy59@gmail.com>

* Fraework: avoid creating wizard folder when it's not needed

Co-authored-by: hgy59 <hpgy59@gmail.com>

Co-authored-by: hgy59 <hpgy59@gmail.com>
Co-authored-by: root <zyrill@github.com>
@hgy59 hgy59 unpinned this issue Mar 27, 2021
@EngMarc
Copy link

EngMarc commented Jun 13, 2021

As for the _GLIBCXX_USE_C99_MATH and al, shouldn't we add them by default in mk/meson|cmake| if TC_GCC = 7.3.0 to make things simpler?

@th0ma7 when this works for ffmpeg too, this is a good proposal.
@th0ma7 is the a new ffmpeg for DSM 7 yet?

@erdoukki
Copy link
Contributor

erdoukki commented Feb 4, 2022

But if you are 3rdparty developer, you can still use root privilege.

This part was removed from the PDF ?

synology has published a beta release of the Development documentation DSM_Developer_Guide_7_0_Beta.pdf. It is newer than the preview version.

One interesting difference I found is for 3rdparty developers:

1. Force lower privilege for package

All packages should provide conf/privilege with package in run-as explicitly. Any privileged operation should be
accomplished via resource worker.
But if you are 3rdparty developer, you can still use root privilege.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.