snap: auto-import assertions from block devices #2044

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
3 participants
Collaborator

mvo5 commented Sep 30, 2016

This branch adds a new snap auto-import command that is run on boot and also on each adding of a block device.

@mvo5 mvo5 closed this Sep 30, 2016

@mvo5 mvo5 reopened this Sep 30, 2016

cmd/snap/cmd_auto_import.go
+ "github.com/snapcore/snapd/osutil"
+)
+
+const autoImportsName = "auto-imports.asserts"
@niemeyer

niemeyer Sep 30, 2016

Contributor

*.assert, per our agreement.

@mvo5

mvo5 Oct 2, 2016

Collaborator

Thanks, fixed.

cmd/snap/cmd_auto_import.go
+ }
+ mountPoint := l[4]
+ mountSrc := l[9]
+ // FIXME: premature optimization?
@niemeyer

niemeyer Sep 30, 2016

Contributor

No, these look fine to me.

cmd/snap/cmd_auto_import.go
+
+type cmdAutoImport struct{}
+
+var shortAutoImportHelp = i18n.G("Auto import assertions")
@niemeyer

niemeyer Sep 30, 2016

Contributor

"Imports assertions from mounted devices"

@mvo5

mvo5 Oct 2, 2016

Collaborator

Thanks, fixed.

cmd/snap/cmd_auto_import.go
+
+var shortAutoImportHelp = i18n.G("Auto import assertions")
+
+var longAutoImportHelp = i18n.G("This command imports all assertions from block devices that are called 'auto-imports.assertions'")
@niemeyer

niemeyer Sep 30, 2016

Contributor

"The auto-import command imports assertions found in the auto-import.assert file in mounted devices."

@mvo5

mvo5 Oct 2, 2016

Collaborator

Thanks, fixed.

+ return ErrExtraArgs
+ }
+
+ // SUCKS: racy because the mount is not done when the script is
@niemeyer

niemeyer Sep 30, 2016

Contributor

Can we do something a bit nicer here, such as trying to stat things more than once depending on the resulting error, to account for such delays?

@mvo5

mvo5 Oct 2, 2016

Collaborator

This gets fixed in #2047 which builds on top of this, the race goes away once we start mounting stuff ourself instread of waiting for it.

@mvo5 mvo5 closed this Oct 3, 2016

Contributor

mwhudson commented Oct 3, 2016

I've just tested this (by merging this PR into current master and installing that into my ubuntu-core branch) and it doesn't seem to pick up block devices that are present at boot. I did this to make a disk image to attach in qemu:

$ genisoimage -volid cidata -joliet -rock -o assertions.disk auto-import.assert

Then if I invoke kvm like so:

$ kvm -m 512 -redir :8022::22 -serial stdio my_output.img -drive file=assertions.disk

and go through console-conf, ssh in and run snap known system-user there is no output.

Running it by hand works:

$ sudo snap auto-import --mount /dev/sdb
2016/10/03 22:06:35.422477 cmd_auto_import.go:82: imported /tmp/snapd-auto-import-mount-951353834/auto-import.assert

And also if I boot the image without the disk attached and then use qemu monitor to attach the drive, the assertion is processed.

Looking into the logs, I find this:

Oct 03 22:03:26 localhost.localdomain /usr/bin/snap[865]: cmd_auto_import.go:111: error: cannot mount /dev/sdb: mount: mount point /tmp/snapd-auto-import-mount-113968483 does not exist

(and a host of amusing errors like this:

Oct 03 22:03:27 localhost.localdomain /usr/bin/snap[860]: cmd_auto_import.go:111: error: cannot mount /dev/ram13: mount: mount point /tmp/snapd-auto-import-mount-153607810 does not exist
Oct 03 22:03:27 localhost.localdomain /usr/bin/snap[933]: cmd_auto_import.go:111: error: cannot mount /dev/ram5: 
                                                          -----
                                                          mount: wrong fs type, bad option, bad superblock on /dev/ram5,
                                                                 missing codepage or helper program, or other error

                                                                 In some cases useful info is found in syslog - try
                                                                 dmesg | tail or so.
                                                          -----

but that's another sort of problem I guess)

So I guess something about the mount namespace is not set up quite appropriately when the snap.autoimport.service runs?

Contributor

mwhudson commented Oct 3, 2016

Ah I may have been testing the wrong version of the code (gh was doing a bad job of telling me which PRs were closed). It still fails with master though, like this this time:

Oct 03 22:25:52 localhost.localdomain /usr/bin/snap[679]: cmd_auto_import.go:80: error: cannot import /tmp/snapd-auto-import-mount-638764835/auto-import.assert: cannot assert: cannot communicate with server: Post http://localhost/v2/assertions: dial unix /run/snapd-snap.socket: connect: no such file or directory

which seems reasonably impossible, I'll file a bug rather than commenting on closed PRs I guess...

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