Commit graph

4988 commits

Author SHA1 Message Date
Jussi Kukkonen
d2f8c99c19 Metadata API: Add default constructor arguments
This allows creating new metadata with less boilerplate:
    root = Metadata(Root())
    targets = Metadata(Targets())

Set reasonable default values for all the arguments -- version to
1, spec_version to current supported version, etc.

Expires does not have a good default value and my original plan was
to require expires argument to be set. That would mean an
incompatible API change though as arguments before expires would be
now optional... So expires now defaults to an arbitrary value of 1
day from moment of creation.

One noteworthy special case is consistent_snapshot where the default
value is True (since that's what we want people to use for new
metadata) but None is also used to imply that metadata does not contain
the field at all.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-23 17:25:40 +02:00
Jussi Kukkonen
b7b035aea1
Merge pull request #1758 from ivanayov/updater_api_input_validation
Add tests for Updater input validation
2022-03-23 15:17:48 +02:00
Jussi Kukkonen
05c295987a
Merge pull request #1915 from MVrachev/test-statics-data-generation
Tests: provide a way to generate a simple metadata set
2022-03-23 15:14:46 +02:00
Lukas Pühringer
b272ac7734
Merge pull request #1918 from lukpueh/pin-direct-test-deps-only
build: pin direct test dependencies only
2022-03-23 13:54:47 +01:00
Lukas Puehringer
ec8a767c10 build: pin direct test dependencies
Fixes #1899
Reverts #1867

In #1867 we started pinning direct and transitive test
dependencies for stable test results, i.e. to not have an unnoticed
update of a used test tool (or their dependencies) break our tests.

This resulted in a dependabot updates inundating our PR tracker,
potentially obfuscating updates, which we care to address with
higher priority.

As a compromise we now only pin direct test dependencies, which
should still give us relatively stable test runs, while reducing
the spam.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-03-23 11:54:01 +01:00
Lukas Puehringer
1e9967b69a Revert "build: pin test requirements for deterministic CI"
This reverts commit 5643cecf68.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-03-23 11:51:37 +01:00
Martin Vrachev
384772efc3 Provide a way to generate a simple repository
I created a new script called "generate_md.py" which can be used
to easily generate a repository. Additionally, I created a new
test file making sure that the locally stored metadata files and
the newly generated metadata roles are the same.
This will allow us to test that we are not changing the metadata
file structure when making changes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-22 18:13:54 +02:00
Martin Vrachev
69cc684230 gitattributes: make all JSON files end with LF
A really specific bug occurred on CI runs on all Windows machines
https://github.com/theupdateframework/python-tuf/runs/5467473050?check_suite_focus=true
where we weren't able to verify that what was generated is the same
as the stored on Git.

After research with Jussi, we found out that the problem comes not
from the content of the file that was generated, but because on Windows
Git proactively replaced all line endings for text files with CRLF symbol
("\r") this made the locally stored JSON files different from the one
generated.

We want to make sure such bugs doesn't occur again and that's why we
disable this behavior for all JSON files.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-22 16:42:00 +02:00
Lukas Pühringer
ff770eacd9
Merge pull request #1896 from ofek/modernize-metadata
Update package metadata
2022-03-22 13:15:47 +01:00
Jussi Kukkonen
1d166f0b4e
Merge pull request #1876 from jku/more-details-on-verify-failure
Logging and error message improvements
2022-03-21 14:21:44 +02:00
Jussi Kukkonen
d9f2d9d24a
Merge pull request #1707 from ivanayov/test_expired_metadata
Test expired metadata from cache
2022-03-21 14:19:01 +02:00
Lukas Pühringer
f2e80a82cb
Merge pull request #1843 from ivanayov/metadata_docstrings_imprv_follow_up
Improve docstrings in Metadata API to be more descriptive
2022-03-21 09:31:01 +01:00
Ivana Atanasova
8d4d9af70b Update expired metadata tests logic
This change improves the logic of expired metadata tests, so that
it is explicitly visible what the expiry time and the versions are
and when update/refresh is called in that period

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 22:01:33 +02:00
Ivana Atanasova
d8d0486514 Fix expired metadata tests
This change fixes the expired metadata tests to mock `datetime`
as previously they mocked `time` incorrectly, which did not affect
update methods, as they use `datetime.datetime.utcnow()` to
calculate now

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 19:53:50 +02:00
Ivana Atanasova
cab99f58b6 Verify validation is performed from local metadata
This change verifies that when local metadata has expired, it is
still used to verify new metadata that's pulled from remote

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 19:53:50 +02:00
Ivana Atanasova
15c8d80b8a Test expired metadata from cache
This tests that an expired timestamp/snapshot/targets when loaded
from cache is not stored as final but is used to verify the new
timestamp

