Skip to content

feat(jwt_issuer): add -priv-in flag to load existing private key from…#477

Open
leifj wants to merge 2 commits into
SUNET:mainfrom
sirosfoundation:feature/priv-in-flag
Open

feat(jwt_issuer): add -priv-in flag to load existing private key from…#477
leifj wants to merge 2 commits into
SUNET:mainfrom
sirosfoundation:feature/priv-in-flag

Conversation

@leifj

@leifj leifj commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

… file

Adds a -priv-in flag that allows specifying an existing private JWK file instead of generating a new key pair on every run. This is useful when you need a stable signing key across multiple invocations.

When -priv-in is not set, behavior is unchanged (new key generated).

… file

Adds a -priv-in flag that allows specifying an existing private JWK file
instead of generating a new key pair on every run. This is useful when
you need a stable signing key across multiple invocations.

When -priv-in is not set, behavior is unchanged (new key generated).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support to developer_tools/scripts/jwt_issuer for reusing an existing private signing key across runs by introducing a new -priv-in flag that loads a private JWK from disk instead of generating a fresh key each invocation. This improves stability for repeated testing against api_server.api_auth.jwks setups where a consistent signing key is required.

Changes:

  • Add -priv-in flag to load an existing private JWK (otherwise keep existing “generate new key” behavior).
  • Update the README with an example invocation and the new flag in the flags table.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
developer_tools/scripts/jwt_issuer/README.md Documents the new -priv-in option and provides a usage example.
developer_tools/scripts/jwt_issuer/main.go Implements loading a private JWK from a file when -priv-in is set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +53 to +57
privJWK, err = jwk.ParseKey(privJSON)
if err != nil {
fatal("parse private key: %v", err)
}
fmt.Printf("Private key loaded from %s\n", *privInFile)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feedback makes sense!

@s-jairl s-jairl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comment from Copilot - otherwise good!

@leifj

leifj commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +53 to +57
privJWK, err = jwk.ParseKey(privJSON)
if err != nil {
fatal("parse private key: %v", err)
}
fmt.Printf("Private key loaded from %s\n", *privInFile)

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.

Fixed in 373ce75 — after parsing, we now export to ecdsa.PrivateKey and verify the curve is P-256. This catches public-only keys, wrong kty, and wrong curves immediately.

Comment on lines 29 to 33
jwtFile := flag.String("jwt-out", "token.jwt", "output file for the signed JWT")
jwkFile := flag.String("jwk-out", "jwks.json", "output file for the JWKS (public keys)")
privFile := flag.String("priv-out", "", "output file for the private JWK (optional)")
privInFile := flag.String("priv-in", "", "input file for an existing private JWK (optional, generates new key if not set)")

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.

Fixed in 373ce75 — added a guard that checks all output paths against -priv-in before proceeding.

- Validate that -priv-in contains an EC P-256 private key immediately
  after parsing, failing fast with a clear error for wrong key type,
  curve, or public-only keys.
- Guard against output files (-jwt-out, -jwk-out, -priv-out) matching
  -priv-in, preventing accidental overwrite of the private key.
@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants