Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

trust: add flag --skip-trusted #3812

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

indradhanush
Copy link

@indradhanush indradhanush commented Sep 23, 2017

Work based on #3756

@indradhanush
Copy link
Author

@lucab PTAL

@indradhanush
Copy link
Author

This is a work in progress.
I'm looking for some early feedback before writing a lot of code unnecessarily. Does this look like a step in the right direction? I'll proceed with writing tests if this looks good or make changes if suggested.

Copy link
Member

@alban alban left a comment

Choose a reason for hiding this comment

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

I suggest to remove the "Fixes #3756" in the commitmsg since this PR is not about making the output parsable.

@@ -110,6 +110,18 @@ func (m *Manager) AddKeys(pkls []string, prefix string, accept AcceptOption) err
return errwrap.Wrap(fmt.Errorf("error displaying the key %s", pkl), err)
}

if overwriteTrusted == false {
Copy link
Member

Choose a reason for hiding this comment

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

Usually we would write if !overwriteTrusted instead of == false.

}

if trusted == true {
log.Printf("Already trusted %q for prefix %q.", pkl, prefix)
Copy link
Member

Choose a reason for hiding this comment

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

missing \n?

rkt/trust.go Outdated
@@ -28,7 +28,7 @@ import (

var (
cmdTrust = &cobra.Command{
Use: "trust [--prefix=PREFIX] [--insecure-allow-http] [--skip-fingerprint-review] [--root] [PUBKEY ...]",
Use: "trust [--prefix=PREFIX] [--insecure-allow-http] [--skip-fingerprint-review] [--root] [PUBKEY ...] [--overwrite-trusted]",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the --overwrite-trusted=... be before the [PUBKEY...]?

I find boolean parameter defaulting to true confusing because just writing --overwrite-trusted would have no effect.

I am not sure how to make things clearer. I overheard other suggestions but they're kind of long:

  • --disable-overwrite-trusted
  • --prevent-trusted-from-being-overwritten

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. --disable-overwrite-trusted seems to do a better job of removing the confusion while also keeping the default to true false for backwards compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

On second thoughts how does --dont-overwrite-trusted sound for the name of the flag?

Copy link
Author

Choose a reason for hiding this comment

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

Another thought, how about --skip-trusted ? It's more concise and also is similar to the --skip-fingerprint-review.

Copy link
Member

Choose a reason for hiding this comment

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

Ack, I think --skip-trusted is a better choice.

Copy link
Member

Choose a reason for hiding this comment

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

What about --skip-already-trusted? Too long?

Copy link
Author

Choose a reason for hiding this comment

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

--skip-already-trusted does feel long. I feel already does not appear to add any additional meaning on --skip-trusted.

Copy link
Author

Choose a reason for hiding this comment

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

Should we stick with --skip-trusted then?

@alban
Copy link
Member

alban commented Sep 25, 2017

TODO:

  • Documentation
  • Tests

--skip-trusted is more concise and also similar to other flags that
  have alredy been implemented. The default for this is `false`
  ensuring that existing this does not break existing users'
  configurations.
The test for --skip-trusted=true without a trusted key already being
present is failing at the moment. Saving progress to get feedback.
@indradhanush indradhanush changed the title trust: add flag --overwrite-trusted trust: add flag --skip-trusted Sep 27, 2017
@indradhanush
Copy link
Author

indradhanush commented Sep 27, 2017

@alban I've made changes as suggested and have added tests. However one of the tests I wrote is failing with the error message:

/tmp/localdir-581577645 --system-config=/tmp/systemdir-483202344 --user-config=/tmp/userdir-884398695 trust --prefix rkt-prefix.com/my-app --skip-trusted key1.gpg
	rkt_tests.go:901: Expected but didn't find "Are you sure you want to trust this key" in pubkey: prefix: "rkt-prefix.com/my-app"
		key: "key1.gpg"
		gpg key fingerprint is: 36B2 87AD D109 5DB1 AFD9  CBF1 25D5 D9FA D9DC EF41
		    Subkey fingerprint: D567 C8E0 5E79 ACA5 9A32  7888 ECA3 3AFD 42E9 C212
			Key for testing only (Key for testing only) <key.for.testing.only@example.com>
		pubkey: Already trusted "key1.gpg" for prefix "rkt-prefix.com/my-app".

I've given this some thought but am unable to understand what could be going wrong. Is there something that I am missing?

@@ -84,4 +84,16 @@ func TestTrust(t *testing.T) {
t.Logf("Now both images can be executed\n")
runImage(t, ctx, imageFile, "Hello", false)
runImage(t, ctx, imageFile2, "Hello", false)
t.Logf("Skip trusted key (rkt trust --skip-trusted) with trusted key absent\n")
runRktTrustSkipTrustedTrue(t, ctx, "rkt-prefix.com/my-app", 1, false)
Copy link
Member

Choose a reason for hiding this comment

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

You pass the parameter alreadyTrusted==false but the key is already trusted from the previous tests (line 67 and line 82). You could do your new test on a different image with a different prefix that is not yet trusted (e.g. imageFile3, see example line 36). The new test would have to be done before the "rkt trust --root".

t.Fatalf("Expected but didn't find %q in %v", expected, err)
}
} else {
assertTrustPrompt(t, prefix, child)
Copy link
Member

Choose a reason for hiding this comment

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

In this 'else" branch, the key will already be trusted anyway because "rkt trust" is executed twice in this fuction:

  • line 916 with runRktTrust
  • line 922 with spawnOrFail

So assertTrustPrompt will fail

Use a new image file with a unique prefix to ensure that the key being
tested is not trusted ahead of time. Also the test for
`rkt trust --root` should be the last test.
runRktTrustSkipTrustedFalse(t, ctx, "rkt-skip-trusted.com/my-app", 1, false)

t.Logf("Now the image can be executed\n")
runImage(t, ctx, imageFile3, "Hello", false)
Copy link
Member

Choose a reason for hiding this comment

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

Could you also try to run the image with runImage after each runRktTrustSkipTrusted* and check it has the correct behavior?

For --skip-trusted=false with trusted key not present, we should use a
separate image as well.
@indradhanush
Copy link
Author

@alban Ping. Updated with latest changes as per review comments.

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

Successfully merging this pull request may close these issues.

None yet

3 participants