Metadata-Version: 2.2
Name: bisos.dnsCap
Version: 0.15
Summary: bisos.dnsCap:  DNS Management Facilities for BISOS Capabilities
Author: Mohsen Banan
Author-email: libre@mohsen.1.banan.byname.net
Maintainer: Mohsen Banan
Maintainer-email: libre@mohsen.1.banan.byname.net
License: AGPL
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: bisos
Requires-Dist: bisos.b
Requires-Dist: bisos.capability
Requires-Dist: bisos.common
Requires-Dist: bisos.csPlayer
Requires-Dist: bisos.csSeed
Requires-Dist: bisos.sbom
Requires-Dist: setuptools==75.8.0
Requires-Dist: wheel==0.38.4
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: license
Dynamic: maintainer
Dynamic: maintainer-email
Dynamic: requires-dist
Dynamic: summary

==============================================================
bisos.dnsCap: DNS Management Facilities for BISOS Capabilities
==============================================================

.. contents::
   :depth: 3
..

Overview
========

*bisos.dnsCap* provides DNS management facilities that contribute to
BISOS **Capabilities**. In BISOS, a **Capability** is a specific
concept, specified and realized through *bisos.capability*. ``dnsCap``
is not itself a Capability; it is one ingredient — the DNS aspect — of a
full **CBS** (Capability Bundle Specification), alongside sibling
aspects such as ``webCap`` and ``sbom``.

Concretely, ``dnsCap`` supplies the DNS naming an application needs. Its
first backend maintains ``/etc/hosts`` entries for the ``.here`` domain
(e.g. ``airflow.here``), using the ``bisos.banna`` dblock machinery to
keep those entries in sync.

``dnsCap_seed.cs`` is a seed. Common usages take the form of a
``<name>-here-dns.pcs`` plant that names the fqdn to manage.

dnsCap also holds BISOS's DNS servers, as bedrock capabilities (decided
2026-10-10, bisos-pip/pals/palsWithBcm README.org 1.2): **Knot DNS** as
the authoritative server, driven tinydns-style from generated zone
files, and **Unbound** as each platform's local resolver, sending
``.intra`` to Knot. ``.here`` stays in ``/etc/hosts``: its names are
loopback addresses, meaningful only on the platform itself. See `Knot
DNS and Unbound <#knot-dns-and-unbound>`__.

.. _table-of-contents:

Table of Contents TOC
=====================

-  `Overview <#overview>`__
-  `Relation to BISOS Capabilities <#relation-to-bisos-capabilities>`__
-  `Part of BISOS — ByStar Internet Services Operating
   System <#part-of-bisos--bystar-internet-services-operating-system>`__
-  `bisos.dnsCap is a Command-Only PyCS
   Facility <#bisosdnscap-is-a-command-only-pycs-facility>`__
-  `Installation <#installation>`__

   -  `Installation With pip <#installation-with-pip>`__
   -  `Installation With pipx <#installation-with-pipx>`__

-  `Usage <#usage>`__

   -  `Example: managing airflow.here in
      /etc/hosts <#example-managing-airflowhere-in-etchosts>`__
   -  `Other /etc/hosts blocks, and work before the
      update <#other-etchosts-blocks-and-work-before-the-update>`__
   -  `Commands <#commands>`__

-  `Knot DNS and Unbound <#knot-dns-and-unbound>`__

   -  `Knot DNS — authoritative,
      tinydns-style <#knot-dns-----authoritative-tinydns-style>`__
   -  `Unbound — the platform's local
      resolver <#unbound-----the-platforms-local-resolver>`__

-  `Key Files <#key-files>`__
-  `Documentation and Blee-Panels <#documentation-and-blee-panels>`__
-  `Support <#support>`__
-  `Planned Improvements <#planned-improvements>`__

Relation to BISOS Capabilities
==============================

A BISOS **Capability** is specified and realized by *bisos.capability*
as a **CBS** (Capability Bundle Specification) — a bundle of component
aspects. ``dnsCap`` is the DNS aspect of that bundle. Its sibling
aspects include:

-  ``dnsCap`` — DNS naming (this package): ``/etc/hosts`` and, later,
   other DNS backends.
-  ``webCap`` — the web-service aspect.
-  ``sbom`` — the Software Bill Of Materials aspect (typically a
   ``*-sbom.pcs`` plant).

