snapcraft.yaml root level plugs doesn't propagate to hooks

Bug #1804006 reported by Ian Johnson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Incomplete
Undecided
Unassigned
snapd
Fix Released
High
Paweł Stołowski

Bug Description

If you have a snapcraft project setup with the snap/hooks folder with any kind of hook in it, and a root level plugs specification in your snapcraft.yaml like so:

```yaml
name: test-snapcraft-root-plugs
version: '0.1'
summary: test of snapcraft.yaml root level plugs and hooks
description: test root level plugs in snapcraft.yaml
grade: devel
confinement: devmode

plugs:
  home: {}
  removable-media: {}
  network: {}
  network-bind: {}

apps:
  test-snapcraft-root-plugs:
    command: echo "hello"
parts:
  my-part:
    plugin: nil
```

the generated snap.yaml has the same root level plugs spec, but nothing about the hook:

```yaml
name: test-snapcraft-root-plugs
version: '0.1'
summary: test of snapcraft.yaml root level plugs and hooks
description: test root level plugs in snapcraft.yaml
architectures:
- amd64
confinement: devmode
grade: devel
plugs:
  home: {}
  network: {}
  network-bind: {}
  removable-media: {}
apps:
  test-snapcraft-root-plugs:
    command: command-test-snapcraft-root-plugs.wrapper
```

The snap.yaml should also propagate to the hooks spec in the snap.yaml, specifying something like this:

```yaml
hooks:
  configure:
    plugs:
    - home
    - network
    - network-bind
    - removable-media
```

This could also be considered a snapd bug where the root level plugs in the snap.yaml also by default cover the hooks too.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

I think there is also a snapd bug here:

- make a snap that has implicitly defined hook (just add a hook to meta/hooks)
- define a top-level plug or slot
- load the info and see what you get:

You will get the hook (yay), you will get the slot (yay) but the slot will not be present on the hook. We don't attach interfaces to implicitly defined hooks.

Zygmunt Krynicki (zyga)
Changed in snapd:
importance: Undecided → High
Changed in snapd:
assignee: nobody → Paweł Stołowski (stolowski)
status: New → In Progress
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On snapcraft's side, don't your hooks in snap/hooks make it to prime/meta/hooks?

With regards to
hooks:
  configure: {}
I do not think this is part of the snap.yaml spec, where did you pick this up from?

Changed in snapcraft:
status: New → Incomplete
Revision history for this message
Ian Johnson (anonymouse67) wrote :

Yes the hooks themselves are installed into the right place in the snap, but the associated confinement, i.e. AppArmor profiles, don't include the policies listed in the root level plugs like the apps do. This is a problem if you need your configure hook to access the network, or home folder, etc. You can fix it by manually also declaring all the plugs in the hooks section in the snapcraft.yaml, but I'm saying that if you use the root level plugs (and hence all apps), you shouldn't have to also declare it for all the hooks you have in the snap.

Re the yaml snippet in snap.yaml, that's generated when you specify it in the root level snapcraft.yaml like so:

```yaml
name: test-snapcraft-root-plugs
version: '0.1'
summary: test of snapcraft.yaml root level plugs and hooks
description: test root level plugs in snapcraft.yaml
grade: devel
confinement: devmode

plugs:
  home: {}
  removable-media: {}
  network: {}
  network-bind: {}

apps:
  test-snapcraft-root-plugs:
    command: echo "hello"

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: nil

hooks:
  configure:
    plugs: [home]
```

which generates the following snap.yaml:

```yaml
name: test-snapcraft-root-plugs
version: '0.1'
summary: test of snapcraft.yaml root level plugs and hooks
description: test root level plugs in snapcraft.yaml
architectures:
- amd64
confinement: devmode
grade: devel
plugs:
  home: {}
  network: {}
  network-bind: {}
  removable-media: {}
hooks:
  configure:
    plugs:
    - home
apps:
  test-snapcraft-root-plugs:
    command: command-test-snapcraft-root-plugs.wrapper

```

Revision history for this message
Paweł Stołowski (stolowski) wrote :
Revision history for this message
Ian Johnson (anonymouse67) wrote :

Is this bug now fixed? It seems that now, hooks will implicitly pick up slots/plugs declared in the root snap.yaml rather than have the relevant interfaces specified explicitly in hooks in the snap.yaml.

Revision history for this message
Samuele Pedroni (pedronis) wrote :

Bug should be now fixed in snapd 2.37.

Changed in snapd:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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