Bug 2275304 - Review Request: osh - Static and Dynamic Analysis as a Service [NEEDINFO]
Summary: Review Request: osh - Static and Dynamic Analysis as a Service
Keywords:
Status: ASSIGNED
Alias: None
Product: Fedora
Classification: Fedora
Component: Package Review
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Miroslav Suchý
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-04-16 15:19 UTC by Siteshwar Vashisht
Modified: 2024-05-06 14:47 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:
msuchy: fedora-review?
svashisht: needinfo? (msuchy)


Attachments (Terms of Use)

Description Siteshwar Vashisht 2024-04-16 15:19:17 UTC
Spec URL: https://download.copr.fedorainfracloud.org/results/@openscanhub/devel/fedora-rawhide-x86_64/07317815-osh/osh.spec
SRPM URL: https://download.copr.fedorainfracloud.org/results/@openscanhub/devel/fedora-rawhide-x86_64/07317815-osh/osh-1.0.0-1.fc41.src.rpm
Description: OpenScanHub is a service for static and dynamic analysis. It consists of central hub, workers and cli client.
Fedora Account System Username: svashisht

Comment 1 Siteshwar Vashisht 2024-04-16 15:24:32 UTC
This is needed to make it easier for the new users to directly install the command line client from the Fedora repositories. Related documentation can be found at https://fedoraproject.org/wiki/OpenScanHub

Comment 2 Miroslav Suchý 2024-04-17 08:14:09 UTC
> Source:         openscanhub-1.0.0.tar.gz
Can you put there either a full URL or comment on how you fetched the tarball?

> %defattr(644,root,root,755)
This is the default. You can remove it.

> %{_unitdir}/osh-retention.*
> %{_unitdir}/osh-stats.*

Do you really want to have this set to root:apache?

># record timestamp
>echo -n '>>> '
>date -R

This looks like development stuff. Definitely should not be in final rpm.

># this only takes an effect if PostgreSQL is running and the database exists
>pg_isready -h localhost && %{python3_sitelib}/osh/hub/manage.py migrate

This is a discouraged practice. You never know how big the DB is. I saw migration that lasted several hours. You do not want to block rpm upgrades because of db upgrade. Or even worse, fail because of that.
This should be separate step, outside of rpm.

>Provides: covscan-client = %{version}
>Obsoletes: covscan-client < %{version}
>Conflicts: covscan-client < %{version}

Provides and Obsoletes are OK. Then you do not need Conflicts.

All descriptions in %description should end with dot. And I believe you can be slightly more verbose there.

