classic confinement requires manually setting PATH and PYTHONPATH

Bug #1670749 reported by Corey Bryant
300
This bug affects 9 people
Affects Status Importance Assigned to Milestone
Snapcraft
New
Undecided
Unassigned

Bug Description

I have to manually set PATH and PYTHONPATH to include $SNAP/bin/ and $SNAP/lib/python2.7/site-packages when creating a snap with classic confinement. Using 'environment:' works fine to set these, but it seems like I shouldn't have to take this extra step.

environment:
  PATH: $PATH:$SNAP/bin/
  PYTHONPATH: $PYTHONPATH:$SNAP/lib/python2.7/site-packages

Note: This is when using the python plugin, so perhaps it's limited to that.

Tags: openstack
summary: - PATH/PYTHONPATH incomplete in classic confinement
+ classic confinement requires manually setting PATH and PYTHONPATH
description: updated
description: updated
Leo Arias (elopio)
tags: added: openstack
summary: - classic confinement requires manually setting PATH and PYTHONPATH
+ opclassic confinement requires manually setting PATH and PYTHONPATH
Revision history for this message
Barry Warsaw (barry) wrote : Re: opclassic confinement requires manually setting PATH and PYTHONPATH

Oh, this might be my problem with switching ubuntu-image to classic confinement. It's a Python 3 application, but suffers what looks like to be exactly this problem (my post to the snapcraft list is probably being held for moderator approval).

I'll test this workaround.

Leo Arias (elopio)
summary: - opclassic confinement requires manually setting PATH and PYTHONPATH
+ classic confinement requires manually setting PATH and PYTHONPATH
Revision history for this message
Corey Bryant (corey.bryant) wrote :

After discussing with snappy team, this is working as designed.

Note: I just tested this with snapcraft 2.22 (due to bug#1670852), and didn't need to set PYTHONPATH. It's possible that PYTHONPATH was required in the prior version of snapcraft that I had used when I initially reported this bug, but I failed to note what version that was.

So after looking at this again it looks like I only need:

environment:
  PATH: $PATH:$SNAP/bin/

and that is because we have a snap command in our snapcraft.yaml (see below) that uses a 'python-packages' dependency from /snap/keystone/current/bin/snap-openstack.

Snippet from snapcraft.yaml:

...
apps:
  api:
    command: snap-openstack keystone-api
    daemon: simple
  manage:
    command: snap-openstack keystone-manage

parts:
  keystone:
    plugin: python
    python-version: python2
    source: http://tarballs.openstack.org/keystone/keystone-master.tar.gz
    python-packages:
      - pymysql
      - uwsgi
      - git+https://github.com/openstack/snap.openstack#egg=snap.openstack
...

Changed in snappy:
status: New → Invalid
Revision history for this message
Barry Warsaw (barry) wrote :

Thanks for the information, however I'm reopening this because with 2.27.1 on Zesty, while snapping up ubuntu-image in classic confinement, I still had to add PYTHONPATH, and I had to make sure that $SNAP/bin comes before $PATH in the $PATH environment. u-i is a Python 3 application, so that's another difference from what you report.

This isn't the only problem I'm having with Python 3 and classic confinement, but I'll follow up on the mailing list with more details after trying some things out.

Changed in snappy:
status: Invalid → New
no longer affects: snappy
Revision history for this message
abdullahc (sneetsher) wrote :

I an facing same issue with `strict` confinement. Ubuntu 16.04 snapcraft 2.28. My current snapcraft.yaml file:

name: alfanous
version: "0.7.29"
summary: Alfanous
description: GNU hello prints a friendly greeting.
  This is part of the snapcraft tour at http://snapcraft.io/create/
confinement: strict

apps:
  alfanous-gui:
    command: usr/bin/alfanous-desktop
    environment:
      PATH: $SNAP/usr/bin:$SNAP/bin/:$PATH
      PYTHONPATH: $SNAP/usr/lib/python2.7/site-packages:$SNAP/usr/lib/python2.7/dist-packages:$PYTHONPATH
    #desktop: usr/share/applications/my-app.desktop
  alfanous-cli:
    command: usr/bin/alfanous-console
    environment:
      PATH: $SNAP/usr/bin:$SNAP/bin/:$PATH
      PYTHONPATH: $SNAP/usr/lib/python2.7/site-packages:$SNAP/usr/lib/python2.7/dist-packages:$PYTHONPATH
parts:
  alfanous-git:
    build-packages:
      #- python
      - sqlite3
      - pyside-tools
      - qt4-linguist-tools
      - python-babel
      - qt4-qmake
      - python-setuptools
      #- python-pyparsing
      #- perl
    #plugin: make
    plugin: python
    python-version: python2
    #source: https://github.com/Alfanous-team/alfanous/archive/0.7.8.tar.gz
    source: https://github.com/Alfanous-team/alfanous.git
    source-type: git
    source-depth: 1
    #source-tag: 0.7.8
    build: |
      make build
    install: |
      #make install_api
      make install_api DESTDIR=$SNAPCRAFT_PART_INSTALL
      make install_desktop DESTDIR=$SNAPCRAFT_PART_INSTALL
    stage-packages:
      - python-pyparsing
      - python-pyside
      #- epydoc
      #- sphinx
      - python-babel
      - python-setuptools
    #python-packages:
    # - pyparsing
    # - pyside
    # - babel

Now, i get additional dir in the path: '/home/sneetsher/Desktop/sandbox/alfanous-snap'

Full sys.path:

['/snap/alfanous/x7/usr/bin',
 '/snap/alfanous/x7/usr/lib/python2.7/site-packages',
 '/snap/alfanous/x7/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/dist-packages',
 '/home/sneetsher/Desktop/sandbox/alfanous-snap',
 '/snap/alfanous/x7/usr/lib/python2.7',
 '/snap/alfanous/x7/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/snap/alfanous/x7/usr/lib/python2.7/lib-tk',
 '/snap/alfanous/x7/usr/lib/python2.7/lib-old',
 '/snap/alfanous/x7/usr/lib/python2.7/lib-dynload']

When I run my app, I get this error message:

  File "/snap/alfanous/x7/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1972, in find_on_path
    for entry in os.listdir(path_item):
OSError: [Errno 13] Permission denied: '/home/sneetsher/Desktop/sandbox/alfanous-snap'

information type: Public → Public Security
Revision history for this message
Jaime Lomeli Rodriguez (jimmylomro) wrote :

This is also affecting me still in snapcraft 3.7:
When snap is run in classic mode root is the same as the host system so paths need to be specified in the environment. This will also affect dynamic link library search (I've seen this happen in a different project), at compile time the path for the library is set relative to the prime directory and, as root is not the prime directory in classic mode, search fails.

confinement: classic
apps:
  netman:
    environment:
      PATH: ${SNAP}/usr/bin:${PATH}
      PYTHONPATH: ${SNAP}/usr/lib/python3.6
    command: python3 netman/index.py

To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.