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

Use mlocked KES internally #1374

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

tdammers
Copy link

This changes Consensus such that mlocked KES keys are used internally.

This is important groundwork for supporting KES agents in the future. In this form, the code will still load KES keys from disk, which is unsound, but the internal machinery is ready to also accept KES keys from other sources, and once loaded, KES keys will be handled appropriately (kept in mlocked RAM at all times, securely erased when expired).

This also involves a restructuring of the HotKey data structure, which now manages not only a KES SignKey, but also the corresponding OpCert. This is necessary for two reasons:

  • With a KES agent, the OpCert will be provided along with the SignKey; this is the easiest way to make sure that the OpCert always matches the SignKey it is used with
  • With the new structure, KES keys can be replaced in a live node kernel, without having to restart it and reload the entire configuration. Because of this, the HotKey, which manages the dynamic part of the node kernel's signing mechanism, needs to be able to replace not just the SignKey (which it already did, in order to handle key evolution), but also the OpCert (which will not change when a SignKey evolves, but it will change when a new SignKey is provided).

Supersedes #1284.

@tdammers tdammers force-pushed the tdammers/mlocked-kes-rebase branch from d7d3c8f to 3c994f0 Compare January 30, 2025 09:44
@tdammers tdammers force-pushed the tdammers/mlocked-kes-rebase branch from 3c994f0 to cfddb02 Compare January 30, 2025 10:15
@tdammers tdammers marked this pull request as ready for review February 12, 2025 15:49
@@ -143,6 +143,9 @@ data BlockForging m blk = BlockForging {
-> [Validated (GenTx blk)] -- Transactions to include
-> IsLeader (BlockProtocol blk) -- Proof we are leader
-> m blk

, finalize :: m ()
Copy link
Contributor

@jasagredo jasagredo Feb 12, 2025

Choose a reason for hiding this comment

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

What is this "finalizing"? (please add some haddocks here too)

@@ -108,6 +109,10 @@ data family CodecConfig blk :: Type
-- avoid circular dependencies.
data family StorageConfig blk :: Type

-- | Credentials needed for block forging. In eras that use KES, this will be
-- a pair of KES sign key and OpCert; in other eras, it should be 'Void'.
type family BlockForgingCredentials blk :: Type
Copy link
Contributor

Choose a reason for hiding this comment

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

This is defined here, and for the HFBlock, but nowhere else?

@@ -77,6 +77,8 @@ deriving stock instance CanHardFork xs => Show (LedgerState (HardForkBlock xs)
deriving stock instance CanHardFork xs => Eq (LedgerState (HardForkBlock xs))
deriving newtype instance CanHardFork xs => NoThunks (LedgerState (HardForkBlock xs))

type instance BlockForgingCredentials (HardForkBlock '[blk]) = BlockForgingCredentials blk
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

@@ -11,6 +11,7 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary?

hardForkFinalize :: (Monad m, All Top xs)
=> NonEmptyOptNP (BlockForging m) xs -> m ()
hardForkFinalize blockForging =
-- pure ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

@@ -475,12 +476,12 @@ protocolInfoCardano paramsCardano
, length credssShelleyBased > 1
= error "Multiple Shelley-based credentials not allowed for mainnet"
| otherwise
= assertWithMsg (validateGenesis genesisShelley)
= assertWithMsg (validateGenesis genesisShelley) $
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
= assertWithMsg (validateGenesis genesisShelley) $
= assertWithMsg (validateGenesis genesisShelley)

Comment on lines +41 to +43
, ProtocolParamsByron
, ProtocolParamsShelleyBased
, CheckpointsMap
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these exported? They are not new to this PR

Comment on lines +5 to +11
- Change `HotKey` to manage not only KES sign keys, but also the corresponding
OpCerts. This is in preparation for KES agent connectivity: with the new
design, the KES agent will provide both KES sign keys and matching OpCerts
together, and we need to be able to dynamically replace them both together.
- Add finalizer to `HotKey`. This takes care of securely forgetting any KES
keys the HotKey may still hold, and will be called automatically when the
owning block forging terminates.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this done in the protocol package instead?

Comment on lines +16 to +18
- The `KesKey` data type in `unstable-cardano-tools` has been renamed to
`UnsoundPureKesKey`, to reflect the fact that it uses the old, unsound KES
API (which does not use mlocking or secure forgetting).
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't reflect these changes in the changelog

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure we want to merge this as is. If we did so Consensus would be unreleasable until those other dependencies are released. I think we should wait until there are no more source-repository-package stanzas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

3 participants