Add support for running hooks. #64

Merged
merged 2 commits into from Jun 30, 2016

Conversation

Projects
None yet
3 participants
Member

kyrofa commented Jun 30, 2016

This involves a move away from "appname" to "security tag".

Add support for running hooks.
This involves a move away from "appname" to something more generic (I
selected "executable name" instead).

Signed-off-by: Kyle Fazzari <kyle@canonical.com>
src/sc-main.c
@@ -54,19 +54,19 @@ int sc_main(int argc, char **argv)
if (argc < NR_ARGS + 1)
die("Usage: %s <security-tag> <binary>", argv[0]);
- const char *appname = argv[1];
- debug("appname is %s", appname);
+ const char *executable_name = argv[1];
@zyga

zyga Jun 30, 2016

Collaborator

In reality this is secuirty_tag.

@zyga

zyga Jun 30, 2016

Collaborator

If you are changing this, can you just call it as such, and remove aa_profile entirely as it was always the same thing

@kyrofa

kyrofa Jun 30, 2016

Member

Yeah might as well.

+ // - <hookname must start with a lowercase letter, then may
+ // contain lowercase letters and '-'
+ const char *whitelist_re =
+ "^snap\\.[a-z](-?[a-z0-9])*\\.([a-zA-Z0-9](-?[a-zA-Z0-9])*|hook\\.[a-z](-?[a-z])*)$";
@zyga

zyga Jun 30, 2016

Collaborator

Can you perhaps link to the snapd code that does similar checks?

@kyrofa

kyrofa Jun 30, 2016

Member

It's here, are you saying you want that link in the code?

src/verify-executable-name-test.c
+
+static void test_verify_executable_name()
+{
+ // First, test the names we know are good
@zyga

zyga Jun 30, 2016

Collaborator

Nice, thank you!

src/verify-executable-name-test.c
+ g_assert_true(verify_executable_name("snap.f00.bar-baz1"));
+ g_assert_true(verify_executable_name("snap.foo.hook.bar"));
+ g_assert_true(verify_executable_name("snap.foo.hook.bar-baz"));
+
@zyga

zyga Jun 30, 2016

Collaborator

Can you add a canary test for "snap.name". At some point we may decide to abbreviate the security tag and this would be a nice test to catch that change.

- const char *whitelist_re = "^snap\\.[a-z][a-z0-9-]*\\.[a-zA-Z0-9-]+$";
+ // - <appname> may contain alphanumerics and '-'
+ // - <hookname must start with a lowercase letter, then may
+ // contain lowercase letters and '-'
@zyga

zyga Jun 30, 2016

Collaborator

can hook names contain digits?

@kyrofa

kyrofa Jun 30, 2016

Member

No, just lowercase letters and hyphens.

@zyga

zyga Jun 30, 2016

Collaborator

OK, thanks

regex_t re;
if (regcomp(&re, whitelist_re, REG_EXTENDED | REG_NOSUB) != 0)
die("can not compile regex %s", whitelist_re);
- int status = regexec(&re, appname, 0, NULL, 0);
@zyga

zyga Jun 30, 2016

Collaborator

Just thinking about something nasty being done. Can we require that total length of security_tag be smaller than some sane default. I don't want to let people explode the system by installing a snap with a long app name that is expensive to check.

If there is something in snapd, let's use that limit, if not then let's make up one now.

@jdstrand ^^ FYI

@kyrofa

kyrofa Jun 30, 2016

Member

I don't know of a limit imposed by snapd, so throw out a number! Though that may be something for another PR.

@jdstrand

jdstrand Jun 30, 2016

Contributor

There are practical limits to how long this can be and the review tools enforce this. The max length enforced by the store is '100' for the full security label ('snap.$snap.$app').

@kyrofa

kyrofa Jun 30, 2016

Member

@zyga do you want that in this PR, or should it be done separately?

@zyga

zyga Jun 30, 2016

Collaborator

This can go in as there wasn't any check around there before. I can take care of that.

Rename executable_name to security_tag.
Signed-off-by: Kyle Fazzari <kyle@canonical.com>
Collaborator

zyga commented Jun 30, 2016

+1, thanks for working on this

@zyga zyga merged commit 1557dfc into snapcore:master Jun 30, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@kyrofa kyrofa deleted the kyrofa:feature/support_hooks branch Jun 30, 2016

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