Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snap, snap/pack: disallow pack and install of snapd, base and os with specific configure hooks #13117

Conversation

ernestl
Copy link
Collaborator

@ernestl ernestl commented Aug 24, 2023

It is currently possible to pack and install snapd, base and core snaps with default-configure and configure hooks, but those hooks are ignored during installation and option setting. My proposal is to extend the snap validation check (covers packing and installation) to prevent these unintended snap/hook combinations and possible silent failure.

Spec:
Implements part of draft spec Prohibit user-defined configuration hooks for specific essential snaps

Approach:
Extend snap/validate.go hook check that was introduced in #13097 as follows:

  • Do not allow default-configure hook for snapd, base or os
  • Do not allow configure hook for snapd, base
  • Allow configure hook for os to prevent new errors for core or ubuntu-core with existing configure hook

Key covered paths: Snap Pack, Firstboot, Store Install, Sideload Install

JIRA: https://warthogs.atlassian.net/browse/SNAPDENG-7297
This PR builds on #13097

@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch 3 times, most recently from 203749a to b490ccc Compare August 25, 2023 15:31
@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch from b490ccc to c10b5b3 Compare January 22, 2025 15:39
Copy link

github-actions bot commented Jan 22, 2025

Thu Feb 20 07:47:21 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13412751831

Failures:

Executing:

  • google:ubuntu-20.04-64:tests/main/preseed-core20

@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch from c10b5b3 to b6a8698 Compare January 24, 2025 12:44
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@2cbce28). Learn more about missing BASE report.
Report is 245 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #13117   +/-   ##
=========================================
  Coverage          ?   77.86%           
=========================================
  Files             ?     1167           
  Lines             ?   156856           
  Branches          ?        0           
=========================================
  Hits              ?   122130           
  Misses            ?    27139           
  Partials          ?     7587           
Flag Coverage Δ
unittests 77.86% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ernestl ernestl closed this Jan 24, 2025
@ernestl ernestl reopened this Jan 24, 2025
@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch 2 times, most recently from 7990b70 to 6e7c4f6 Compare January 25, 2025 06:04
@ernestl ernestl changed the title snap/pack: disallow packing snapd, os and base snaps with default-/configure hooks snap/pack: disallow pack, install and sideload of snapd, os and base with default-/configure hooks Jan 25, 2025
@ernestl ernestl changed the title snap/pack: disallow pack, install and sideload of snapd, os and base with default-/configure hooks snap/pack: disallow pack and install of snapd, os and base with default-/configure hooks Jan 25, 2025
@ernestl ernestl changed the title snap/pack: disallow pack and install of snapd, os and base with default-/configure hooks snap/pack: disallow pack and install of snapd, base and core with default-/configure hooks Jan 25, 2025
@ernestl ernestl changed the title snap/pack: disallow pack and install of snapd, base and core with default-/configure hooks snap/pack: disallow pack and install of snapd, base and core with configure hooks Jan 25, 2025
@ernestl ernestl changed the title snap/pack: disallow pack and install of snapd, base and core with configure hooks snap/pack: disallow pack and install of snapd, base and os with configure hooks Jan 25, 2025
@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch 3 times, most recently from 4d8c591 to 4d38e1d Compare January 27, 2025 07:51
@ernestl ernestl added this to the 2.70 milestone Jan 27, 2025
@ernestl ernestl requested a review from pedronis January 27, 2025 09:18
@ernestl ernestl added the Needs Samuele review Needs a review from Samuele before it can land label Jan 27, 2025
@ernestl ernestl marked this pull request as ready for review January 27, 2025 09:57
@ernestl ernestl closed this Jan 27, 2025
@ernestl ernestl reopened this Jan 27, 2025
@ernestl ernestl force-pushed the SNAPDENG-7297_Prohibit_Configuration_Hooks_For_Core_Base_Snapd branch from 4d38e1d to 7a4f5ec Compare January 27, 2025 10:18
Copy link
Contributor

@miguelpires miguelpires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@ZeyadYasser ZeyadYasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments

@ernestl ernestl changed the title snap/pack: disallow pack and install of snapd, base and os with configure hooks snap, snap/pack: disallow pack and install of snapd and base with configure and os with default-configure hook Feb 5, 2025
@ernestl ernestl changed the title snap, snap/pack: disallow pack and install of snapd and base with configure and os with default-configure hook snap, snap/pack: disallow pack and install of snapd, base and os with specific configure hooks Feb 5, 2025
@ernestl ernestl added the Squash-merge Please squash this PR when merging. label Feb 5, 2025
@ernestl ernestl requested a review from pedronis February 5, 2025 11:31
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the changes, something seems a bit off with the error message building logic though, otoh made a different suggestion

snap/validate.go Outdated
}

if info.SnapType == TypeSnapd || info.SnapType == TypeBase || (info.SnapType == TypeOS && info.InstanceName() != "core") {
if info.SnapType == TypeSnapd || info.SnapType == TypeBase || info.SnapType == TypeOS {
var hookNames strings.Builder
if hasDefaultConfigureHook {
hookNames.WriteString(`"default-configure"`)
if hasConfigureHook {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now needs to become the same check as below, no? but then I'm unsure using a strings.Builder is the best approach, wouldn't a []string and using Join with " or " be simpler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, corrected and simplified this and corresponding test

@ernestl ernestl requested a review from pedronis February 13, 2025 20:46
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, @ernestl this has changed a bit since. maybe you can get one of the original reviewers to do a quick 2nd pass?

@ernestl ernestl requested a review from miguelpires February 17, 2025 10:45
Copy link
Contributor

@miguelpires miguelpires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some comments on testing

Comment on lines 208 to 212
configureHooks := []string{"configure"}
c.Assert(os.Mkdir(filepath.Join(sourceDir, "meta", "hooks"), 0755), IsNil)
for _, hook := range configureHooks {
c.Assert(os.WriteFile(filepath.Join(sourceDir, "meta", "hooks", hook), []byte("#!/bin/sh"), 0755), IsNil)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
configureHooks := []string{"configure"}
c.Assert(os.Mkdir(filepath.Join(sourceDir, "meta", "hooks"), 0755), IsNil)
for _, hook := range configureHooks {
c.Assert(os.WriteFile(filepath.Join(sourceDir, "meta", "hooks", hook), []byte("#!/bin/sh"), 0755), IsNil)
}
c.Assert(os.Mkdir(filepath.Join(sourceDir, "meta", "hooks"), 0755), IsNil)
c.Assert(os.WriteFile(filepath.Join(sourceDir, "meta", "hooks", "configure"), []byte("#!/bin/sh"), 0755), IsNil)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, improved

Copy link
Contributor

@miguelpires miguelpires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks for the clarification

@ernestl ernestl merged commit 699b1b4 into canonical:master Feb 20, 2025
63 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Samuele review Needs a review from Samuele before it can land Squash-merge Please squash this PR when merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants