Skip to content

Commit 81200f7

Browse files
committed
oci/nodeNixosSvc: add kes agent cli arg support
1 parent 22b61a5 commit 81200f7

2 files changed

Lines changed: 60 additions & 10 deletions

File tree

nix/docker/context/node/bin/run-node

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ fi
4848

4949
# Block producer key defaults -- only relevant when CARDANO_BLOCK_PRODUCER=true
5050
if [[ $CARDANO_BLOCK_PRODUCER == true ]]; then
51-
if [[ -z ${CARDANO_SHELLEY_KES_KEY:-} ]]; then
51+
# Only default the KES key when not using a KES agent socket
52+
if [[ -z ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} && -z ${CARDANO_SHELLEY_KES_KEY:-} ]]; then
5253
CARDANO_SHELLEY_KES_KEY="$CARDANO_CONFIG_BASE/keys/kes.skey"
5354
fi
5455

@@ -81,7 +82,11 @@ printRunEnv () {
8182
[[ -n ${CARDANO_TRACER_SOCKET_PATH_CONNECT:-} ]] && echo "CARDANO_TRACER_SOCKET_PATH_CONNECT=$CARDANO_TRACER_SOCKET_PATH_CONNECT"
8283

8384
if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
84-
echo "CARDANO_SHELLEY_KES_KEY=$CARDANO_SHELLEY_KES_KEY"
85+
if [[ -n ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} ]]; then
86+
echo "CARDANO_SHELLEY_KES_AGENT_SOCKET=$CARDANO_SHELLEY_KES_AGENT_SOCKET"
87+
else
88+
echo "CARDANO_SHELLEY_KES_KEY=$CARDANO_SHELLEY_KES_KEY"
89+
fi
8590
echo "CARDANO_SHELLEY_VRF_KEY=$CARDANO_SHELLEY_VRF_KEY"
8691
echo "CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=$CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE"
8792
fi
@@ -99,7 +104,10 @@ cat << EOF > /usr/local/bin/env
99104
# Docker run ENV vars
100105
EOF
101106

102-
# TODO-SRE: Add kes-agent CLI arg once available
107+
if [[ -n ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} ]]; then
108+
echo "CARDANO_SHELLEY_KES_AGENT_SOCKET=\"$CARDANO_SHELLEY_KES_AGENT_SOCKET\"" \
109+
>> /usr/local/bin/env
110+
fi
103111

104112
if [[ -n ${CARDANO_TRACER_SOCKET_NETWORK_ACCEPT:-} ]]; then
105113
echo "CARDANO_TRACER_SOCKET_NETWORK_ACCEPT=\"$CARDANO_TRACER_SOCKET_NETWORK_ACCEPT\"" \
@@ -163,13 +171,20 @@ runNode () {
163171
)
164172

165173
if [[ $CARDANO_BLOCK_PRODUCER == true ]]; then
174+
if [[ -n ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} ]]; then
175+
effopts+=(
176+
"--shelley-kes-agent-socket" "$CARDANO_SHELLEY_KES_AGENT_SOCKET"
177+
)
178+
else
179+
effopts+=(
180+
"--shelley-kes-key" "$CARDANO_SHELLEY_KES_KEY"
181+
)
182+
fi
166183
effopts+=(
167-
"--shelley-kes-key" "$CARDANO_SHELLEY_KES_KEY"
168184
"--shelley-vrf-key" "$CARDANO_SHELLEY_VRF_KEY"
169185
"--shelley-operational-certificate" "$CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE"
170186
)
171187
fi
172-
173188
[[ -n ${CARDANO_TRACER_SOCKET_NETWORK_ACCEPT:-} ]] && effopts+=("--tracer-socket-network-accept" "$CARDANO_TRACER_SOCKET_NETWORK_ACCEPT")
174189
[[ -n ${CARDANO_TRACER_SOCKET_NETWORK_CONNECT:-} ]] && effopts+=("--tracer-socket-network-connect" "$CARDANO_TRACER_SOCKET_NETWORK_CONNECT")
175190
[[ -n ${CARDANO_TRACER_SOCKET_PATH_ACCEPT:-} ]] && effopts+=("--tracer-socket-path-accept" "$CARDANO_TRACER_SOCKET_PATH_ACCEPT")
@@ -203,6 +218,7 @@ do
203218
--socket-path) CARDANO_SOCKET_PATH=${val}; found=true;;
204219
--host-addr) CARDANO_BIND_ADDR=${val}; found=true;;
205220
--port) CARDANO_PORT=${val}; found=true;;
221+
--shelley-kes-agent-socket) CARDANO_SHELLEY_KES_AGENT_SOCKET=${val}; found=true;;
206222
--shelley-kes-key) CARDANO_SHELLEY_KES_KEY=${val}; found=true;;
207223
--shelley-vrf-key) CARDANO_SHELLEY_VRF_KEY=${val}; found=true;;
208224
--shelley-operational-certificate) CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=${val}; found=true;;
@@ -224,6 +240,11 @@ for arg in "${options[@]}"; do
224240
[[ -n $arg ]] && filteredOpts+=("$arg")
225241
done
226242