Fixes #1681

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 19:53:50 +02:00
Ivana Atanasova
e26363cf6a Add tests for Updater input validation
This test covers `targetinfo`, `target_path`, `target_base_url`,
`metadata_dir` and `filepath` input validation of the `Updater`
methods

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 18:59:05 +02:00
Ivana Atanasova
e71aa4a7d7 Improve Signer docstrings in Metadata API
Change to @lukpueh proposal with more clarification on why and how
the `securesystemslib.signer.Signer` interface is used

Co-authored-by: Lukas Pühringer <luk.puehringer@gmail.com>

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 18:32:25 +02:00
Ivana Atanasova
db7fbb21fa Improve docstrings in Metadata API to be more descritpive
This change updates some parts of the Metadata API docstrings
that did not give enough details and context

Fixes #1600

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-03-18 18:32:25 +02:00
Ofek Lev
98db711cca Update package metadata
Signed-off-by: Ofek Lev <ofekmeister@gmail.com>
2022-03-18 11:30:07 -04:00
Lukas Pühringer
9c8622d125
Merge pull request #1908 from MVrachev/update-spec-ver
Use spec version from tuf/api/metadata in examples
2022-03-17 16:37:59 +01:00
Martin Vrachev
06118843ca Use spec version from tuf/api/metadata in examples
Replace the hardcoded specification version with the one defined inside
tuf/api/metadata.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-17 15:41:05 +02:00
Jussi Kukkonen
8ac7167f8d
Merge pull request #1900 from joshuagl/joshuagl/build-nits
Minor, mostly packaging, clean-ups
2022-03-11 14:19:59 +02:00
Joshua Lock
150bfd0eec gitignore: fix directory patterns
Fix the directory ignore patterns to ignore the entire directories,
including child directories.
https://git-scm.com/docs/gitignore#_pattern_format

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2022-03-09 11:54:15 +00:00
Joshua Lock
22fee97dc3 setup: remove upper bound limit on python_requires
Setting upper bound version constraints in libraries is a source of
problems for users of those libraries, see:
https://iscinumpy.dev/post/bound-version-constraints/

The intent of the python-tuf version constraint is to ensure we're
using a version of Python which supports all the features we rely
on, this is a better fit for a lower limit.

Suggested-by: Ofek Lev <ofekmeister@gmail.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2022-03-09 11:53:55 +00:00
Joshua Lock
430bdf5750 test: use tox isolated environments
Enable tox isolated environments to perform build operations in a virtual
environment.
See https://tox.wiki/en/latest/config.html#conf-isolated_build

Co-Authored-By: Ofek Lev <ofekmeister@gmail.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2022-03-09 11:53:49 +00:00
Joshua Lock
0d2f6951a7 Remove redundant comment about version
The version is no longer duplicated in setup.cfg (since 5155ba74), so remove
redundant TODO suggesting folks update in two places.

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
Signed-off-by: Joshua Lock <jlock@vmware.com>
2022-03-09 11:53:13 +00:00
Jussi Kukkonen
e7037cf8c4
Merge pull request #1860 from MVrachev/serialization-bytes-array
Metadata test full serialization cycle
2022-03-07 11:14:31 +02:00
Jussi Kukkonen
29e4e63d46
Merge pull request #1895 from jku/single-source-version
Single source version number
2022-03-04 13:32:26 +02:00
Jussi Kukkonen
bf511ec0c6 docs: Update release docs
* version number is single sourced now
* Mention that using pip against test.pypi.org is unsafe
* Fix some filenames in the examples

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-03 16:04:08 +02:00
Jussi Kukkonen
5155ba7431 build: Single source version number
As of setuptools 46.4.0, one can accomplish single source version
number with
    version = attr: package.__version__
in setup.cfg: As long as setuptools simplified AST parser is able to
read the file, this works without actually importing anything.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-03 15:30:13 +02:00
Jussi Kukkonen
248dabddd8
Merge pull request #1892 from theupdateframework/dependabot/github_actions/actions/checkout-3
build(deps): bump actions/checkout from 2.4.0 to 3
2022-03-02 14:54:15 +02:00
dependabot[bot]
38b5e07f62
build(deps): bump actions/checkout from 2.4.0 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](ec3a7ce113...a12a3943b4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 10:21:30 +00:00
Jussi Kukkonen
0504866236
Merge pull request #1891 from theupdateframework/dependabot/github_actions/actions/setup-python-3
build(deps): bump actions/setup-python from 2.3.2 to 3
2022-03-01 16:05:31 +02:00
dependabot[bot]
311120a192
build(deps): bump actions/setup-python from 2.3.2 to 3
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2.3.2 to 3.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](7f80679172...0ebf233433)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-01 10:21:10 +00:00
Lukas Pühringer
84486191fe
Merge pull request #1887 from jku/remove-blog-header-links
docs: Clean up blog header
2022-03-01 09:47:24 +01:00
Jussi Kukkonen
a74f7a1762
Merge pull request #1775 from MVrachev/validation-during-serialization
Add  a "validate" argument option to JSONSerializer.

