Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asserts: define registry-control assertion #14508

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

st3v3nmw
Copy link

@st3v3nmw st3v3nmw commented Sep 16, 2024

This PR adds the registry-control assertion to snapd (SD172). This doesn't include signing or acknowledging of said assertion as we need a different approach since we're signing with the device key - that will be the next PR. Finally, the API changes will follow (SD186).

This also introduces a registry-control feature flag.

Copy link

github-actions bot commented Sep 16, 2024

Everyone contributing to this PR have now signed the CLA. Thanks!

@st3v3nmw st3v3nmw changed the title many: add registry-control assertion asserts: define registry-control assertion Sep 16, 2024
@st3v3nmw st3v3nmw force-pushed the add-registry-control-assertion branch 3 times, most recently from 5149fd0 to b47e694 Compare September 17, 2024 08:09
@MiguelPires MiguelPires self-requested a review September 17, 2024 08:10
@st3v3nmw st3v3nmw marked this pull request as ready for review September 17, 2024 08:10
@st3v3nmw st3v3nmw force-pushed the add-registry-control-assertion branch 3 times, most recently from 234c56e to 6a94aa1 Compare September 17, 2024 09:26
Copy link

github-actions bot commented Sep 17, 2024

Everyone contributing to this PR have now signed the CLA. Thanks!

@st3v3nmw st3v3nmw force-pushed the add-registry-control-assertion branch from 6a94aa1 to 318806c Compare September 17, 2024 09:39
Copy link
Contributor

@MiguelPires MiguelPires left a comment

Choose a reason for hiding this comment

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

Thanks, left some comments

}

// Revoke revokes remote registry control over <account-id>/<registry>/<view>.
func (rgCtrl *RegistryControl) Revoke(accountID, registryName, view string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

The return type error can be removed since the function always returns nil

// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2022-2024 Canonical Ltd
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Copyright (C) 2022-2024 Canonical Ltd
* Copyright (C) 2024 Canonical Ltd

Comment on lines 85 to 87
accountID := parts[0]
registryName := parts[1]
viewName := parts[2]
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: these are short enough that we can condense this a bit

Suggested change
accountID := parts[0]
registryName := parts[1]
viewName := parts[2]
accountID, registryName, viewName := parts[0], parts[1], parts[2]

// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2022-2024 Canonical Ltd
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Copyright (C) 2022-2024 Canonical Ltd
* Copyright (C) 2024 Canonical Ltd

Registries: "registries",

Registries: "registries",
RegistryControl: "registry-control",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remote-registry-control or registry-delegation would be clearer for users?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pedronis may have an opinion

c.Assert(err.Error(), Equals, tc.err, cmt)
} else {
c.Assert(err, IsNil, cmt)
c.Check(rgCtrl, Not(IsNil), cmt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c.Check(rgCtrl, Not(IsNil), cmt)
c.Check(rgCtrl, NotNil, cmt)

Comment on lines 90 to 91
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, tc.err, cmt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, tc.err, cmt)
c.Assert(err, ErrorMatches, tc.err, cmt)

Views map[string]*delegatedView // key is the view's name
}

type delegatedView struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type seems unnecessary, do we expect to add something to it? It only carries the view's name so AFAICT we don't need it?

Copy link
Author

@st3v3nmw st3v3nmw Sep 17, 2024

Choose a reason for hiding this comment

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

I added the type to match SD172 which looks like this:

views:
    - name:  	<account-id>/<registry>/<view>
    - name:  	<account-id>/<registry>/<view>

name is the only field currently. It was done this way to allow space for future expansion but I can't think of possible fields to add (maybe the authentication or authority fields?). I'll bring this up for discussion again. Thanks.

type delegatedRegistry struct {
AccountID string
Name string
Views map[string]*delegatedView // key is the view's name
Copy link
Contributor

Choose a reason for hiding this comment

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

The keys and values are the same so this can be replaced with a list of view names with no loss

rgCtrl.Registries[key] = registry
}

registry.Views[view] = &delegatedView{Name: view}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, this is what I'm referring to. This can be replaced with a slice or, if we ever expect this to grow very large, a map[string]bool or map[string]struct{}

@st3v3nmw st3v3nmw force-pushed the add-registry-control-assertion branch from 318806c to 5684cee Compare September 17, 2024 13:15
@st3v3nmw st3v3nmw marked this pull request as draft September 19, 2024 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants