Skip to content

TUF TrustUpdater basic logging - #518

Merged
woodruffw merged 7 commits into
mainfrom
jl/368
Mar 8, 2023
Merged

woodruffw merged 7 commits into
mainfrom
jl/368

Conversation

@jleightcap

Copy link
Copy Markdown
Contributor

Stripping down prior branch to just one logger.debug call in TrustUpdater. Here, just log each of the cache items and their contained key.

Closes #368

Example: SIGSTORE_LOGLEVEL="debug" make run ARGS="verify ..."

# ...
DEBUG:sigstore._internal.tuf:TUF metadata: /Users/jleightcap/Library/Application Support/sigstore-python/tuf/https%3A%2F%2Fsigstore-tuf-root.storage.googleapis.com%2F
DEBUG:sigstore._internal.tuf:TUF targets cache: /Users/jleightcap/Library/Caches/sigstore-python/tuf/https%3A%2F%2Fsigstore-tuf-root.storage.googleapis.com%2F
DEBUG:sigstore._internal.tuf:TUF cache target Rekor ['Active']: rekor.pub with hash
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2G2Y+2tabdTV5BcGiBIx0a9fAFwr
kBbmLSGtks4L3qX6yYY0zufBnhC8Ur/iy55GhWP/9A/bY2LhC30M9+RYtw==
-----END PUBLIC KEY-----

DEBUG:sigstore._internal.tuf:TUF cache target CTFE ['Active']: ctfe.pub with hash
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbfwR+RJudXscgRBRpKX1XFDy3Pyu
dDxz/SfnRi1fT8ekpfBd2O1uoz7jr3Z8nKzxA69EUQ+eFCFI3zeubPWU7w==
-----END PUBLIC KEY-----
DEBUG:sigstore._internal.tuf:TUF cache target CTFE ['Active']: ctfe_2022.pub with hash
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiPSlFi0CmFTfEjCUqF9HuCEcYXNK
AaYalIJmBZ8yyezPjTqhxrKBpMnaocVtLJBI1eM3uXnQzQGAJdJ4gs9Fyw==
-----END PUBLIC KEY-----

DEBUG:sigstore._internal.tuf:TUF cache target Fulcio ['Active', 'Expired']: fulcio.crt.pem with hash
-----BEGIN CERTIFICATE-----
MIIB+DCCAX6gAwIBAgITNVkDZoCiofPDsy7dfm6geLbuhzAKBggqhkjOPQQDAzAq
MRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxETAPBgNVBAMTCHNpZ3N0b3JlMB4XDTIx
MDMwNzAzMjAyOVoXDTMxMDIyMzAzMjAyOVowKjEVMBMGA1UEChMMc2lnc3RvcmUu
ZGV2MREwDwYDVQQDEwhzaWdzdG9yZTB2MBAGByqGSM49AgEGBSuBBAAiA2IABLSy
A7Ii5k+pNO8ZEWY0ylemWDowOkNa3kL+GZE5Z5GWehL9/A9bRNA3RbrsZ5i0Jcas
taRL7Sp5fp/jD5dxqc/UdTVnlvS16an+2Yfswe/QuLolRUCrcOE2+2iA5+tzd6Nm
MGQwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYE
FMjFHQBBmiQpMlEk6w2uSu1KBtPsMB8GA1UdIwQYMBaAFMjFHQBBmiQpMlEk6w2u
Su1KBtPsMAoGCCqGSM49BAMDA2gAMGUCMH8liWJfMui6vXXBhjDgY4MwslmN/TJx
Ve/83WrFomwmNf056y1X48F9c4m3a3ozXAIxAKjRay5/aj/jsKKGIkmQatjI8uup
Hr/+CxFvaJWmpYqNkLDGRU+9orzh5hI2RrcuaQ==
-----END CERTIFICATE-----
DEBUG:sigstore._internal.tuf:TUF cache target Fulcio ['Active', 'Expired']: fulcio_intermediate_v1.crt.pem with hash
-----BEGIN CERTIFICATE-----
MIICGjCCAaGgAwIBAgIUALnViVfnU0brJasmRkHrn/UnfaQwCgYIKoZIzj0EAwMw
KjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0y
MjA0MTMyMDA2MTVaFw0zMTEwMDUxMzU2NThaMDcxFTATBgNVBAoTDHNpZ3N0b3Jl
LmRldjEeMBwGA1UEAxMVc2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gQWBBRY
wB5fkUWlZql6zJChkyLQKsXF+jAfBgNVHSMEGDAWgBRYwB5fkUWlZql6zJChkyLQ
KsXF+jAKBggqhkjOPQQDAwNpADBmAjEAj1nHeXZp+13NWBNa+EDsDP8G1WWg1tCM
WP/WHPqpaVo0jhsweNFZgSs0eE7wYI4qAjEA2WB9ot98sIkoF3vZYdd3/VtWB5b9
TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ
-----END CERTIFICATE-----
# ...