A CBS composes these aspects into the complete specification of a
Capability. ``dnsCap`` can be used on its own (as shown below) or as an
ingredient invoked from within a CBS. For the Capability concept itself,
see `bisos.capability <https://github.com/bisos-pip/capability>`__.

Part of BISOS — ByStar Internet Services Operating System
=========================================================

Layered on top of Debian, **BISOS** (By\* Internet Services Operating
System) is a unified and universal framework for developing both
internet services and software-service continuums that use internet
services. See `Bootstrapping ByStar, BISOS and
Blee <https://github.com/bxGenesis/start>`__ for information about
getting started with BISOS.

**BISOS** is a foundation for **The Libre-Halaal ByStar Digital
Ecosystem** which is described as a cure for losses of autonomy and
privacy in a book titled: `Nature of
Polyexistentials <https://github.com/bxplpc/120033>`__

*bisos.dnsCap* is part of BISOS. It is a standalone package that can be
used independently of the full BISOS environment.

bisos.dnsCap is a Command-Only PyCS Facility
============================================

bisos.dnsCap is a command-line tool. It is a PyCS single-unit command
service. PyCS is a framework that converges development of CLI tools and
services. PyCS is an alternative to FastAPI, Typer and Click.

bisos.dnsCap uses the PyCS-Framework to provide the DNS aspect of a
BISOS Capability:

#. Update ``/etc/hosts`` with the DNS entries for a ``.here`` fqdn (via
   the ``bisos.banna`` dblock machinery).
#. Verify that ``/etc/hosts`` contains the expected banna dblock
   markers.
#. Resolve and ping a managed fqdn to confirm the entry is in effect.

The core of PyCS-Framework is the *bisos.b* package (the
PyCS-Foundation). See `bisos.b <https://github.com/bisos-pip/b>`__ for
an overview.

Installation
============

The sources for the bisos.dnsCap pip package are maintained at:
https://github.com/bisos-pip/dnsCap.

The bisos.dnsCap pip package is available at PYPI as
https://pypi.org/project/bisos.dnsCap

You can install bisos.dnsCap with pip or pipx.

Installation With pip
---------------------

If you need access to bisos.dnsCap as a python module, you can install
it with pip:

.. code:: bash

   pip install bisos.dnsCap

Installation With pipx
----------------------

If you only need access to bisos.dnsCap on command-line, you can install
it with pipx:

.. code:: bash

   pipx install bisos.dnsCap

Usage
=====

Example: managing airflow.here in /etc/hosts
--------------------------------------------

A plant such as ``airflow-here-dns.pcs`` names the fqdn and the DNS
backend:

.. code:: python

   from bisos.dnsCap import dnsCap_seedInfo
   cntrlInfo = dnsCap_seedInfo.cmndsControlInfo
   cntrlInfo.dnsSpecMethod = dnsCap_seedInfo.DnsSpecMethod.etcHosts
   cntrlInfo.fqdn = "airflow.here"

With that plant in place, the full cycle is:

.. code:: bash

   bin/airflow-here-dns.pcs -i dnsCap_update

   bin/airflow-here-dns.pcs -i dnsCap_verify

   bin/airflow-here-dns.pcs -i dnsCap_resolve  airflow.here
   bin/airflow-here-dns.pcs -i dnsCap_fqdnPing airflow.here

After ``dnsCap_update``, ``/etc/hosts`` contains a banna-generated
block, e.g.:

.. code:: text

   ####+BEGIN: bx:dblock:global:run-result-stdout :command "bannaInfo.cs -i bannaForEtcHosts"
   127.0.22.100  airflow.here  # port=24006
   127.0.22.122  astroStarter.here  # port=24019
   127.0.22.123  astroStarter_dev.here  # port=25019
   127.0.22.101  csLineInvoker.here  # port=24002
   127.0.22.102  csLineInvoker_dev.here  # port=25002
   127.0.22.103  csPlayerPerf.here  # port=23001
   127.0.22.104  csPlayerPerf_dev.here  # port=23501
   127.0.22.105  csPlayerUi.here  # port=24001
   127.0.22.106  csPlayerUi_dev.here  # port=25001
   127.0.22.117  devpi.here  # port=24015
   127.0.22.119  geneweb.here  # port=24017
   127.0.22.118  gitlab.here  # port=24016
   127.0.22.115  grafana.here  # port=24011
   127.0.22.113  kafka.here  # port=24009
   127.0.22.120  platform.here  # port=24018
   127.0.22.121  platform_dev.here  # port=25018
   127.0.22.114  prometheus.here  # port=24010
   127.0.22.116  pypiserver.here  # port=24013
   127.0.22.107  sonCliLineInvoker.here  # port=24004
   127.0.22.108  sonCliLineInvoker_dev.here  # port=25004
   127.0.22.109  sonCliPlayerUi.here  # port=24003
   127.0.22.110  sonCliPlayerUi_dev.here  # port=25003
   127.0.22.111  starterSidebar.here  # port=24005
   127.0.22.112  starterSidebar_dev.here  # port=25005

   ####+END:

and ``ping airflow.here`` then resolves to ``127.0.22.100``.

Other /etc/hosts blocks, and work before the update
---------------------------------------------------

A plant may need a block other than banna's, and something done before
``/etc/hosts`` is touched. Two more control-info fields cover that; a
plant that sets neither gets banna's block only:

-  ``cntrlInfo.hostsDblockCommands`` — the commands of the dblocks to
   create (when absent) and verify, e.g.
   ``[dnsCap_seedInfo.bannaHostsDblockCommand, "palsHereInfo.cs -i palsForEtcHosts"]``.
-  ``cntrlInfo.preUpdateFuncs`` — functions ``dnsCap_update`` calls
   first; one returning False fails the update before ``/etc/hosts`` is
   touched.

bisos.pals's ``pals-here-dns.spcs`` sets both
(``palsHere.dnsCapSetup()``): it adds the PALS's ``.here`` name to its
list, then has its ``127.0.55.x`` block created and filled beside
banna's.

Commands
--------

+------------------------------+--------------------------------------+
| Command                      | What it does                         |
+==============================+======================================+
| ``dnsCap_update``            | Run ``preUpdateFuncs``, ensure the   |
|                              | dblocks, safe-copy ``/etc/hosts``,   |
+------------------------------+--------------------------------------+
|                              | then rewrite its dblocks (sudo).     |
+------------------------------+--------------------------------------+
| ``dnsCap_ensureHostsDblock`` | Append an empty skeleton for each    |
|                              | missing dblock (backup first:        |
+------------------------------+--------------------------------------+
|                              | ``<file>.<dateTag>.preEnsure``).     |
+------------------------------+--------------------------------------+
| ``dnsCap_verify``            | Check that ``/etc/hosts`` has a      |
|                              | BEGIN line for each dblock, and END. |
+------------------------------+--------------------------------------+
| ``dnsCap_resolve``           | Resolve the fqdn via                 |
|                              | ``getent hosts``.                    |
+------------------------------+--------------------------------------+
| ``dnsCap_fqdnPing``          | Ping the fqdn once to confirm the    |
|                              | entry is in effect.                  |
+------------------------------+--------------------------------------+

Knot DNS and Unbound
====================

Both are built but not yet run on a host; testing is on another machine.
Design and open items: ``AI-WorkPlan.org`` Stage 4
(``<<knotStartingPoint>>``, ``<<unboundStartingPoint>>``).

+-----------------+---------------+----------------------------------+
| Names           | Scope         | Resolved by                      |
+=================+===============+==================================+
| ``.here``       | this platform | ``/etc/hosts``                   |
|                 |               | (``dnsCap_update``, above)       |
+-----------------+---------------+----------------------------------+
| ``.intra``      | this site     | Unbound -> stub zone -> Knot     |
|                 |               | (``127.0.53.1@53``)              |
+-----------------+---------------+----------------------------------+
| everything else | the world     | Unbound, full recursion with     |
|                 |               | DNSSEC validation                |
+-----------------+---------------+----------------------------------+

Knot DNS — authoritative, tinydns-style
---------------------------------------

BISOS data is the single source. dnsCap generates plain zone files and
``knot.conf``, validates them (``kzonecheck``, ``knotc conf-check``),
installs them only when changed — an unchanged zone keeps its SOA serial
— and publishes with ``knotc zone-reload``. The server keeps no state of
its own (``zonefile-load: whole``, ``journal-content: none``,
``zonefile-sync: -1``). Zones: ``here.`` (from banna, for testing only)
and ``intra.`` (SOA/NS so far). Debian's ``knot.service`` is used as is.

