Stage package not found: scp

I’m working on a snap that uses the python plugin where the python script makes subprocess calls to ssh and scp. The snapcraft.yaml looks something like:

base: core22
confinement: strict

environment:
  PATH: $SNAP/bin:$SNAP/usr/bin:$PATH
plugs:
  shared-memory:
    private: true

apps:
  func:
    command: bin/func
    plugs: [home, network, shared-memory]

parts:
  mysnap:
    plugin: python
    stage-packages:
    - git
    - ping
    - ssh
    - scp
    source: ...
    source-branch: ...
    source-type: git

Now, the snap staging fails with:

Stage package not found in part '<mysnap>': scp.

If I remove scp from the stage-packages, my script fails with:

2023-01-10 18:36:24 [INFO]   File "/usr/lib/python3.10/subprocess.py", line 969, in __init__
2023-01-10 18:36:24 [INFO]     self._execute_child(args, executable, preexec_fn, close_fds,
2023-01-10 18:36:24 [INFO]   File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child
2023-01-10 18:36:24 [INFO]     raise child_exception_type(errno_num, err_msg, err_filename)
2023-01-10 18:36:24 [INFO] PermissionError: [Errno 13] Permission denied: 'scp'

The weird thing is that snapcraft does not complain about git, ping, or ssh, even though they are all installed in the same location as scp. If I debug the snap I can access scp, which means that it is installed in the snap.

Does anyone have an idea how to fix this?

I collected a more detailed output of snapcraft:

2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.931 Stage package not found in part 'mysnap': scp.
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940 Traceback (most recent call last):
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 860, in _fetch_stage_packages
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940     fetched_packages = packages.Repository.fetch_stage_packages(
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/packages/deb.py", line 587, in fetch_stage_packages
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940     return cls._fetch_stage_debs(
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/packages/deb.py", line 261, in wrapped
2023-01-10 19:07:43.565 :: 2023-01-10 19:07:42.940     return method(*args, **kwargs)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/packages/deb.py", line 626, in _fetch_stage_debs
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940     apt_cache.mark_packages(set(package_names))
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/packages/apt_cache.py", line 302, in mark_packages
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940     raise errors.PackageNotFound(name_arch)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940 craft_parts.packages.errors.PackageNotFound: Package not found: scp.
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940 During handling of the above exception, another exception occurred:
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940 Traceback (most recent call last):
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940   File "/snap/snapcraft/8619/lib/python3.8/site-packages/snapcraft/parts/parts.py", line 169, in run
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.940     aex.execute(action, stdout=stream, stderr=stream)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 301, in execute
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     self._executor.execute(actions, stdout=stdout, stderr=stderr)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 126, in execute
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     self._run_action(act, stdout=stdout, stderr=stderr)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 189, in _run_action
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     handler.run_action(action, stdout=stdout, stderr=stderr)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 161, in run_action
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     state = handler(step_info, stdout=stdout, stderr=stderr)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 182, in _run_pull
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     fetched_packages = self._fetch_stage_packages(step_info=step_info)
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 868, in _fetch_stage_packages
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     raise errors.StagePackageNotFound(
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941 craft_parts.errors.StagePackageNotFound: Stage package not found in part 'mysnap': scp.
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941 The above exception was the direct cause of the following exception:
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941 Traceback (most recent call last):
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 284, in _run_command
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     _run_lifecycle_and_pack(
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 327, in _run_lifecycle_and_pack
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     lifecycle.run(
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941   File "/snap/snapcraft/8619/lib/python3.8/site-packages/snapcraft/parts/parts.py", line 184, in run
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941     raise errors.PartsLifecycleError(str(err)) from err
2023-01-10 19:07:43.566 :: 2023-01-10 19:07:42.941 snapcraft.errors.PartsLifecycleError: Stage package not found in part 'mysnap': scp.
2023-01-10 19:07:45.598 Failed to execute pack in instance.

Note that “scp” is not a package name, the tool is in the “openssh-client” package which is staged as a dependency of “ssh”.