@jleightcap
jleightcap requested a review from woodruffw March 4, 2023 01:08
@jleightcap
jleightcap marked this pull request as ready for review March 4, 2023 01:12
Comment thread sigstore/_internal/tuf.py Outdated
path = self._updater.download_target(target_info)
with open(path, "rb") as f:
data.append(f.read())
target_hash = f.read()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does the target_hash variable name come from? If I'm reading this right this variable actually holds the TUF targets' raw contents, not a hash.

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.

From #368,

[...] TrustUpdater to log the hash (and maybe even the cached file location)

Yeah, this should be called target_cert or something. Is there an additional field on the target I'm not aware of here that the issue is referring to -- as far as I can tell this is all the actual data flow being logged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you refer to my idea in the original issue:

the simplest thing might be for the TrustUpdater to log the hash (and maybe even the cached file location) of the artifacts

If that seems like a good idea, then you can just access target_info: it is of type TargetFile -- maybe something like f"Updated {target_info.path}: {target_info.hashes}" would work as a log line?

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.

Thanks for the docs. link, @jku 😄
Logging the whole cert is verbose, at one log level lower logging the sha256 then at debug the whole cert:

INFO:sigstore._internal.tuf:TUF cache target Fulcio ['Active', 'Expired']: fulcio_v1.crt.pem sha256 f989aa23def87c549404eadba767768d2a3c8d6d30a8b793f9f518a8eafd2cf5
DEBUG:sigstore._internal.tuf:TUF cache target fulcio_v1.crt.pem:
-----BEGIN CERTIFICATE-----
MIIB9zCCAXygAwIBAgIUALZNAPFdxHPwjeDloDwyYChAO/4wCgYIKoZIzj0EAwMw
KjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0y
MTEwMDcxMzU2NTlaFw0zMTEwMDUxMzU2NThaMCoxFTATBgNVBAoTDHNpZ3N0b3Jl
LmRldjERMA8GA1UEAxMIc2lnc3RvcmUwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAT7
XeFT4rb3PQGwS4IajtLk3/OlnpgangaBclYpsYBr5i+4ynB07ceb3LP0OIOZdxex
X69c5iVuyJRQ+Hz05yi+UF3uBWAlHpiS5sh0+H2GHE7SXrk1EC5m1Tr19L9gg92j
YzBhMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRY
wB5fkUWlZql6zJChkyLQKsXF+jAfBgNVHSMEGDAWgBRYwB5fkUWlZql6zJChkyLQ
KsXF+jAKBggqhkjOPQQDAwNpADBmAjEAj1nHeXZp+13NWBNa+EDsDP8G1WWg1tCM
WP/WHPqpaVo0jhsweNFZgSs0eE7wYI4qAjEA2WB9ot98sIkoF3vZYdd3/VtWB5b9
TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ
-----END CERTIFICATE-----

does that make sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM -- although I don't remember if all targets are text files... if they are not, then the decode may fail

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe they all are, although maybe that's a bad future-looking assumption for us to make. Maybe we should limit debug logging to targets that should always be text?

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.

Not being very familiar with the targets, does checking the target type and:

  • logging the contents, if a file (which we believe them all to be, for the moment)
  • log the type of the target, otherwise

make sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, all TUF targets are (conceptually) "files": a target is just a name and an associated bag of bytes.

The real underlying issue here (I think) is that not all TUF targets are guaranteed to be text; some might be binary instead. But that shouldn't be an issue with anything we currently attempt to retrieve for Sigstore purposes.

@woodruffw

Copy link
Copy Markdown
Member

/gcbrun

Comment thread sigstore/_internal/tuf.py Resolved
Signed-off-by: William Woodruff <[email protected]>
@woodruffw woodruffw mentioned this pull request Mar 7, 2023
@woodruffw
woodruffw enabled auto-merge (squash) March 8, 2023 14:59
@woodruffw
woodruffw merged commit 0ed9850 into main Mar 8, 2023
@woodruffw
woodruffw deleted the jl/368 branch March 8, 2023 15:00
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.

Improve (audit) logging of key/certificate material

3 participants