overlord/ifacestate: remove connection state with discard-conns task, on the removal of last snap #958

Merged
merged 24 commits into from Apr 15, 2016

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Apr 14, 2016

This branch changes profile setup/remove logic so that:

  • setup-profiles sets up profiles (and handles autoconnect as before)
  • remove-profiles just removes profiles without touching persistent connections
  • dicard-conns just discards persistent connections (and supports undo)

The snap manager now injects discard-conns when removing the last snap in the sequence (last as in the only one)

zyga added some commits Apr 14, 2016

overlord/ifacestate: fix addSetupSnapSecurityChange to use snapName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: remove connection state on remove-snap-security
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate/ifacemgr_test.go
@@ -336,6 +349,44 @@ func (s *interfaceManagerSuite) TestDoSetupSnapSecuirtyKeepsExistingConnectionSt
})
}
+func (s *interfaceManagerSuite) TestDoRemoveSnapSecurityRemovesConnectionsFromStateWhenInvokedOnPlugSide(c *C) {
@niemeyer

niemeyer Apr 14, 2016

Contributor

Okay, that is getting off limits. :) This is a function name, not documentation. Let's please come up with a name that is at most half the length of this one.

@niemeyer

niemeyer Apr 14, 2016

Contributor

Feel free to add actual docs, though. (// blah blah blah).

@zyga

zyga Apr 14, 2016

Contributor

Sorry, that's my python ancestry showing. Abbreviated now.

overlord/ifacestate/ifacemgr_test.go
+ s.testDoRemoveSnapSecurityRemovesConnectionsFromStateWhenInvokedOn(c, "consumer")
+}
+
+func (s *interfaceManagerSuite) TestDoRemoveSnapSecurityRemovesConnectionsFromStateWhenInvokedOnSlotSide(c *C) {
@niemeyer

niemeyer Apr 14, 2016

Contributor

Same.

@zyga

zyga Apr 14, 2016

Contributor

Abbreviated

overlord/ifacestate/ifacemgr_test.go
+ s.testDoRemoveSnapSecurityRemovesConnectionsFromStateWhenInvokedOn(c, "producer")
+}
+
+func (s *interfaceManagerSuite) testDoRemoveSnapSecurityRemovesConnectionsFromStateWhenInvokedOn(c *C, snapName string) {
@niemeyer

niemeyer Apr 14, 2016

Contributor

Same.

@zyga

zyga Apr 14, 2016

Contributor

Abbreviated

overlord/ifacestate/ifacemgr.go
+ conns, err := getConns(task.State())
@niemeyer

niemeyer Apr 14, 2016

Contributor

We cannot do this here. We need to be able to distinguish between removing the profiles, and discarding the connections. Otherwise we'll end up killing user data when deactivating a snap, or removing an old revision.

I suggest clarifying the security tasks we have, with the following set:

  • setup-profiles
  • remove-profiles
  • discard-conns
@niemeyer

niemeyer Apr 14, 2016

Contributor

Then, on snapstate.Remove, distinguish between last snap being removed and obsolete snap being removed, and conditionally inject discard-conns after remove-profiles.

@zyga

zyga Apr 14, 2016

Contributor

This makes a lot of sense. Earlier when I was working on setup-snap-security I realized that it would be much easier if there were some more fine-grained tasks (e.g. setup that could be reused by connect) and it looks like the same is true for remove-snap-security.

So let's review how each of those would be used:

setup-profiles: on snap install, snap refresh and maybe snap activate
remove-profiles: on snap deactivate
discard-conns: on snap remove

@niemeyer @mvo5 ^^ does that make sense?

@niemeyer

niemeyer Apr 14, 2016

Contributor

Almost.. snap remove may be used to remove one of several snaps. We cannot discard connections if we still have a snap with the same name installed (and perhaps even active!).

@zyga

zyga Apr 14, 2016

Contributor

I see now how there can be multiple snaps with the same name but I'm not sure this correctly translates that to security. Security identifiers don't contain snap revision so removing security for a given snap (at any revision) will impact the security for other snaps with the same name (but with different revision)

I'm not sure how security-affecting tasks and snap-affecting tasks are related wrt multiple revisions now.

@zyga

zyga Apr 14, 2016

Contributor

All sorted out now. I understand what has to happen

zyga added some commits Apr 14, 2016

overlord/ifacestate: abbreviate test names
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: add doDiscardConns
This patch adds a new task, dicard-conns, which removes persistent
connection information iff a snap is no longer present in the state.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: don't crash if connection cannot be reloaded
This patch changes the interface manager to gracefully ignore errors
when trying to reload connections. This can fail if the snap in question
does not get mounted (for any reason) and the resulting system will
appear not to have that snap installed.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: test both slot and plug side of discard-conns
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: rename tasks to setup/remove-profiles
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: don't change connection state in doRemoveProfiles
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: use setupSnapSecurity in doRemoveProfiles
This patch uses setupSnapSecurity to apply appropriate changes to all
of the snaps affected by the remove-profiles task. This seems strange
at first but SetupSnapSecurity also removes security.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: make remove-profiles behave
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate/ifacemgr.go
- affectedSnaps = append(affectedSnaps, snapInfo)
+
+ if err == nil && len(snapState.Sequence) != 0 {
+ return fmt.Errorf("cannot discard connections of a snap %q while it is present", snapName)
@niemeyer

niemeyer Apr 14, 2016

Contributor

s/of a snap %q/for snap %q/

@zyga

zyga Apr 15, 2016

Contributor

Done

+ conns, err := getConns(st)
+ if err != nil {
+ return err
+ }
@niemeyer

niemeyer Apr 14, 2016

Contributor

// TODO Record removed connections in task state to recover it on undo.

@zyga

zyga Apr 14, 2016

Contributor

Oh, great idea. I was wondering how to make this robust and I forgot that there's a reason each task has a state! Will do.

@zyga

zyga Apr 15, 2016

Contributor

I've implemented a simple undo handler. I'm not sure if that's the right way so have look please.

Contributor

niemeyer commented Apr 14, 2016

Good direction. A couple of comments, and needs to update snapstate to match.

zyga added some commits Apr 15, 2016

overlord/ifacestate: record removed connections for undo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/state: fix typo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: add undo handler for discard-conns
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: tweak error message
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Collaborator

mvo5 commented Apr 15, 2016

retest this please

zyga added some commits Apr 15, 2016

overlord/snapstate: rename setup-snap-security to setup-profiles
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/snapstate: rename remove-snap-security to remove-profiles
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/snapstate: use fake handler for discard-conns during testing
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/snapstate: chain discard-conns when removing last revision o…
…f snap

This patch changes snap removal logic so that persistent connections are
discarded along with the last revision of the snap. If there is more than
one revision present then security profiles are removed but connections
in the state are persisted.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

@zyga zyga changed the title from overlord/ifacestate: remove connection state on remove-snap-security to overlord/ifacestate: remove connection state with discard-conns task, on the removal of last snap Apr 15, 2016

zyga added some commits Apr 15, 2016

overlord/snapstate: ensure that discard-conns is the last task
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
addNext(discardSnap)
+ if len(snapst.Sequence) == 1 {
@niemeyer

niemeyer Apr 15, 2016

Contributor

Please drop comment above about discard-snap being the last task.

@zyga

zyga Apr 15, 2016

Contributor

Done

overlord/snapstate/snapmgr_test.go
@@ -698,7 +698,9 @@ func (s *snapmgrTestSuite) TestRemoveIntegration(c *C) {
// verify snapSetup info
tasks := ts.Tasks()
- task := tasks[len(tasks)-1]
+ // XXX -2 because the last task is discard-conns and snap-setup is in the
+ // discard-snap, just before discard-conns.
@niemeyer

niemeyer Apr 15, 2016

Contributor

Let's please replace the comment by:

// snap-setup is in discard-snap above discard-conns.

@zyga

zyga Apr 15, 2016

Contributor

Done

zyga added some commits Apr 15, 2016

overlord/snapstate: tweak/remove comments
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
po: refresh translation templates
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

zyga commented Apr 15, 2016

@niemeyer This is now ready for final review and landing. Tested locally with cap-test from the store and a side-loaded version and various sequences of install/remove/refresh tasks.

@niemeyer niemeyer merged commit 15a017c into snapcore:master Apr 15, 2016

3 checks passed

Integration tests Success
Details
autopkgtest Success
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@zyga zyga deleted the zyga:overlord-remove-snap-security-removes-state branch Dec 12, 2016

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