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

seed: ReadSystemEssentialAndBetterEarliestTime #10005

Merged
merged 3 commits into from
Mar 18, 2021

Conversation

pedronis
Copy link
Collaborator

@pedronis pedronis commented Mar 5, 2021

ReadSystemEssentialAndBetterEarliestTime retrieves in one go
information about the model and essential snaps of the given types
for the Core 20 recovery system seed specified by seedDir and label
(which cannot be empty).
It can operate even if current system time is unreliable by taking
a earliestTime lower bound for current time.
It returns as well an improved lower bound by considering appropriate
assertions in the seed.

@pedronis
Copy link
Collaborator Author

pedronis commented Mar 5, 2021

based on #10004

@pedronis pedronis requested review from anonymouse64 and mvo5 March 5, 2021 13:24
@pedronis pedronis force-pushed the seed-better-earliest-time branch from 8f889ad to e12e040 Compare March 5, 2021 13:32
@pedronis pedronis changed the title asserts: ReadSystemEssentialAndBetterEarliestTime seed: ReadSystemEssentialAndBetterEarliestTime Mar 5, 2021
@mvo5 mvo5 added this to the 2.49 milestone Mar 8, 2021
have a variant of CommitTo that supports a callback to consider each
assertion immediately after it has been added to the database, at
which point it also verified
ReadSystemEssentialAndBetterEarliestTime retrieves in one go
information about the model and essential snaps of the given types
for the Core 20 recovery system seed specified by seedDir and label
(which cannot be empty).
It can operate even if current system time is unreliable by taking
a earliestTime lower bound for current time.
It returns as well an improved lower bound by considering appropriate
assertions in the seed.
@pedronis pedronis force-pushed the seed-better-earliest-time branch from e12e040 to 6dc91da Compare March 15, 2021 13:42
@pedronis pedronis marked this pull request as ready for review March 15, 2021 13:43
Copy link
Contributor

@anonymouse64 anonymouse64 left a comment

Choose a reason for hiding this comment

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

I think we should also do this for snap-declarations too, but other than that looks great to me (minus some nitpicky wording things in the doc-comments)

seed/seed.go Outdated
// and more recent than snap-declarations anyway,
// other assertions are ignored as they might be added
// with unreliable times
if a.Type() == asserts.SnapRevisionType {
Copy link
Contributor

Choose a reason for hiding this comment

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

as mentioned on IRC, we could also use the snap-declaration timestamp here, since the checkConsistency method also verified that the snap-declarations are store-signed too, the case is unlikely where the snap-declaration is newer than the snap-revision, but it could happen and I think it's okay to be slightly more accepting of assertion types here

seed/seed.go Outdated
Comment on lines 177 to 180
// we consider only snap-revisions as they are stored-signed
// and more recent than snap-declarations anyway,
// other assertions are ignored as they might be added
// with unreliable times
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
// we consider only snap-revisions as they are stored-signed
// and more recent than snap-declarations anyway,
// other assertions are ignored as they might be added
// with unreliable times
// we consider only snap-revision and snap-declaration
// assertions here as they must be store-signed, see
// checkConsistency for each type
// other assertions are ignored as they might have a root
// of trust that does not include the brand key that signed
// the model assertion; thereby allowing an attacker with an
// account-key that was signed by canonical to inject new
// assertions that are not rooted in trust with the store directly
// or with the brand key directly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used a slightly different explanation in the end

seed/seed.go Outdated
return nil, nil, time.Time{}, err
}

// consider model own timestamp as well
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
// consider model own timestamp as well
// consider the model's timestamp as well - it must be signed
// by the brand so is safe from the attack detailed above


// this is the order they needed to be added
c.Check(seen, DeepEquals, []*asserts.Ref{

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(essSnaps, DeepEquals, t.expected)
c.Check(betterTime.Equal(improvedTime), Equals, true, Commentf("%v expected: %v", betterTime, improvedTime))
}

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

thanks @anonymouse64

also remove some spurious blank lines here and in asserts
@pedronis pedronis added the Squash-merge Please squash this PR when merging. label Mar 16, 2021
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thanks for this

}

improve := func(a asserts.Assertion) {
// we consider only snap-revision and snap-declaration
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this comment

// containing unreliable time
var tstamp time.Time
switch a.Type() {
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

(nitpick^99) most of the switch/case I have seen has the default as the last entry but that is really probably my most nitpicky comment yet.

@pedronis pedronis merged commit 35c76d6 into canonical:master Mar 18, 2021
mvo5 pushed a commit to mvo5/snappy that referenced this pull request Mar 26, 2021
ReadSystemEssentialAndBetterEarliestTime retrieves in one go
information about the model and essential snaps of the given types
for the Core 20 recovery system seed specified by seedDir and label
(which cannot be empty).
It can operate even if current system time is unreliable by taking
a earliestTime lower bound for current time.
It returns as well an improved lower bound by considering appropriate
assertions in the seed.

* asserts: Batch.CommitToAndObserve

have a variant of CommitTo that supports a callback to consider each
assertion immediately after it has been added to the database, at
which point it also verified
@pedronis pedronis deleted the seed-better-earliest-time branch April 9, 2021 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Squash-merge Please squash this PR when merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants