manta-node 0.6b6.dev846__py3-none-any.whl → 0.6b6.dev850__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ This file is auto-generated at build time by scripts/generate_version.py.
4
4
  Do not edit manually.
5
5
  """
6
6
 
7
- __version__ = "2026.11.10.3bb2e6d0"
8
- __build_date__ = "2026.11.10"
9
- __commit_id__ = "3bb2e6d0"
7
+ __version__ = "2026.11.13.086befb4"
8
+ __build_date__ = "2026.11.13"
9
+ __commit_id__ = "086befb4"
10
10
  __package_version__ = "0.6b6" # release-series base, moved by scripts/bump_version.py
@@ -1,9 +1,6 @@
1
1
  import asyncio
2
- import base64
3
2
  import inspect
4
- import json
5
3
  import os
6
- import re
7
4
  import time
8
5
  from collections.abc import Awaitable, Callable
9
6
  from dataclasses import dataclass
@@ -48,6 +45,7 @@ from ..filesystem.dataset_manager import DatasetManager
48
45
  from ..grpc.client import NodeClient
49
46
  from ..metrics.collector import Collector
50
47
  from ..metrics.metrics_collector import MetricsCollectorBase
48
+ from ..security.auth_agent import node_id_from_token
51
49
  from ..security.broker_certificate import BrokerCertificateStore
52
50
 
53
51
  TIMEOUT = 1 # s
@@ -63,11 +61,13 @@ _CONNACK_IDENTITY_REFUSALS = frozenset({0x85, 0x86, 0x87, 0x8C})
63
61
 
64
62
  @dataclass(frozen=True)
65
63
  class CertificateBroker:
66
- """The certificate-only listener and the folder of the node's certificate."""
64
+ """The certificate-only listener, the folder of the node's certificate, and
65
+ the node id its CN must name."""
67
66
 
68
67
  host: str
69
68
  port: int
70
69
  folder: Path
70
+ node_id: str
71
71
 
72
72
 
73
73
  # A restarted node replays the request that restarted it until the supervisor
@@ -106,30 +106,6 @@ def _mqtt_reason_code(exc: Exception) -> int | None:
106
106
  return None
107
107
 
108
108
 
109
- _NODE_ID_CLAIM_PATTERN = re.compile(r"^[0-9a-fA-F]{24}$")
110
-
111
-
112
- def _node_id_from_token(secured_token: str) -> str | None:
113
- """Return the 24-hex ``node_id`` claim from a JWT payload, else None.
114
-
115
- Reads the payload without verifying the signature: the node trusts the
116
- manager-minted token it already holds. Never logs the token.
117
- """
118
- try:
119
- _, payload, _ = secured_token.split(".", 2)
120
- except ValueError:
121
- return None
122
- try:
123
- padded = payload + "=" * (-len(payload) % 4)
124
- claims = json.loads(base64.urlsafe_b64decode(padded))
125
- except (ValueError, UnicodeDecodeError):
126
- return None
127
- node_id = claims.get("node_id") if isinstance(claims, dict) else None
128
- if not isinstance(node_id, str) or not _NODE_ID_CLAIM_PATTERN.fullmatch(node_id):
129
- return None
130
- return node_id
131
-
132
-
133
109
  class CommandHandler(Collector, MqttBase):
134
110
  """
135
111
  CommandHandler class to handle commands from the Manager.
@@ -216,7 +192,7 @@ class CommandHandler(Collector, MqttBase):
216
192
 
217
193
  # Never expose the cluster JWT as the client id: derive it from the node_id claim.
218
194
  client_id = ID(
219
- _node_id_from_token(node_client.secured_token)
195
+ node_id_from_token(node_client.secured_token)
220
196
  or b2x(node_client.secured_token.encode())
221
197
  )
222
198
 
@@ -291,9 +267,11 @@ class CommandHandler(Collector, MqttBase):
291
267
  same certificate in date and fail again, a crash loop under a supervisor.
292
268
  """
293
269
  broker = cast(CertificateBroker, self._certificate_broker)
294
- if not BrokerCertificateStore(broker.folder).has_usable_certificate():
270
+ if not BrokerCertificateStore(broker.folder).has_usable_certificate(
271
+ broker.node_id
272
+ ):
295
273
  self._fall_back_to_password_listener(
296
- f"the node certificate in {broker.folder} is no longer in date"
274
+ f"the node certificate in {broker.folder} is no longer usable"
297
275
  )
298
276
  return
299
277
  reason_code = _mqtt_reason_code(exc)
@@ -63,7 +63,9 @@ _ESCALATION_THRESHOLD = 3
63
63
  _MAX_BACKOFF_SECONDS = 300.0
64
64
  _BACKOFF_BASE_SECONDS = 5.0
65
65
 
66
- _NODE_ID_CLAIM_PATTERN = re.compile(r"^[0-9a-fA-F]{24}$")
66
+ # The manager's node id is a 128-bit hex string of up to 32 characters, the id
67
+ # the MQTT topics and the broker certificate's CN use. Never narrow it.
68
+ _NODE_ID_CLAIM_PATTERN = re.compile(r"^[0-9a-fA-F]{1,32}$")
67
69
 
68
70
 
69
71
  def _decode_claims(token: str) -> dict | None:
@@ -100,7 +102,7 @@ def decode_exp(token: str) -> float | None:
100
102
 
101
103
 
102
104
  def node_id_from_token(token: str) -> str | None:
103
- """Return the 24-hex ``node_id`` claim, or ``None``."""
105
+ """Return the hex ``node_id`` claim, up to 32 characters, or ``None``."""
104
106
  claims = _decode_claims(token)
105
107
  node_id = claims.get("node_id") if claims else None
106
108
  if not isinstance(node_id, str) or not _NODE_ID_CLAIM_PATTERN.fullmatch(node_id):
@@ -33,6 +33,12 @@ def _public_bytes(public_key) -> bytes:
33
33
  )
34
34
 
35
35
 
36
+ def _common_name(certificate: x509.Certificate) -> str:
37
+ names = certificate.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
38
+ value = names[0].value if names else ""
39
+ return value if isinstance(value, str) else value.decode()
40
+
41
+
36
42
  class BrokerCertificateStore:
37
43
  """The node's key and broker certificate in one folder.
38
44
 
@@ -48,8 +54,14 @@ class BrokerCertificateStore:
48
54
  self.key_path = folder / KEY_FILE
49
55
  self.certificate_path = folder / CERTIFICATE_FILE
50
56
 
51
- def has_usable_certificate(self, now: datetime | None = None) -> bool:
52
- """Whether the stored certificate exists, is in date, and matches the key."""
57
+ def has_usable_certificate(self, node_id: str, now: datetime | None = None) -> bool:
58
+ """Whether the stored certificate exists, is in date, matches the key,
59
+ and names ``node_id`` as its CN.
60
+
61
+ A certificate for another node id, left by an earlier registration on
62
+ this machine, would connect as that node: the broker takes the CN as
63
+ the node's identity.
64
+ """
53
65
  try:
54
66
  key = self._load_key()
55
67
  certificate = x509.load_pem_x509_certificate(
@@ -57,6 +69,8 @@ class BrokerCertificateStore:
57
69
  )
58
70
  except (OSError, ValueError, TypeError):
59
71
  return False
72
+ if not node_id or _common_name(certificate).lower() != node_id.lower():
73
+ return False
60
74
  now = now or datetime.now(timezone.utc)
61
75
  if not (
62
76
  certificate.not_valid_before_utc <= now < certificate.not_valid_after_utc
@@ -578,16 +578,9 @@ class Node:
578
578
 
579
579
  # After the node client holds the node token: the certificate call
580
580
  # names the node by that token.
581
- certificate_folder = await self._node_certificate_folder(
581
+ certificate_broker = await self._certificate_broker(
582
582
  registration, node_token
583
583
  )
584
- certificate_broker = None
585
- if certificate_folder is not None:
586
- certificate_broker = CertificateBroker(
587
- host=registration.mqtt_certificate_broker_host,
588
- port=registration.mqtt_certificate_broker_port,
589
- folder=certificate_folder,
590
- )
591
584
 
592
585
  # Ensure light service port is assigned
593
586
  self._ensure_light_service_port()
@@ -699,10 +692,11 @@ class Node:
699
692
  await self.stop()
700
693
  raise NodeFatalError(f"[ERROR] {message}") from exc
701
694
 
702
- async def _node_certificate_folder(
695
+ async def _certificate_broker(
703
696
  self, registration: Registration, node_token: str
704
- ) -> Path | None:
705
- """The folder of a usable node certificate, or None for the password path.
697
+ ) -> CertificateBroker | None:
698
+ """The certificate listener with a usable node certificate, or None for
699
+ the password path.
706
700
 
707
701
  With ``security.node_certificate`` on, a node that holds no usable
708
702
  certificate requests one over its node token (#546). Every failure
@@ -720,19 +714,28 @@ class Node:
720
714
  )
721
715
  return None
722
716
 
723
- store = BrokerCertificateStore(
724
- Path(self.config.security.node_certificate_folder).expanduser()
725
- )
726
- if store.has_usable_certificate():
727
- self.tracer.info(f"Using the node certificate in {store.folder}")
728
- return store.folder
729
-
730
717
  node_id = node_id_from_token(node_token)
731
718
  if node_id is None:
732
719
  self.tracer.warning(
733
720
  "The node token carries no node id; using the broker password"
734
721
  )
735
722
  return None
723
+ store = BrokerCertificateStore(
724
+ Path(self.config.security.node_certificate_folder).expanduser()
725
+ )
726
+ broker = CertificateBroker(
727
+ host=registration.mqtt_certificate_broker_host,
728
+ port=registration.mqtt_certificate_broker_port,
729
+ folder=store.folder,
730
+ node_id=node_id,
731
+ )
732
+ if store.has_usable_certificate(node_id):
733
+ self.tracer.info(f"Using the node certificate in {store.folder}")
734
+ return broker
735
+
736
+ # A certificate for another node id is replaced, its key kept: the
737
+ # manager refuses a new key for a node that already holds a
738
+ # certificate, so discarding the key could strand this node.
736
739
  try:
737
740
  request = NodeCertificateRequest(
738
741
  certificate_request_pem=store.certificate_request(node_id)
@@ -749,7 +752,7 @@ class Node:
749
752
  )
750
753
  return None
751
754
  self.tracer.info(f"Node certificate issued and stored in {store.folder}")
752
- return store.folder
755
+ return broker
753
756
 
754
757
  async def stop(self) -> None:
755
758
  """Stop the node"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: manta_node
3
- Version: 0.6b6.dev846
3
+ Version: 0.6b6.dev850
4
4
  Summary: Node side software of the Manta platform. It is responsible for the communication with the Manta Core and the execution of the tasks.
5
5
  Author-email: Hugo Miralles <hugo.miralles@manta-tech.io>, Matthew Thompson <matthew.thompson@manta-tech.io>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -1,13 +1,13 @@
1
1
  manta_node/__init__.py,sha256=bgGWXH3yQVhNf0v1ZGUBAy5Y51fqb0Y-EaLnocbcino,153
2
2
  manta_node/__main__.py,sha256=SjrJyuMg_ZFKV6WOVe3MrtWM8Qmu065dkKZYl4n2YLw,1665
3
- manta_node/node_orchestrator.py,sha256=7pPDYFgTUCMJnkfV7eLPF3Lo1mZA0k8vHYFkaK-NokU,32936
3
+ manta_node/node_orchestrator.py,sha256=d6oPblvea4dJ8mwezRUtExg-XxkKWpbD9hml4O_uCeo,33056
4
4
  manta_node/seam.py,sha256=nGLjNVlSrnRJPdrp7L8piyJai1bQveiqT5JDBWeFeGI,6501
5
5
  manta_node/task_manager.py,sha256=xRE-yKdUW0FFR8vtX1jDwl1AxTbqVD_JS7QVR62GA00,38002
6
6
  manta_node/tasks.py,sha256=o837Hi-KFVJg9LF5iOtE8oD6UuTOfrEPWR-JOdhRGeY,6983
7
7
  manta_node/update_path.py,sha256=6N_bN9z8MqnyWWfGTe1-aJFijf2tSy_IvO6VHvNSQVU,1667
8
8
  manta_node/utils.py,sha256=Hw4Iw2jYQYsfVLVJuBMt-_rMFBeml3nCDE2jiiXc8YM,1155
9
9
  manta_node/cli/__init__.py,sha256=arzO3mXDJ-E2yeeytbZfN7mCswwxdQ43_QjyeL2E5yE,134
10
- manta_node/cli/_version_generated.py,sha256=TnJT-Dw3DTO5FBfZd7vudq_lbbjicHTJEbc3n3TSO3o,332
10
+ manta_node/cli/_version_generated.py,sha256=l_LAoTb-qg0rFstCDRbZ1bi2_MuQYo4yd0GlfolDQwM,332
11
11
  manta_node/cli/config_manager.py,sha256=BCju9zqzraviL3KrzRnB-vZQUY__Q5kuEqb7EdB8YdI,4409
12
12
  manta_node/cli/main.py,sha256=dZa6zrypWBvpN8hd4qpxevvlyNFhxKINCg1537NJ36w,4318
13
13
  manta_node/cli/version.py,sha256=L4lNTz-Uw_ejumy1tXJcJhcjhb-5FRcRQ6ogZM5N1Xo,5136
@@ -42,7 +42,7 @@ manta_node/infrastructure/metrics/__init__.py,sha256=ODGAj9s63F5jba2c3dQRMfNK6I4
42
42
  manta_node/infrastructure/metrics/collector.py,sha256=9ESw__Pc2tV6ldG5yhos2IS7T5Td59KxTIwDRZc_G4w,3067
43
43
  manta_node/infrastructure/metrics/metrics_collector.py,sha256=osIYrNzU3g9WCAxVQ14isM9YEQ3eJ7F3QgKBbpgeMJs,13077
44
44
  manta_node/infrastructure/mqtt/__init__.py,sha256=riXo1sXgO4YV6DHCmWRqK61BAmuGLdHiVdQFunAJadA,140
45
- manta_node/infrastructure/mqtt/command_handler.py,sha256=X2fu_ZLIZNbXrDCOUaVkf82o2m25R9S5w0Ev3ZO5V-c,43321
45
+ manta_node/infrastructure/mqtt/command_handler.py,sha256=CDrd6tHX8zs6z8cgdn3ymyRB-_0ebU1WQKZ4HhajWGo,42588
46
46
  manta_node/infrastructure/network/__init__.py,sha256=On3XLgycFQoc-fBCa5hFuFDfEJjmFy7Wl2CK3D2LkdI,478
47
47
  manta_node/infrastructure/network/event_registry.py,sha256=iWEfUJRzDnWjOrDinpYqVyIUpGKJjp7RZkjMDPfpplM,1661
48
48
  manta_node/infrastructure/network/factory.py,sha256=-LvHbBp5nBpQ7fyQT1T0pvK3aczZqWc9QNDW37brBeU,3897
@@ -51,8 +51,8 @@ manta_node/infrastructure/network/wireguard_provider.py,sha256=1U4wbpxG3fQng6d5d
51
51
  manta_node/infrastructure/process/__init__.py,sha256=MpKkA3k-6ND-Nb7uyzrpw8MdQssQQ6NaiUTLuLnzNbE,53
52
52
  manta_node/infrastructure/process/executor.py,sha256=Ab1XvNuelEGCD5KdZLgYYnpjYZ5dpKRKOzRWL68AxQg,11601
