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

pelican generate keygen creates invalid public keys #2084

Closed
jhiemstrawisc opened this issue Mar 7, 2025 · 3 comments · Fixed by #2085
Closed

pelican generate keygen creates invalid public keys #2084

jhiemstrawisc opened this issue Mar 7, 2025 · 3 comments · Fixed by #2085
Assignees
Labels
bug Something isn't working client Issue affecting the OSDF client
Milestone

Comments

@jhiemstrawisc
Copy link
Member

It looks like the pelican generate keygen command is creating public keys that don't have a kid or an alg field, both of which are required for token verification.

From @brianaydemir:

[baydemir@local Desktop]> pelican generate keygen --private-key foo --public-key bar
Successfully generated keys at: 
Private key: foo
Public Key: bar
[baydemir@local Desktop]> cat foo 
-----BEGIN PRIVATE KEY-----
<keep it secret, keep it safe>
-----END PRIVATE KEY-----
[baydemir@local Desktop]> cat bar 
{
        "keys": [
                {
                        "crv": "P-256",
                        "kty": "EC",
                        "x": "IzQKHe5_dg1J97rdyNgmjTjoEaiFtjG9eHdtctXmDsU",
                        "y": "zV1uxDLfu6AQh9oTHEsx-I14ffZaxNO1LvSBPvEH0hU"
                }
        ]
}[baydemir@local Desktop]> pelican --version
Version: 7.14.0
Build Date: 2025-03-05T17:39:03Z
Build Commit: 7bb5a5a4b1bae77fdf09b4c0ad9d1afffb22a98c
Built By: goreleaser

Brian also reports that testing this command with Pelican v7.9.X generates a valid public key, so the fix here should really have a regression test.

@jhiemstrawisc
Copy link
Member Author

I'll further note that starting an origin locally does result in a valid public key at <origin url>/.well-known/issuer.jwks, so there must be drift in the way we're producing these keys. Let's make sure they're all driven by the same function when we implement a fix.

@brianaydemir
Copy link
Contributor

7.13.1 is affected by this bug. 7.12.4 is not affected.

@brianaydemir
Copy link
Contributor

In 7.12.4 and earlier, generate keygen relied on the same machinery as the server initialization flow:

viper.Set(param.IssuerKey.GetName(), privateKeyPath)
// GetIssuerPublicJWKS will generate the private key at IssuerKey if it does not exist
// and parse the private key and generate the corresponding public key for us
pubkey, err := config.GetIssuerPublicJWKS()

In 7.13, the command was updated with its own key generation flow, because the server now initializes a directory of private keys. While I'm having trouble groking the code flow, I suspect something like the following got dropped in the process:

// Add the algorithm to the key, needed for verifying tokens elsewhere
err = key.Set(jwk.AlgorithmKey, jwa.ES256)
if err != nil {
return nil, errors.Wrap(err, "Failed to add alg specification to key header")
}
// Assign key id to the private key so that the public key obtainer thereafter
// has the same kid
err = jwk.AssignKeyID(key)
if err != nil {
return nil, errors.Wrap(err, "Failed to assign key ID to private key")
}

@brianaydemir brianaydemir added bug Something isn't working client Issue affecting the OSDF client labels Mar 7, 2025
@brianaydemir brianaydemir self-assigned this Mar 7, 2025
@brianaydemir brianaydemir added this to the v7.15 milestone Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working client Issue affecting the OSDF client
Projects
None yet
2 participants