Skip to content

Fix terminating in fixture generation and getMetadataForTarget() - #216

Merged
phenaproxima merged 50 commits into
mainfrom
tedbow-fix_terminating_2
Jul 2, 2021
Merged

phenaproxima merged 50 commits into
mainfrom
tedbow-fix_terminating_2

Conversation

@tedbow

@tedbow tedbow commented May 28, 2021 •

Copy link
Copy Markdown
Contributor

3 problems

  1. in create python function for creating delegations #212 we didn't take into account the 1 role level_2_after_terminating where terminating should be true.

generate_fixtures.TUFTestFixtureBase.delegate_role() didn't take this into account.
2.

self.delegate_role_with_file(delegator_role=level_1_delegation,
                                     delegated_role_name='level_2_after_terminating',
                                     paths=['level_2_*.txt'],
                                     target_file='level_2_after_terminating_unfindable.txt')

The paths here 'level_2_.txt' will never have a match for the role was delegated from 'unclaimed' which has a patch 'level_1_.txt'.

File must match all level of the chain so it will not be found because of that not because it is after the delegation.

if (!$delegatedRole->matchesPath($target)) {
     // Targets must match the path in all roles in the delegation chain so if the path does not match
     // do not evaluate this role or any roles it delegates to.
     continue;
 }

 $this->fetchAndVerifyTargetsMetadata($delegatedRoleName);
 /** @var \Tuf\Metadata\TargetsMetadata $newTargetsData */
 $newTargetsData = $this->metadataFactory->load($delegatedRoleName);
 if ($newTargetsData->hasTarget($target)) {
     return $newTargetsData;
 }
 $searchedRoles[] = $delegatedRole;
 // § 5.6.7.2.1
 //  If the current delegation is a multi-role delegation, recursively visit each role, and check that each has signed exactly the same non-custom metadata (i.e., length and hashes) about the target (or the lack of any such metadata).
 if ($matchingTargetMetadata = $this->getMetadataForTarget($target, $newTargetsData, $searchedRoles)) {
     return $matchingTargetMetadata;
 }
 if ($delegatedRole->isTerminating()) {
     // § 5.6.7.2.2
     // If the role is terminating then abort searching for a target.
     return null;
 }          

This is part of the logic for evaluating each delegate role.

At the top check if the path matches if it does not we go to the next delegated role.
At the bottom we check if the role is terminating and return null if it is.

So if we have terminating role that does not match target path its termination will not take affect. I think this is wrong but we should check.

@phenaproxima phenaproxima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense to me. One punctuation nitpick.

Comment thread src/Client/Updater.php Resolved
@tedbow

tedbow commented May 28, 2021 •

Copy link
Copy Markdown
Contributor Author

I checked the last TUF spec to make sure we don't have to change the logic again.

The description has changed

See latest 1.0.19 https://theupdateframework.github.io/specification/v1.0.19/#update-targets

and 1.0.17 the version we are on: https://theupdateframework.github.io/specification/v1.0.17/#update-targets

This switch the order that terminating is evaluated. So we should figure out how to get to 1.0.19 and do that version

See this issue theupdateframework/specification#140
I may have mis-read what "multi-role" means. This was taken out of 1.x of the TUF spec

Here is the commit where it changed theupdateframework/specification@718f133

@tedbow

tedbow commented May 28, 2021

Copy link
Copy Markdown
Contributor Author

@tedbow
tedbow marked this pull request as draft May 28, 2021 20:47
@tedbow

tedbow commented May 28, 2021

Copy link
Copy Markdown
Contributor Author

Making this a draft because we still need clarification on how this should work

@tedbow

tedbow commented May 28, 2021

Copy link
Copy Markdown
Contributor Author

After chatting more with @trishankatdatadog I think 1 & 2 from my original comment on the issue are still a problem but 3 is not.

