Skip to content

Commit ee3ec0b

Browse files
authored
feat: WorldManifest model and world_manifest_from_spec helper
2 parents 1813e15 + 372fb19 commit ee3ec0b

3 files changed

Lines changed: 157 additions & 2 deletions

File tree

netengine/spec/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
BoundaryPolicy,
99
ResolverPolicy,
1010
TrustBundle,
11+
WorldManifest,
1112
default_authorities_for_spec,
13+
world_manifest_from_spec,
1214
resolver_policy_from_boundary,
1315
)
1416

@@ -20,6 +22,8 @@
2022
"BoundaryPolicy",
2123
"ResolverPolicy",
2224
"TrustBundle",
25+
"WorldManifest",
2326
"default_authorities_for_spec",
27+
"world_manifest_from_spec",
2428
"resolver_policy_from_boundary",
2529
]

netengine/spec/authority.py

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from enum import Enum
44
from pydantic import Field, model_validator
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Any
66

77

88
from netengine.spec.models import CrossWorldPeer, ServiceMirror, SpecModel
9-
from netengine.spec.types import GatewayCrossWorldMode, GatewayRealInternetMode
9+
from netengine.spec.types import GatewayCrossWorldMode, GatewayRealInternetMode, Lifecycle
1010

1111
if TYPE_CHECKING:
1212
from netengine.spec.models import NetEngineSpec
@@ -105,6 +105,34 @@ def validate_trust_bundle(self) -> "TrustBundle":
105105
return self
106106

107107

108+
class WorldManifest(SpecModel):
109+
"""Authority-layer manifest for a NetEngine world.
110+
111+
The manifest provides a compact authority/spec-domain view of the
112+
governance, naming, identity, trust, registry, numbering, and boundary
113+
surfaces that define a world.
114+
"""
115+
116+
world_id: str = Field(...)
117+
world_name: str = Field(...)
118+
lifecycle: Lifecycle = Field(...)
119+
authority_model: str = Field(...)
120+
authorities: list[Authority] = Field(default_factory=list)
121+
dns_root_authority: str = Field(...)
122+
ca_trust_authority: str = Field(...)
123+
platform_identity_issuer: str = Field(...)
124+
inworld_identity_issuer: str = Field(...)
125+
world_registry_authority: str = Field(...)
126+
domain_registry_authority: str = Field(...)
127+
numbering_authority: str = Field(...)
128+
transit_boundary_authority: str = Field(...)
129+
real_internet_posture: GatewayRealInternetMode = Field(...)
130+
cross_world_posture: GatewayCrossWorldMode = Field(...)
131+
exported_authority_metadata: dict[str, Any] = Field(default_factory=dict)
132+
importable_authority_metadata: dict[str, Any] = Field(default_factory=dict)
133+
trust_bundles: list[TrustBundle] = Field(default_factory=list)
134+
135+
108136
class BoundaryPolicy(SpecModel):
109137
"""Authority-layer policy for traffic and trust at the world boundary."""
110138

@@ -307,3 +335,61 @@ def default_authorities_for_spec(spec: "NetEngineSpec") -> list[Authority]:
307335
description="Authority over the application service catalog.",
308336
),
309337
]
338+
339+
340+
def _trust_bundles_from_spec(spec: "NetEngineSpec") -> list[TrustBundle]:
341+
"""Derive importable trust bundles from configured cross-world peers."""
342+
343+
bundles: list[TrustBundle] = []
344+
for peer in spec.gateway_portal.cross_world.peers:
345+
mode = peer.mode
346+
if mode == GatewayCrossWorldMode.NONE:
347+
continue
348+
349+
if mode == GatewayCrossWorldMode.FEDERATED and not (
350+
peer.trust_anchor_cert or peer.trust_bundle
351+
):
352+
continue
353+
354+
bundles.append(
355+
TrustBundle(
356+
peer_id=peer.name,
357+
peer_name=peer.name,
358+
mode=mode,
359+
dns_suffixes=[peer.name],
360+
peer_root_ca=peer.trust_anchor_cert,
361+
oidc_issuer=peer.trust_bundle,
362+
)
363+
)
364+
365+
return bundles
366+
367+
368+
def world_manifest_from_spec(spec: "NetEngineSpec") -> WorldManifest:
369+
"""Build an authority-layer world manifest from a parsed NetEngine spec.
370+
371+
NetEngine specs do not currently expose a dedicated stronger world-id field,
372+
so the manifest intentionally seeds both identity fields from
373+
``spec.metadata.name``.
374+
"""
375+
376+
authorities = default_authorities_for_spec(spec)
377+
378+
return WorldManifest(
379+
world_id=spec.metadata.name,
380+
world_name=spec.metadata.name,
381+
lifecycle=spec.metadata.lifecycle,
382+
authority_model="default",
383+
authorities=authorities,
384+
dns_root_authority="root-naming",
385+
ca_trust_authority="trust-root",
386+
platform_identity_issuer="platform-identity",
387+
inworld_identity_issuer="inworld-identity",
388+
world_registry_authority="world-root",
389+
domain_registry_authority="domain-registry",
390+
numbering_authority="numbering",
391+
transit_boundary_authority="transit-boundary",
392+
real_internet_posture=spec.gateway_portal.real_internet.mode,
393+
cross_world_posture=spec.gateway_portal.cross_world.mode,
394+
trust_bundles=_trust_bundles_from_spec(spec),
395+
)

tests/test_authority_spec.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BoundaryPolicy,
1212
ResolverPolicy,
1313
TrustBundle,
14+
default_authorities_for_spec,
1415
resolver_policy_from_boundary,
1516
)
1617
from netengine.spec.models import CrossWorldPeer, ServiceMirror
@@ -307,3 +308,67 @@ def test_default_authorities_for_spec_maps_spec_sections(minimal_spec) -> None:
307308
]
308309
assert by_id["mail-authority"].controls == ["world_services.mail"]
309310
assert by_id["service-catalog"].controls == ["org_apps.catalog"]
311+
312+
313+
def test_world_manifest_from_spec_uses_metadata_name_and_default_authorities(minimal_spec) -> None:
314+
from netengine.spec import WorldManifest, world_manifest_from_spec
315+
316+
manifest = world_manifest_from_spec(minimal_spec)
317+
318+
assert isinstance(manifest, WorldManifest)
319+
assert manifest.world_id == minimal_spec.metadata.name
320+
assert manifest.world_name == minimal_spec.metadata.name
321+
assert manifest.lifecycle == minimal_spec.metadata.lifecycle
322+
assert manifest.authority_model == "default"
323+
assert [authority.id for authority in manifest.authorities] == [
324+
authority.id for authority in default_authorities_for_spec(minimal_spec)
325+
]
326+
assert manifest.dns_root_authority == "root-naming"
327+
assert manifest.ca_trust_authority == "trust-root"
328+
assert manifest.platform_identity_issuer == "platform-identity"
329+
assert manifest.inworld_identity_issuer == "inworld-identity"
330+
assert manifest.world_registry_authority == "world-root"
331+
assert manifest.domain_registry_authority == "domain-registry"
332+
assert manifest.numbering_authority == "numbering"
333+
assert manifest.transit_boundary_authority == "transit-boundary"
334+
assert manifest.real_internet_posture == minimal_spec.gateway_portal.real_internet.mode
335+
assert manifest.cross_world_posture == minimal_spec.gateway_portal.cross_world.mode
336+
assert manifest.exported_authority_metadata == {}
337+
assert manifest.importable_authority_metadata == {}
338+
assert manifest.trust_bundles == []
339+
340+
341+
def test_world_manifest_from_spec_derives_cross_world_trust_bundles(minimal_spec) -> None:
342+
from netengine.spec import world_manifest_from_spec
343+
344+
spec = minimal_spec.model_copy(
345+
update={
346+
"gateway_portal": minimal_spec.gateway_portal.model_copy(
347+
update={
348+
"cross_world": minimal_spec.gateway_portal.cross_world.model_copy(
349+
update={
350+
"mode": GatewayCrossWorldMode.FEDERATED,
351+
"peers": [
352+
CrossWorldPeer(
353+
name="world-b.internal",
354+
endpoint="10.99.0.1:8443",
355+
mode=GatewayCrossWorldMode.FEDERATED,
356+
trust_anchor_cert="-----BEGIN CERTIFICATE-----...",
357+
)
358+
],
359+
}
360+
)
361+
}
362+
)
363+
}
364+
)
365+
366+
manifest = world_manifest_from_spec(spec)
367+
368+
assert manifest.cross_world_posture == GatewayCrossWorldMode.FEDERATED
369+
assert len(manifest.trust_bundles) == 1
370+
assert manifest.trust_bundles[0].peer_id == "world-b.internal"
371+
assert manifest.trust_bundles[0].peer_name == "world-b.internal"
372+
assert manifest.trust_bundles[0].mode == GatewayCrossWorldMode.FEDERATED
373+
assert manifest.trust_bundles[0].dns_suffixes == ["world-b.internal"]
374+
assert manifest.trust_bundles[0].peer_root_ca == "-----BEGIN CERTIFICATE-----..."

0 commit comments

Comments
 (0)