Comment 3 Kamil Dudka 2024-04-17 08:40:53 UTC
(In reply to Miroslav Suchý from comment #2)
> ># record timestamp
> >echo -n '>>> '
> >date -R
> 
> This looks like development stuff. Definitely should not be in final rpm.

Is there a better way to log what happened in %post?

The same RPM package can be installed multiple times and the log is appended each time.  We need an admin-friendly way to distinguish each run of %post in the log file.

> ># this only takes an effect if PostgreSQL is running and the database exists
> >pg_isready -h localhost && %{python3_sitelib}/osh/hub/manage.py migrate
> 
> This is a discouraged practice.

Could you please point us to the corresponding guideline?

> You never know how big the DB is. I saw migration that lasted several hours.

Yes and the DB on the internal OSH instance has always been migrated this way.  As far as I know there is no timeout for executing %post.

> You do not want to block rpm upgrades because of db upgrade. Or even worse, fail because of that.

Why?

1. We want application upgrades to run unattendedly where possible.
2. If we fail to upgrade our RPM-packaged application, we want to know about it rather sooner than later.

> This should be separate step, outside of rpm.

It could be done as a separate step.  But what advantage would it bring to the OSH admin?  Why should they manually do something that can be done fully automatically during the installation?

Comment 4 Miroslav Suchý 2024-04-17 18:58:51 UTC
> Is there a better way to log what happened in %post?

echo foo >> /var/log/osh/something.log

> Could you please point us to the corresponding guideline?

No. It is not written anywhere. I am just sharing my 15+ experience with DB maintenance. Feel free to ask any other experienced db admin. Or feel free to ignore and learn it the hard way, one day.

Comment 5 Kamil Dudka 2024-04-17 20:40:06 UTC
The interpreter of %post has its stdout/stderr redirected to `/var/log/osh/hub/post-install-%{name}-%{version}-%{release}.log`:
https://github.com/openscanhub/openscanhub/blob/e800d57100abdc802ab742dee9ddf9d471a65ebd/osh.spec#L253

Hence any output produced in %post is written to a log file as you suggest.  The pair of commands you quoted just records a timestamp in the log file.  Here is an example of how the content of the log file looks like:

# cat /var/log/osh/hub/post-install-osh-0.9.7.20240405.175258.ga916dec.pr_228-1.el9.log
>>> Fri, 05 Apr 2024 18:05:20 +0200
+ umask 0026
+ test -e /var/lib/osh/hub/secret_key
+ pg_isready -h localhost
localhost:5432 - accepting connections
+ /usr/lib/python3.9/site-packages/osh/hub/manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, hub, kobo_auth, scan, sessions, sites, stats, upload, waiving, xmlrpc
Running migrations:
  No migrations to apply.
+ '[' 2 -eq 1 ']'
>>> Mon, 08 Apr 2024 15:10:29 +0200
+ umask 0026
+ test -e /var/lib/osh/hub/secret_key
+ pg_isready -h localhost
localhost:5432 - accepting connections
+ /usr/lib/python3.9/site-packages/osh/hub/manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, hub, kobo_auth, scan, sessions, sites, stats, upload, waiving, xmlrpc
Running migrations:
  No migrations to apply.
+ '[' 2 -eq 1 ']'

Comment 6 Miroslav Suchý 2024-04-18 07:37:54 UTC
> The interpreter of %post has its stdout/stderr redirected to `/var/log/osh/hub/post-install-%{name}-%{version}-%{release}.log`:

Ahh. I see now. This is quite an ugly hack. But ok.

Comment 7 Siteshwar Vashisht 2024-04-18 12:44:58 UTC
https://github.com/openscanhub/openscanhub/pull/259/files

Comment 8 Siteshwar Vashisht 2024-04-18 14:48:53 UTC
It would be easier for me to make changes before merging PR in comment 7. Please review it on GitHub.

Comment 10 Miroslav Suchý 2024-04-22 09:18:00 UTC
Package Review
==============

Legend:
[x] = Pass, [!] = Fail, [-] = Not applicable, [?] = Not evaluated
[ ] = Manual review needed


Issues:
=======
- Permissions on files are set properly.
  Note: See rpmlint output
  See: https://docs.fedoraproject.org/en-US/packaging-
  guidelines/#_file_permissions
- If (and only if) the source package includes the text of the license(s)
  in its own file, then that file, containing the text of the license(s)
  for the package is included in %license.
  Note: License file LICENSE-SELECT2.md is not marked as %license
  See: https://docs.fedoraproject.org/en-US/packaging-
  guidelines/LicensingGuidelines/#_license_text
- systemd_post is invoked in %post, systemd_preun in %preun, and
  systemd_postun in %postun for Systemd service files.
  Note: Systemd service file(s) in osh-worker, osh-hub
  See: https://docs.fedoraproject.org/en-US/packaging-
  guidelines/Scriptlets/#_scriptlets
- license file must be installed
- there is no owner of /etc/osh directory
Should:
- note that usually the order of section is %prep, %build, %install, all scriptlet, all %files section. Your style of mixing %files and scriptlets make it hard for me to read the spec file.
- when using tarball from GH then you should specify full URL in URL tag. See https://docs.fedoraproject.org/en-US/packaging-guidelines/SourceURL/#_tag_example
- the tarball has test, can it be run in %check?
- instead of cp -R you want to use cp -aR (and I think the R is not needed at all).



===== MUST items =====

Generic:
[x]: Package is licensed with an open-source compatible license and meets
     other legal requirements as defined in the legal section of Packaging
     Guidelines.
[x]: License field in the package spec file matches the actual license.
[!]: License file installed when any subpackage combination is installed.
[x]: Package requires other packages for directories it uses.
[!]: Package must own all directories that it creates.
     Note: Directories without known owners: /etc/osh
[x]: Package contains no bundled libraries without FPC exception.
[x]: Changelog in prescribed format.
[x]: Sources contain only permissible code or content.
[-]: Package contains desktop file if it is a GUI application.
[-]: Development files must be in a -devel package
[x]: Package uses nothing in %doc for runtime.
[x]: Package consistently uses macros (instead of hard-coded directory
     names).
[x]: Package is named according to the Package Naming Guidelines.
[x]: Package does not generate any conflict.
[x]: Package obeys FHS, except libexecdir and /usr/target.
[-]: If the package is a rename of another package, proper Obsoletes and
     Provides are present.
[x]: Requires correct, justified where necessary.
[x]: Spec file is legible and written in American English.
[x]: Package contains systemd file(s) if in need.
[x]: Package is not known to require an ExcludeArch tag.
[x]: Package complies to the Packaging Guidelines
[x]: Package successfully compiles and builds into binary rpms on at least
     one supported primary architecture.
[x]: Package installs properly.
[x]: Rpmlint is run on all rpms the build produces.
     Note: There are rpmlint messages (see attachment).
[x]: The License field must be a valid SPDX expression.
[x]: Package does not own files or directories owned by other packages.
[x]: Package uses either %{buildroot} or $RPM_BUILD_ROOT
[x]: Package does not run rm -rf %{buildroot} (or $RPM_BUILD_ROOT) at the
     beginning of %install.
[x]: Macros in Summary, %description expandable at SRPM build time.
[x]: Dist tag is present.
[x]: Package does not contain duplicates in %files.
[x]: Package must not depend on deprecated() packages.
[x]: Package use %makeinstall only when make install DESTDIR=... doesn't
     work.
[x]: Package is named using only allowed ASCII characters.
[x]: Package does not use a name that already exists.
[x]: Package is not relocatable.
[x]: Sources used to build the package match the upstream source, as
     provided in the spec URL.
[x]: Spec file name must match the spec package %{name}, in the format
     %{name}.spec.
[x]: File names are valid UTF-8.
[x]: Large documentation must go in a -doc subpackage. Large could be size
     (~1MB) or number of files.
     Note: Documentation size is 0 bytes in 0 files.
[x]: Packages must not store files under /srv, /opt or /usr/local

Python:
[-]: Binary eggs must be removed in %prep
     Note: Cannot find any build in BUILD directory (--prebuilt option?)
[-]: Python eggs must not download any dependencies during the build
     process.
[-]: A package which is used by another package via an egg interface should
     provide egg info.
[x]: Package meets the Packaging Guidelines::Python
[x]: Package contains BR: python2-devel or python3-devel
[x]: Packages MUST NOT have dependencies (either build-time or runtime) on
     packages named with the unversioned python- prefix unless no properly
     versioned package exists. Dependencies on Python packages instead MUST
     use names beginning with python2- or python3- as appropriate.
[x]: Python packages must not contain %{pythonX_site(lib|arch)}/* in %files

===== SHOULD items =====

Generic:
[x]: If the source package does not include license text(s) as a separate
     file from upstream, the packager SHOULD query upstream to include it.
[x]: Final provides and requires are sane (see attachments).
[-]: Fully versioned dependency in subpackages if applicable.
[?]: Package functions as described.
[x]: Latest version is packaged.
[x]: Package does not include license text files separate from upstream.
[!]: Scriptlets must be sane, if used.
[!]: SourceX tarball generation or download is documented.
     Note: Package contains tarball without URL, check comments
[-]: Sources are verified with gpgverify first in %prep if upstream
     publishes signatures.
     Note: gpgverify is not used.
[?]: Package should compile and build into binary rpms on all supported
     architectures.
[!]: %check is present and all tests pass.
[!]: Packages should try to preserve timestamps of original installed
     files.
[x]: Reviewer should test that the package builds in mock.
[x]: Buildroot is not present
[x]: Package has no %clean section with rm -rf %{buildroot} (or
     $RPM_BUILD_ROOT)
[x]: No file requires outside of /etc, /bin, /sbin, /usr/bin, /usr/sbin.
[x]: Packager, Vendor, PreReq, Copyright tags should not be in spec file
[x]: SourceX is a working URL.
[x]: Spec use %global instead of %define unless justified.

===== EXTRA items =====

Generic:
[x]: Rpmlint is run on all installed packages.
     Note: There are rpmlint messages (see attachment).
[x]: Spec file according to URL is the same as in SRPM.


rpmlint warning - and I removed all that are not relevant. But these remaining should be addressed:
osh-hub-conf-devel.noarch: W: python-bytecode-without-source /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.opt-1.pyc
osh-hub-conf-devel.noarch: W: python-bytecode-without-source /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.pyc
osh-worker.noarch: E: non-standard-executable-perm /usr/sbin/osh-worker 754
osh-hub-conf-devel.noarch: E: non-readable /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.opt-1.pyc 640
osh-hub-conf-devel.noarch: E: non-readable /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.pyc 640
osh-hub-conf-devel.noarch: E: non-readable /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.opt-1.pyc 640
osh-hub-conf-devel.noarch: E: non-readable /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.pyc 640
osh-hub.noarch: E: non-executable-script /usr/lib/python3.12/site-packages/osh/hub/scripts/osh-xmlrpc-client.py 644 /usr/bin/env python3
osh-hub.noarch: E: non-executable-script /usr/lib/python3.12/site-packages/osh/hub/scripts/umb-emit.py 644 /usr/bin/env python3
osh-hub-conf-devel.noarch: W: non-etc-or-var-file-marked-as-conffile /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.opt-1.pyc
osh-hub-conf-devel.noarch: W: non-etc-or-var-file-marked-as-conffile /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.pyc
osh-hub-conf-devel.noarch: W: non-etc-or-var-file-marked-as-conffile /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.opt-1.pyc
osh-hub-conf-devel.noarch: W: non-etc-or-var-file-marked-as-conffile /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.pyc
osh-hub-conf-devel.noarch: W: non-etc-or-var-file-marked-as-conffile /usr/lib/python3.12/site-packages/osh/hub/settings_local.py
osh-client.noarch: W: no-manual-page-for-binary covscan
osh-client.noarch: W: no-manual-page-for-binary osh-cli
osh-hub.noarch: W: no-manual-page-for-binary osh-retention
osh-hub.noarch: W: no-manual-page-for-binary osh-stats
osh-worker.noarch: W: no-manual-page-for-binary osh-worker
osh-client.noarch: W: no-documentation
osh-common.noarch: W: no-documentation
osh-hub.noarch: W: no-documentation
osh-hub-conf-devel.noarch: W: no-documentation
osh-worker.noarch: W: no-documentation
osh-worker-conf-devel.noarch: W: no-documentation
osh-hub.noarch: W: log-files-without-logrotate ['/var/log/osh']
osh-worker.noarch: W: log-files-without-logrotate ['/var/log/osh']
osh.spec: W: invalid-url Source0: openscanhub-1.0.0.20240419.115116.g843b9dd.tar.gz
osh-hub-conf-devel.noarch: E: hardlink-across-config-files /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.pyc /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.ci.cpython-312.opt-1.pyc
osh-hub-conf-devel.noarch: E: hardlink-across-config-files /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.pyc /usr/lib/python3.12/site-packages/osh/hub/__pycache__/settings_local.cpython-312.opt-1.pyc
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Add2_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Add2_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Add_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Add_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Document_content_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Document_content_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Message_log_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Message_log_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Ok_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Ok_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/Warning_32.png /usr/lib/python3.12/site-packages/osh/hub/static-assets/Warning_32.png
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/css/redhat.css /usr/lib/python3.12/site-packages/osh/hub/static-assets/css/redhat.css
osh-hub.noarch: W: files-duplicate /usr/lib/python3.12/site-packages/osh/hub/static/admin/js/vendor/select2/LICENSE.md /usr/lib/python3.12/site-packages/osh/hub/static/admin/css/vendor/select2/LICENSE-SELECT2.md
osh-hub.noarch: W: empty-%postun

Comment 11 Siteshwar Vashisht 2024-04-23 13:50:31 UTC
SPEC: https://download.copr.fedorainfracloud.org/results/packit/openscanhub-openscanhub-261/srpm-builds/07340017/osh.spec
SRPM: https://download.copr.fedorainfracloud.org/results/packit/openscanhub-openscanhub-261/srpm-builds/07340017/osh-1.0.0.20240423.152702.g044fd77.pr_261-1.src.rpm

PR: https://github.com/openscanhub/openscanhub/pull/261/files

Please review the changes directly there.

> Issues:
> =======
> - Permissions on files are set properly.
>   Note: See rpmlint output
>   See: https://docs.fedoraproject.org/en-US/packaging-
>   guidelines/#_file_permissions

I fixed some of them. Others are needed to keep the current deployment working.
Please see comments on the spec file.

> - If (and only if) the source package includes the text of the license(s)
>   in its own file, then that file, containing the text of the license(s)
>   for the package is included in %license.
>   Note: License file LICENSE-SELECT2.md is not marked as %license
>   See: https://docs.fedoraproject.org/en-US/packaging-
>   guidelines/LicensingGuidelines/#_license_text

This is from a dependency. I would skip listing it.

> - systemd_post is invoked in %post, systemd_preun in %preun, and
>   systemd_postun in %postun for Systemd service files.
>   Note: Systemd service file(s) in osh-worker, osh-hub
>   See: https://docs.fedoraproject.org/en-US/packaging-
>   guidelines/Scriptlets/#_scriptlets

It is invoked as expected. 

> - license file must be installed

Fixed.

> - there is no owner of /etc/osh directory

It is owned by `osh-common` package.

> Should:
> - note that usually the order of section is %prep, %build, %install, all
> scriptlet, all %files section. Your style of mixing %files and scriptlets
> make it hard for me to read the spec file.

I could take that as a separate issue. I would avoid doing it now to make it
easy to do reviews.

> - when using tarball from GH then you should specify full URL in URL tag.
> See
> https://docs.fedoraproject.org/en-US/packaging-guidelines/SourceURL/
> #_tag_example

It was removed by PackIt. It should be fixed now.

> - the tarball has test, can it be run in %check?

I could take that as a separate issue.

> - instead of cp -R you want to use cp -aR (and I think the R is not needed
> at all).

Fixed.

Comment 13 Siteshwar Vashisht 2024-05-06 14:47:59 UTC
We discussed this issue with msuchy and kdudka and below items need to be resolved:

- The settings configuration file from django should move under `/etc`.
- Exclude the `.py*` files.


Note You need to log in before you can comment on or make changes to this bug.