Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zhangyoufu
Copy link
Contributor

@zhangyoufu zhangyoufu commented Jul 22, 2024

Before #4096, the trusted keys always comes from rootcertbundle public keys, the kids are generated using libtrust's non-standard keyIDFromCryptoKey.

rootPool := x509.NewCertPool()
trustedKeys := make(map[string]libtrust.PublicKey, len(rootCerts))
for _, rootCert := range rootCerts {
rootPool.AddCert(rootCert)
pubKey, err := libtrust.FromCryptoPublicKey(crypto.PublicKey(rootCert.PublicKey))
if err != nil {
return nil, fmt.Errorf("unable to get public key from token auth root certificate: %s", err)
}
trustedKeys[pubKey.KeyID()] = pubKey
}

After #4096, the public keys of rootcertbundle is no longer trusted by default. The trusted keys must be configured via jwks option pointing to a JWKS (JSON Web Key Set) file.

rootPool := x509.NewCertPool()
for _, rootCert := range rootCerts {
rootPool.AddCert(rootCert)
}
trustedKeys := make(map[string]crypto.PublicKey)
if jwks != nil {
for _, key := range jwks.Keys {
trustedKeys[key.KeyID] = key.Public()
}
}

It is not trivial to extract public key from PEM format public key, convert it to JWK, append a libtrust flavor kid to the JWK, then compose a JWKS file. And in my opinion, this is the most troublesome part during my migration to distribution v3.

This change replicated keyid generation logic from libtrust, trusts public keys of rootcertbundle by default. It is intended to help more people migrates to distribution v3 without experiencing auth issues like #4299.

for the sake of backward compatibility

Fix distribution#4096
Fix distribution#4299

Signed-off-by: Youfu Zhang <[email protected]>
// SHA256(DER encoded ASN1)
// Then truncated to 240 bits and encoded into 12 base32 groups like so:
// ABCD:EFGH:IJKL:MNOP:QRST:UVWX:YZ23:4567:ABCD:EFGH:IJKL:MNOP
func libtrustKeyIDFromPublicKey(pubKey any) string {
Copy link
Member

Choose a reason for hiding this comment

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

the issue we had with libtrust is it does things that are not standardized anywhere like this ID generation func.

That was actually the main reason we went for explicit JWKs defined on the consumer side.

Copy link
Contributor Author

@zhangyoufu zhangyoufu Jul 22, 2024

Choose a reason for hiding this comment

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

The intention to introduce breaking changes should be guided by the goal of minimizing disruption. For instance, when implementing breaking changes in Go, there are multiple phases such as opt-in, opt-out, and eventual removal.

I agree that non-standard key id generation like this is not good. But libtrust is already gone, the key id generation in this PR is more likely mental burden instead of maintainance burden. A phased deprecation plan with decent migration guidance would be helpful to the community.

PS: The document still states that rootcertbundle is a required configuration option. If I understand correctly, it should be optionally after the introduce of jwks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants