The Wayback Machine - https://web.archive.org/web/20260314082831/https://github.com/docker/cli/pull/1112
Skip to content

Fix docker trust signer removal#1112

Merged
thaJeztah merged 4 commits intodocker:masterfrom
n4ss:fix-trust-signer-remove
Jun 15, 2018
Merged

Fix docker trust signer removal#1112
thaJeztah merged 4 commits intodocker:masterfrom
n4ss:fix-trust-signer-remove

Conversation

@n4ss
Copy link
Contributor

@n4ss n4ss commented Jun 6, 2018

Signed-off-by: Nassim 'Nass' Eddequiouaq eddequiouaq.nassim@gmail.com

- What I did

Only print "Successfully removed " if the signer is removed.

- How I did it

Make trust.removeSingleSigner return a second value besides the error; whether or not a removal actually happened and decides on output printing based on it.

- How to verify it

$> docker signer add foobar myrepo/isthebest --key path/to/pubkey
$> docker sign myrepo/isthebest:latest
$> docker signer remove foobar myrepo/isthebest
The signer "foobar" signed the last released version of myrepo/isthebest. Removing this signer will make myrepo/isthebest unpullable. Are you sure you want to continue? [y/N]
N

Aborting action.

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
@n4ss
Copy link
Contributor Author

n4ss commented Jun 6, 2018

/cc @vdemeester @thaJeztah @moscowrage @endophage @vieux

this is a very high priority btw for the next release.

cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetLoadedNotaryRepository)
err := removeSingleSigner(cli, "signed-repo", "test", true)
_, err := removeSingleSigner(cli, "signed-repo", "test", true)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we want to check the returned boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix.

errRepos = append(errRepos, repo)
} else {
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", options.signer, repo)
if didRemove {
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can do

 		} else if didRemove {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix.

}
return notaryRepo.Publish()

return true, nil
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be simpler to move the logged success message before this return?

    fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", signerName, repoName)
    return nil

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say that I prefer to have it outside as it makes it more maintainable in the case where there are different codepaths that lead to a successful removal in this function and simply have this one return whether or not a removal happened.

Copy link
Member

Choose a reason for hiding this comment

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

OK but for now there is only one code path which does that, this would minimize the changes required and there is already output logged in a similar way in the function e.g.

fmt.Fprintf(cli.Out(), "\nAborting action.\n")

Anyway it's just my personal view, obviously :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! fixed.

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

gofmt

} else {
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", options.signer, repo)
} else if didRemove {
fmt.Fprintf(cli.Out(), "Successfully removed %s from %s\n\n", options.signer, repo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
@n4ss n4ss force-pushed the fix-trust-signer-remove branch from ccd0697 to 5ebb7a6 Compare June 6, 2018 14:25
@n4ss
Copy link
Contributor Author

n4ss commented Jun 6, 2018

@vdemeester done

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@n4ss
Copy link
Contributor Author

n4ss commented Jun 7, 2018

cc @andrewhsu as well

for _, repo := range options.repos {
fmt.Fprintf(cli.Out(), "Removing signer \"%s\" from %s...\n", options.signer, repo)
if err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
if didRemove, err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: didRemove -> removed maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.


_, err = removeSingleSigner(cli, "signed-repo", "releases", true)
assert.Error(t, err, "releases is a reserved keyword and cannot be removed")
assert.Equal(t, didRemove, false, "No signer should be removed")
Copy link
Contributor

Choose a reason for hiding this comment

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

I may miss something, but I think didRemove was not updated on the second call here (as the boolean result is dropped _, err = removeSingleSigner)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch thanks, done.

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
for _, repo := range options.repos {
fmt.Fprintf(cli.Out(), "Removing signer \"%s\" from %s...\n", options.signer, repo)
if err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
if _, err := removeSingleSigner(cli, repo, options.signer, options.forceYes); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I would argue that there is no need to return a bool as all now that it's dropped here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will implement more tests that need to know if the signer got actually removed, and I need the information through this boolean.


func removeSingleSigner(cli command.Cli, repoName, signerName string, forceYes bool) error {
// removeSingleSigner returns whether the signer has been removed during this operation and an error
// Note: the signer not being removed doesn't necessarily raise an error (eg. User saying "No" to the confirmation prompt)
Copy link
Member

Choose a reason for hiding this comment

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

Besides dropping the bool I would remove the Note: and add punctuation, something like:

removeSingleSigner attempts to remove a single signer.
The signer not being removed doesn't necessarily raise an error e.g. user choosing "No" when prompted for confirmation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix.

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, but not very fond of the boolean return. Looks like there may be a bit too much logic in that function, so we should do some refactoring in a follow up

@thaJeztah thaJeztah merged commit 8de0753 into docker:master Jun 15, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.06.0 milestone Jun 15, 2018
@thaJeztah
Copy link
Member

Arf; probably should've needed some squashing 😞

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.

6 participants