243+
if [[ -n ${CARDANO_SHELLEY_KES_KEY:-} && -n ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} ]]; then
244+
echo "ERROR: CARDANO_SHELLEY_KES_KEY and CARDANO_SHELLEY_KES_AGENT_SOCKET are mutually exclusive; use one or the other, not both."
245+
exit 1
246+
fi
247+
227248
printRunEnv
228249
writeRootEnv
229250

@@ -232,7 +253,10 @@ for f in "$CARDANO_CONFIG" "$CARDANO_TOPOLOGY"; do
232253
[[ -f $f ]] || { echo "ERROR: required file not found: $f"; exit 1; }
233254
done
234255
if [[ $CARDANO_BLOCK_PRODUCER == true ]]; then
235-
for f in "$CARDANO_SHELLEY_KES_KEY" "$CARDANO_SHELLEY_VRF_KEY" "$CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE"; do
256+
if [[ -z ${CARDANO_SHELLEY_KES_AGENT_SOCKET:-} ]]; then
257+
[[ -f $CARDANO_SHELLEY_KES_KEY ]] || { echo "ERROR: required block producer key file not found: $CARDANO_SHELLEY_KES_KEY"; exit 1; }
258+
fi
259+
for f in "$CARDANO_SHELLEY_VRF_KEY" "$CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE"; do
236260
[[ -f $f ]] || { echo "ERROR: required block producer key file not found: $f"; exit 1; }
237261
done
238262
fi

nix/nixos/cardano-node-service.nix

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ let
147147
"--shelley-kes-key ${cfg.kesKey}"}"
148148
"${optionalString (cfg.operationalCertificate != null)
149149
"--shelley-operational-certificate ${cfg.operationalCertificate}"}"
150+
"${optionalString (cfg.shelleyKesAgentSocket != null)
151+
"--shelley-kes-agent-socket ${cfg.shelleyKesAgentSocket}"}"
150152
];
151153
Cardano = [
152154
"${optionalString (cfg.signingKey != null)
@@ -159,6 +161,8 @@ let
159161
"--shelley-kes-key ${cfg.kesKey}"}"
160162
"${optionalString (cfg.operationalCertificate != null)
161163
"--shelley-operational-certificate ${cfg.operationalCertificate}"}"
164+
"${optionalString (cfg.shelleyKesAgentSocket != null)
165+
"--shelley-kes-agent-socket ${cfg.shelleyKesAgentSocket}"}"
162166
];
163167
};
164168
instanceDbPath = cfg.databasePath i;
@@ -449,6 +453,14 @@ in {
449453
'';
450454
};
451455

456+
shelleyKesAgentSocket = mkOption {
457+
type = nullOr (either str path);
458+
default = null;
459+
description = ''
460+
Path to the KES agent socket.
461+
'';
462+
};
463+
452464
socketPath = mkOption {
453465
type = funcToOr str;
454466
default = i : "${runtimeDir i}/node.socket";
@@ -909,8 +921,6 @@ in {
909921
`cardano-cli query ledger-peer-snapshot`
910922
'';
911923
};
912-
913-
# TODO-SRE: Add kes-agent CLI arg opts once available
914924
};
915925
};
916926

@@ -1022,8 +1032,24 @@ in {
10221032
as a prefix, for each instance!";
10231033
}
10241034
{
1025-
assertion = (cfg.kesKey == null) == (cfg.vrfKey == null) && (cfg.kesKey == null) == (cfg.operationalCertificate == null);
1026-
message = "Shelley Era: all of three [operationalCertificate kesKey vrfKey] options must be defined (or none of them).";
1035+
assertion = let
1036+
hasKes = cfg.kesKey != null;
1037+
hasVrf = cfg.vrfKey != null;
1038+
hasOpcert = cfg.operationalCertificate != null;
1039+
hasAgent = cfg.shelleyKesAgentSocket != null;
1040+
in
1041+
# (1) No forging: none of the four options set
1042+
(!hasKes && !hasVrf && !hasOpcert && !hasAgent)
1043+
# (2) Direct KES forging: kesKey + vrfKey + operationalCertificate, no agent socket
1044+
|| (hasKes && !hasAgent && hasVrf && hasOpcert)
1045+
# (3) KES agent forging: shelleyKesAgentSocket + vrfKey + operationalCertificate, no kesKey
1046+
|| (!hasKes && hasAgent && hasVrf && hasOpcert);
1047+
message = ''
1048+
Shelley Era: valid forging configurations are:
1049+
(1) none of [operationalCertificate kesKey vrfKey shelleyKesAgentSocket] (relay/non-producer node),
1050+
(2) all of [operationalCertificate kesKey vrfKey] without shelleyKesAgentSocket (direct KES key forging), or
1051+
(3) [operationalCertificate vrfKey shelleyKesAgentSocket] without kesKey (KES agent forging).
1052+
'';
10271053
}
10281054
{
10291055
assertion = !(cfg.systemdSocketActivation && (cfg.useNewTopology != false));

0 commit comments

Comments
 (0)