Skip to content

make sure the standard algorithms are registered#64

Merged
vbatts merged 1 commit intoopencontainers:masterfrom
thaJeztah:fix_algorithms_not_being_registered
Aug 18, 2021
Merged

make sure the standard algorithms are registered#64
vbatts merged 1 commit intoopencontainers:masterfrom
thaJeztah:fix_algorithms_not_being_registered

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

This makes sure that the expected algorithms are registered when using this package.

Currently, the consumer of the package must import these, otherwise it's not registered, resultig in "unsupported digest algorithm" errors.

relates to moby/moby#42755 (comment)

@thaJeztah thaJeztah requested a review from vbatts August 18, 2021 14:21
@thaJeztah
Copy link
Copy Markdown
Member Author

@vbatts @dmcgowan PTAL 🤗

Copy link
Copy Markdown
Member

@vbatts vbatts left a comment

Choose a reason for hiding this comment

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

LGTM

I could only guess that some implementations may want to choose to import those explicit packages, but that probably doesn't matter here.

@thaJeztah
Copy link
Copy Markdown
Member Author

Yeah, I was a bit in doubt, but these seem to be the "minimum" set of them, so I thought it made sense to include them automatically.

I stumbled on it when I removed the import in one of our utilities, and as a side-effect, things broke in completely unrelated areas 😂

@AkihiroSuda AkihiroSuda requested a review from dmcgowan August 18, 2021 15:36
@thaJeztah
Copy link
Copy Markdown
Member Author

I just found that moby is using v1.0.0, which does not yet have this change, this is only in master/main:

go-digest/sha.go

Lines 7 to 17 in b9e02e0

const (
SHA256 Algorithm = "sha256" // sha256 with hex encoding (lower case only)
SHA384 Algorithm = "sha384" // sha384 with hex encoding (lower case only)
SHA512 Algorithm = "sha512" // sha512 with hex encoding (lower case only)
)
func init() {
RegisterAlgorithm(SHA256, crypto.SHA256)
RegisterAlgorithm(SHA384, crypto.SHA384)
RegisterAlgorithm(SHA512, crypto.SHA512)
}

Would that already be enough? (need to try that)
Discussing with @dmcgowan on slack, and if we still need the imports, it's probably clearer to move it to that file.

Let me push a quick test commit

@thaJeztah
Copy link
Copy Markdown
Member Author

Ok, they're needed; I'm moving them to the sha.go file

This makes sure that the expected algorithms are registered when
using this package.

Currently, the consumer of the package must import these, otherwise it's
not registered, resultig in "unsupported digest algorithm" errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the fix_algorithms_not_being_registered branch from ec210b1 to 084376b Compare August 18, 2021 21:45
@thaJeztah
Copy link
Copy Markdown
Member Author

thaJeztah commented Aug 18, 2021

We were discussing if SHA512 should be enabled automatically, as it's generally not "recommended" (doesn't add much over SHA256), but it looks to be mentioned in the spec, so we should probably keep it by default; https://github.com/opencontainers/image-spec/blob/083f635f2b04f7f340685a1e0c4393a0feec3679/descriptor.md#registered-algorithms

@dmcgowan
Copy link
Copy Markdown
Member

Thanks, the update looks good. Considering the algorithms are expected to be registered for the image-spec, it makes sense to do them here since they are registered as part of the base package. If we had wanted to separate them out, then putting them in sub-packages (such as with blake) would have been the way to do it. My nit now requires someone else to LGTM it again though, sorry 😉

@thaJeztah
Copy link
Copy Markdown
Member Author

Side note: looks like pullaprove configuration is out of sync with the active list of maintainers;

Screenshot 2021-08-19 at 00 12 38

We should remove it in favour of GitHub's required checks

@dmcgowan
Copy link
Copy Markdown
Member

The list is based on the Github team which is not in sync, so not exactly pullapprove's fault. However, we have had issues with it in the past and it doesn't offer us anything that Github doesn't already give us now.

Copy link
Copy Markdown
Member

@vbatts vbatts left a comment

Choose a reason for hiding this comment

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

🥑

@vbatts vbatts merged commit e9915b9 into opencontainers:master Aug 18, 2021
@thaJeztah thaJeztah deleted the fix_algorithms_not_being_registered branch August 18, 2021 22:40
thaJeztah added a commit to thaJeztah/docker that referenced this pull request Jan 14, 2025
commit 572498b moved the ioutils.HashData
utility to the libnetwork resolvconf package.

After removing, we saw some tests  in the reference  pacakge failing;

    === Failed
    === FAIL: reference TestLoad (0.00s)
        store_test.go:53: failed to parse reference: unsupported digest algorithm

    === FAIL: reference TestSave (0.00s)
        store_test.go:82: failed to parse reference: unsupported digest algorithm

    === FAIL: reference TestAddDeleteGet (0.00s)
        store_test.go:174: could not parse reference: unsupported digest algorithm

    === FAIL: reference TestInvalidTags (0.00s)
        store_test.go:355: assertion failed: error is not nil: unsupported digest algorithm

Those failures were because those tests depended on a side-effect of the
ioutils package being imported, which (before removal of HashData) imported
crypto/sha256, registering that algorithms, which on its turn was used by
github.com/opencontainers/go-digest to determnin if a given algorithm must
be accepted (see [go-digest#64]).

As a workaround, these imports were added. pkg/ioutils is now imported
in less places, and should not be depended on for this purpose.

Let's remove this workaround; if needed, these imports can be added in
a more relevant location.

This reverts commit 98caf09.

[go-digest#64]: opencontainers/go-digest#64

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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.

4 participants