Problem running example of locationd


#1

Hey everyone,

I am relatively new to snapcraft and I am trying to build the locationd example application provided here:
https://docs.ubuntu.com/core/en/stacks/location/location-service/docs/obtain-location

I first tried a simple snapcraft.yml with no plugs defined and had the following error:

ERROR:dbus.proxies:Introspect error on :1.132:/com/ubuntu/location/Service: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.168" (uid=1000 pid=2861 comm="/snap/gpssensorlog/x10/usr/bin/python3 /snap/gpsse") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.132" (uid=0 pid=26004 comm="/snap/locationd/163/bin/locationd run --bus=system")
Traceback (most recent call last):
  File "/snap/gpssensorlog/x10/bin/publish_gps.py", line 22, in <module>
    session_path = service.CreateSessionForCriteria(requirements)
  File "/snap/gpssensorlog/x10/usr/lib/python3/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/snap/gpssensorlog/x10/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/snap/gpssensorlog/x10/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.168" (uid=1000 pid=2861 comm="/snap/gpssensorlog/x10/usr/bin/python3 /snap/gpsse") interface="com.ubuntu.location.Service" member="CreateSessionForCriteria" error name="(unset)" requested_reply="0" destination=":1.132" (uid=0 pid=26004 comm="/snap/locationd/163/bin/locationd run --bus=system")

I then added the following plugs:
plugs:
location-observe:
interface: location-observe
location-control:
interface: location-control

So my snapcraft.yml now looks like this:

name: gpssensorlog # you probably want to 'snapcraft register <name>'
version: '1.0' # just for humans, typically '1.2+git' or '1.3.2'
summary: Logs the gps sensor values to a file
description: |
  This program captures the gps data and logs it to a file that can be shipped to the backend.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
    publish:
        command: bin/publish_gps.py
        plugs: ["location-observe", "location-control"]

plugs:
  location-observe:  # name that is used with 'snap connect' on plugs side
    interface: location-observe
  location-control:  # name that is used with 'snap connect' on plugs side
    interface: location-control

parts:
    files:
        plugin: python
        python-version: python3
        source: .
        stage-packages:
        - python3-dbus

I then connected the 2 interfaces:

snap connect gpssensorlog:location-observe locationd:service-observe snap connect gpssensorlog:location-control locationd:service-control

Resulting in one less error and one other error:

ERROR:dbus.proxies:Introspect error on :1.132:/com/ubuntu/location/Service: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.175" (uid=1000 pid=3447 comm="/snap/gpssensorlog/x11/usr/bin/python3 /snap/gpsse") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.132" (uid=0 pid=26004 comm="/snap/locationd/163/bin/locationd run --bus=system")
Traceback (most recent call last):
  File "/snap/gpssensorlog/x11/bin/publish_gps.py", line 22, in <module>
    session_path = service.CreateSessionForCriteria(requirements)
  File "/snap/gpssensorlog/x11/usr/lib/python3/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/snap/gpssensorlog/x11/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/snap/gpssensorlog/x11/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.InvalidArgs: Type of message, '(a{sb})', does not match expected type '(a{sv})'

I have no clue how to proceed with this maybe someone can help me out?

Kind Regards,
Stijn De Haes


#2

Hey,

let me look into this, will do some tests and get back to you.

Best,
K


#3

Sorry it took a while, meanwhile I had a day off.

What you are experiencing is an AppArmor denial on calling the Introspect method on org.freedesktop.DBus.Introspectable interface.

I have checked the location_{observe, control} interface definitions and they both allow for such calls.

Could you share how do you run your program?

Moreover do the steps described https://docs.snapcraft.io/build-snaps/debugging in the “Debugging confined apps section” and let’s take it from there.

Cheers.


#4

I believe you’ve connected these incorrectly. I think they should be connected to core, though I may be wrong, which happens automatically when you don’t specify a target slot:

snap connect gpssensorlog:location-observe
snap connect gpssensorlog:location-control

You also do not need to define the plugs in your yaml as they are provided by the system, so you are possibly masking the default implementations. Remove the following lines:

plugs:
  location-observe:  # name that is used with 'snap connect' on plugs side
    interface: location-observe
  location-control:  # name that is used with 'snap connect' on plugs side
    interface: location-control

#5

I ran into the same issue when trying to implement the example from https://docs.ubuntu.com/core/en/stacks/location/location-service/docs/obtain-location

I have defined the plugs

plugs: [ location-observe ]

And then try the prime

snap try prime --jailmode
snap connect location-dbus:location-observe locationd:service-observe

The following error:

ERROR:dbus.proxies:Introspect error on :1.184:/com/ubuntu/location/Service: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.238" (uid=0 pid=18915 comm="python3 -m location_dbus.location " label="snap.location-dbus.location (complain)") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.184" (uid=0 pid=23503 comm="/snap/locationd/163/bin/locationd run --bus=system" label="snap.locationd.run (enforce)")
Traceback (most recent call last):
  File "/snap/location-dbus/x12/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/snap/location-dbus/x12/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/shaned24/code/location_dbus/location_dbus/location.py", line 17, in <module>
    session_path = service.CreateSessionForCriteria(requirements)
  File "/snap/location-dbus/x12/usr/lib/python3/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/snap/location-dbus/x12/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/snap/location-dbus/x12/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.InvalidArgs: Type of message, '(a{sb})', does not match expected type '(a{sv})'

Further information:

Unfortunately there is no core interface slot called “location-observe” I can only connect my location-observe plug to locationd:service-observe

Debugging with snappy debug shows:

= AppArmor =
Time: Dec 11 01:58:15
Log: apparmor="DENIED" operation="dbus_method_call"  bus="system" path="/com/ubuntu/location/Service" interface="org.freedesktop.DBus.Introspectable" member="Introspect" name=":1.238" mask="receive" pid=23503 label="snap.locationd.run" peer_pid=18915 peer_label="snap.location-dbus.location"
DBus access
Suggestion:
* try adding 'location-observe' to 'plugs'

My interfaces:

snap interfaces | grep location
:network                                  locationd
:network-manager                           locationd
locationd:service-control                  location-dbus:location-control,locationd:client-control
locationd:service-observe                  location-dbus:location-observe,locationd:client-observe
-                                          locationd:ubx
-                                          locationd:wpa