-
Notifications
You must be signed in to change notification settings - Fork 27
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
Allow multiple private keys but use the latest one #1748
Open
h2zh
wants to merge
21
commits into
PelicanPlatform:main
Choose a base branch
from
h2zh:multiple-private-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…new private key(s) if new file(s) are detected
…ks that fix all problems happened in the unit tests
h2zh
added
enhancement
New feature or request
origin
Issue relating to the origin component
registry
Issue relating to the registry component
go
Pull requests that update Go code
security
labels
Nov 26, 2024
… behavior; linter problems fix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
go
Pull requests that update Go code
origin
Issue relating to the origin component
registry
Issue relating to the registry component
security
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
In issue #561, we want to rotate out old private key when the new one is provided. This PR mainly changed the functions chain starting from GetIssuerPrivateJWK(), in order to support multiple private key files in a new directory specified by a new config param
IssuerKeysDirectory
, along with a new goroutine to monitor the changes there every 5 mins.New Key
In this PR, admin can create new private key through either of the following two ways:
IssuerKeysDirectory
points to, which by default is/etc/pelican/issuer-keys
), or modify any .pem there. Pelican program will pick up the last modified .pem file through a goroutine running every 5 mins, set the private key it contains as the active one, add it to an in-memory map, and update the public key in registry sqlite db.Design thinking
Existing file hierarchy:
To ensure backward compatibility, the new directory that stores the private keys (saved as .pem files) is mounted to a new config param
IssuerKeysDirectory
. User doesn’t need to change the value ofIssuerKey
, though all functions are not longer using it. The private keyIssuerKey
refers to will be migrated to the new directory specified byIssuerKeysDirectory
. The new file hierarchy looks like this:Algorithm efficiency tradeoff
For a map using atomic.pointer, it requires to copy the entire map before update any key-value pair. In the
loadPEMFiles
func, because it runs every 5 minutes to update the in-memory key map from the file, which is not frequent, we think the memory use by a map using atomic.pointer is still acceptable.Test
No private key file
TODO
One existing private key file, adding a new private key
a) an existing private key file at config param
IssuerKey
(usually.../issuer.jwk
), adding a new private key manuallyb) an existing private key file at config param
IssuerKey
(usually.../issuer.jwk
), adding a new private key via APIc) an existing private key file at config param
IssuerKeysDirectory
(usually.../issuer-keys
), adding a new private key manuallyd) an existing private key file at config param
IssuerKeysDirectory
(usually.../issuer-keys
), adding a new private key via API--> result of any scenario in this section: in-memory active key: second; public key of this origin's namespaces in registry db: second
Two existing private key files
a) never run pelican before (empty registry db)
--> in-memory active key: second; public key of this origin's namespaces in registry db: second
b) first key is registered in registry db
--> in-memory active key: second; public key of this origin's namespaces in registry db: second
c) second key is registered in registry db
--> in-memory active key: second; public key of this origin's namespaces in registry db: second
d) second key is registered in registry db, adding the third key through API
--> in-memory active key: third; public key of this origin's namespaces in registry db: third
Note: "first", "second" key are keys in chronological order of their private key file modification time.
In-memory active key can be copied at the top-right key icon in origin webUI; db public key of this namespace can be found at the
registry.sqlite
file, whose directory is specified by config param Registry.DbLocation, or inetc/pelican
by defaultFuture work
At this moment, we use the most recent modified .pem file as the active private key. In the future, we want to allow multiple active private keys in use.
Eventually, when multiple origins have the same namespace, the admin of these origins can append a common private key to all. Then these origin servers will register the corresponding shared public key in the registry. Currently this operation needs to manually done by OSDF admin.