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

seedwriter: check if the optionSnap channel is same as model assert #14071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AristoChen
Copy link
Contributor

If we define presence: optional for an app snap in model assertion, and the default channel is 24/stable for example, then when we pass --snap=SNAP=24/stable to snap prepare-image with a model assertion that has model grade higher than dangerous, I will get an error error: cannot override channels, add devmode snaps, local snaps, or extra snaps with a model of grade higher than dangerous

However, I am expecting that snapd should check whether the channel for option snap is same as the channel defined in model assertion, maybe snapd should only return error if channel is not the same and the model grade is higher than dangerous

@AristoChen AristoChen force-pushed the check_option_snap_channel_with_model_assertion branch from cd8b4f3 to c1cad8d Compare June 12, 2024 09:18
@bboozzoo bboozzoo self-requested a review June 17, 2024 08:56
@@ -427,9 +427,23 @@ func (w *Writer) SetOptionsSnaps(optSnaps []*OptionsSnap) error {
if err != nil {
return fmt.Errorf("cannot use option channel for snap %q: %v", whichSnap, err)
}
if err := w.policy.checkSnapChannel(ch, whichSnap); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIU the original check is intentional and if you are using a mode with grade > dangerous, the channel is already specified in the model itself, thus it is a mistake to attempt to pass one in the command line.

Note that it is enough to pass the snap name as --snap <name> to include an optional snap. During seeding the snap will be set up to track the right channel

@bboozzoo bboozzoo requested a review from pedronis June 28, 2024 11:31
@pedronis pedronis self-assigned this Jun 28, 2024
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.

The current behavior is mostly so that the check is very simple and consistent, and there is no giving the impression that one can specify a different channel if grade != dangerous. What's the use case for passing in a channel anyway? As @bboozzoo explained --snap <name> is enough to trigger inclusion of the optional snap.

If we define `presence: optional` for an app snap in the model assertion, and the
default channel is `24/stable` for example, then when we pass `--snap=SNAP=24/stable`
to `snap prepare-image` with a model assertion that has model grade higher than
`dangerous`, I will get an error `error: cannot override channels, add devmode snaps,
local snaps, or extra snaps with a model of grade higher than dangerous`

However, I am expecting that snapd should check whether the channel for option snap
is same as the channel defined in model assertion, maybe snapd should only return
error if channel is not the same and the model grade is higher than dangerous

Signed-off-by: Aristo Chen <[email protected]>
@AristoChen AristoChen force-pushed the check_option_snap_channel_with_model_assertion branch from c1cad8d to 633b7a2 Compare July 3, 2024 09:51
@AristoChen
Copy link
Contributor Author

Thanks for the explanation!

Previously I wasn't familiar with the presence: optional, so I tried --snap=SNAP_NAME=CHANNEL to see if it the snap can be included in the image, but the error message(error: cannot override channels, add devmode snaps, local snaps, or extra snaps with a model of grade higher than dangerous) is confusing because I am not overriding the channels.

IMO, maybe snapd should accept both --snap=SNAP_NAME=CHANNEL and --snap SNAP_NAME if presence is set to optional, or at least snapd should print a more meaningful message to let user know --snap SNAP_NAME should be used instead of --snap=SNAP_NAME=CHANNEL

I just realized that my original patch will affect all scenarios even if presence is not set to optional, so I just force pushed a new commit to make it more restrict and only works for presence: optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants