From 9008f1582a78560d4c2227bb74cfa1a1d66e1c41 Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 1/6] deploy: add an isolated NDNd network alongside NFD --- .gitignore | 3 +- README.md | 80 +++++++ anchors/ndnd-root.base64 | 1 + config.yml | 66 ++++++ docker-compose.yml | 201 ++++++++++++++++++ framework/http-ca-server.py | 125 ++++++++++- framework/internal/conf.py | 12 +- framework/internal/ndnd_network.py | 138 ++++++++++++ framework/ndnd-network-init.py | 18 ++ framework/test_ndnd_deployment.py | 156 ++++++++++++++ framework/test_ndnd_network.py | 112 ++++++++++ framework/test_ndnd_status_trust.py | 84 ++++++++ host_vars/ARIZONA | 4 + host_vars/FRANKFURT | 4 + host_vars/HK | 4 + host_vars/MEMPHIS | 4 + host_vars/SINGAPORE | 4 + host_vars/UCLA | 4 + scripts/cert-renew.sh | 75 +++++-- scripts/cron-host.sh | 5 +- scripts/cron-master.sh | 3 + scripts/ndnd-infra-security.py | 167 +++++++++++---- templates/caddy/Caddyfile.j2 | 18 ++ templates/file-server/ndnd/dv-schema.lvs.j2 | 1 + templates/ndnd-dv/dv-schema.lvs.j2 | 17 ++ templates/ndnd-dv/dv.yml.j2 | 19 ++ templates/ndnd-dv/renew.sh.j2 | 21 ++ .../ndnd-http-status-server/dv-schema.lvs.j2 | 1 + .../ndnd-http-status-server/root.cert.pem.j2 | 3 + .../management-schema.lvs.j2 | 28 +++ templates/ndnd-network-merkle/merkle.yml.j2 | 8 + templates/ndnd-network-merkle/renew.sh.j2 | 14 ++ .../management-schema.lvs.j2 | 33 +++ templates/ndnd-network-repo/renew.sh.j2 | 14 ++ templates/ndnd-network-repo/repo.yml.j2 | 8 + templates/ndnd-root-ca/ca.json.j2 | 40 ++++ .../ndnd-root-http-ca/http-ca-server.yml.j2 | 19 ++ templates/ndnd-site-ca/ca.json.j2 | 19 ++ templates/ndnd-site-ca/renew.sh.j2 | 22 ++ templates/ndnd/yanfd.yml.j2 | 24 +++ templates/nlsr/nlsr.conf.j2 | 3 + 41 files changed, 1508 insertions(+), 74 deletions(-) create mode 100644 anchors/ndnd-root.base64 create mode 100644 framework/internal/ndnd_network.py create mode 100644 framework/ndnd-network-init.py create mode 100644 framework/test_ndnd_deployment.py create mode 100644 framework/test_ndnd_network.py create mode 100644 framework/test_ndnd_status_trust.py create mode 100644 templates/file-server/ndnd/dv-schema.lvs.j2 create mode 100644 templates/ndnd-dv/dv-schema.lvs.j2 create mode 100644 templates/ndnd-dv/dv.yml.j2 create mode 100644 templates/ndnd-dv/renew.sh.j2 create mode 100644 templates/ndnd-http-status-server/dv-schema.lvs.j2 create mode 100644 templates/ndnd-http-status-server/root.cert.pem.j2 create mode 100644 templates/ndnd-network-merkle/management-schema.lvs.j2 create mode 100644 templates/ndnd-network-merkle/merkle.yml.j2 create mode 100644 templates/ndnd-network-merkle/renew.sh.j2 create mode 100644 templates/ndnd-network-repo/management-schema.lvs.j2 create mode 100644 templates/ndnd-network-repo/renew.sh.j2 create mode 100644 templates/ndnd-network-repo/repo.yml.j2 create mode 100644 templates/ndnd-root-ca/ca.json.j2 create mode 100644 templates/ndnd-root-http-ca/http-ca-server.yml.j2 create mode 100644 templates/ndnd-site-ca/ca.json.j2 create mode 100644 templates/ndnd-site-ca/renew.sh.j2 create mode 100644 templates/ndnd/yanfd.yml.j2 diff --git a/.gitignore b/.gitignore index de5742c..8ce2603 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ dist/ secrets.yml .env -root-ca-home/ \ No newline at end of file +root-ca-home/ +ndnd-root-ca-home/ diff --git a/README.md b/README.md index 977bff2..c768d1f 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ docker compose exec -e HOME=/testbed/root-ca-home master ndnsec list -c Each node runs the pinned `ndnd-repo` container with identity `/ndnd/repo` (e.g. `/ndn/edu/ucla/ndnd/repo`). Master generates a dedicated key, obtains a certificate from the local site CA, and installs the public chain selected by `globals.ndnd_repo_anchors`. The repo can write only its keychain and storage; it has no access to CA private keys or master renewal scripts. +## NDNd Distance Vector + +Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. Router identities are root-signed as `/32=DV`, and peers are selected from the existing NLSR neighbor inventory, limited to NDNd-enabled sites. + ## NDNd Merkle Only UCLA runs the `ndnd-merkle` container, selected by `services.ndnd-merkle.hosts: [UCLA]` in `config.yml`, with identity `/ndn/edu/ucla/ndnd/merkle`. Master automatically provisions and renews its dedicated site-issued certificate using the same testbed anchors as the repo. Its trust schema permits testbed-certified users to append under their own identities and only the log key to sign responses. History persists in `dist/ndnd-merkle/storage`. @@ -144,3 +148,79 @@ sudo systemctl enable unattended-upgrades sudo systemctl start unattended-upgrades sudo unattended-upgrades --debug ``` + +## NDNd status + +The NDNd forwarder, DV router, status server, CA services, and `/ndnd` Merkle log +use the digest-pinned DV2 staging image configured in Compose. The `/ndnd` +repository retains its separately pinned DV2 image. +Upgrade the forwarder, DV router, and status server together; the DV2 BIFT +management dataset uses TLV encoding. Both repository configurations explicitly +supply their management trust schema. + +The existing NFD-connected services retain upstream's image settings. They use +NFD RIB registration; the separate NDNd services use DV prefix advertising. + +On hosts with `ndnd_enabled: true`, Caddy exposes: + +- `/ndnd-status/`: HTML status page. +- `/ndnd-status/status.xml`: XML status report. +- `/ndnd-status/status.json`: JSON status report. + +For example: `https://suns.cs.ucla.edu/ndnd-status/status.json`. + +The renderer compiles `templates/ndnd-dv/dv-schema.lvs.j2` for both DV and the +status server. It permits only inventoried NDNd router certificates, issued +directly by the `/ndnd` root, to sign their routing and status datasets. DV +explicitly loads this schema; the status server receives the same schema and +the public root certificate in PEM format through a separate read-only mount. +It has no access to router private keys. Changes to either status trust file +cause the existing renderer to restart the status server. +The same compiled schema is published at `/file-server/ndnd/dv-schema.tlv` +for clients. + +The status server validates `//32=DV/32=STATUS` before including the +routing dataset. It does not fall back to an unrestricted schema. The local +DV summary remains available if the signed dataset cannot be validated; check +the status server logs and the report's routing state in that case. + + +The CA host requires the existing root `ca.key.pem` and `ca.cert.pem` in +`ndnd-root-ca-home/ndnd/`, owned by the service UID (root in the pinned images), +with the private key mode set to `0600`. The certificate must match the committed trust anchor; +the root services load these credentials directly. Master renders service +configuration and renews service certificates before marking itself ready, +using the same lifecycle as the existing testbed. Cron performs subsequent +renewals and reloads. Root creation and replacement remain operator tasks. +NDNd-enabled sites set `VAR_NDND_ROOT_CA_SECRET` in `.env` for root enrollment; +NFD-only sites do not need that setting. + +## NDNd network bridge + +NDNd-enabled sites bridge the two forwarders locally over UDP. NFD sends `/ndnd` +Interests to NDNd through a capture route, excluding inherited root routes, and +advertises `/ndnd` through NLSR. NDNd installs a `/ndn` PET +next hop toward NFD and advertises it through DV. Producers still register on +the network matching their top-level prefix; the bridge does not redistribute +producer registrations or change application trust policies. + +Each enabled host needs a unique, stable `ndnd_bier_index`. The forwarder loads +that index at startup, and `framework/ndnd-network-init.py` registers the same +router-to-index inventory on every node and rebuilds the BIFT. Both cron scripts +run this initializer after service updates. It binds announcements to permanent +UDP faces, restores entries after restarts, and reloads NDNd-connected producers +when their forwarder's startup time changes. The NFD-connected repository and +Merkle service are outside that restart group. + +NDNd uses the NLSR neighbor connections between enabled sites. DV2 currently +uses a fixed cost of 1 per link; it does not use NLSR's configured link costs. + +To reconcile a running node manually from its checkout: + +```bash +docker compose exec -T -e PWD="$PWD" master python3 framework/ndnd-network-init.py +``` + +The bridge has static routes. An abrupt peer failure does not automatically +withdraw its gateway advertisement; alternative gateway advertisements alone do +not guarantee immediate failover. Gateway health tracking is not implemented here. diff --git a/anchors/ndnd-root.base64 b/anchors/ndnd-root.base64 new file mode 100644 index 0000000..38157ab --- /dev/null +++ b/anchors/ndnd-root.base64 @@ -0,0 +1 @@ +BugHIwgEbmRuZAgDS0VZCAiErVznAwK56QgCTkE2CAAAAaFYpS5aFAkYAQIZBAA27oAVLDAqMAUGAytlcAMhAOi1L42QxRzGB/yMvduMM19dM3ukSmyubURXLZG9RvY1FkYbAQUcFwcVCARuZG5kCANLRVkICIStXOcDArnp/QD9Jv0A/g8yMDI2MTAyMFQwOTI5NDL9AP8PMjAyNzEwMjBUMDkyOTQyF0Aj+qOlJSdFN9wGXmnobfYLUmjqNikwnydWB6qUAmp1EGZN5d3q8kcQ5By/6B44uzeVau5TksFdwRZKoB7HtxwE diff --git a/config.yml b/config.yml index 4fc53d5..589ec19 100644 --- a/config.yml +++ b/config.yml @@ -6,6 +6,44 @@ host_vars_path: host_vars # This must match exactly with the docker-compose.yml file services: + ndnd: + enabled_by: ndnd_enabled + profile: ndnd + template_path: templates/ndnd + render_path: dist/ndnd + + ndnd-dv: + enabled_by: ndnd_enabled + profile: ndnd + template_path: templates/ndnd-dv + render_path: dist/ndnd-dv + + ndnd-http-status-server: + enabled_by: ndnd_enabled + profile: ndnd + template_path: templates/ndnd-http-status-server + render_path: dist/ndnd-http-status-server + + ndnd-site-ca: + enabled_by: ndnd_enabled + profile: ndnd-site-ca + template_path: templates/ndnd-site-ca + render_path: dist/ndnd-site-ca + + ndnd-root-ca: + hosts: [UCLA] + enabled_by: ndnd_enabled + profile: ndnd-root-ca + template_path: templates/ndnd-root-ca + render_path: dist/ndnd-root-ca + + ndnd-root-http-ca: + hosts: [UCLA] + enabled_by: ndnd_enabled + profile: ndnd-root-ca + template_path: templates/ndnd-root-http-ca + render_path: dist/ndnd-root-http-ca + caddy: template_path: templates/caddy render_path: dist/caddy @@ -39,12 +77,25 @@ services: template_path: templates/ndnd-repo render_path: dist/ndnd-repo + ndnd-network-repo: + enabled_by: ndnd_enabled + profile: ndnd + template_path: templates/ndnd-network-repo + render_path: dist/ndnd-network-repo + ndnd-merkle: hosts: [UCLA] profile: merkle-log template_path: templates/ndnd-merkle render_path: dist/ndnd-merkle + ndnd-network-merkle: + hosts: [UCLA] + enabled_by: ndnd_enabled + profile: ndnd-merkle-log + template_path: templates/ndnd-network-merkle + render_path: dist/ndnd-network-merkle + ndncert: template_path: templates/ndncert render_path: dist/ndncert @@ -74,6 +125,17 @@ globals: # Explicitly select the active root; retain additional roots here during rollover. ndnd_repo_anchors: - anchors/ndn-testbed-root.ndncert.2204.base64 + ndnd_udp_port: 6364 + ndnd_dv_network: /ndnd + ndnd_ca_host: UCLA + ndnd_ca_info: "NDNd Testbed Root CA" + ndnd_ca_max_validity_period: "7776000" + ndnd_ca_max_suffix_length: "5" + ndnd_ca_supported_challenges: [email, dns] + ndnd_site_ca_supported_challenges: [email] + ndnd_root_http_ca_url: https://suns.cs.ucla.edu/ndnd-ca + ndnd_root_anchor_path: anchors/ndnd-root.base64 + ndnd_root_http_ca_internal_url: http://ndnd-root-http-ca:8777 # Declare variables available for each host # You can use lint.py to check variables, their types and @@ -97,8 +159,12 @@ variables: memsize: number neighbors: dict position: list + ndnd_ca_prefix: "?string" hr_angle: number hr_radius: number ethernet_device: string is_root_ca: "?boolean" is_status_page: "?boolean" + ndnd_enabled: "?boolean" + ndnd_router_prefix: "?string" + ndnd_bier_index: "?number" diff --git a/docker-compose.yml b/docker-compose.yml index ded6a7b..849ab51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,6 +43,136 @@ services: logging: driver: local + ndnd: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd] + init: true + volumes: + - /run/ndnd:/run/ndnd + - ${PWD}/dist/ndnd:/config:ro + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + command: [fw, run, /config/yanfd.yml] + ports: + - 6364:6364/udp + restart: unless-stopped + healthcheck: + test: [CMD, /ndnd, fw, status] + interval: 1m + start_period: 30s + depends_on: + master: { condition: service_healthy } + logging: + driver: local + + ndnd-dv: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-dv/dv.yml:/config/dv.yml:ro + - ${PWD}/dist/ndnd-dv/dv-schema.tlv:/config/dv-schema.tlv:ro + - ${PWD}/dist/ndnd-dv/keys:/config/keys + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + command: [dv, run, /config/dv.yml] + network_mode: none + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + logging: + driver: local + + ndnd-http-status-server: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-http-status-server:/config:ro + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + command: [fw, status-server, --trust-schema, /config/dv-schema.tlv, --trust-anchor, /config/root.cert.pem] + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + logging: + driver: local + + ndnd-site-ca: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd-site-ca] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-site-ca:/config:ro + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + NDND_SMTP_PASSWORD: ${VAR_SMTP_PASSWORD:-} + command: [sec, certca, /config/ca.json, /config/ca.cert.pem, /config/ca.key.pem] + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + logging: + driver: local + + ndnd-root-ca: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd-root-ca] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/ndnd-root-ca-home/ndnd:/ca:ro + - ${PWD}/dist/ndnd-root-ca:/config:ro + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + NDND_SMTP_PASSWORD: ${VAR_SMTP_PASSWORD:-} + command: [sec, certca, /config/ca.json, /ca/ca.cert.pem, /ca/ca.key.pem] + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + logging: + driver: local + + ndnd-root-http-ca: + image: ghcr.io/named-data/testbed-master:20261012 + profiles: [ndnd-root-ca] + init: true + tty: true + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${PWD}/framework/http-ca-server.py:/app/http-ca-server.py:ro + - ${PWD}/dist/ndnd-root-http-ca:/config:ro + - ${PWD}/dist/ndnd-root-http-ca/cert-store:/cert-store + environment: + # Enforced by the signer at runtime; inactive profiles must still parse. + NDND_ROOT_CA_SECRET: ${VAR_NDND_ROOT_CA_SECRET:-} + NDND_CA_IMAGE: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + NDND_CA_HOST_DIR: ${PWD}/ndnd-root-ca-home/ndnd + entrypoint: [python3, /app/http-ca-server.py] + command: [/config/http-ca-server.yml] + restart: unless-stopped + logging: + driver: local + nfd: image: ghcr.io/named-data/nfd:20250420 init: true @@ -175,6 +305,39 @@ services: logging: driver: local + ndnd-network-repo: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:cd362167f0d34804ba79cc33ba654e35d666f39c9a729debafe0e93b40348a9c + profiles: [ndnd] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-network-repo/keys:/config/keys + - ${PWD}/dist/ndnd-network-repo/storage:/config/storage + - type: bind + source: ${PWD}/dist/ndnd-network-repo/repo.yml + target: /config/repo.yml + read_only: true + bind: + create_host_path: false + - type: bind + source: ${PWD}/dist/ndnd-network-repo/management-schema.tlv + target: /config/management-schema.tlv + read_only: true + bind: + create_host_path: false + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + command: [repo, run, /config/repo.yml] + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + ndnd-dv: { condition: service_started } + logging: + driver: local + ndnd-merkle: image: ghcr.io/named-data/ndnd:20261012 pull_policy: always @@ -203,6 +366,44 @@ services: logging: driver: local + ndnd-network-merkle: + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + pull_policy: always + profiles: [ndnd-merkle-log] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-network-merkle/keys:/config/keys + - ${PWD}/dist/ndnd-network-merkle/storage:/config/storage + - type: bind + source: ${PWD}/dist/ndnd-network-merkle/merkle.yml + target: /config/merkle.yml + read_only: true + bind: + create_host_path: false + - type: bind + source: ${PWD}/dist/ndnd-network-merkle/management-schema.tlv + target: /config/management-schema.tlv + read_only: true + bind: + create_host_path: false + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + command: [merkle, run, /config/merkle.yml] + network_mode: none + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + mem_limit: 2g + cpus: 1 + pids_limit: 128 + restart: unless-stopped + depends_on: + ndnd: { condition: service_healthy } + ndnd-dv: { condition: service_started } + logging: + driver: local + ndncert: image: ghcr.io/ucla-irl/ndncert-ca:20250923 init: true diff --git a/framework/http-ca-server.py b/framework/http-ca-server.py index f2bff58..979a1fe 100755 --- a/framework/http-ca-server.py +++ b/framework/http-ca-server.py @@ -7,6 +7,10 @@ import subprocess import ndn import ipaddress +import os +import struct +from datetime import datetime, timedelta +from urllib.parse import parse_qs from dataclasses import dataclass from http.server import BaseHTTPRequestHandler, HTTPServer @@ -17,9 +21,23 @@ class Config: secret: str hosts: dict[str, dict] port: int + signer_backend: str = 'ndnsec' + ndnd_ca_image: str = '' + ndnd_ca_host_dir: str = '' config: Config = None + +def is_ndnd_csr_name(prefix: str, name: list[bytes]) -> bool: + prefix_name = ndn.encoding.Name.normalize(prefix) + if len(name) != len(prefix_name) + 4 or name[:len(prefix_name)] != prefix_name: + return False + component = ndn.encoding.Component + return (name[len(prefix_name)] == component.from_str('KEY') + and name[len(prefix_name) + 2] == component.from_str('self') + and component.get_type(name[-1]) == component.TYPE_VERSION) + + class MyHTTPRequestHandler(BaseHTTPRequestHandler): def which_host_ip(self, address: str) -> dict|None: for _, host in config.hosts.items(): @@ -29,8 +47,16 @@ def which_host_ip(self, address: str) -> dict|None: return None def sign(self, path: str, query: str, data: bytes) -> None: - # Check if the secret is correct from query parameter - if query != f'secret={config.secret}': + if config.signer_backend == 'ndnd-go': + try: + params = parse_qs(query, strict_parsing=True) + except ValueError: + self.send_error(400, "Invalid query parameters") + return + authorized = self.headers.get('Authorization') == f'Bearer {config.secret}' + else: + authorized = query == f'secret={config.secret}' + if not authorized: self.send_error(401, "Invalid secret") return @@ -43,14 +69,76 @@ def sign(self, path: str, query: str, data: bytes) -> None: # Validate prefix of the CSR pfx = host['prefix'] - name = ndn.encoding.ndn_format_0_3.parse_data(base64.b64decode(data))[0] - if not ndn.encoding.name.Name.is_prefix(pfx, name): + if config.signer_backend == 'ndnd-go': + try: + csr_wire = base64.b64decode(b''.join(data.split()), validate=True) + name = ndn.encoding.ndn_format_0_3.parse_data(csr_wire)[0] + if name is None: + raise ValueError('CSR has no name') + except (ValueError, IndexError, struct.error, ndn.encoding.DecodeError): + self.send_error(400, "Invalid CSR") + return + valid_name = is_ndnd_csr_name(pfx, name) + ca_prefix = host.get('ca_prefix') + if ca_prefix: + valid_name = valid_name or is_ndnd_csr_name(ca_prefix, name) + else: + name = ndn.encoding.ndn_format_0_3.parse_data(base64.b64decode(data))[0] + valid_name = ndn.encoding.name.Name.is_prefix(pfx, name) + if not valid_name: str_name = ndn.encoding.name.Name.to_str(name) self.send_error(400, f"Invalid name {str_name}, expected prefix {pfx}") return - # Sign a certificate for the name - proc = subprocess.run(['ndnsec', 'cert-gen', '-s', config.global_prefix, '-'], input=data, capture_output=True) + if config.signer_backend == 'ndnd-go': + not_before = params.get('not_before', []) + not_after = params.get('not_after', []) + if bool(not_before) != bool(not_after) or len(not_before) > 1 or len(not_after) > 1: + self.send_error(400, "Both validity bounds must be provided once") + return + + if not_before: + try: + start = datetime.strptime(not_before[0], '%Y%m%d%H%M%S') + end = datetime.strptime(not_after[0], '%Y%m%d%H%M%S') + except ValueError: + self.send_error(400, "Invalid certificate validity bounds") + return + if end <= start or end - start > timedelta(days=90): + self.send_error(400, "Certificate validity must be positive and no longer than 90 days") + return + + csr_pem = (b'-----BEGIN NDN CERT-----\n' + base64.encodebytes(csr_wire) + + b'-----END NDN CERT-----\n') + command = ['docker', 'run', '--rm', '-i', '-v', + f'{config.ndnd_ca_host_dir}:/ca:ro', config.ndnd_ca_image, + 'sec', 'sign-cert', '/ca/ca.key.pem'] + if not_before: + command.extend(['--start', not_before[0], '--end', not_after[0]]) + try: + proc = subprocess.run(command, input=csr_pem, capture_output=True, timeout=30) + except subprocess.TimeoutExpired: + self.send_error(504, "NDNd signer timed out") + return + if proc.returncode == 0: + try: + body = proc.stdout.split(b'-----BEGIN NDN CERT-----', 1)[1].split( + b'-----END NDN CERT-----', 1)[0] + wire = base64.b64decode(b''.join( + line.strip() for line in body.splitlines() if b':' not in line), validate=True) + cert_name = ndn.encoding.ndn_format_0_3.parse_data(wire)[0] + if cert_name is None: + raise ValueError('Certificate has no name') + proc.stdout = base64.encodebytes(wire) + except (ValueError, IndexError, struct.error, ndn.encoding.DecodeError): + self.send_error(502, "Invalid certificate output from NDNd signer") + return + elif config.signer_backend == 'ndnsec': + proc = subprocess.run(['ndnsec', 'cert-gen', '-s', config.global_prefix, '-'], + input=data, capture_output=True) + else: + self.send_error(500, "Unsupported signer backend") + return if proc.returncode != 0: self.send_error(500, f"Failed to sign certificate: {proc.stderr}") @@ -58,7 +146,8 @@ def sign(self, path: str, query: str, data: bytes) -> None: # Log the certificate name certificate = proc.stdout - cert_name = ndn.encoding.ndn_format_0_3.parse_data(base64.b64decode(certificate))[0] + if config.signer_backend == 'ndnsec': + cert_name = ndn.encoding.ndn_format_0_3.parse_data(base64.b64decode(certificate))[0] print(f"Issued certificate: {ndn.encoding.name.Name.to_str(cert_name)}") # Send the signed certificate @@ -66,8 +155,15 @@ def sign(self, path: str, query: str, data: bytes) -> None: self.end_headers() self.wfile.write(certificate) - # Store the certificate if path provided - if path := host.get('cert_file'): + path = host.get('cert_file') + if config.signer_backend == 'ndnd-go': + identity = ndn.encoding.name.Name.to_str(cert_name[:-4]) if len(cert_name) >= 4 else '' + ca_prefix = host.get('ca_prefix') + if ca_prefix and identity == ca_prefix: + path = host.get('ca_cert_file') + elif identity != pfx: + path = None + if path: with open(path, 'wb') as f: f.write(certificate) @@ -102,7 +198,16 @@ def address_string(self) -> str: if __name__ == '__main__': # Read YAML config with open(sys.argv[1], 'r') as f: - config = Config(**yaml.safe_load(f)) + config_data = yaml.safe_load(f) + if config_data.get('signer_backend') == 'ndnd-go': + config_data['secret'] = os.environ.get('NDND_ROOT_CA_SECRET', '') + config_data['ndnd_ca_image'] = os.environ.get('NDND_CA_IMAGE', '') + config_data['ndnd_ca_host_dir'] = os.environ.get('NDND_CA_HOST_DIR', '') + if not config_data['secret']: + raise RuntimeError('NDNd HTTP CA secret must be configured') + if not config_data['ndnd_ca_image'] or not config_data['ndnd_ca_host_dir']: + raise RuntimeError('NDNd signer image and CA directory must be configured') + config = Config(**config_data) # Start server server_address = ('', config.port) diff --git a/framework/internal/conf.py b/framework/internal/conf.py index 88017c6..b51451f 100644 --- a/framework/internal/conf.py +++ b/framework/internal/conf.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from os import getenv +from pathlib import Path from typing import Any from .utils import read_dotenv @@ -34,7 +35,16 @@ def get() -> Config: def service_enabled(service: dict, node: str) -> bool: - return 'hosts' not in service or node in service['hosts'] + if 'hosts' in service and node not in service['hosts']: + return False + enabled_by = service.get('enabled_by') + if enabled_by is None: + return True + if not node: + return False + with open(Path(get().host_vars_path) / node) as stream: + host_vars = yaml.safe_load(stream) or {} + return bool(host_vars.get(enabled_by, False)) def compose_profiles(node: str = None) -> str: diff --git a/framework/internal/ndnd_network.py b/framework/internal/ndnd_network.py new file mode 100644 index 0000000..bb2d2eb --- /dev/null +++ b/framework/internal/ndnd_network.py @@ -0,0 +1,138 @@ +"""Initialize BIER and the local NFD–NDNd gateway after service startup.""" + +import json +import os +from pathlib import Path +import re +import subprocess +import time + +import yaml + +from . import conf + + +def router_indices(hosts): + routers = {} + for name, host in hosts.items(): + if not host.get('ndnd_enabled', False): + continue + index = host.get('ndnd_bier_index') + if type(index) is not int or index < 0: + raise ValueError(f'{name}: ndnd_bier_index must be a non-negative integer') + prefix = host['ndnd_router_prefix'] + if index in routers or prefix in routers.values(): + raise ValueError(f'{name}: duplicate NDNd router prefix or BIER index') + routers[index] = prefix + return routers + + +def run(args, check=True, timeout=30): + result = subprocess.run(args, capture_output=True, text=True, timeout=timeout) + if check and result.returncode: + raise RuntimeError(f'{args}: {result.stderr.strip()}') + return result + + +def wait_ready(command): + for _ in range(20): + result = run(command, check=False) + if result.returncode == 0: + return + time.sleep(1) + raise RuntimeError(f'Service not ready: {command}: {result.stderr.strip()}') + + +def face_id(output, uri): + for match in re.finditer(r'^faceid=(\d+) remote=(\S+)', output, re.MULTILINE): + if match[2] == uri: + return match[1] + return None + + +def configure(containers, routers, network, port, previous): + nfd, fw = containers['nfd'], containers['ndnd'] + networks = nfd['NetworkSettings']['Networks'].keys() & fw['NetworkSettings']['Networks'].keys() + if len(networks) != 1: + raise RuntimeError('NFD and NDNd must share exactly one Docker network') + docker_network = next(iter(networks)) + to_nfd = 'udp4://' + nfd['NetworkSettings']['Networks'][docker_network]['IPAddress'] + ':6363' + to_ndnd = 'udp4://' + fw['NetworkSettings']['Networks'][docker_network]['IPAddress'] + ':' + str(port) + nfd_cmd = ['docker', 'exec', nfd['Id'], 'nfdc'] + ndnd_cmd = ['docker', 'exec', fw['Id'], '/ndnd'] + changed = previous.get('forwarder_started') != fw['State']['StartedAt'] + + wait_ready(ndnd_cmd + ['fw', 'status']) + wait_ready(nfd_cmd + ['status']) + for index, prefix in sorted(routers.items()): + run(ndnd_cmd + ['fw', 'bift-register', 'prefix=' + prefix, 'index=' + str(index)]) + run(ndnd_cmd + ['fw', 'bift-rebuild']) + if changed or not containers['ndnd-dv']['State']['Running']: + run(['docker', 'restart', containers['ndnd-dv']['Id']]) + wait_ready(ndnd_cmd + ['dv', 'status']) + + # Remove our previous bridge entries if Docker assigned a new peer address. + if previous.get('to_nfd') not in (None, to_nfd) and not changed: + old_face = face_id(run(ndnd_cmd + ['fw', 'face-list']).stdout, previous['to_nfd']) + if old_face: + run(ndnd_cmd + ['dv', 'prefix-withdraw', 'prefix=/ndn', 'face=' + old_face]) + run(ndnd_cmd + ['fw', 'pet-remove-nexthop', 'prefix=/ndn', 'face=' + old_face]) + if previous.get('to_ndnd') not in (None, to_ndnd): + # A missing old face means NFD already removed its routes. + if face_id(run(nfd_cmd + ['face', 'list']).stdout, previous['to_ndnd']): + run(nfd_cmd + ['route', 'remove', network, previous['to_ndnd']]) + + # nfdc updates existing on-demand faces too; NDNd's create-only CLI returns 409. + # Mount only the socket directory; nfdc needs its own writable client keychain. + socket_dir = next(m['Source'] for m in fw['Mounts'] if m['Destination'] == '/run/ndnd') + run(['docker', 'run', '--rm', '--network', 'none', + '--mount', 'type=bind,src=' + socket_dir + ',dst=/run/ndnd,readonly', + '-e', 'NDN_CLIENT_TRANSPORT=unix:///run/ndnd/ndnd.sock', + '--entrypoint', '/usr/bin/nfdc', nfd['Image'], + 'face', 'create', to_nfd, 'persistency', 'permanent']) + run(nfd_cmd + ['face', 'create', to_ndnd, 'persistency', 'permanent']) + # Exclude inherited application/default routes from the foreign namespace. + run(nfd_cmd + ['route', 'add', network, to_ndnd, 'capture']) + bridge_face = face_id(run(ndnd_cmd + ['fw', 'face-list']).stdout, to_nfd) + if bridge_face is None: + raise RuntimeError('NDNd bridge face was not created') + run(ndnd_cmd + ['fw', 'pet-add-nexthop', 'prefix=/ndn', 'face=' + bridge_face]) + # Bind the announcement to the UDP face, not this short-lived CLI connection. + run(ndnd_cmd + ['dv', 'prefix-announce', 'prefix=/ndn', 'face=' + bridge_face]) + run(ndnd_cmd + ['fw', 'bift-rebuild']) + + if changed: + # These services keep registrations on the forwarder's Unix socket. + dependents = ['ndnd-http-status-server', 'ndnd-site-ca', 'ndnd-root-ca', + 'ndnd-network-repo', 'ndnd-network-merkle'] + restart = [containers[s]['Id'] for s in dependents + if s in containers and containers[s]['State']['Running']] + if restart: + run(['docker', 'restart', *restart], timeout=120) + return {'forwarder_started': fw['State']['StartedAt'], 'to_nfd': to_nfd, 'to_ndnd': to_ndnd} + + +def reconcile(node): + config = conf.get() + hosts = {path.name: yaml.safe_load(path.read_text()) + for path in Path(config.host_vars_path).iterdir() if path.is_file()} + if not hosts[node].get('ndnd_enabled', False): + return + routers = router_indices(hosts) + os.environ['COMPOSE_PROFILES'] = conf.compose_profiles(node) + ids = run(['docker', 'compose', 'ps', '-aq']).stdout.split() + containers = {c['Config']['Labels']['com.docker.compose.service']: c + for c in json.loads(run(['docker', 'inspect', *ids]).stdout)} if ids else {} + if 'ndnd-dv' not in containers: + raise RuntimeError('ndnd-dv must be created before NDNd network initialization') + for service in ['nfd', 'ndnd']: + if service not in containers or not containers[service]['State']['Running']: + raise RuntimeError(f'{service} must be running before NDNd network initialization') + state_file = Path('dist/.ndnd-network-state.json') + previous = json.loads(state_file.read_text()) if state_file.exists() else {} + state = configure(containers, routers, config.globals['ndnd_dv_network'], + config.globals['ndnd_udp_port'], previous) + temporary = state_file.with_suffix('.tmp') + temporary.write_text(json.dumps(state)) + temporary.replace(state_file) + print('NDNd BIER and symmetric NFD gateway initialized') diff --git a/framework/ndnd-network-init.py b/framework/ndnd-network-init.py new file mode 100644 index 0000000..d64ddb6 --- /dev/null +++ b/framework/ndnd-network-init.py @@ -0,0 +1,18 @@ +"""Reconcile the local NDNd network after Compose or certificate updates.""" + +import fcntl +import os +from pathlib import Path + +from internal.ndnd_network import reconcile + + +if __name__ == '__main__': + Path('dist').mkdir(exist_ok=True) + with open('dist/.ndnd-network.lock', 'w') as lock: + try: + fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError: + print('NDNd network initialization already running') + else: + reconcile(os.environ['MANAGED_HOST']) diff --git a/framework/test_ndnd_deployment.py b/framework/test_ndnd_deployment.py new file mode 100644 index 0000000..67f352d --- /dev/null +++ b/framework/test_ndnd_deployment.py @@ -0,0 +1,156 @@ +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +from types import SimpleNamespace +import unittest +from unittest.mock import patch + +import jinja2 +import yaml + +from internal import conf + + +ROOT = Path(__file__).resolve().parent.parent + + +class DeploymentTest(unittest.TestCase): + def test_nfd_only_compose_needs_no_ndnd_secret(self): + env = dict(os.environ, PWD=str(ROOT), MANAGED_HOST='AVEIRO', COMPOSE_PROFILES='') + env.pop('VAR_NDND_ROOT_CA_SECRET', None) + result = subprocess.run( + ['docker', 'compose', '--env-file', '/dev/null', 'config', '--format', 'json'], + cwd=ROOT, env=env, capture_output=True, text=True, timeout=30) + self.assertEqual(result.returncode, 0, result.stderr) + services = json.loads(result.stdout)['services'] + self.assertIn('nfd', services) + self.assertNotIn('ndnd-root-http-ca', services) + + def test_enabled_signer_still_rejects_an_empty_secret(self): + with tempfile.TemporaryDirectory() as directory: + config = Path(directory) / 'signer.yml' + config.write_text(yaml.safe_dump({ + 'global_prefix': '/ndnd', 'secret': '', 'hosts': {}, + 'port': 0, 'signer_backend': 'ndnd-go', + })) + result = subprocess.run( + [sys.executable, str(ROOT / 'framework/http-ca-server.py'), str(config)], + env=dict(os.environ, NDND_ROOT_CA_SECRET=''), + capture_output=True, text=True, timeout=10) + self.assertNotEqual(result.returncode, 0) + self.assertIn('NDNd HTTP CA secret must be configured', result.stderr) + + def test_root_services_follow_host_and_network_enablement(self): + services = conf.get().services + with tempfile.TemporaryDirectory() as directory: + with patch.object(conf, 'get', return_value=SimpleNamespace(host_vars_path=directory)): + for host in ['UCLA', 'AVEIRO']: + for enabled in [True, False]: + Path(directory, host).write_text(yaml.safe_dump({'ndnd_enabled': enabled})) + for service in ['ndnd-root-ca', 'ndnd-root-http-ca']: + with self.subTest(host=host, enabled=enabled, service=service): + self.assertEqual(conf.service_enabled(services[service], host), + host == 'UCLA' and enabled) + + def test_disabled_root_site_has_no_ndnd_proxy_routes(self): + config = conf.get() + values = yaml.safe_load((ROOT / 'host_vars/UCLA').read_text()) + template = jinja2.Environment(undefined=jinja2.StrictUndefined).from_string( + (ROOT / 'templates/caddy/Caddyfile.j2').read_text()) + for enabled in [True, False]: + with self.subTest(enabled=enabled): + rendered = template.render(**dict(values, **config.globals, + inventory_hostname='UCLA', ndnd_enabled=enabled)) + self.assertEqual('/ndnd-ca/*' in rendered, enabled) + self.assertEqual('/ndnd-status/*' in rendered, enabled) + self.assertIn('http://nfd:9696', rendered) + + +class RenewalTest(unittest.TestCase): + def run_renewal(self, root, failure='', force=False, enabled=True): + (root / 'scripts').mkdir() + (root / 'bin').mkdir() + (root / 'scripts/utils.sh').write_text( + 'HAS_FORCE=""\n[[ "$*" == *--force* ]] && HAS_FORCE=--force\n' + 'needs_renewal() { echo 1; }\n') + services = { + 'ndncert': 'ndncert', 'nlsr': 'nlsr', 'ndn-python-repo': 'ndn-python-repo', + 'ndnd-repo': 'ndnd-repo', 'ndnd-merkle': 'ndnd-merkle', + 'ndnd-site-ca': 'ndnd-site-ca', 'ndnd-dv': 'ndnd-dv', + 'ndnd-network-repo': 'ndnd-network-repo', + 'ndnd-network-merkle': 'ndnd-network-merkle', + } + for service, folder in services.items(): + directory = root / 'dist' / folder + directory.mkdir(parents=True) + (directory / 'renew.sh').write_text( + f'echo "renew {service} $*" >> "$CALL_LOG"\n' + f'exit {23 if service == failure else 0}\n') + for directory in ['ndncert', 'ndnd-repo', 'ndnd-merkle', 'ndnd-site-ca', + 'ndnd-dv', 'ndnd-network-repo', 'ndnd-network-merkle']: + path = root / 'dist' / directory + path.mkdir(exist_ok=True) + (path / '.security-changed').touch() + stubs = { + 'python3': '#!/bin/bash\n' + 'if [[ "$*" == *"--service ndnd-dv"* || "$*" == *"--service ndnd-site-ca"* || ' + '"$*" == *"--service ndnd-network-"* ]]; then echo "$TEST_NDND_ENABLED"; ' + 'elif [[ "$*" == *--service* ]]; then echo 1; else echo ndnd; fi\n', + 'docker': '#!/bin/bash\necho "docker $*" >> "$CALL_LOG"\n' + '[[ "$*" == *" ps "* ]] && echo running-container\nexit 0\n', + } + for name, text in stubs.items(): + path = root / 'bin' / name + path.write_text(text) + path.chmod(0o700) + script = root / 'scripts/cert-renew.sh' + script.write_bytes((ROOT / 'scripts/cert-renew.sh').read_bytes()) + log = root / 'calls.log' + result = subprocess.run( + ['bash', str(script), *(['--force'] if force else [])], cwd=root, + env=dict(os.environ, PATH=str(root / 'bin') + ':' + os.environ['PATH'], + CALL_LOG=str(log), TEST_NDND_ENABLED=str(int(enabled))), + capture_output=True, text=True, timeout=15) + return result, log.read_text().splitlines() + + def test_nfd_only_renewal_does_not_run_ndnd_services(self): + with tempfile.TemporaryDirectory() as directory: + result, calls = self.run_renewal(Path(directory), failure='ndnd-site-ca', enabled=False) + self.assertEqual(result.returncode, 0, result.stderr) + for service in ['ndnd-site-ca', 'ndnd-dv', 'ndnd-network-repo', 'ndnd-network-merkle']: + self.assertFalse(any(call.startswith('renew ' + service + ' ') for call in calls)) + self.assertIn('docker compose restart nlsr ndncert serve-certs ndn-python-repo', calls) + + def test_ndnd_failure_does_not_block_nfd_reloads(self): + for failure, marker in [('ndnd-site-ca', 'ndnd-site-ca'), + ('ndnd-dv', 'ndnd-dv'), + ('ndnd-network-repo', 'ndnd-network-repo')]: + with self.subTest(failure=failure), tempfile.TemporaryDirectory() as directory: + root = Path(directory) + result, calls = self.run_renewal(root, failure=failure) + self.assertEqual(result.returncode, 23, result.stderr) + failed = next(i for i, call in enumerate(calls) if call.startswith('renew ' + failure + ' ')) + for command in ['docker compose restart nlsr ndncert serve-certs ndn-python-repo', + 'docker compose restart ndnd-repo', + 'docker compose restart ndnd-merkle']: + self.assertIn(command, calls) + self.assertLess(calls.index(command), failed) + for service in ['ndncert', 'ndnd-repo', 'ndnd-merkle']: + self.assertFalse((root / 'dist' / service / '.security-changed').exists()) + self.assertTrue((root / 'dist' / marker / '.security-changed').exists()) + + def test_nfd_renewal_does_not_force_ndnd_but_manual_force_does(self): + for force in [False, True]: + with self.subTest(force=force), tempfile.TemporaryDirectory() as directory: + result, calls = self.run_renewal(Path(directory), force=force) + self.assertEqual(result.returncode, 0, result.stderr) + for service in ['ndnd-site-ca', 'ndnd-dv', 'ndnd-network-repo', 'ndnd-network-merkle']: + call = next(call for call in calls if call.startswith('renew ' + service + ' ')) + self.assertEqual('--force' in call, force, call) + + +if __name__ == '__main__': + unittest.main() diff --git a/framework/test_ndnd_network.py b/framework/test_ndnd_network.py new file mode 100644 index 0000000..86cfb5a --- /dev/null +++ b/framework/test_ndnd_network.py @@ -0,0 +1,112 @@ +import subprocess +import unittest +from unittest.mock import patch + +import jinja2 +import yaml + +from internal import ndnd_network +from internal import conf + + +class NetworkInitTest(unittest.TestCase): + def setUp(self): + self.commands = [] + self.containers = {} + for service, ip in [('nfd', '172.20.0.2'), ('ndnd', '172.20.0.3'), + ('ndnd-dv', ''), ('ndnd-network-repo', ''), + ('ndnd-site-ca', ''), ('ndnd-repo', ''), ('nlsr', '')]: + self.containers[service] = { + 'Id': service, 'Image': 'nfd-image', + 'Mounts': [{'Source': '/run/ndnd', 'Destination': '/run/ndnd'}, + {'Source': '/read-only/config', 'Destination': '/config'}], + 'State': {'Running': True, 'StartedAt': 'start-1'}, + 'NetworkSettings': {'Networks': {'default': {'IPAddress': ip}}}, + } + self.previous = {'forwarder_started': 'start-1', + 'to_nfd': 'udp4://172.20.0.2:6363', + 'to_ndnd': 'udp4://172.20.0.3:6364'} + + def run_command(self, args, check=True, **kwargs): + self.commands.append(args) + output = '' + if args[-2:] == ['fw', 'face-list']: + output = 'faceid=42 remote=udp4://172.20.0.2:6363\nfaceid=43 remote=udp4://172.20.0.9:6363\n' + elif args[-2:] == ['face', 'list']: + output = 'faceid=70 remote=udp4://172.20.0.8:6364\n' + return subprocess.CompletedProcess(args, 0, output, '') + + def configure(self, previous=None): + with patch.object(ndnd_network, 'run', side_effect=self.run_command): + return ndnd_network.configure(self.containers, {0: '/ndnd/a', 1: '/ndnd/b'}, + '/ndnd', 6364, self.previous if previous is None else previous) + + def test_announcement_uses_persistent_udp_face(self): + state = self.configure() + self.assertIn(['docker', 'exec', 'ndnd', '/ndnd', 'dv', 'prefix-announce', + 'prefix=/ndn', 'face=42'], self.commands) + self.assertEqual(state, self.previous) + self.assertIn(['docker', 'exec', 'nfd', 'nfdc', 'route', 'add', + '/ndnd', self.previous['to_ndnd'], 'capture'], self.commands) + self.assertTrue(any(c[:3] == ['docker', 'run', '--rm'] and + 'type=bind,src=/run/ndnd,dst=/run/ndnd,readonly' in c and + '--volumes-from' not in c and c[-4:] == ['create', self.previous['to_nfd'], + 'persistency', 'permanent'] + for c in self.commands)) + + def test_repeated_initialization_does_not_restart_services(self): + self.configure() + self.assertFalse(any(command[1] == 'restart' for command in self.commands)) + + def test_forwarder_restart_restores_only_its_dependents(self): + self.configure({}) + restarted = [command[2:] for command in self.commands if command[1] == 'restart'] + self.assertEqual(restarted, [['ndnd-dv'], ['ndnd-site-ca', 'ndnd-network-repo']]) + self.assertEqual(sum('bift-register' in command for command in self.commands), 2) + + def test_peer_address_change_removes_old_bridge_routes(self): + previous = dict(self.previous, to_nfd='udp4://172.20.0.9:6363', + to_ndnd='udp4://172.20.0.8:6364') + self.configure(previous) + self.assertIn(['docker', 'exec', 'ndnd', '/ndnd', 'dv', 'prefix-withdraw', + 'prefix=/ndn', 'face=43'], self.commands) + self.assertIn(['docker', 'exec', 'nfd', 'nfdc', 'route', 'remove', + '/ndnd', previous['to_ndnd']], self.commands) + + def test_stopped_dv_restarts_without_restarting_producers(self): + self.containers['ndnd-dv']['State']['Running'] = False + self.configure() + self.assertEqual([c[2:] for c in self.commands if c[1] == 'restart'], [['ndnd-dv']]) + + def test_duplicate_indices_rejected(self): + hosts = {'A': {'ndnd_enabled': True, 'ndnd_bier_index': 0, 'ndnd_router_prefix': '/ndnd/a'}, + 'B': {'ndnd_enabled': True, 'ndnd_bier_index': 0, 'ndnd_router_prefix': '/ndnd/b'}} + with self.assertRaises(ValueError): + ndnd_network.router_indices(hosts) + + def test_invalid_index_rejected(self): + for index in [None, -1, True, 1.5]: + with self.subTest(index=index), self.assertRaises(ValueError): + ndnd_network.router_indices({'A': {'ndnd_enabled': True, 'ndnd_bier_index': index}}) + + def test_enabled_hosts_have_stable_unique_indices_and_bridge_advertisements(self): + from pathlib import Path + config = conf.get() + hosts = {p.name: yaml.safe_load(p.read_text()) + for p in Path(config.host_vars_path).iterdir() if p.is_file()} + indices = ndnd_network.router_indices(hosts) + self.assertEqual(len(indices), 6) + env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'), undefined=jinja2.StrictUndefined) + for host in hosts.values(): + context = dict(host, **config.globals) + context['hostvars'] = {n: dict(h, **config.globals) for n, h in hosts.items()} + rendered = env.get_template('templates/nlsr/nlsr.conf.j2').render(**context) + advertising = rendered.split('advertising\n{', 1)[1].split('}', 1)[0] + self.assertEqual('/ndnd 0' in advertising, bool(host.get('ndnd_enabled'))) + if host.get('ndnd_enabled'): + fw = yaml.safe_load(env.get_template('templates/ndnd/yanfd.yml.j2').render(**context)) + self.assertEqual(indices[fw['fw']['bier_index']], host['ndnd_router_prefix']) + + +if __name__ == '__main__': + unittest.main() diff --git a/framework/test_ndnd_status_trust.py b/framework/test_ndnd_status_trust.py new file mode 100644 index 0000000..4aadbd7 --- /dev/null +++ b/framework/test_ndnd_status_trust.py @@ -0,0 +1,84 @@ +import base64 +from pathlib import Path +import unittest + +import jinja2 +import yaml +from ndn.app_support.light_versec import Checker, compile_lvs + +from internal import conf +from internal.render import JINJA_FUNCTIONS + + +class TestNdndStatusTrust(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.config = conf.get() + cls.hostvars = {} + for path in Path(cls.config.host_vars_path).iterdir(): + if path.is_file(): + cls.hostvars[path.name] = { + **yaml.safe_load(path.read_text()), + **cls.config.globals, + 'inventory_hostname': path.name, + } + cls.environment = jinja2.Environment( + loader=jinja2.FileSystemLoader(cls.config.environment_path), + undefined=jinja2.StrictUndefined, + trim_blocks=True, + lstrip_blocks=True, + ) + + def render(self, template, host): + return self.environment.get_template(template).render( + **self.hostvars[host], hostvars=self.hostvars, **JINJA_FUNCTIONS) + + def test_router_and_status_authorization(self): + root = self.config.globals['ndnd_dv_network'] + root_cert = root + '/KEY/root/self/v=1' + for host, values in self.hostvars.items(): + if not values.get('ndnd_enabled'): + continue + with self.subTest(host=host): + routing = self.render('templates/ndnd-dv/dv-schema.lvs.j2', host) + status = self.render('templates/ndnd-http-status-server/dv-schema.lvs.j2', host) + model = compile_lvs(routing) + self.assertEqual(0x00011000, model.version) + self.assertEqual(bytes(model.encode()), bytes(compile_lvs(status).encode())) + published = self.render('templates/file-server/ndnd/dv-schema.lvs.j2', host) + self.assertEqual(bytes(model.encode()), bytes(compile_lvs(published).encode())) + checker = Checker(model, {}) + router = values['ndnd_router_prefix'] + cert = router + '/32=DV/KEY/router/root/v=1' + self.assertTrue(checker.check(cert, root_cert)) + for name in [router + '/32=DV/32=STATUS', + '/localhop' + router + '/32=DV/32=ADV/v=1', + root + '/32=DV/32=PSD' + router + '/t=1/seq=1']: + self.assertTrue(checker.check(name, cert), name) + self.assertFalse(checker.check(name, root_cert), name) + self.assertFalse(checker.check(name, router + '/g/user/KEY/key/site/v=1'), name) + for peer, peer_values in self.hostvars.items(): + if peer != host and peer_values.get('ndnd_enabled'): + peer_cert = peer_values['ndnd_router_prefix'] + '/32=DV/KEY/router/root/v=1' + self.assertFalse(checker.check(name, peer_cert), name) + outsider = root + '/unlisted/32=DV' + self.assertFalse(checker.check(outsider + '/KEY/router/root/v=1', root_cert)) + self.assertFalse(checker.check(outsider + '/32=STATUS', cert)) + + dv = yaml.safe_load(self.render('templates/ndnd-dv/dv.yml.j2', host))['dv'] + self.assertEqual('/config/dv-schema.tlv', dv['trust_schema']) + fw = yaml.safe_load(self.render('templates/ndnd/yanfd.yml.j2', host)) + self.assertEqual(router, fw['fw']['router_name']) + + def test_public_status_anchor_matches_pin(self): + for host, values in self.hostvars.items(): + if values.get('ndnd_enabled'): + with self.subTest(host=host): + pem = self.render('templates/ndnd-http-status-server/root.cert.pem.j2', host) + wire = base64.b64decode(''.join(pem.splitlines()[1:-1]), validate=True) + pinned = base64.b64decode(''.join(Path(values['ndnd_root_anchor_path']).read_text().split()), validate=True) + self.assertEqual(pinned, wire) + + +if __name__ == '__main__': + unittest.main() diff --git a/host_vars/ARIZONA b/host_vars/ARIZONA index 1ea4965..138ddc0 100644 --- a/host_vars/ARIZONA +++ b/host_vars/ARIZONA @@ -32,6 +32,10 @@ neighbors: position: - 32.2289614 - -110.9483226 +ndnd_ca_prefix: /ndnd/arizona hr_angle: 2.97033 hr_radius: 16.2305 ethernet_device: eth0 +ndnd_enabled: true +ndnd_router_prefix: /ndnd/arizona +ndnd_bier_index: 2 diff --git a/host_vars/FRANKFURT b/host_vars/FRANKFURT index b367e10..7d0c2e0 100644 --- a/host_vars/FRANKFURT +++ b/host_vars/FRANKFURT @@ -34,6 +34,10 @@ neighbors: position: - 50.1187 - 8.6842 +ndnd_ca_prefix: /ndnd/frankfurt hr_angle: 0 hr_radius: 0 ethernet_device: eth0 +ndnd_enabled: true +ndnd_router_prefix: /ndnd/frankfurt +ndnd_bier_index: 5 diff --git a/host_vars/HK b/host_vars/HK index e71458b..0d01efa 100644 --- a/host_vars/HK +++ b/host_vars/HK @@ -24,6 +24,10 @@ neighbors: position: - 22.3193 - 114.1694 +ndnd_ca_prefix: /ndnd/hk hr_angle: 0 hr_radius: 0 ethernet_device: eth0 +ndnd_enabled: true +ndnd_router_prefix: /ndnd/hk +ndnd_bier_index: 3 diff --git a/host_vars/MEMPHIS b/host_vars/MEMPHIS index 0e4e254..6b53709 100644 --- a/host_vars/MEMPHIS +++ b/host_vars/MEMPHIS @@ -27,6 +27,10 @@ neighbors: position: - 35.1186099 - -89.93700109999999 +ndnd_ca_prefix: /ndnd/memphis hr_angle: 2.9836 hr_radius: 15.2647 ethernet_device: eth1 +ndnd_enabled: true +ndnd_router_prefix: /ndnd/memphis +ndnd_bier_index: 1 diff --git a/host_vars/SINGAPORE b/host_vars/SINGAPORE index 18cd1db..140e10a 100644 --- a/host_vars/SINGAPORE +++ b/host_vars/SINGAPORE @@ -32,6 +32,10 @@ neighbors: position: - 1.2868 - 103.8503 +ndnd_ca_prefix: /ndnd/singapore hr_angle: 0 hr_radius: 0 ethernet_device: eth0 +ndnd_enabled: true +ndnd_router_prefix: /ndnd/singapore +ndnd_bier_index: 4 diff --git a/host_vars/UCLA b/host_vars/UCLA index cccbe67..05e4d79 100644 --- a/host_vars/UCLA +++ b/host_vars/UCLA @@ -40,7 +40,11 @@ neighbors: position: - 34.0728225 - -118.4387398 +ndnd_ca_prefix: /ndnd/ucla hr_angle: 2.99911 hr_radius: 16.5866 ethernet_device: eth0 is_root_ca: true +ndnd_enabled: true +ndnd_router_prefix: /ndnd/ucla +ndnd_bier_index: 0 diff --git a/scripts/cert-renew.sh b/scripts/cert-renew.sh index dc2f14d..b80f018 100644 --- a/scripts/cert-renew.sh +++ b/scripts/cert-renew.sh @@ -2,6 +2,9 @@ source "$(pwd)/scripts/utils.sh" +COMPOSE_PROFILES=$(python3 framework/service-profiles.py) || exit $? +export COMPOSE_PROFILES + NDNCERT_CERTFILE="$(pwd)/dist/ndncert/site.ndncert" FORCE="" @@ -36,27 +39,59 @@ if [[ -f dist/ndnd-repo/.security-changed ]]; then rm -f dist/ndnd-repo/.security-changed fi -# Optional services run after the core renewals and retain their own retry state. -MERKLE_ENABLED=$(python3 framework/service-profiles.py --service ndnd-merkle) || exit $? -if [[ "${MERKLE_ENABLED}" == 1 ]]; then - MERKLE_DIR=dist/ndnd-merkle - if [[ -n "${FORCE}" ]]; then - touch "${MERKLE_DIR}/.renew-pending" - fi - MERKLE_FORCE="" - if [[ -f "${MERKLE_DIR}/.renew-pending" ]]; then - MERKLE_FORCE="--force" +reload_changed() { + local service="$1" directory="$2" running + if [[ -f "${directory}/.security-changed" ]]; then + running=$(PWD="${ROOT_DIR:-$PWD}" docker compose ps --status running -q "$service") || return $? + if [[ -n "$running" ]]; then + PWD="${ROOT_DIR:-$PWD}" docker compose restart "$service" || return $? + fi + rm -f "${directory}/.security-changed" fi - if bash "${MERKLE_DIR}/renew.sh" ${MERKLE_FORCE:+"${MERKLE_FORCE}"}; then - rm -f "${MERKLE_DIR}/.renew-pending" - if [[ -f "${MERKLE_DIR}/.security-changed" ]]; then - RUNNING_LOG=$(PWD="${ROOT_DIR:-$PWD}" docker compose ps --status running -q ndnd-merkle) || exit $? - if [[ -n "${RUNNING_LOG}" ]]; then - PWD="${ROOT_DIR:-$PWD}" docker compose restart ndnd-merkle || exit $? - fi - rm -f "${MERKLE_DIR}/.security-changed" +} + +# Optional services retain their own renewal and reload retry state. +renew_merkle() { + local MERKLE_SERVICE="$1" + local MERKLE_ENABLED MERKLE_DIR MERKLE_FORCE + MERKLE_ENABLED=$(python3 framework/service-profiles.py --service "${MERKLE_SERVICE}") || return $? + if [[ "${MERKLE_ENABLED}" == 1 ]]; then + MERKLE_DIR="dist/${MERKLE_SERVICE}" + if [[ -n "$2" ]]; then + touch "${MERKLE_DIR}/.renew-pending" + fi + MERKLE_FORCE="" + if [[ -f "${MERKLE_DIR}/.renew-pending" ]]; then + MERKLE_FORCE="--force" + fi + if bash "${MERKLE_DIR}/renew.sh" ${MERKLE_FORCE:+"${MERKLE_FORCE}"}; then + rm -f "${MERKLE_DIR}/.renew-pending" + reload_changed "$MERKLE_SERVICE" "$MERKLE_DIR" || return $? + else + echo "${MERKLE_SERVICE} credential renewal failed; core services renewed, log will retry next poll" >&2 fi - else - echo "NDNd Merkle credential renewal failed; core services renewed, log will retry next poll" >&2 fi +} + +# Finish existing NFD renewals and reloads before processing the separate network. +renew_merkle ndnd-merkle "${FORCE}" || exit $? + +# A site-certificate change on NFD must not force unrelated NDNd credentials. +NDND_FORCE=${HAS_FORCE:+--force} +DV_ENABLED=$(python3 framework/service-profiles.py --service ndnd-dv) || exit $? +if [[ "${DV_ENABLED}" == 1 ]]; then + SITE_CA_ENABLED=$(python3 framework/service-profiles.py --service ndnd-site-ca) || exit $? + if [[ "${SITE_CA_ENABLED}" == 1 ]]; then + SITE_CA_DIR=dist/ndnd-site-ca + bash "${SITE_CA_DIR}/renew.sh" ${NDND_FORCE:+"${NDND_FORCE}"} || exit $? + reload_changed ndnd-site-ca "${SITE_CA_DIR}" || exit $? + fi + DV_DIR=dist/ndnd-dv + bash "${DV_DIR}/renew.sh" ${NDND_FORCE:+"${NDND_FORCE}"} || exit $? + reload_changed ndnd-dv "${DV_DIR}" || exit $? + NETWORK_REPO_DIR=dist/ndnd-network-repo + bash "${NETWORK_REPO_DIR}/renew.sh" ${NDND_FORCE:+"${NDND_FORCE}"} || exit $? + reload_changed ndnd-network-repo "${NETWORK_REPO_DIR}" || exit $? fi + +renew_merkle ndnd-network-merkle "${NDND_FORCE}" || exit $? diff --git a/scripts/cron-host.sh b/scripts/cron-host.sh index a09bd3f..74ae02a 100755 --- a/scripts/cron-host.sh +++ b/scripts/cron-host.sh @@ -29,6 +29,9 @@ COMPOSE_PROFILES=$(docker compose exec -T master python3 framework/service-profi export COMPOSE_PROFILES # Ensure services are running -docker compose up -d --remove-orphans +docker compose up -d --remove-orphans || exit $? + +# Services must be running before their management commands can install routes. +docker compose exec -T -e PWD="$PWD" master python3 framework/ndnd-network-init.py || exit $? echo -e "Finished cron-host at $(date)" >&2 diff --git a/scripts/cron-master.sh b/scripts/cron-master.sh index 5baef03..db84201 100755 --- a/scripts/cron-master.sh +++ b/scripts/cron-master.sh @@ -29,4 +29,7 @@ PWD="${ROOT_DIR}" python3 framework/main.py || exit $? # Renew certificates if needed bash $(pwd)/scripts/cert-renew.sh || exit $? +# Restore runtime forwarding entries after rendered services or credentials changed. +PWD="${ROOT_DIR:-$PWD}" python3 framework/ndnd-network-init.py || exit $? + echo -e "Finished cron-master at $(date)" >&2 diff --git a/scripts/ndnd-infra-security.py b/scripts/ndnd-infra-security.py index 6b77abf..8068f13 100644 --- a/scripts/ndnd-infra-security.py +++ b/scripts/ndnd-infra-security.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Provision NDNd's directory keychain using the existing ndn-cxx site CA.""" +"""Provision NDNd service keychains using the testbed certificate authorities.""" import argparse import base64 @@ -12,13 +12,15 @@ import subprocess import tempfile import time +from urllib.parse import urlencode +from urllib.request import Request, urlopen from Cryptodome.PublicKey import ECC, RSA import yaml from ndn.app_support.security_v2 import new_cert, parse_certificate from ndn.encoding import Component, ContentType, MetaInfo, Name, SignatureType, make_data, parse_data from ndn.security import Sha256WithEcdsaSigner -from ndn.security.validator import verify_ecdsa, verify_rsa +from ndn.security.validator import verify_ecdsa, verify_ed25519, verify_rsa def decode_certificate(path): @@ -61,6 +63,18 @@ def import_packet(directory, wire, kind): return write_atomic(path, pem(wire, kind)) +def sign_with_root_ca(csr, root_ca_url, secret, before, after): + query = urlencode({ + 'not_before': before.strftime('%Y%m%d%H%M%S'), + 'not_after': after.strftime('%Y%m%d%H%M%S'), + }) + url = f'{root_ca_url.rstrip("/")}/sign?{query}' + request = Request(url, data=base64.encodebytes(csr), method='POST', + headers={'Authorization': f'Bearer {secret}'}) + with urlopen(request, timeout=30) as response: + return base64.b64decode(b''.join(response.read().split()), validate=True) + + def validity(wire): period = parse_certificate(wire).signature_info.validity_period return tuple(datetime.strptime(bytes(value).decode(), '%Y%m%dT%H%M%S').replace(tzinfo=timezone.utc) @@ -82,6 +96,8 @@ def verify_certificate(wire, issuer): return verify_ecdsa(ECC.import_key(bytes(parent.content)), pointers) if signature_type == SignatureType.SHA256_WITH_RSA: return verify_rsa(RSA.import_key(bytes(parent.content)), pointers) + if signature_type == SignatureType.ED25519: + return verify_ed25519(ECC.import_key(bytes(parent.content)), pointers) return False @@ -112,41 +128,83 @@ def get_key(directory, identity): return name, key, wire -def provision(directory, site_home, site_prefix, anchors_path, force=False, renew_before_days=30, service='repo'): +def provision(directory, site_home, site_prefix, anchors_path, force=False, renew_before_days=30, + service='repo', root_ca_url='', root_cert_path=None, identity=None): # Serialize overlapping cron/manual renewal runs without rotating the key. + directory.mkdir(mode=0o700, parents=True, exist_ok=True) with (directory / '.security.lock').open('a') as lock: fcntl.flock(lock, fcntl.LOCK_EX) - return provision_locked(directory, site_home, site_prefix, anchors_path, force, renew_before_days, service) + return provision_locked(directory, site_home, site_prefix, anchors_path, force, renew_before_days, + service, root_ca_url, root_cert_path, identity) -def provision_locked(directory, site_home, site_prefix, anchors_path, force, renew_before_days, service): - if service not in ('repo', 'merkle'): +def provision_locked(directory, site_home, site_prefix, anchors_path, force, renew_before_days, + service, root_ca_url, root_cert_path, identity): + if service not in ('repo', 'merkle', 'dv', 'ca'): raise ValueError('Unsupported NDNd service') - if service == 'merkle' and site_prefix != '/ndn/edu/ucla': + if service == 'merkle' and site_prefix not in ('/ndn/edu/ucla', '/ndnd/ucla'): raise ValueError('Merkle log provisioning is restricted to UCLA') - with (directory / f'{service}.yml').open() as stream: - config = yaml.safe_load(stream)[service] - identity = Name.normalize(config['name']) - if Name.to_bytes(identity) != Name.to_bytes(Name.normalize(site_prefix + '/ndnd/' + service)): - raise ValueError(f'Identity must be /ndnd/{service}') + if service == 'ca': + config = {} + else: + with (directory / f'{service}.yml').open() as stream: + config = yaml.safe_load(stream)[service] + if service == 'dv': + identity = Name.normalize(config['router'] + '/32=DV') + expected_identity = Name.normalize(site_prefix + '/32=DV') + elif service == 'ca': + if not identity: + raise ValueError('Site CA provisioning requires an explicit identity') + identity = Name.normalize(identity) + expected_identity = Name.normalize(site_prefix) + else: + expected_identity = Name.normalize(identity or (site_prefix + '/ndnd/' + service)) + identity = Name.normalize(config['name']) + if not Name.is_prefix(Name.normalize(site_prefix), expected_identity): + raise ValueError('Service identity must be beneath the site prefix') + if Name.to_bytes(identity) != Name.to_bytes(expected_identity): + raise ValueError(f'Invalid {service} identity {Name.to_str(identity)}') now = datetime.now(timezone.utc) - site_wire = decode_certificate(site_home / 'site.ndncert') - site = parse_certificate(site_wire) - if Name.to_bytes(site.name[:-4]) != Name.to_bytes(Name.normalize(site_prefix)): - raise ValueError('Site certificate has the wrong identity') - available = {} - for path in anchors_path.glob('*.base64'): - wire = decode_certificate(path) - available[Name.to_str(parse_certificate(wire).name)] = wire - anchor_wires = [available[name] for name in config['trust_anchors']] - if not anchor_wires: - raise ValueError('At least one pinned trust anchor is required') - issuer = next((wire for wire in anchor_wires if verify_certificate(site_wire, wire)), None) - if issuer is None: - raise ValueError('Site certificate does not verify against a pinned testbed root') - site_before, site_after = validity(site_wire) - root_before, root_after = validity(issuer) + if service in ('dv', 'ca'): + if not root_ca_url or not os.environ.get('NDND_ROOT_CA_SECRET') or root_cert_path is None: + raise ValueError('Root-issued credentials require a CA URL, secret and pinned certificate') + issuer = decode_certificate(root_cert_path) + root = parse_certificate(issuer) + root_identity = root.name[:-4] + expected_root = Name.normalize('/ndnd') + if Name.to_bytes(root_identity) != Name.to_bytes(expected_root): + raise ValueError(f'NDNd CA certificate identity must be /ndnd, got {Name.to_str(root_identity)}') + if service == 'dv' and Name.to_str(root.name) not in config.get('trust_anchors', []): + raise ValueError('DV configuration does not trust the configured NDNd root certificate') + if not verify_certificate(issuer, issuer): + raise ValueError('NDNd root certificate is not self-signed by its own key') + anchor_wires = [issuer] + signing_issuer = issuer + root_before, root_after = validity(issuer) + site_before = root_before + site_after = root_after + else: + site_cert_path = site_home / 'site.ndncert' + if not site_cert_path.exists(): + site_cert_path = site_home / 'ca.ndncert' + site_wire = decode_certificate(site_cert_path) + site = parse_certificate(site_wire) + if Name.to_bytes(site.name[:-4]) != Name.to_bytes(Name.normalize(site_prefix)): + raise ValueError('Site certificate has the wrong identity') + available = {} + for path in anchors_path.glob('*.base64'): + wire = decode_certificate(path) + available[Name.to_str(parse_certificate(wire).name)] = wire + anchor_wires = [available[name] for name in config['trust_anchors']] + if not anchor_wires: + raise ValueError('At least one pinned trust anchor is required') + issuer = next((wire for wire in anchor_wires if verify_certificate(site_wire, wire)), None) + if issuer is None: + raise ValueError('Site certificate does not verify against a pinned testbed root') + signing_issuer = site_wire + site_before, site_after = validity(site_wire) + root_before, root_after = validity(issuer) # ndn-cxx rounds NotBefore up to a whole second when issuing a certificate. # Wait for that boundary rather than accepting a certificate before it is valid. starts = max(site_before, root_before) @@ -170,49 +228,76 @@ def provision_locked(directory, site_home, site_prefix, anchors_path, force, ren renew |= (not before <= now < after - margin or Name.to_bytes(cert.name[:-2]) != Name.to_bytes(key_name) or bytes(cert.content) != key.public_key().export_key(format='DER') - or not verify_certificate(cert_wire, site_wire) + or not verify_certificate(cert_wire, signing_issuer) or before < max(site_before, root_before) or after > min(site_after, root_after)) if renew: before = max(now - timedelta(minutes=5), site_before, root_before).replace(microsecond=0) after = min(now + timedelta(days=90), site_after, root_after).replace(microsecond=0) + if service in ('dv', 'ca'): + after = min(after, before + timedelta(days=90)) if after <= now + margin: raise ValueError('Renew the site/root certificate before issuing a service certificate') signer = Sha256WithEcdsaSigner(key_name, key.export_key(format='DER', use_pkcs8=False)) _, csr = new_cert(key_name, Component.from_str('self'), key.public_key().export_key(format='DER'), signer, before, after) - command = ['ndnsec', 'cert-gen', '-s', site_prefix, - '-S', before.strftime('%Y%m%d%H%M%S'), '-E', after.strftime('%Y%m%d%H%M%S'), '-'] - result = subprocess.run(command, input=base64.encodebytes(csr), stdout=subprocess.PIPE, - env={**os.environ, 'HOME': str(site_home)}, check=True, timeout=30) - cert_wire = base64.b64decode(b''.join(result.stdout.split()), validate=True) + if service in ('dv', 'ca'): + cert_wire = sign_with_root_ca(csr, root_ca_url, os.environ['NDND_ROOT_CA_SECRET'], before, after) + elif site_cert_path.name == 'ca.ndncert': + site_key_wire = decode_pem((site_home / 'ca.key.pem').read_text(), 'KEY') + _, _, secret, _ = parse_data(site_key_wire) + site_key = ECC.import_key(bytes(secret)) + if site_key.public_key().export_key(format='DER') != bytes(site.content): + raise ValueError('Site CA private key does not match its certificate') + site_signer = Sha256WithEcdsaSigner(site.name[:-2], site_key.export_key(format='DER', use_pkcs8=False)) + _, cert_wire = new_cert(key_name, Component.from_str('site'), + key.public_key().export_key(format='DER'), site_signer, before, after) + else: + command = ['ndnsec', 'cert-gen', '-s', site_prefix, + '-S', before.strftime('%Y%m%d%H%M%S'), '-E', after.strftime('%Y%m%d%H%M%S'), '-'] + result = subprocess.run(command, input=base64.encodebytes(csr), stdout=subprocess.PIPE, + env={**os.environ, 'HOME': str(site_home)}, check=True, timeout=30) + cert_wire = base64.b64decode(b''.join(result.stdout.split()), validate=True) cert = parse_certificate(cert_wire) actual_before, actual_after = validity(cert_wire) if (Name.to_bytes(cert.name[:-2]) != Name.to_bytes(key_name) or bytes(cert.content) != key.public_key().export_key(format='DER') - or not verify_certificate(cert_wire, site_wire) + or not verify_certificate(cert_wire, signing_issuer) or not before <= actual_before <= now < actual_after <= after): raise ValueError('Site CA returned an invalid service certificate') # Prepare every credential before marking it for a service reload. changed = import_packet(keys, key_wire, 'KEY') - for wire in [*anchor_wires, site_wire, cert_wire]: + certificates = [*anchor_wires, cert_wire] + if service not in ('dv', 'ca'): + certificates.insert(len(anchor_wires), site_wire) + for wire in certificates: changed |= import_packet(keys, wire, 'CERT') changed |= write_atomic(cert_path, base64.encodebytes(cert_wire)) + if service == 'ca': + changed |= write_atomic(directory / 'ca.cert.pem', pem(cert_wire, 'CERT')) + changed |= write_atomic(directory / 'ca.key.pem', pem(key_wire, 'KEY')) if changed: write_atomic(directory / '.security-changed', b'\n') - print(f"NDNd {service} {config['name']}: {'credentials updated' if changed else 'credentials current'}") + print(f"NDNd {service} {Name.to_str(identity)}: {'credentials updated' if changed else 'credentials current'}") return changed if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--directory', type=Path, required=True) - parser.add_argument('--site-home', type=Path, required=True) + parser.add_argument('--site-home', type=Path) parser.add_argument('--site-prefix', required=True) - parser.add_argument('--anchors', type=Path, required=True) - parser.add_argument('--service', choices=('repo', 'merkle'), default='repo') + parser.add_argument('--anchors', type=Path) + parser.add_argument('--service', choices=('repo', 'merkle', 'dv', 'ca'), default='repo') + parser.add_argument('--identity') + parser.add_argument('--root-ca-url', default='') + parser.add_argument('--root-cert', type=Path) parser.add_argument('--force', action='store_true') args = parser.parse_args() - provision(args.directory, args.site_home, args.site_prefix, args.anchors, args.force, service=args.service) + if args.service in ('repo', 'merkle') and (args.site_home is None or args.anchors is None): + parser.error('--site-home and --anchors are required for repo and merkle') + provision(args.directory, args.site_home, args.site_prefix, args.anchors, args.force, + service=args.service, root_ca_url=args.root_ca_url, root_cert_path=args.root_cert, + identity=args.identity) diff --git a/templates/caddy/Caddyfile.j2 b/templates/caddy/Caddyfile.j2 index bb6973f..0cc5f18 100644 --- a/templates/caddy/Caddyfile.j2 +++ b/templates/caddy/Caddyfile.j2 @@ -1,10 +1,28 @@ {{ ansible_host }} { + {% if ndnd_enabled | default(false) %} + redir /ndnd-status /ndnd-status/ 308 + handle_path /ndnd-status/* { + reverse_proxy http://ndnd-http-status-server:6380 + } + + @ndndws path /ndnd /ndnd/* + reverse_proxy @ndndws http://ndnd:9696 + {% endif %} + @nfdstatus path / /nfd-status.xsl /xslt-polyfill.min.js /*.css reverse_proxy @nfdstatus http://nfd-http-status-server:6380 @ws path /ws /ws/* reverse_proxy @ws http://nfd:9696 + {% if ndnd_enabled | default(false) and inventory_hostname == ndnd_ca_host %} + handle_path /ndnd-ca/* { + reverse_proxy http://ndnd-root-http-ca:8777 { + header_up X-Forwarded-For {remote_host} + } + } + {% endif %} + root * /srv file_server diff --git a/templates/file-server/ndnd/dv-schema.lvs.j2 b/templates/file-server/ndnd/dv-schema.lvs.j2 new file mode 100644 index 0000000..25418dd --- /dev/null +++ b/templates/file-server/ndnd/dv-schema.lvs.j2 @@ -0,0 +1 @@ +{% include "templates/ndnd-dv/dv-schema.lvs.j2" %} diff --git a/templates/ndnd-dv/dv-schema.lvs.j2 b/templates/ndnd-dv/dv-schema.lvs.j2 new file mode 100644 index 0000000..0fc1e63 --- /dev/null +++ b/templates/ndnd-dv/dv-schema.lvs.j2 @@ -0,0 +1,17 @@ +// All NDNd routers use the shared /ndnd DV network. The testbed root +// directly issues each site router's /32=DV certificate. +#KEY: "KEY"/_/_/_ +#network: {{ ndn_lvs_name(ndnd_dv_network) }} +#network_cert: {{ ndn_lvs_name(ndnd_dv_network) }}/#KEY +#prefix_state: #network/"32=DV"/"32=PSD" + +{% for host, values in hostvars.items() %} +{% if values.get('ndnd_enabled', false) %} +{% set router = ndn_lvs_name(values.ndnd_router_prefix) %} +#router_{{ loop.index }}: {{ router }} +#router_cert_{{ loop.index }}: #router_{{ loop.index }}/"32=DV"/#KEY <= #network_cert +#advertisement_data_{{ loop.index }}: /"localhop"/#router_{{ loop.index }}/"32=DV"/"32=ADV"/_ <= #router_cert_{{ loop.index }} +#status_data_{{ loop.index }}: #router_{{ loop.index }}/"32=DV"/"32=STATUS" <= #router_cert_{{ loop.index }} +#prefix_state_data_{{ loop.index }}: #prefix_state/#router_{{ loop.index }}/_/_ <= #router_cert_{{ loop.index }} +{% endif %} +{% endfor %} diff --git a/templates/ndnd-dv/dv.yml.j2 b/templates/ndnd-dv/dv.yml.j2 new file mode 100644 index 0000000..7a25c92 --- /dev/null +++ b/templates/ndnd-dv/dv.yml.j2 @@ -0,0 +1,19 @@ +dv: + network: {{ ndnd_dv_network | tojson }} + router: {{ ndnd_router_prefix | tojson }} + keychain: dir:///config/keys + trust_schema: /config/dv-schema.tlv + trust_anchors: + - {{ ndn_cert_name(read_file(ndnd_root_anchor_path)) | tojson }} + neighbors: + {% set peers = namespace(count=0) %} + {% for host in neighbors %} + {% set values = hostvars[host] %} + {% if host != inventory_hostname and values.get('ndnd_enabled', false) %} + - uri: {{ ("udp4://" + values.host_ip + ":" + str(ndnd_udp_port)) | tojson }} + {% set peers.count = peers.count + 1 %} + {% endif %} + {% endfor %} + {% if peers.count == 0 %} + [] + {% endif %} diff --git a/templates/ndnd-dv/renew.sh.j2 b/templates/ndnd-dv/renew.sh.j2 new file mode 100644 index 0000000..de3f95f --- /dev/null +++ b/templates/ndnd-dv/renew.sh.j2 @@ -0,0 +1,21 @@ +#!/bin/bash + +set -eu + +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TESTBED_DIR="$(cd "${REPO_DIR}/../.." && pwd)" +source "${TESTBED_DIR}/.env" +NDND_ROOT_CA_SECRET="${VAR_NDND_ROOT_CA_SECRET:?Set VAR_NDND_ROOT_CA_SECRET in .env}" +export NDND_ROOT_CA_SECRET +{% if inventory_hostname == ndnd_ca_host %} +NDND_ROOT_HTTP_CA_URL={{ ndnd_root_http_ca_internal_url | tojson }} +{% else %} +NDND_ROOT_HTTP_CA_URL={{ ndnd_root_http_ca_url | tojson }} +{% endif %} + +python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ + --directory "${REPO_DIR}" \ + --site-prefix {{ ndnd_router_prefix | tojson }} \ + --service dv \ + --root-ca-url "${NDND_ROOT_HTTP_CA_URL}" \ + --root-cert "${TESTBED_DIR}/{{ ndnd_root_anchor_path }}" "$@" diff --git a/templates/ndnd-http-status-server/dv-schema.lvs.j2 b/templates/ndnd-http-status-server/dv-schema.lvs.j2 new file mode 100644 index 0000000..25418dd --- /dev/null +++ b/templates/ndnd-http-status-server/dv-schema.lvs.j2 @@ -0,0 +1 @@ +{% include "templates/ndnd-dv/dv-schema.lvs.j2" %} diff --git a/templates/ndnd-http-status-server/root.cert.pem.j2 b/templates/ndnd-http-status-server/root.cert.pem.j2 new file mode 100644 index 0000000..960f641 --- /dev/null +++ b/templates/ndnd-http-status-server/root.cert.pem.j2 @@ -0,0 +1,3 @@ +-----BEGIN NDN CERT----- +{{ oneline(read_file(ndnd_root_anchor_path)) }} +-----END NDN CERT----- diff --git a/templates/ndnd-network-merkle/management-schema.lvs.j2 b/templates/ndnd-network-merkle/management-schema.lvs.j2 new file mode 100644 index 0000000..ac172f5 --- /dev/null +++ b/templates/ndnd-network-merkle/management-schema.lvs.j2 @@ -0,0 +1,28 @@ +// Root -> user, or root -> site -> user/log; only the local log signs responses. +#key: "KEY"/_/_/_ +#root: {{ ndn_lvs_name(ndnd_dv_network) }}/#key +{% for depth in range(1, 7) %} +#root_user_{{ depth }}: {{ ndn_lvs_name(ndnd_dv_network) }}{% for n in range(depth) %}/rootuser{{ n }}{% endfor %} + +#root_user_key_{{ depth }}: #root_user_{{ depth }}/#key <= #root +#root_append_{{ depth }}: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/#root_user_{{ depth }}/_ <= #root_user_key_{{ depth }} +{% endfor %} +{% for host, values in hostvars.items() %} +{% if values.get('ndnd_enabled', false) %} +{% set site_id = loop.index %} +#site_{{ site_id }}: {{ ndn_lvs_name(values.ndnd_ca_prefix) }}/#key <= #root +{% for depth in range(1, 6) %} +{% set id = site_id ~ '_' ~ depth %} +#user_{{ id }}: {{ ndn_lvs_name(values.ndnd_ca_prefix) }}{% for n in range(depth) %}/user{{ n }}{% endfor %} + +#user_key_{{ id }}: #user_{{ id }}/#key <= #site_{{ site_id }} +#append_{{ id }}: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/#user_{{ id }}/_ <= #user_key_{{ id }} +{% endfor %} +{% if host == inventory_hostname %} +#log_key: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/#key <= #site_{{ site_id }} +{% endif %} +{% endif %} +{% endfor %} +// Object validation removes terminal version and segment components. +#append_response: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/_ <= #log_key +#check_response: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=check"/_ <= #log_key diff --git a/templates/ndnd-network-merkle/merkle.yml.j2 b/templates/ndnd-network-merkle/merkle.yml.j2 new file mode 100644 index 0000000..1fbea6a --- /dev/null +++ b/templates/ndnd-network-merkle/merkle.yml.j2 @@ -0,0 +1,8 @@ +merkle: + name: {{ (ndnd_router_prefix + '/merkle') | tojson }} + storage_dir: /config/storage + max_entries: 1000000 + keychain: dir:///config/keys + trust_schema: /config/management-schema.tlv + trust_anchors: + - {{ ndn_cert_name(read_file(ndnd_root_anchor_path)) | tojson }} diff --git a/templates/ndnd-network-merkle/renew.sh.j2 b/templates/ndnd-network-merkle/renew.sh.j2 new file mode 100644 index 0000000..a0c9ee5 --- /dev/null +++ b/templates/ndnd-network-merkle/renew.sh.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +set -eu + +SERVICE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TESTBED_DIR="$(cd "${SERVICE_DIR}/../.." && pwd)" + +python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ + --service merkle \ + --directory "${SERVICE_DIR}" \ + --site-home "${TESTBED_DIR}/dist/ndnd-site-ca" \ + --site-prefix {{ ndnd_ca_prefix | tojson }} \ + --identity {{ (ndnd_router_prefix + '/merkle') | tojson }} \ + --anchors "${TESTBED_DIR}/anchors" "$@" diff --git a/templates/ndnd-network-repo/management-schema.lvs.j2 b/templates/ndnd-network-repo/management-schema.lvs.j2 new file mode 100644 index 0000000..2b56274 --- /dev/null +++ b/templates/ndnd-network-repo/management-schema.lvs.j2 @@ -0,0 +1,33 @@ +#key: "KEY"/_/_/_ +#root: {{ ndn_lvs_name(ndnd_dv_network) }}/#key +#flat_user: {{ ndn_lvs_name(ndnd_dv_network) }}/user +#flat_user_key: #flat_user/#key <= #root +#flat_command: #flat_user/"32=repo" <= #flat_user_key +#flat_security: #flat_user/"32=repo-security" <= #flat_user_key +{% for depth in range(2, 7) %} +// Root-issued NDNCERT identities may have multiple components (e.g. com/gmail/user). +#root_user_{{ depth }}: {{ ndn_lvs_name(ndnd_dv_network) }}{% for n in range(depth) %}/rootuser{{ n }}{% endfor %} + +#root_user_key_{{ depth }}: #root_user_{{ depth }}/#key <= #root +#root_command_{{ depth }}: #root_user_{{ depth }}/"32=repo" <= #root_user_key_{{ depth }} +#root_security_{{ depth }}: #root_user_{{ depth }}/"32=repo-security" <= #root_user_key_{{ depth }} +{% endfor %} +{% for host, values in hostvars.items() %} +{% if values.get('ndnd_enabled', false) %} +{% set site_id = loop.index %} +#site_{{ site_id }}: {{ ndn_lvs_name(values.ndnd_ca_prefix) }}/#key <= #root +#flat_user_key: #flat_user/#key <= #site_{{ site_id }} +{% for depth in range(1, 6) %} +{% set id = site_id ~ '_' ~ depth %} +#user_{{ id }}: {{ ndn_lvs_name(values.ndnd_ca_prefix) }}{% for n in range(depth) %}/user{{ n }}{% endfor %} + +#user_key_{{ id }}: #user_{{ id }}/#key <= #site_{{ site_id }} +#command_{{ id }}: #user_{{ id }}/"32=repo" <= #user_key_{{ id }} +#security_{{ id }}: #user_{{ id }}/"32=repo-security" <= #user_key_{{ id }} +{% endfor %} +{% if host == inventory_hostname %} +#repo_key: {{ ndn_lvs_name(ndnd_router_prefix + '/repo') }}/#key <= #site_{{ site_id }} +{% endif %} +{% endif %} +{% endfor %} +#response: {{ ndn_lvs_name(ndnd_router_prefix + '/repo') }}/"32=cmd"/_ <= #repo_key diff --git a/templates/ndnd-network-repo/renew.sh.j2 b/templates/ndnd-network-repo/renew.sh.j2 new file mode 100644 index 0000000..f12b392 --- /dev/null +++ b/templates/ndnd-network-repo/renew.sh.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +set -eu + +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TESTBED_DIR="$(cd "${REPO_DIR}/../.." && pwd)" + +python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ + --directory "${REPO_DIR}" \ + --site-home "${TESTBED_DIR}/dist/ndnd-site-ca" \ + --site-prefix {{ ndnd_ca_prefix | tojson }} \ + --identity {{ (ndnd_router_prefix + '/repo') | tojson }} \ + --anchors "${TESTBED_DIR}/anchors" \ + --service repo "$@" diff --git a/templates/ndnd-network-repo/repo.yml.j2 b/templates/ndnd-network-repo/repo.yml.j2 new file mode 100644 index 0000000..282c3d6 --- /dev/null +++ b/templates/ndnd-network-repo/repo.yml.j2 @@ -0,0 +1,8 @@ +repo: + name: {{ (ndnd_router_prefix + '/repo') | tojson }} + storage_dir: /config/storage + keychain: dir:///config/keys + trust_schema: /config/management-schema.tlv + trust_anchors: + - {{ ndn_cert_name(read_file(ndnd_root_anchor_path)) | tojson }} + ignore_validity: false diff --git a/templates/ndnd-root-ca/ca.json.j2 b/templates/ndnd-root-ca/ca.json.j2 new file mode 100644 index 0000000..a4c896a --- /dev/null +++ b/templates/ndnd-root-ca/ca.json.j2 @@ -0,0 +1,40 @@ +{ + "ca-prefix": {{ ndnd_dv_network | tojson }}, + "ca-info": {{ ndnd_ca_info | tojson }}, + "max-validity-period": {{ ndnd_ca_max_validity_period | tojson }}, + "max-suffix-length": {{ ndnd_ca_max_suffix_length | tojson }}, + "probe-parameters": [{ "probe-parameter-key": "email" }], + "name-assignment": { "email": "/nonexist" }, + "redirect-to": [ + {% set redirects = namespace(comma=false) %} + {% for host, values in hostvars.items() %} + {% if values.get('ndnd_enabled', false) %} + {% set cert_path = "./dist/ndnd-root-http-ca/cert-store/site-ca." + host + ".ndncert" %} + {% if path_exists(cert_path) %} + {% set cert_oneline = oneline(read_file(cert_path)) %} + {% for email_domain in values.site_email_domain %} + {% if redirects.comma %},{% endif %} + { + "ca-prefix": {{ values.ndnd_ca_prefix | tojson }}, + "certificate": {{ cert_oneline | tojson }}, + "policy-type": "email", + "policy-param": {{ email_domain | tojson }} + } + {% set redirects.comma = true %} + {% endfor %} + {% endif %} + {% endif %} + {% endfor %} + ], + "supported-challenges": [ + {% for challenge in ndnd_ca_supported_challenges %}{ "challenge": {{ challenge | tojson }} }{% if not loop.last %},{% endif %}{% endfor %} + ], + "email": { + "smtp-server": {{ SMTP_SERVER | tojson }}, + "smtp-port": 587, + "smtp-username": {{ SMTP_USER | tojson }}, + "smtp-password-env": "NDND_SMTP_PASSWORD", + "from": "NDN Certificate Robot ", + "subject": "Your NDNCERT verification code" + } +} diff --git a/templates/ndnd-root-http-ca/http-ca-server.yml.j2 b/templates/ndnd-root-http-ca/http-ca-server.yml.j2 new file mode 100644 index 0000000..aee5918 --- /dev/null +++ b/templates/ndnd-root-http-ca/http-ca-server.yml.j2 @@ -0,0 +1,19 @@ +global_prefix: {{ ndnd_dv_network | tojson }} +port: 8777 +signer_backend: ndnd-go + +hosts: + {% for host, values in hostvars.items() %} + {% if values.get('ndnd_enabled', false) %} + {{ host }}: + subnets: + - {{ values.host_ip }}/32 + {% if host == ndnd_ca_host %} + - 172.16.0.0/12 + - 192.168.0.0/16 + {% endif %} + prefix: {{ (values.ndnd_router_prefix + '/32=DV') | tojson }} + ca_prefix: {{ values.ndnd_ca_prefix | tojson }} + ca_cert_file: /cert-store/site-ca.{{ host }}.ndncert + {% endif %} + {% endfor %} diff --git a/templates/ndnd-site-ca/ca.json.j2 b/templates/ndnd-site-ca/ca.json.j2 new file mode 100644 index 0000000..66a10f3 --- /dev/null +++ b/templates/ndnd-site-ca/ca.json.j2 @@ -0,0 +1,19 @@ +{ + "ca-prefix": {{ ndnd_ca_prefix | tojson }}, + "ca-info": {{ ("NDN Testbed NDNCERT Site CA for " + inventory_hostname) | tojson }}, + "max-validity-period": {{ ndnd_ca_max_validity_period | tojson }}, + "max-suffix-length": {{ ndnd_ca_max_suffix_length | tojson }}, + "probe-parameters": [{ "probe-parameter-key": "email" }], + "name-assignment": { "email": {{ site | tojson }} }, + "supported-challenges": [ + {% for challenge in ndnd_site_ca_supported_challenges %}{ "challenge": {{ challenge | tojson }} }{% if not loop.last %},{% endif %}{% endfor %} + ], + "email": { + "smtp-server": {{ SMTP_SERVER | tojson }}, + "smtp-port": 587, + "smtp-username": {{ SMTP_USER | tojson }}, + "smtp-password-env": "NDND_SMTP_PASSWORD", + "from": "NDN Certificate Robot ", + "subject": "Your NDNCERT verification code" + } +} diff --git a/templates/ndnd-site-ca/renew.sh.j2 b/templates/ndnd-site-ca/renew.sh.j2 new file mode 100644 index 0000000..33295de --- /dev/null +++ b/templates/ndnd-site-ca/renew.sh.j2 @@ -0,0 +1,22 @@ +#!/bin/bash + +set -eu + +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TESTBED_DIR="$(cd "${REPO_DIR}/../.." && pwd)" +source "${TESTBED_DIR}/.env" +NDND_ROOT_CA_SECRET="${VAR_NDND_ROOT_CA_SECRET:?Set VAR_NDND_ROOT_CA_SECRET in .env}" +export NDND_ROOT_CA_SECRET +{% if inventory_hostname == ndnd_ca_host %} +NDND_ROOT_HTTP_CA_URL={{ ndnd_root_http_ca_internal_url | tojson }} +{% else %} +NDND_ROOT_HTTP_CA_URL={{ ndnd_root_http_ca_url | tojson }} +{% endif %} + +python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ + --directory "${TESTBED_DIR}/dist/ndnd-site-ca" \ + --site-prefix {{ ndnd_ca_prefix | tojson }} \ + --identity {{ ndnd_ca_prefix | tojson }} \ + --service ca \ + --root-ca-url "${NDND_ROOT_HTTP_CA_URL}" \ + --root-cert "${TESTBED_DIR}/{{ ndnd_root_anchor_path }}" "$@" diff --git a/templates/ndnd/yanfd.yml.j2 b/templates/ndnd/yanfd.yml.j2 new file mode 100644 index 0000000..cb1a929 --- /dev/null +++ b/templates/ndnd/yanfd.yml.j2 @@ -0,0 +1,24 @@ +fw: + bier_index: {{ ndnd_bier_index }} + router_name: {{ ndnd_router_prefix | tojson }} + +mgmt: + allow_localhop: true + +faces: + udp: + enabled_unicast: true + enabled_multicast: false + port_unicast: {{ ndnd_udp_port }} + tcp: + enabled: false + unix: + enabled: true + socket_path: /run/ndnd/ndnd.sock + websocket: + enabled: true + bind: "" + port: 9696 + tls_enabled: false + http3: + enabled: false diff --git a/templates/nlsr/nlsr.conf.j2 b/templates/nlsr/nlsr.conf.j2 index 4ca01c0..a8d0cb2 100644 --- a/templates/nlsr/nlsr.conf.j2 +++ b/templates/nlsr/nlsr.conf.j2 @@ -53,6 +53,9 @@ fib advertising { + {% if ndnd_enabled | default(false) and ndnd_dv_network not in advertised_prefixes %} + {{ ndnd_dv_network }} 0 + {% endif %} {% for prefix in advertised_prefixes %} {{ prefix }} 0 {% endfor %} From d685d7f3f48dc0008a2d1eebf4574364595fe546 Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 2/6] deploy: add NDNd ping service and image workflow --- .github/workflows/docker.yml | 12 ++++++++++ Dockerfile | 16 +++++++++++++ README.md | 4 +++- config.yml | 6 +++++ docker-compose.yml | 25 +++++++++++++++++++ framework/internal/ndnd_network.py | 11 +++++---- framework/test_ndnd_network.py | 28 +++++++++++++++++----- templates/ndnd-pingserver/entrypoint.sh.j2 | 3 +++ 8 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 templates/ndnd-pingserver/entrypoint.sh.j2 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3f09b55..e6ca62a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,5 +1,9 @@ name: Docker on: + push: + paths: + - Dockerfile + - .github/workflows/docker.yml schedule: # monthly on day 5 - cron: '20 15 5 * *' @@ -13,12 +17,20 @@ permissions: jobs: testbed-master: + if: github.event_name != 'push' uses: named-data/actions/.github/workflows/docker-image.yml@v1 with: name: testbed-master target: testbed-master testbed-caddy: + if: github.event_name != 'push' uses: named-data/actions/.github/workflows/docker-image.yml@v1 with: name: testbed-caddy target: testbed-caddy + testbed-ndnd-tools: + uses: named-data/actions/.github/workflows/docker-image.yml@v1 + with: + name: testbed-ndnd-tools + target: testbed-ndnd-tools + tag-with-sha: true diff --git a/Dockerfile b/Dockerfile index 8a998ec..93552f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,22 @@ VOLUME /testbed WORKDIR /testbed +# NDNd is scratch-based; add a shell for rendered tool entrypoints. +FROM busybox:1.37.0-musl@sha256:f6a95d611e0a8780fabdb2aec43e31275b2720dfefa3e41b16835bfc42454478 AS ndnd-tools-shell + +FROM golang:1.24 AS ndnd-tools-build + +# The ping-prefix fix is isolated from the deployed router/repository images. +ADD --keep-git-dir=true https://github.com/markverick/ndnd.git#f9c34574aa0dc7d295fa28bacd8b3060c650df15 /src +WORKDIR /src +RUN make + +FROM ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b AS testbed-ndnd-tools + +COPY --from=ndnd-tools-build /src/ndnd /ndnd +COPY --from=ndnd-tools-shell /bin/busybox /bin/sh + + FROM caddy:2-alpine AS testbed-caddy ADD --unpack https://nfd-status-page.ndn.today/NDNts-NFD-status-page.txz /srv/n diff --git a/README.md b/README.md index c768d1f..ea2efa1 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ Each node runs the pinned `ndnd-repo` container with identity `/ Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. Router identities are root-signed as `/32=DV`, and peers are selected from the existing NLSR neighbor inventory, limited to NDNd-enabled sites. +Each enabled node also runs `ndnd pingserver --expose ` in a separate container, serving `/ping/`. The `testbed-ndnd-tools` image builds pinned DV2 source with the ping-prefix registration fix and adds a shell for the rendered entrypoint. The existing Docker workflow publishes this image. The ping server registers only `/ping`, leaving the site CA's registration separate. For example, Arizona serves `/ndnd/arizona/ping/`. + ## NDNd Merkle Only UCLA runs the `ndnd-merkle` container, selected by `services.ndnd-merkle.hosts: [UCLA]` in `config.yml`, with identity `/ndn/edu/ucla/ndnd/merkle`. Master automatically provisions and renews its dedicated site-issued certificate using the same testbed anchors as the repo. Its trust schema permits testbed-certified users to append under their own identities and only the log key to sign responses. History persists in `dist/ndnd-merkle/storage`. @@ -209,7 +211,7 @@ that index at startup, and `framework/ndnd-network-init.py` registers the same router-to-index inventory on every node and rebuilds the BIFT. Both cron scripts run this initializer after service updates. It binds announcements to permanent UDP faces, restores entries after restarts, and reloads NDNd-connected producers -when their forwarder's startup time changes. The NFD-connected repository and +when their forwarder's or DV router's startup time changes. The NFD-connected repository and Merkle service are outside that restart group. NDNd uses the NLSR neighbor connections between enabled sites. DV2 currently diff --git a/config.yml b/config.yml index 589ec19..525ab32 100644 --- a/config.yml +++ b/config.yml @@ -24,6 +24,12 @@ services: template_path: templates/ndnd-http-status-server render_path: dist/ndnd-http-status-server + ndnd-pingserver: + enabled_by: ndnd_enabled + profile: ndnd + template_path: templates/ndnd-pingserver + render_path: dist/ndnd-pingserver + ndnd-site-ca: enabled_by: ndnd_enabled profile: ndnd-site-ca diff --git a/docker-compose.yml b/docker-compose.yml index 849ab51..d84cbfc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,6 +79,10 @@ services: environment: NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock command: [dv, run, /config/dv.yml] + healthcheck: + test: [CMD, /ndnd, dv, status] + interval: 10s + start_period: 30s network_mode: none read_only: true cap_drop: [ALL] @@ -89,6 +93,27 @@ services: logging: driver: local + ndnd-pingserver: + image: ghcr.io/markverick/testbed-ndnd-tools:ndnd-staging@sha256:3c325f9a688d95c2d6b111bef4e73d13d80fb79e476d2420c2c1ef271e5f6e34 + pull_policy: always + profiles: [ndnd] + init: true + volumes: + - /run/ndnd:/run/ndnd:ro + - ${PWD}/dist/ndnd-pingserver:/config:ro + environment: + NDN_CLIENT_TRANSPORT: unix:///run/ndnd/ndnd.sock + entrypoint: [/bin/sh, /config/entrypoint.sh] + network_mode: none + read_only: true + cap_drop: [ALL] + security_opt: [no-new-privileges:true] + restart: unless-stopped + depends_on: + ndnd-dv: { condition: service_healthy } + logging: + driver: local + ndnd-http-status-server: image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b pull_policy: always diff --git a/framework/internal/ndnd_network.py b/framework/internal/ndnd_network.py index bb2d2eb..053f09e 100644 --- a/framework/internal/ndnd_network.py +++ b/framework/internal/ndnd_network.py @@ -70,6 +70,8 @@ def configure(containers, routers, network, port, previous): if changed or not containers['ndnd-dv']['State']['Running']: run(['docker', 'restart', containers['ndnd-dv']['Id']]) wait_ready(ndnd_cmd + ['dv', 'status']) + dv_started = run(['docker', 'inspect', '--format', '{{.State.StartedAt}}', + containers['ndnd-dv']['Id']]).stdout.strip() # Remove our previous bridge entries if Docker assigned a new peer address. if previous.get('to_nfd') not in (None, to_nfd) and not changed: @@ -101,15 +103,16 @@ def configure(containers, routers, network, port, previous): run(ndnd_cmd + ['dv', 'prefix-announce', 'prefix=/ndn', 'face=' + bridge_face]) run(ndnd_cmd + ['fw', 'bift-rebuild']) - if changed: - # These services keep registrations on the forwarder's Unix socket. - dependents = ['ndnd-http-status-server', 'ndnd-site-ca', 'ndnd-root-ca', + if changed or previous.get('dv_started') != dv_started: + # DV loses advertisements on restart even if producer sockets stay open. + dependents = ['ndnd-http-status-server', 'ndnd-pingserver', 'ndnd-site-ca', 'ndnd-root-ca', 'ndnd-network-repo', 'ndnd-network-merkle'] restart = [containers[s]['Id'] for s in dependents if s in containers and containers[s]['State']['Running']] if restart: run(['docker', 'restart', *restart], timeout=120) - return {'forwarder_started': fw['State']['StartedAt'], 'to_nfd': to_nfd, 'to_ndnd': to_ndnd} + return {'forwarder_started': fw['State']['StartedAt'], 'dv_started': dv_started, + 'to_nfd': to_nfd, 'to_ndnd': to_ndnd} def reconcile(node): diff --git a/framework/test_ndnd_network.py b/framework/test_ndnd_network.py index 86cfb5a..e396381 100644 --- a/framework/test_ndnd_network.py +++ b/framework/test_ndnd_network.py @@ -15,7 +15,8 @@ def setUp(self): self.containers = {} for service, ip in [('nfd', '172.20.0.2'), ('ndnd', '172.20.0.3'), ('ndnd-dv', ''), ('ndnd-network-repo', ''), - ('ndnd-site-ca', ''), ('ndnd-repo', ''), ('nlsr', '')]: + ('ndnd-site-ca', ''), ('ndnd-pingserver', ''), + ('ndnd-repo', ''), ('nlsr', '')]: self.containers[service] = { 'Id': service, 'Image': 'nfd-image', 'Mounts': [{'Source': '/run/ndnd', 'Destination': '/run/ndnd'}, @@ -23,7 +24,7 @@ def setUp(self): 'State': {'Running': True, 'StartedAt': 'start-1'}, 'NetworkSettings': {'Networks': {'default': {'IPAddress': ip}}}, } - self.previous = {'forwarder_started': 'start-1', + self.previous = {'forwarder_started': 'start-1', 'dv_started': 'start-1', 'to_nfd': 'udp4://172.20.0.2:6363', 'to_ndnd': 'udp4://172.20.0.3:6364'} @@ -34,6 +35,10 @@ def run_command(self, args, check=True, **kwargs): output = 'faceid=42 remote=udp4://172.20.0.2:6363\nfaceid=43 remote=udp4://172.20.0.9:6363\n' elif args[-2:] == ['face', 'list']: output = 'faceid=70 remote=udp4://172.20.0.8:6364\n' + elif args[:2] == ['docker', 'inspect']: + output = self.containers['ndnd-dv']['State']['StartedAt'] + '\n' + elif args == ['docker', 'restart', 'ndnd-dv']: + self.containers['ndnd-dv']['State']['StartedAt'] = 'start-2' return subprocess.CompletedProcess(args, 0, output, '') def configure(self, previous=None): @@ -61,7 +66,7 @@ def test_repeated_initialization_does_not_restart_services(self): def test_forwarder_restart_restores_only_its_dependents(self): self.configure({}) restarted = [command[2:] for command in self.commands if command[1] == 'restart'] - self.assertEqual(restarted, [['ndnd-dv'], ['ndnd-site-ca', 'ndnd-network-repo']]) + self.assertEqual(restarted, [['ndnd-dv'], ['ndnd-pingserver', 'ndnd-site-ca', 'ndnd-network-repo']]) self.assertEqual(sum('bift-register' in command for command in self.commands), 2) def test_peer_address_change_removes_old_bridge_routes(self): @@ -73,10 +78,21 @@ def test_peer_address_change_removes_old_bridge_routes(self): self.assertIn(['docker', 'exec', 'nfd', 'nfdc', 'route', 'remove', '/ndnd', previous['to_ndnd']], self.commands) - def test_stopped_dv_restarts_without_restarting_producers(self): + def test_stopped_dv_restarts_and_restores_producers(self): self.containers['ndnd-dv']['State']['Running'] = False - self.configure() - self.assertEqual([c[2:] for c in self.commands if c[1] == 'restart'], [['ndnd-dv']]) + state = self.configure() + self.assertEqual([c[2:] for c in self.commands if c[1] == 'restart'], + [['ndnd-dv'], ['ndnd-pingserver', 'ndnd-site-ca', 'ndnd-network-repo']]) + self.assertEqual(state['dv_started'], 'start-2') + + def test_independent_dv_restart_restores_producers_once(self): + self.containers['ndnd-dv']['State']['StartedAt'] = 'start-2' + state = self.configure() + self.assertEqual([c[2:] for c in self.commands if c[1] == 'restart'], + [['ndnd-pingserver', 'ndnd-site-ca', 'ndnd-network-repo']]) + self.commands.clear() + self.configure(state) + self.assertFalse(any(c[1] == 'restart' for c in self.commands)) def test_duplicate_indices_rejected(self): hosts = {'A': {'ndnd_enabled': True, 'ndnd_bier_index': 0, 'ndnd_router_prefix': '/ndnd/a'}, diff --git a/templates/ndnd-pingserver/entrypoint.sh.j2 b/templates/ndnd-pingserver/entrypoint.sh.j2 new file mode 100644 index 0000000..f5430d4 --- /dev/null +++ b/templates/ndnd-pingserver/entrypoint.sh.j2 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /ndnd pingserver --expose {{ ndnd_router_prefix | tojson }} From a51243757436da9bdff1c250c61105973fe0783c Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 3/6] deploy: preserve NFD-connected service images --- README.md | 2 +- docker-compose.yml | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea2efa1..41a46fa 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Upgrade the forwarder, DV router, and status server together; the DV2 BIFT management dataset uses TLV encoding. Both repository configurations explicitly supply their management trust schema. -The existing NFD-connected services retain upstream's image settings. They use +The existing NFD-connected services retain their deployed image settings. They use NFD RIB registration; the separate NDNd services use DV prefix advertising. On hosts with `ndnd_enabled: true`, Caddy exposes: diff --git a/docker-compose.yml b/docker-compose.yml index d84cbfc..5a18cc7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -291,7 +291,7 @@ services: driver: local ndn-python-repo: - image: ghcr.io/ucla-irl/ndn-python-repo:20240508 + image: ghcr.io/ucla-irl/ndn-python-repo:20261023@sha256:781c3db4aad30a91a0672da787b316599ee08957b63961219f09d7c4408cf763 init: true volumes: - /run/nfd:/run/nfd:ro @@ -309,7 +309,8 @@ services: driver: local ndnd-repo: - image: ghcr.io/named-data/ndnd:20261012 + image: ghcr.io/named-data/ndnd:20261022@sha256:1816103c4fec8ea04253ed3d5f9e5c53c6657067a2cbc4d3c1fbb6be7ed28c3a + pull_policy: always init: true volumes: - /run/nfd:/run/nfd:ro @@ -364,7 +365,7 @@ services: driver: local ndnd-merkle: - image: ghcr.io/named-data/ndnd:20261012 + image: ghcr.io/named-data/ndnd:20261022@sha256:1816103c4fec8ea04253ed3d5f9e5c53c6657067a2cbc4d3c1fbb6be7ed28c3a pull_policy: always profiles: [merkle-log] # selected by config.yml through maintenance init: true From 5779f0b60d34440458c6bfb99d0d81696cbacc57 Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 4/6] ndnd: use hierarchical site and router names --- README.md | 4 ++-- framework/test_ndnd_network.py | 15 +++++++++++++-- host_vars/ARIZONA | 4 ++-- host_vars/FRANKFURT | 4 ++-- host_vars/HK | 4 ++-- host_vars/MEMPHIS | 4 ++-- host_vars/SINGAPORE | 4 ++-- host_vars/UCLA | 4 ++-- scripts/ndnd-infra-security.py | 2 +- .../ndnd-network-merkle/management-schema.lvs.j2 | 10 +++++----- templates/ndnd-network-merkle/merkle.yml.j2 | 2 +- templates/ndnd-network-merkle/renew.sh.j2 | 2 +- .../ndnd-network-repo/management-schema.lvs.j2 | 4 ++-- templates/ndnd-network-repo/renew.sh.j2 | 2 +- templates/ndnd-network-repo/repo.yml.j2 | 2 +- templates/ndnd-pingserver/entrypoint.sh.j2 | 2 +- 16 files changed, 40 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 41a46fa..1e722e7 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,9 @@ Each node runs the pinned `ndnd-repo` container with identity `/ ## NDNd Distance Vector -Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. Router identities are root-signed as `/32=DV`, and peers are selected from the existing NLSR neighbor inventory, limited to NDNd-enabled sites. +Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. All routers belong to the `/ndnd` DV network. Site and router names mirror the NFD convention as `/ndnd` and `/ndnd/%C1.Router/`. Router identities are root-signed as `/32=DV`, and peers are selected from the existing NLSR neighbor inventory, limited to NDNd-enabled sites. -Each enabled node also runs `ndnd pingserver --expose ` in a separate container, serving `/ping/`. The `testbed-ndnd-tools` image builds pinned DV2 source with the ping-prefix registration fix and adds a shell for the rendered entrypoint. The existing Docker workflow publishes this image. The ping server registers only `/ping`, leaving the site CA's registration separate. For example, Arizona serves `/ndnd/arizona/ping/`. +Each enabled node also runs `ndnd pingserver --expose ` in a separate container, serving `/ping/`. The `testbed-ndnd-tools` image builds pinned DV2 source with the ping-prefix registration fix and adds a shell for the rendered entrypoint. The existing Docker workflow publishes this image. The ping server registers only `/ping`, leaving the site CA's registration separate. For example, Arizona serves `/ndnd/edu/arizona/ping/`. ## NDNd Merkle diff --git a/framework/test_ndnd_network.py b/framework/test_ndnd_network.py index e396381..0451e53 100644 --- a/framework/test_ndnd_network.py +++ b/framework/test_ndnd_network.py @@ -1,3 +1,4 @@ +import json import subprocess import unittest from unittest.mock import patch @@ -7,6 +8,7 @@ from internal import ndnd_network from internal import conf +from internal.render import JINJA_FUNCTIONS class NetworkInitTest(unittest.TestCase): @@ -113,15 +115,24 @@ def test_enabled_hosts_have_stable_unique_indices_and_bridge_advertisements(self indices = ndnd_network.router_indices(hosts) self.assertEqual(len(indices), 6) env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'), undefined=jinja2.StrictUndefined) - for host in hosts.values(): - context = dict(host, **config.globals) + for host_name, host in hosts.items(): + context = dict(host, **config.globals, inventory_hostname=host_name) context['hostvars'] = {n: dict(h, **config.globals) for n, h in hosts.items()} rendered = env.get_template('templates/nlsr/nlsr.conf.j2').render(**context) advertising = rendered.split('advertising\n{', 1)[1].split('}', 1)[0] self.assertEqual('/ndnd 0' in advertising, bool(host.get('ndnd_enabled'))) if host.get('ndnd_enabled'): + self.assertEqual(host['ndnd_ca_prefix'], '/ndnd' + host['site']) + self.assertEqual(host['ndnd_router_prefix'], + host['ndnd_ca_prefix'] + '/%C1.Router/' + host['router_name']) fw = yaml.safe_load(env.get_template('templates/ndnd/yanfd.yml.j2').render(**context)) self.assertEqual(indices[fw['fw']['bier_index']], host['ndnd_router_prefix']) + dv = yaml.safe_load(env.get_template('templates/ndnd-dv/dv.yml.j2').render( + **context, **JINJA_FUNCTIONS)) + self.assertEqual(dv['dv']['network'], '/ndnd') + self.assertEqual(dv['dv']['router'], host['ndnd_router_prefix']) + ping = env.get_template('templates/ndnd-pingserver/entrypoint.sh.j2').render(**context) + self.assertIn(' --expose ' + json.dumps(host['ndnd_ca_prefix']), ping) if __name__ == '__main__': diff --git a/host_vars/ARIZONA b/host_vars/ARIZONA index 138ddc0..78b7c23 100644 --- a/host_vars/ARIZONA +++ b/host_vars/ARIZONA @@ -32,10 +32,10 @@ neighbors: position: - 32.2289614 - -110.9483226 -ndnd_ca_prefix: /ndnd/arizona +ndnd_ca_prefix: /ndnd/edu/arizona hr_angle: 2.97033 hr_radius: 16.2305 ethernet_device: eth0 ndnd_enabled: true -ndnd_router_prefix: /ndnd/arizona +ndnd_router_prefix: /ndnd/edu/arizona/%C1.Router/hobo ndnd_bier_index: 2 diff --git a/host_vars/FRANKFURT b/host_vars/FRANKFURT index 7d0c2e0..09981b3 100644 --- a/host_vars/FRANKFURT +++ b/host_vars/FRANKFURT @@ -34,10 +34,10 @@ neighbors: position: - 50.1187 - 8.6842 -ndnd_ca_prefix: /ndnd/frankfurt +ndnd_ca_prefix: /ndnd/pcl/frankfurt hr_angle: 0 hr_radius: 0 ethernet_device: eth0 ndnd_enabled: true -ndnd_router_prefix: /ndnd/frankfurt +ndnd_router_prefix: /ndnd/pcl/frankfurt/%C1.Router/vm ndnd_bier_index: 5 diff --git a/host_vars/HK b/host_vars/HK index 0d01efa..984756d 100644 --- a/host_vars/HK +++ b/host_vars/HK @@ -24,10 +24,10 @@ neighbors: position: - 22.3193 - 114.1694 -ndnd_ca_prefix: /ndnd/hk +ndnd_ca_prefix: /ndnd/pcl/hk hr_angle: 0 hr_radius: 0 ethernet_device: eth0 ndnd_enabled: true -ndnd_router_prefix: /ndnd/hk +ndnd_router_prefix: /ndnd/pcl/hk/%C1.Router/vm ndnd_bier_index: 3 diff --git a/host_vars/MEMPHIS b/host_vars/MEMPHIS index 6b53709..194c4b9 100644 --- a/host_vars/MEMPHIS +++ b/host_vars/MEMPHIS @@ -27,10 +27,10 @@ neighbors: position: - 35.1186099 - -89.93700109999999 -ndnd_ca_prefix: /ndnd/memphis +ndnd_ca_prefix: /ndnd/edu/memphis hr_angle: 2.9836 hr_radius: 15.2647 ethernet_device: eth1 ndnd_enabled: true -ndnd_router_prefix: /ndnd/memphis +ndnd_router_prefix: /ndnd/edu/memphis/%C1.Router/titan ndnd_bier_index: 1 diff --git a/host_vars/SINGAPORE b/host_vars/SINGAPORE index 140e10a..bc18b95 100644 --- a/host_vars/SINGAPORE +++ b/host_vars/SINGAPORE @@ -32,10 +32,10 @@ neighbors: position: - 1.2868 - 103.8503 -ndnd_ca_prefix: /ndnd/singapore +ndnd_ca_prefix: /ndnd/pcl/singapore hr_angle: 0 hr_radius: 0 ethernet_device: eth0 ndnd_enabled: true -ndnd_router_prefix: /ndnd/singapore +ndnd_router_prefix: /ndnd/pcl/singapore/%C1.Router/vm ndnd_bier_index: 4 diff --git a/host_vars/UCLA b/host_vars/UCLA index 05e4d79..ac14977 100644 --- a/host_vars/UCLA +++ b/host_vars/UCLA @@ -40,11 +40,11 @@ neighbors: position: - 34.0728225 - -118.4387398 -ndnd_ca_prefix: /ndnd/ucla +ndnd_ca_prefix: /ndnd/edu/ucla hr_angle: 2.99911 hr_radius: 16.5866 ethernet_device: eth0 is_root_ca: true ndnd_enabled: true -ndnd_router_prefix: /ndnd/ucla +ndnd_router_prefix: /ndnd/edu/ucla/%C1.Router/suns ndnd_bier_index: 0 diff --git a/scripts/ndnd-infra-security.py b/scripts/ndnd-infra-security.py index 8068f13..fb5cf07 100644 --- a/scripts/ndnd-infra-security.py +++ b/scripts/ndnd-infra-security.py @@ -142,7 +142,7 @@ def provision_locked(directory, site_home, site_prefix, anchors_path, force, ren service, root_ca_url, root_cert_path, identity): if service not in ('repo', 'merkle', 'dv', 'ca'): raise ValueError('Unsupported NDNd service') - if service == 'merkle' and site_prefix not in ('/ndn/edu/ucla', '/ndnd/ucla'): + if service == 'merkle' and site_prefix not in ('/ndn/edu/ucla', '/ndnd/edu/ucla'): raise ValueError('Merkle log provisioning is restricted to UCLA') if service == 'ca': config = {} diff --git a/templates/ndnd-network-merkle/management-schema.lvs.j2 b/templates/ndnd-network-merkle/management-schema.lvs.j2 index ac172f5..0a05c5c 100644 --- a/templates/ndnd-network-merkle/management-schema.lvs.j2 +++ b/templates/ndnd-network-merkle/management-schema.lvs.j2 @@ -5,7 +5,7 @@ #root_user_{{ depth }}: {{ ndn_lvs_name(ndnd_dv_network) }}{% for n in range(depth) %}/rootuser{{ n }}{% endfor %} #root_user_key_{{ depth }}: #root_user_{{ depth }}/#key <= #root -#root_append_{{ depth }}: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/#root_user_{{ depth }}/_ <= #root_user_key_{{ depth }} +#root_append_{{ depth }}: {{ ndn_lvs_name(ndnd_ca_prefix + '/merkle') }}/"32=append"/#root_user_{{ depth }}/_ <= #root_user_key_{{ depth }} {% endfor %} {% for host, values in hostvars.items() %} {% if values.get('ndnd_enabled', false) %} @@ -16,13 +16,13 @@ #user_{{ id }}: {{ ndn_lvs_name(values.ndnd_ca_prefix) }}{% for n in range(depth) %}/user{{ n }}{% endfor %} #user_key_{{ id }}: #user_{{ id }}/#key <= #site_{{ site_id }} -#append_{{ id }}: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/#user_{{ id }}/_ <= #user_key_{{ id }} +#append_{{ id }}: {{ ndn_lvs_name(ndnd_ca_prefix + '/merkle') }}/"32=append"/#user_{{ id }}/_ <= #user_key_{{ id }} {% endfor %} {% if host == inventory_hostname %} -#log_key: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/#key <= #site_{{ site_id }} +#log_key: {{ ndn_lvs_name(ndnd_ca_prefix + '/merkle') }}/#key <= #site_{{ site_id }} {% endif %} {% endif %} {% endfor %} // Object validation removes terminal version and segment components. -#append_response: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=append"/_ <= #log_key -#check_response: {{ ndn_lvs_name(ndnd_router_prefix + '/merkle') }}/"32=check"/_ <= #log_key +#append_response: {{ ndn_lvs_name(ndnd_ca_prefix + '/merkle') }}/"32=append"/_ <= #log_key +#check_response: {{ ndn_lvs_name(ndnd_ca_prefix + '/merkle') }}/"32=check"/_ <= #log_key diff --git a/templates/ndnd-network-merkle/merkle.yml.j2 b/templates/ndnd-network-merkle/merkle.yml.j2 index 1fbea6a..02e80b2 100644 --- a/templates/ndnd-network-merkle/merkle.yml.j2 +++ b/templates/ndnd-network-merkle/merkle.yml.j2 @@ -1,5 +1,5 @@ merkle: - name: {{ (ndnd_router_prefix + '/merkle') | tojson }} + name: {{ (ndnd_ca_prefix + '/merkle') | tojson }} storage_dir: /config/storage max_entries: 1000000 keychain: dir:///config/keys diff --git a/templates/ndnd-network-merkle/renew.sh.j2 b/templates/ndnd-network-merkle/renew.sh.j2 index a0c9ee5..5087cb3 100644 --- a/templates/ndnd-network-merkle/renew.sh.j2 +++ b/templates/ndnd-network-merkle/renew.sh.j2 @@ -10,5 +10,5 @@ python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ --directory "${SERVICE_DIR}" \ --site-home "${TESTBED_DIR}/dist/ndnd-site-ca" \ --site-prefix {{ ndnd_ca_prefix | tojson }} \ - --identity {{ (ndnd_router_prefix + '/merkle') | tojson }} \ + --identity {{ (ndnd_ca_prefix + '/merkle') | tojson }} \ --anchors "${TESTBED_DIR}/anchors" "$@" diff --git a/templates/ndnd-network-repo/management-schema.lvs.j2 b/templates/ndnd-network-repo/management-schema.lvs.j2 index 2b56274..997b48a 100644 --- a/templates/ndnd-network-repo/management-schema.lvs.j2 +++ b/templates/ndnd-network-repo/management-schema.lvs.j2 @@ -26,8 +26,8 @@ #security_{{ id }}: #user_{{ id }}/"32=repo-security" <= #user_key_{{ id }} {% endfor %} {% if host == inventory_hostname %} -#repo_key: {{ ndn_lvs_name(ndnd_router_prefix + '/repo') }}/#key <= #site_{{ site_id }} +#repo_key: {{ ndn_lvs_name(ndnd_ca_prefix + '/repo') }}/#key <= #site_{{ site_id }} {% endif %} {% endif %} {% endfor %} -#response: {{ ndn_lvs_name(ndnd_router_prefix + '/repo') }}/"32=cmd"/_ <= #repo_key +#response: {{ ndn_lvs_name(ndnd_ca_prefix + '/repo') }}/"32=cmd"/_ <= #repo_key diff --git a/templates/ndnd-network-repo/renew.sh.j2 b/templates/ndnd-network-repo/renew.sh.j2 index f12b392..3256d32 100644 --- a/templates/ndnd-network-repo/renew.sh.j2 +++ b/templates/ndnd-network-repo/renew.sh.j2 @@ -9,6 +9,6 @@ python3 "${TESTBED_DIR}/scripts/ndnd-infra-security.py" \ --directory "${REPO_DIR}" \ --site-home "${TESTBED_DIR}/dist/ndnd-site-ca" \ --site-prefix {{ ndnd_ca_prefix | tojson }} \ - --identity {{ (ndnd_router_prefix + '/repo') | tojson }} \ + --identity {{ (ndnd_ca_prefix + '/repo') | tojson }} \ --anchors "${TESTBED_DIR}/anchors" \ --service repo "$@" diff --git a/templates/ndnd-network-repo/repo.yml.j2 b/templates/ndnd-network-repo/repo.yml.j2 index 282c3d6..ec921ed 100644 --- a/templates/ndnd-network-repo/repo.yml.j2 +++ b/templates/ndnd-network-repo/repo.yml.j2 @@ -1,5 +1,5 @@ repo: - name: {{ (ndnd_router_prefix + '/repo') | tojson }} + name: {{ (ndnd_ca_prefix + '/repo') | tojson }} storage_dir: /config/storage keychain: dir:///config/keys trust_schema: /config/management-schema.tlv diff --git a/templates/ndnd-pingserver/entrypoint.sh.j2 b/templates/ndnd-pingserver/entrypoint.sh.j2 index f5430d4..c10d55b 100644 --- a/templates/ndnd-pingserver/entrypoint.sh.j2 +++ b/templates/ndnd-pingserver/entrypoint.sh.j2 @@ -1,3 +1,3 @@ #!/bin/sh -exec /ndnd pingserver --expose {{ ndnd_router_prefix | tojson }} +exec /ndnd pingserver --expose {{ ndnd_ca_prefix | tojson }} From 743af401e0f3830a6dbdfb3121a7c56f789dfc87 Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 5/6] deploy: update NDNd images --- docker-compose.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5a18cc7..44bc2a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,7 +44,7 @@ services: driver: local ndnd: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd] init: true @@ -67,7 +67,7 @@ services: driver: local ndnd-dv: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd] init: true @@ -115,7 +115,7 @@ services: driver: local ndnd-http-status-server: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd] init: true @@ -135,7 +135,7 @@ services: driver: local ndnd-site-ca: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd-site-ca] init: true @@ -156,7 +156,7 @@ services: driver: local ndnd-root-ca: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd-root-ca] init: true @@ -190,7 +190,7 @@ services: environment: # Enforced by the signer at runtime; inactive profiles must still parse. NDND_ROOT_CA_SECRET: ${VAR_NDND_ROOT_CA_SECRET:-} - NDND_CA_IMAGE: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + NDND_CA_IMAGE: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 NDND_CA_HOST_DIR: ${PWD}/ndnd-root-ca-home/ndnd entrypoint: [python3, /app/http-ca-server.py] command: [/config/http-ca-server.yml] @@ -393,7 +393,7 @@ services: driver: local ndnd-network-merkle: - image: ghcr.io/named-data/ndnd:dv2-staging@sha256:aba4d409d0f3ed2a7b134bd5d0ade0e0c9c37ad55e69254951c306f961b36d5b + image: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 pull_policy: always profiles: [ndnd-merkle-log] init: true From 332d0bcd5f1f568fe3abfcb40e158568042bc5ed Mon Sep 17 00:00:00 2001 From: Sirapop Theeranantachai Date: Sat, 14 Nov 2026 01:16:58 -0800 Subject: [PATCH 6/6] docs: clarify the NDNd deployment --- Dockerfile | 3 +-- README.md | 25 +++++++++---------- docker-compose.yml | 2 +- framework/internal/ndnd_network.py | 14 +++++------ scripts/cert-renew.sh | 4 +-- .../management-schema.lvs.j2 | 2 +- .../management-schema.lvs.j2 | 2 +- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93552f8..87c71d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,12 +34,11 @@ VOLUME /testbed WORKDIR /testbed -# NDNd is scratch-based; add a shell for rendered tool entrypoints. +# Supply a shell for rendered NDNd tool entrypoints. FROM busybox:1.37.0-musl@sha256:f6a95d611e0a8780fabdb2aec43e31275b2720dfefa3e41b16835bfc42454478 AS ndnd-tools-shell FROM golang:1.24 AS ndnd-tools-build -# The ping-prefix fix is isolated from the deployed router/repository images. ADD --keep-git-dir=true https://github.com/markverick/ndnd.git#f9c34574aa0dc7d295fa28bacd8b3060c650df15 /src WORKDIR /src RUN make diff --git a/README.md b/README.md index 1e722e7..a32f05b 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,9 @@ Each node runs the pinned `ndnd-repo` container with identity `/ ## NDNd Distance Vector -Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. All routers belong to the `/ndnd` DV network. Site and router names mirror the NFD convention as `/ndnd` and `/ndnd/%C1.Router/`. Router identities are root-signed as `/32=DV`, and peers are selected from the existing NLSR neighbor inventory, limited to NDNd-enabled sites. +Nodes with `ndnd_enabled: true` run the NDNd forwarder and a separate `ndnd dv` router. The router connects to the forwarder's `/run/ndnd/ndnd.sock` and exchanges DV traffic over its UDP listener on port 6364. All routers belong to the `/ndnd` DV network. Each site prefix prepends `/ndnd` to the configured `site` value; its router prefix appends `/%C1.Router/`. Router identities are root-signed as `/32=DV`, and peers are selected from the configured NLSR neighbors that also enable NDNd. -Each enabled node also runs `ndnd pingserver --expose ` in a separate container, serving `/ping/`. The `testbed-ndnd-tools` image builds pinned DV2 source with the ping-prefix registration fix and adds a shell for the rendered entrypoint. The existing Docker workflow publishes this image. The ping server registers only `/ping`, leaving the site CA's registration separate. For example, Arizona serves `/ndnd/edu/arizona/ping/`. +Each enabled node also runs `ndnd pingserver --expose ` in a separate container, serving `/ping/`. The `testbed-ndnd-tools` image builds pinned DV2 source with the ping-prefix registration fix and adds a shell for the rendered entrypoint. The Docker workflow publishes this image. The ping server registers only `/ping`, leaving the site CA's registration separate. For example, Arizona serves `/ndnd/edu/arizona/ping/`. ## NDNd Merkle @@ -151,17 +151,17 @@ sudo systemctl start unattended-upgrades sudo unattended-upgrades --debug ``` -## NDNd status +## NDNd Status The NDNd forwarder, DV router, status server, CA services, and `/ndnd` Merkle log use the digest-pinned DV2 staging image configured in Compose. The `/ndnd` -repository retains its separately pinned DV2 image. +repository uses a repository-capable DV2 image. Upgrade the forwarder, DV router, and status server together; the DV2 BIFT management dataset uses TLV encoding. Both repository configurations explicitly supply their management trust schema. -The existing NFD-connected services retain their deployed image settings. They use -NFD RIB registration; the separate NDNd services use DV prefix advertising. +NFD-connected services use their service-specific images and NFD RIB registration. +NDNd-connected services use DV prefix advertising. On hosts with `ndnd_enabled: true`, Caddy exposes: @@ -177,7 +177,7 @@ directly by the `/ndnd` root, to sign their routing and status datasets. DV explicitly loads this schema; the status server receives the same schema and the public root certificate in PEM format through a separate read-only mount. It has no access to router private keys. Changes to either status trust file -cause the existing renderer to restart the status server. +cause the renderer to restart the status server. The same compiled schema is published at `/file-server/ndnd/dv-schema.tlv` for clients. @@ -186,18 +186,17 @@ routing dataset. It does not fall back to an unrestricted schema. The local DV summary remains available if the signed dataset cannot be validated; check the status server logs and the report's routing state in that case. - -The CA host requires the existing root `ca.key.pem` and `ca.cert.pem` in +The CA host requires the root `ca.key.pem` and `ca.cert.pem` in `ndnd-root-ca-home/ndnd/`, owned by the service UID (root in the pinned images), with the private key mode set to `0600`. The certificate must match the committed trust anchor; the root services load these credentials directly. Master renders service configuration and renews service certificates before marking itself ready, -using the same lifecycle as the existing testbed. Cron performs subsequent +using the same lifecycle as other testbed services. Cron performs subsequent renewals and reloads. Root creation and replacement remain operator tasks. NDNd-enabled sites set `VAR_NDND_ROOT_CA_SECRET` in `.env` for root enrollment; NFD-only sites do not need that setting. -## NDNd network bridge +## NDNd Network Bridge NDNd-enabled sites bridge the two forwarders locally over UDP. NFD sends `/ndnd` Interests to NDNd through a capture route, excluding inherited root routes, and @@ -214,8 +213,8 @@ UDP faces, restores entries after restarts, and reloads NDNd-connected producers when their forwarder's or DV router's startup time changes. The NFD-connected repository and Merkle service are outside that restart group. -NDNd uses the NLSR neighbor connections between enabled sites. DV2 currently -uses a fixed cost of 1 per link; it does not use NLSR's configured link costs. +NDNd uses the NLSR neighbor connections between enabled sites. DV2 assigns a +fixed cost of 1 per link; it does not use NLSR's configured link costs. To reconcile a running node manually from its checkout: diff --git a/docker-compose.yml b/docker-compose.yml index 44bc2a7..c28a0eb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -188,7 +188,7 @@ services: - ${PWD}/dist/ndnd-root-http-ca:/config:ro - ${PWD}/dist/ndnd-root-http-ca/cert-store:/cert-store environment: - # Enforced by the signer at runtime; inactive profiles must still parse. + # Allow inactive profiles to render; the signer rejects an empty secret. NDND_ROOT_CA_SECRET: ${VAR_NDND_ROOT_CA_SECRET:-} NDND_CA_IMAGE: ghcr.io/named-data/ndnd:dv2-staging@sha256:ba13140ce270c8186bb61f4ae69ee0e86cc977c0144db931efbea2ce76515a89 NDND_CA_HOST_DIR: ${PWD}/ndnd-root-ca-home/ndnd diff --git a/framework/internal/ndnd_network.py b/framework/internal/ndnd_network.py index 053f09e..7d0735e 100644 --- a/framework/internal/ndnd_network.py +++ b/framework/internal/ndnd_network.py @@ -73,19 +73,19 @@ def configure(containers, routers, network, port, previous): dv_started = run(['docker', 'inspect', '--format', '{{.State.StartedAt}}', containers['ndnd-dv']['Id']]).stdout.strip() - # Remove our previous bridge entries if Docker assigned a new peer address. + # Remove stale bridge entries after a Docker address change. if previous.get('to_nfd') not in (None, to_nfd) and not changed: old_face = face_id(run(ndnd_cmd + ['fw', 'face-list']).stdout, previous['to_nfd']) if old_face: run(ndnd_cmd + ['dv', 'prefix-withdraw', 'prefix=/ndn', 'face=' + old_face]) run(ndnd_cmd + ['fw', 'pet-remove-nexthop', 'prefix=/ndn', 'face=' + old_face]) if previous.get('to_ndnd') not in (None, to_ndnd): - # A missing old face means NFD already removed its routes. + # NFD may have already removed the old face and its routes. if face_id(run(nfd_cmd + ['face', 'list']).stdout, previous['to_ndnd']): run(nfd_cmd + ['route', 'remove', network, previous['to_ndnd']]) - # nfdc updates existing on-demand faces too; NDNd's create-only CLI returns 409. - # Mount only the socket directory; nfdc needs its own writable client keychain. + # NDNd's create-only CLI rejects an existing face; nfdc updates it in place. + # Mount only the socket directory so nfdc uses its own client keychain. socket_dir = next(m['Source'] for m in fw['Mounts'] if m['Destination'] == '/run/ndnd') run(['docker', 'run', '--rm', '--network', 'none', '--mount', 'type=bind,src=' + socket_dir + ',dst=/run/ndnd,readonly', @@ -93,18 +93,18 @@ def configure(containers, routers, network, port, previous): '--entrypoint', '/usr/bin/nfdc', nfd['Image'], 'face', 'create', to_nfd, 'persistency', 'permanent']) run(nfd_cmd + ['face', 'create', to_ndnd, 'persistency', 'permanent']) - # Exclude inherited application/default routes from the foreign namespace. + # Prevent inherited routes from crossing into the other namespace. run(nfd_cmd + ['route', 'add', network, to_ndnd, 'capture']) bridge_face = face_id(run(ndnd_cmd + ['fw', 'face-list']).stdout, to_nfd) if bridge_face is None: raise RuntimeError('NDNd bridge face was not created') run(ndnd_cmd + ['fw', 'pet-add-nexthop', 'prefix=/ndn', 'face=' + bridge_face]) - # Bind the announcement to the UDP face, not this short-lived CLI connection. + # Bind the announcement to the UDP face instead of the CLI connection. run(ndnd_cmd + ['dv', 'prefix-announce', 'prefix=/ndn', 'face=' + bridge_face]) run(ndnd_cmd + ['fw', 'bift-rebuild']) if changed or previous.get('dv_started') != dv_started: - # DV loses advertisements on restart even if producer sockets stay open. + # Producers must advertise again after a DV restart. dependents = ['ndnd-http-status-server', 'ndnd-pingserver', 'ndnd-site-ca', 'ndnd-root-ca', 'ndnd-network-repo', 'ndnd-network-merkle'] restart = [containers[s]['Id'] for s in dependents diff --git a/scripts/cert-renew.sh b/scripts/cert-renew.sh index b80f018..5f4c4e6 100644 --- a/scripts/cert-renew.sh +++ b/scripts/cert-renew.sh @@ -73,10 +73,10 @@ renew_merkle() { fi } -# Finish existing NFD renewals and reloads before processing the separate network. +# Renew the NFD-connected Merkle service before NDNd services. renew_merkle ndnd-merkle "${FORCE}" || exit $? -# A site-certificate change on NFD must not force unrelated NDNd credentials. +# Propagate --force to NDNd services only when explicitly requested. NDND_FORCE=${HAS_FORCE:+--force} DV_ENABLED=$(python3 framework/service-profiles.py --service ndnd-dv) || exit $? if [[ "${DV_ENABLED}" == 1 ]]; then diff --git a/templates/ndnd-network-merkle/management-schema.lvs.j2 b/templates/ndnd-network-merkle/management-schema.lvs.j2 index 0a05c5c..c7050e4 100644 --- a/templates/ndnd-network-merkle/management-schema.lvs.j2 +++ b/templates/ndnd-network-merkle/management-schema.lvs.j2 @@ -1,4 +1,4 @@ -// Root -> user, or root -> site -> user/log; only the local log signs responses. +// Root- and site-issued users may append; only the local log signs responses. #key: "KEY"/_/_/_ #root: {{ ndn_lvs_name(ndnd_dv_network) }}/#key {% for depth in range(1, 7) %} diff --git a/templates/ndnd-network-repo/management-schema.lvs.j2 b/templates/ndnd-network-repo/management-schema.lvs.j2 index 997b48a..9695c50 100644 --- a/templates/ndnd-network-repo/management-schema.lvs.j2 +++ b/templates/ndnd-network-repo/management-schema.lvs.j2 @@ -5,7 +5,7 @@ #flat_command: #flat_user/"32=repo" <= #flat_user_key #flat_security: #flat_user/"32=repo-security" <= #flat_user_key {% for depth in range(2, 7) %} -// Root-issued NDNCERT identities may have multiple components (e.g. com/gmail/user). +// Root-issued NDNCERT identities may contain two to six components. #root_user_{{ depth }}: {{ ndn_lvs_name(ndnd_dv_network) }}{% for n in range(depth) %}/rootuser{{ n }}{% endfor %} #root_user_key_{{ depth }}: #root_user_{{ depth }}/#key <= #root