snapcraft icon indicating copy to clipboard operation
snapcraft copied to clipboard

Validity of `base` is not checked when using `--destructive-mode`

Open dilyn-corner opened this issue 1 year ago • 0 comments

Bug Description

When building a snap with snapcraft --destructive-mode (or setting the corresponding environment variable), the base of the snap is not checked.

The base is installed as a prerequisite (build-snap) on the host system; so long as the base is a valid target to snap install, no additional checks are run.

To Reproduce

mkdir test && cd test
snapcraft init
sed -i 's/base: core22/base: core24/' snap/snapcraft.yaml
snapcraft --destructive-mode

Environment

Any Ubuntu base, snapcraft 8.x.

snapcraft.yaml

name: my-snap-name # you probably want to 'snapcraft register <name>'
base: core24 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

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

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

Relevant log output

dilyn@Ares:~/test -> snapcraft --destructive-mode --verbosity=trace
Starting Snapcraft 8.0.2.post14+git89961cfc
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240205-180421.093035.log'
2024-02-05 18:04:21.093 Starting Snapcraft 8.0.2.post14+git89961cfc
2024-02-05 18:04:21.093 Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20240205-180421.093035.log'
2024-02-05 18:04:21.093 Raw pre-parsed sysargs: args={'help': False, 'verbose': False, 'quiet': False, 'verbosity': 'trace', 'version': False, 'trace': False} filtered=['--destructive-mode']
2024-02-05 18:04:21.094 Using default command: 'pack'
2024-02-05 18:04:21.094 General parsed sysargs: command='pack' args=['--destructive-mode']
2024-02-05 18:04:21.094 Command parsed sysargs: Namespace(destructive_mode=True, use_lxd=False, debug=False, enable_manifest=True, manifest_image_information=None, bind_ssh=False, build_for=None, http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-05 18:04:21.095 lifecycle command: 'pack', arguments: Namespace(destructive_mode=True, use_lxd=False, debug=False, enable_manifest=True, manifest_image_information=None, bind_ssh=False, build_for=None, http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-05 18:04:21.095 command: pack, arguments: Namespace(destructive_mode=True, use_lxd=False, debug=False, enable_manifest=True, manifest_image_information=None, bind_ssh=False, build_for=None, http_proxy=None, https_proxy=None, ua_token=None, enable_experimental_ua_services=False, enable_experimental_plugins=False, enable_experimental_extensions=False, enable_developer_debug=False, enable_experimental_target_arch=False, target_arch=None, provider=None, directory=None, output=None)
2024-02-05 18:04:21.104 Created build plan:
  build-on: amd64 build-for: amd64
2024-02-05 18:04:21.105 CPU count (from process affinity): 24
2024-02-05 18:04:21.105 Invalid SNAPCRAFT_MAX_PARALLEL_BUILD_COUNT ''
2024-02-05 18:04:21.105 Running on amd64 for amd64
2024-02-05 18:04:21.106 Initializing parts lifecycle
2024-02-05 18:04:21.106 is_snap: True, SNAP_NAME set to snapcraft
2024-02-05 18:04:21.107 process my-part:Step.PULL
2024-02-05 18:04:21.107 add action my-part:Step.PULL(ActionType.RUN)
2024-02-05 18:04:21.107 process my-part:Step.BUILD
2024-02-05 18:04:21.107 add action my-part:Step.BUILD(ActionType.RUN)
2024-02-05 18:04:21.107 process my-part:Step.STAGE
2024-02-05 18:04:21.107 add action my-part:Step.STAGE(ActionType.RUN)
2024-02-05 18:04:21.108 process my-part:Step.PRIME
2024-02-05 18:04:21.108 add action my-part:Step.PRIME(ActionType.RUN)
2024-02-05 18:04:21.108 Installing build-packages
2024-02-05 18:04:21.108 Installing build-snaps
2024-02-05 18:04:21.528 Installing snap: core24
2024-02-05 18:04:24.157 verify plugin environment for part 'my-part'
2024-02-05 18:04:24.158 Pulling my-part
2024-02-05 18:04:24.158 execute action my-part:Action(part_name='my-part', step=Step.PULL, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-05 18:04:24.166 Building my-part
2024-02-05 18:04:24.166 execute action my-part:Action(part_name='my-part', step=Step.BUILD, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-05 18:04:24.166 load state file: /home/dilyn/test/parts/my-part/state/pull
2024-02-05 18:04:24.203 remove directory /home/dilyn/test/parts/my-part/build
2024-02-05 18:04:24.205 Executing PosixPath('/home/dilyn/test/parts/my-part/run/build.sh')
2024-02-05 18:04:27.739 Staging my-part
2024-02-05 18:04:27.740 execute action my-part:Action(part_name='my-part', step=Step.STAGE, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-05 18:04:27.759 Priming my-part
2024-02-05 18:04:27.759 execute action my-part:Action(part_name='my-part', step=Step.PRIME, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-02-05 18:04:27.779 patch_elf: not enabled for part 'my-part'
2024-02-05 18:04:27.780 Extracting and updating metadata...
2024-02-05 18:04:27.780 Copying snap assets...
2024-02-05 18:04:27.780 Generating snap metadata...
2024-02-05 18:04:27.782 Generated snap metadata
2024-02-05 18:04:27.782 Generating snap manifest...
2024-02-05 18:04:27.782 load state file: /home/dilyn/test/parts/my-part/state/pull
2024-02-05 18:04:27.786 load state file: /home/dilyn/test/parts/my-part/state/prime
2024-02-05 18:04:27.790 Generated snap manifest
2024-02-05 18:04:27.800 Reading snap metadata...
2024-02-05 18:04:27.801 Running linters...
2024-02-05 18:04:27.801 Running linter: classic
2024-02-05 18:04:27.801 Running linter: library
2024-02-05 18:04:27.806 pack_snap: output=None, compression='xz'
2024-02-05 18:04:27.807 pack_snap: check skeleton
2024-02-05 18:04:27.824 Creating snap package...
2024-02-05 18:04:27.824 Pack command: ['snap', 'pack', '--filename', 'my-snap-name_0.1_amd64.snap', '--compression', 'xz', PosixPath('/home/dilyn/test/prime'), PosixPath('/home/dilyn/test')]
2024-02-05 18:04:27.850 Created snap package my-snap-name_0.1_amd64.snap

Additional context

In the specific case of using a dev-level base (as core24 is), this behavior should at least be locked behind grade: devel so as to avoid allowing publishing potentially broken snaps to stable or candidate tracks in the store. It may also be preferable to disallow using base: coreXX under any circumstances when that base has yet to be officially released (that is to say, while its usage when not using --destructive-mode is still guarded by a build-base check).

dilyn-corner avatar Feb 05 '24 23:02 dilyn-corner