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

x/mod/sumdb: Server.ServeHTTP serves data tiles in different format than sum.golang.org #69348

Closed
mjl- opened this issue Sep 8, 2024 · 6 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done. proxy.golang.org
Milestone

Comments

@mjl-
Copy link

mjl- commented Sep 8, 2024

Go version

n/a (go1.23.1 on linux/amd64)

Output of go env in your module/workspace:

n/a

What did you do?

I used https://pkg.go.dev/golang.org/x/[email protected]/sumdb#Server.ServeHTTP to write a sumdb server for local testing.

I already had earlier code that parses data tiles (level -1 tiles) into records, and then verifies the hash of each record. It's part of gopherwatch, with the parsing at https://github.com/mjl-/gopherwatch/blob/3d50ff988dade2e571f3983c4194e451515a39d1/sums.go#L288. The parser is a bit sloppy, but it can verify the data tiles served by sum.golang.org.

Configuring gopherwatch to verify the data tiles of a sumdb server written with sumdb#Server.ServeHTTP was giving me unexpected verification errors (hashes of record data different than expected based on the tiles containing hashes).

It turns out that data tiles served by sum.golang.org have a different format than the data tiles served by golang.org/x/mod/sumdb.Server. In sumdb.Server, each record is prefixed with its record ID and a newline. On sum.golang.org they are not. The hashes of the records stored in the level 0 tiles are calculated over the record data without a record ID, that explains the errors I was seeing.

For example, a (random) data tile from sum.golang.org: https://sum.golang.org/tile/8/data/x115/673

It looks like this:

github.com/hewo233/cxsj_homework1 v0.0.0-20240826052307-bcb3e2e71e36 h1:QRoUMkmrcJluJBuUNVVVDUfaB1YyFlgbbZwDwrjPrss=
github.com/hewo233/cxsj_homework1 v0.0.0-20240826052307-bcb3e2e71e36/go.mod h1:6C5wTFANZQ6jZIu6UdOkia0qn8b4fQ+HFLF4CijMthE=

github.com/arkadiyt/bounty-targets-data v0.0.0-20240908180608-4f76f96365cf h1:vPLwkW3FLd+R2haNqSfa3CMizSYn2nSEaUyGg12aEeI=
github.com/arkadiyt/bounty-targets-data v0.0.0-20240908180608-4f76f96365cf/go.mod h1:0QqDOBpcXYlM/8MU2nsGjwvUOgJkKrVA/RA5hxf078s=

github.com/jaganathanb/dapps-api v0.0.0-20240617075156-dbbed11228b4 h1:IHcmr6+bukh2ZCyKbH2VkVfUsJGiwTYZKRbP7WCb7n8=
github.com/jaganathanb/dapps-api v0.0.0-20240617075156-dbbed11228b4/go.mod h1:ZBo/O1yJ08TwyEtzMQIQDL8dQz4vyLyW4m1Fss3WDDA=

...

However, a data tile served by sumdb.Server would look like this (note the extra number before the record data: the record id):

1234
github.com/hewo233/cxsj_homework1 v0.0.0-20240826052307-bcb3e2e71e36 h1:QRoUMkmrcJluJBuUNVVVDUfaB1YyFlgbbZwDwrjPrss=
github.com/hewo233/cxsj_homework1 v0.0.0-20240826052307-bcb3e2e71e36/go.mod h1:6C5wTFANZQ6jZIu6UdOkia0qn8b4fQ+HFLF4CijMthE=

1235
github.com/arkadiyt/bounty-targets-data v0.0.0-20240908180608-4f76f96365cf h1:vPLwkW3FLd+R2haNqSfa3CMizSYn2nSEaUyGg12aEeI=
github.com/arkadiyt/bounty-targets-data v0.0.0-20240908180608-4f76f96365cf/go.mod h1:0QqDOBpcXYlM/8MU2nsGjwvUOgJkKrVA/RA5hxf078s=

1236
github.com/jaganathanb/dapps-api v0.0.0-20240617075156-dbbed11228b4 h1:IHcmr6+bukh2ZCyKbH2VkVfUsJGiwTYZKRbP7WCb7n8=
github.com/jaganathanb/dapps-api v0.0.0-20240617075156-dbbed11228b4/go.mod h1:ZBo/O1yJ08TwyEtzMQIQDL8dQz4vyLyW4m1Fss3WDDA=

...

The data tiles are composed at https://github.com/golang/mod/blob/46a3137daeac7bd5e64dc5971191e4a7207e6d89/sumdb/server.go#L148,
using tlog.FormatRecord from https://github.com/golang/mod/blob/46a3137daeac7bd5e64dc5971191e4a7207e6d89/sumdb/tlog/note.go#L75.
The comment on that function also says that format is used by a data tile. That is true for sumdb.Server, but not for sum.golang.org.

The record format (with signature) is used in the responses to individual module lookups, e.g. https://sum.golang.org/lookup/github.com/mjl-/[email protected].

The Go tooling may not be parsing the data tiles, working only on lookups and the tiles containing hashes. But I think it would be good to have sumdb.Server serve the same format as sum.golang.org for data tiles, so clients that can process data tiles from sum.golang.org can also parse data tiles served by a sumdb.Server.

There could be concerns about compatibility: existing code may now depend on the format currently served by sumdb.Server. But parsing data tiles doesn't seem very common.

If the format of sumdb.Server is deemed better and should stay, it would be good to document this difference. Clients parsing the data tiles could then recognize both formats.

What did you see happen?

sumdb.Server.ServeHTTP serving data tiles in a format different from what sum.golang.org is serving.

What did you expect to see?

sumdb.Server.ServeHTTP serving data tiles in the same format as sum.golang.org.

@gopherbot gopherbot added this to the Unreleased milestone Sep 8, 2024
@timothy-king timothy-king added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 9, 2024
@timothy-king
Copy link
Contributor

CC @matloob @samthanawalla as owners of x/mod.

@adonovan
Copy link
Member

cc @rsc, as author of this package.

@FiloSottile
Copy link
Contributor

Thank you for the thorough report! Indeed, it looks like tlog.FormatRecord reflects the /lookup format but not the sumdb data tiles. I think the x/mod/sumdb package should mirror the sum.golang.org implementation, so I'm in favor of editing the comment of tlog.FormatRecord not to mention data tiles, and changing the served format of Server.ServeHTTP.

I doubt anyone is depending on the current format since no one noticed the discrepancy before.

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 12, 2024
@hyangah hyangah modified the milestones: Unreleased, Backlog Oct 3, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618135 mentions this issue: sumdb: make data tiles by Server compatible with sum.golang.org

@dmitshur dmitshur modified the milestones: Backlog, Unreleased Oct 18, 2024
gopherbot pushed a commit to golang/mod that referenced this issue Nov 1, 2024
Make the format of sumdb.Server data tile responses compatible with those
served by sum.golang.org: Like formatted records for the lookup endpoint, but
without each record IDs.

Updates documentation for sumdb/tlog.FormatRecord about data tiles.
Server still calls FormatRecord to keep the validation, then removes the first
line.

For golang/go#69348

Change-Id: I1bea45b3343c58acc90982aaff5d41e32b06ae8c
Reviewed-on: https://go-review.googlesource.com/c/mod/+/618135
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
@findleyr
Copy link
Member

findleyr commented Nov 7, 2024

@mjl- thanks for the CL. Should that have fixed this issue?

@mjl-
Copy link
Author

mjl- commented Nov 15, 2024

@findleyr yes, thanks! closing the issue.

@mjl- mjl- closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done. proxy.golang.org
Projects
None yet
Development

No branches or pull requests

9 participants