53
53
  manta_node/infrastructure/security/__init__.py,sha256=lI6vkbUmfmt0m363iO4HzuzVNoQAc7Clp2R5vAhZbgE,64
54
- manta_node/infrastructure/security/auth_agent.py,sha256=WkPTg_g0gix7xomb_on_Ft3TNX0FpeqS7gwgJW9mTvk,11037
55
- manta_node/infrastructure/security/broker_certificate.py,sha256=xY2T7CF7sxGXVp7nZeQpHw34PS9Ylz4_JYrtOD2xzKg,5341
54
+ manta_node/infrastructure/security/auth_agent.py,sha256=ScQbxMOkib6Z2aiPLeWL_4T9JHZKipt7vxGnnhh1Cj8,11208
55
+ manta_node/infrastructure/security/broker_certificate.py,sha256=1mpYM6amCxAWL_1wsIpVbzSatYBA10IfOkoYkuoYBKM,5932
56
56
  manta_node/infrastructure/security/token_provider.py,sha256=u3bcbQYNBskFzunO-wOSZpGkDN_CU1BCB5HUbZTC4Vg,1832
57
57
  manta_node/supervisor/__init__.py,sha256=kgdoNce1tM4e7jvdxkdmnNJV1L92-NI2cRfYSdm9vsw,542
58
58
  manta_node/supervisor/bounds.py,sha256=MlUfj0tYY-US348JsxYA-Ph5pSpgoOPlRdVTwmrPtZA,3181
@@ -64,9 +64,9 @@ manta_node/supervisor/records.py,sha256=O1YjNN2bH1xzOJo_3l1G6FRvWo1CmdAfvSDJBj6s
64
64
  manta_node/supervisor/seam.py,sha256=4kczRku5Ctn4xRvXS-pyzaDFau7LnX5bYOn6IRNKRyE,9665
65
65
  manta_node/supervisor/sequence.py,sha256=eYu7rrk1ecc4Y2jQhhJ7CopPz3m0lOsFLJj5lT2PwBw,1685
66
66
  manta_node/supervisor/switch.py,sha256=PbWLNnRwQFhOBDAUSLcDwZsIW5jPHq_zNKIyS7Hd8C0,22342
67
- manta_node-0.6b6.dev846.dist-info/licenses/LICENSE,sha256=9mBgLhiB9goQPQjg9XQJ6FjgVxYw9Q8lyOZYkPGwF_c,34484
68
- manta_node-0.6b6.dev846.dist-info/METADATA,sha256=ANDWeMJw_E0rXfhV1vf-I7lDqgmjgUUOkYCuxb8vzc8,4937
69
- manta_node-0.6b6.dev846.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
70
- manta_node-0.6b6.dev846.dist-info/entry_points.txt,sha256=uCwggRApalLEsYs1YxwTBN0-e9oMJAkMoBp01HaSdoY,110
71
- manta_node-0.6b6.dev846.dist-info/top_level.txt,sha256=nbT5J5WETuXM9UPoQckl29uUOq8wMYdRb9QDx5kAFeo,11
72
- manta_node-0.6b6.dev846.dist-info/RECORD,,
67
+ manta_node-0.6b6.dev850.dist-info/licenses/LICENSE,sha256=9mBgLhiB9goQPQjg9XQJ6FjgVxYw9Q8lyOZYkPGwF_c,34484
68
+ manta_node-0.6b6.dev850.dist-info/METADATA,sha256=a9pjWNjneGUbd1InC_UirezNkTZbZiQN6asj5GCDysY,4937
69
+ manta_node-0.6b6.dev850.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
70
+ manta_node-0.6b6.dev850.dist-info/entry_points.txt,sha256=uCwggRApalLEsYs1YxwTBN0-e9oMJAkMoBp01HaSdoY,110
71
+ manta_node-0.6b6.dev850.dist-info/top_level.txt,sha256=nbT5J5WETuXM9UPoQckl29uUOq8wMYdRb9QDx5kAFeo,11
72
+ manta_node-0.6b6.dev850.dist-info/RECORD,,