.. code:: bash

   knot-sbom.pcs -i sbom_fullUpdate          # knot, knot-dnssecutils, knot-dnsutils; then publish
   knotDns.cs -i knotZoneStdout here         # a zone as it would be generated (writes nothing)
   knotDns.cs -i knotFullUpdate              # zones, then knot.conf
   knotDns.cs -i knotQuery kafka.here        # kdig @127.0.53.1

Unbound — the platform's local resolver
---------------------------------------

Full recursion by default (no ISP resolver log), DNSSEC validation,
QNAME minimisation; a ``forwardTls`` mode forwards over DNS-over-TLS
instead. Company/VPN domains are forwarded to their connection's own DNS
servers by a NetworkManager dispatcher. Firefox and Chrome/Chromium
policies turn their DNS-over-HTTPS off, so they use this resolver.
``/etc/resolv.conf`` is switched only after Unbound answers;
``resolverRevert`` undoes it.

.. code:: bash

   unbound-sbom.pcs -i sbom_fullUpdate       # unbound; then conf, switch, browser policies
   unboundDns.cs -i unboundConfStdout        # bisos.conf as it would be generated
   unboundDns.cs -i unboundQuery debian.org  # kdig @127.0.0.1
   unboundDns.cs -i resolverRevert           # restore the original resolv.conf

Known trade-off: with its DoH off, Firefox does not use Encrypted Client
Hello. A local DoH endpoint on Unbound (needs the platform CA,
palsWithBcm 1.4) is the planned fix.

Key Files
=========

-  ``py3/bin/dnsCap_seed.cs`` — the seed entry point.
-  ``py3/bin/airflow-here-dns.pcs`` — example plant for
   ``airflow.here``.
-  ``py3/bin/exmpl-here-dns.pcs`` — example plant for ``exmpl.here``.
-  ``py3/bisos/dnsCap/dnsCap_csu.py`` — the four ``dnsCap_*`` commands.
-  ``py3/bisos/dnsCap/dnsCap_seedInfo.py`` — ``DnsSpecMethod`` enum
   (``etcHosts``, ``tinydns``) and the ``fqdn`` / ``dnsSpecMethod``
   control info.
-  ``py3/bisos/dnsCap/knotInfo.py``, ``knot_csu.py``,
   ``py3/bin/knotDns.cs`` — Knot DNS: facts and generators, Cmnds, entry
   point. ``knot-sbom.pcs``, ``knot-cbs.pcs``, ``cbmProc-knot.spcs`` —
   its sbom, bedrock CBS and CBM leaf (``collective/bedrock/knot``).
-  ``py3/bisos/dnsCap/unboundInfo.py``, ``unbound_csu.py``,
   ``py3/bin/unboundDns.cs`` — Unbound, likewise; ``unbound-sbom.pcs``,
   ``unbound-cbs.pcs``, ``cbmProc-unbound.spcs``.

Documentation and Blee-Panels
=============================

bisos.dnsCap is part of ByStar Digital Ecosystem http://www.by-star.net.

This module's primary documentation is in the form of Blee-Panels.

See
`file:./panels/bisos.dnsCap/_nodeBase_/fullUsagePanel-en.org <./panels/bisos.dnsCap/_nodeBase_/fullUsagePanel-en.org>`__
for a starting point.

Support
=======

| For support, criticism, comments and questions; please contact the
  author/maintainer
| `Mohsen Banan <http://mohsen.1.banan.byname.net>`__ at:
  http://mohsen.1.banan.byname.net/contact

Planned Improvements
====================

-  ``DnsSpecMethod.knot``, so a ``-here-dns.pcs`` plant can publish into
   Knot. (The ``tinydns`` placeholder is superseded: BISOS uses Knot
   DNS, palsWithBcm 1.2.)
-  Run Knot and Unbound on a real host; then DNSSEC (palsWithBcm 1.6)
   and the ``.intra`` data source.
-  The certificate aspect: a planted ``*-cert.pcs`` beside each
   ``*-here-dns.pcs`` (bisos.crypt README.org, "BISOS Certificates —
   Umbrella Design").
-  Handle ``dnsCap_update`` on a fresh ``/etc/hosts`` with no
   pre-existing dblock markers.