@tedbow
tedbow marked this pull request as ready for review June 7, 2021 20:18
.create_target('e.txt', signing_role='e') \
.delegate('f', ['*.txt']) \
.create_target('f.txt', signing_role='f') \
.publish()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@phenaproxima I haven't made the phpunit test that uses this fixture yet but I think this is how to make the test case specified in theupdateframework/specification#168

I looked through the json files and I think it produces the correct fixture but let me know if you think it produces the correct fixture.

BTW I love how easy this is to make with the new FixtureBuilder class !

Comment thread src/Client/Updater.php Outdated
}
$searchedRoles[] = $delegatedRoleName;
// § 5.6.7.2.1
// If the current delegation is a multi-role delegation, recursively visit each role, and check that each has signed exactly the same non-custom metadata (i.e., length and hashes) about the target (or the lack of any such metadata).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: how do we know if the current delegation is a "multi-role" delegation? What does that mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"multi-role" wording was wrong. This was taken out of spec. I thought it meant a role that delegate to more than 1 more role. but it actually refers to something else that is not in 1.x version of the spec and is being considered for 2.x.

I updated the wording from the current version of the spec.

Comment thread tests/Client/UpdaterTest.php Outdated
'level_3' => 1,
'level_3_below_terminated' => 1,
],
// Roles after terminating delegation where the target path does not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"...where the target path does not the terminating role are..." seems like odd phrasing. Missing a word?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added more context. Take another look

@phenaproxima phenaproxima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is really good. I'm super happy about the robust test coverage. My concerns lie more with overall grokkability -- the TUF spec, as we know, is poorly worded about this recursive search for targets within a delegation tree, and therefore I think we need to be completely clear about what we're doing and how we expect it to work. I think my biggest wishlist item after this review is inline comments for all the test cases where, at the very least, we explain what the expected outcome is.

Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Outdated
* @param bool $terminated
*
* @return \Tuf\Metadata\TargetsMetadata|null
* The target metadata that is the end node for search or null if the target metadata does not make any delegations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rephrase this too. Maybe "The targets metadata that was the last visited node in the delegation tree, or null if there were no delegated roles to search. If targets metadata is returned, it may or may not contain information about the desired target."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I simplified this method so only returns a targets metadata object if it has the info about the file. So the comment is simpler now

Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Outdated
}

/**
* Performs a search of delegate roles for a metadata containing information about a target.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Performs a search of delegate roles for a metadata containing information about a target.
* Searches delegated roles for metadata containing information about a target.

Comment thread src/Client/Updater.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
@tedbow

tedbow commented Jul 1, 2021

Copy link
Copy Markdown
Contributor Author

I think my biggest wishlist item after this review is inline comments for all the test cases where, at the very least, we explain what the expected outcome is.

I wondering if the test cases would be easier to understand if we combined testVerifiedDelegatedDownload() and testDelegationErrors() this could be another PR but....

Right now testDelegationErrors() might be poorly named. It is basically when you can't find target for some reason like a terminating delegation before the targets file that has the info is evaluated.

So basically these 2 test methods maybe be better named testTargetFound() and testTargetNotFound()

But regardless of the naming if we wanted to see all the test cases for 1 fixture you would have to look at 2 provider methods.
So for example if you want to see all the test cases for TUFTestFixtureTerminatingDelegation now you would have to look at providerVerifiedDelegatedDownload() for targets targets.txt a.txt b.txt c.txt d.txt and providerDelegationErrors() for e.txt f.txt.

We could combine this into 1 test method testTargetDownload() with 1 provider and add extra param bool $expectFound.
That way you could see 1 block of tests cases all the found and not found target.

Comment thread src/Client/Updater.php Resolved
Comment thread src/Client/Updater.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved

@phenaproxima phenaproxima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made a small change, but otherwise I think I'm okay deferring documentation to a follow-up.

Comment thread tests/Client/UpdaterTest.php Resolved
Comment thread tests/Client/UpdaterTest.php Resolved
@phenaproxima
phenaproxima merged commit 5781d08 into main Jul 2, 2021
@phenaproxima
phenaproxima deleted the tedbow-fix_terminating_2 branch July 2, 2021 21:24
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