The argument defaults to false: by default serialization works exactly as before.
2022-02-28 15:57:43 +02:00
Martin Vrachev
6ea5372edb Take order into account for certain cases
After we have dropped OrderedDict in e3b267e2e0
we are relying on python3.7+ default behavior to preserve the insertion
order, but there is one caveat.
When comparing dictionaries the order is still irrelevant compared to
OrderedDict. For example:
>>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)])
False
>>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)])
True

There are two special attributes, defined in the specification, where
the order makes a difference when comparing two objects:
- Metadata.signatures
- Targets.delegations.roles.
We want to make sure that the order in those two cases makes a
difference when comparing two objects and that's why those changes
are required inside two __eq__ implementations.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-28 14:42:06 +02:00
Martin Vrachev
a17ceda4e5 Add "validation" arg in JSONSerializer
If the "validation" argument is set then when
serializing the metadata object will be validated.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-28 14:42:06 +02:00
Martin Vrachev
5d24956ded Test __eq__ implementation for all classes
Test the "__eq__" implementation for all classes defined in
tuf/api/metadata.py
The tests are many but simple. The idea is to test each of the metadata
classes one by one and with this to make sure there are no possible
cases missed.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-28 14:42:06 +02:00
Martin Vrachev
30a707c297 Add __eq__ to classes in Metadata API
By adding __eq__ we can compare that two objects are equal.
That will be useful when adding validation API call.

One bug I have found during testing is that I don't check if the type
of "other" in the __eq__ implementations are the expected ones.
I assumed that when comparing "root == obj" if "obj" is None that
automatically the result will be false.
Later after a mypy warning, I realized we should implement the __eq__
methods to accept "Any" type as other and we should check manually
that "other" is the expected type.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-28 14:42:04 +02:00
Jussi Kukkonen
45e8898d4a docs: Clean up blog header
Minima theme by default adds all files in blog root (docs/) as links in
the header. This looks ridiculous in our case: let's just have a link to
blog front page.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-28 12:01:06 +02:00
Lukas Pühringer
a75abe36f0
Merge pull request #1886 from jku/add-development-blog
Add development blog
2022-02-28 10:39:36 +01:00
Jussi Kukkonen
5ee575ef33 docs: Add a new 200px icon
Also rename the existing icon so differences are obvious.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-25 10:54:08 +02:00
Jussi Kukkonen
e78ffc18f9 docs: Add a blog post
This is https://ssl.engineering.nyu.edu/blog/2022-02-21-tuf-1_0_0
only slightly modified (the logo would break the excerpts in the index
page so I moved it a bit).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-24 16:12:34 +02:00
Jussi Kukkonen
92c7721d02 docs: Add blog configuration
Add config for GitHub Pages so that we can use it as a project blog.
* _config.yml is jekyll configuration
* index.md contains description and title for the blog main page.
* Any files matching "_posts/YYYY-MM-DD-TITLE.md" are considered posts

The Github Pages configuration only allows "/" or "/docs/" as the Jekyll
root directory: The clutter in docs/ is annoying but otherwise this is a
very easy setup.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-24 16:07:18 +02:00
Lukas Pühringer
84c632ee8d
Merge pull request #1867 from lukpueh/update-req-pinned
build: pin test requirements for deterministic CI
2022-02-22 11:04:02 +01:00
Jussi Kukkonen
fc1558bfd4 Metadata API: Log details of verify error
We don't want to error out from the whole verify_delegate() process if
e.g. a single key fails to load but we do want to provide details for
debugging in the unexpected failure cases.

This means "example_client -vv  download file1.txt" fails like this:

    Found trusted root in /home/jku/.local/share/python-tuf-client-example
    INFO:tuf.api.metadata:Key
4e777de0d275f9d28588dd9a1606cc748e548f9e22b6795b7cb3f63f98035fcb failed
to verify sig: Failed to load PEM key bogus-key-content-here
    INFO:tuf.api.metadata:Key 4e777de0d275f9d28588dd9a1606cc748e548f9e22b6795b7cb3f63f98035fcb failed to verify root
    Failed to download target x: root was signed by 0/1 keys

Fixes #1875

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-21 16:35:49 +02:00
Jussi Kukkonen
d4814e86d8 Metadata API: Add messages to serialization errors
We can't really add any details but this at least means
printing the error works.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-21 16:04:55 +02:00
Jussi Kukkonen
03d023219b
Merge pull request #1873 from jku/1.0.0-release
1.0.0 release
2022-02-21 12:41:44 +02:00