kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Configure-time port election and proxy-aware URL advertising

Open rtibbles opened this issue 5 months ago • 1 comments

Overview

A server that comes up on a different port than its advertised URLs breaks every bookmark — the port is decided once, at setup time, and pinned (parent: #14960). Kolibri owns the election itself so installers only grant the bind privilege.

Complexity: Medium Target branch: develop

Acceptance Criteria

General

  • [ ] At configure time, with no explicitly configured port, Kolibri attempts the preferred port (80), falls back to 8080, and pins the result to options.ini.
  • [ ] An explicitly set HTTP_PORT skips the election entirely.
  • [ ] "Explicitly set" is determined via Kolibri's options machinery, which transparently proxies env vars (IIAB sets KOLIBRI_HTTP_PORT in its systemd unit).
  • [ ] Election runs on fresh setup or explicit request only, never on upgrade.
  • [ ] When 80 is blocked, the outcome report names the occupying process/service where the OS allows discovery.
  • [ ] A non-interactive kolibri configure flag sets the port preference for scripts and images.
  • [ ] A new option advertises a public port different from the bound port, for proxied deployments (kolibri-server: nginx on 80, kolibri on 8080).
  • [ ] URL production (get_urls(), zeroconf broadcast, device-info API) honors the advertised port.
  • [ ] URLs omit the port when it's the scheme default (http://kolibri.local/, not http://kolibri.local:80/).

Testing

  • [ ] Unit: election pins 80 when bindable.
  • [ ] Unit: election pins the fallback when 80 is busy.
  • [ ] Unit: election never changes an explicitly configured port.
  • [ ] Unit: busy-port report names the occupant.
  • [ ] Unit: URLs omit the scheme-default port.
  • [ ] Unit: URLs carry a non-default port.
  • [ ] Unit: advertised port overrides bound port in get_urls() and the broadcast.

References

  • kolibri configure commands: kolibri/utils/cli.py.
  • URL construction: get_urls() in kolibri/utils/server/__init__.py.
  • Default-port omission precedent: kolibri/core/discovery/utils/network/urls.py.

AI usage

Written with Claude Code in an interactive design session; all decisions were made by the author in dialogue.

rtibbles avatar Jul 04 '26 05:07 rtibbles

Plan: kolibri configure setup elects and pins port 80 (else 8080) on fresh setup or on request; URLs drop :80 and honor a new advertised-port option.

  • [ ] update_options_file stops persisting env-var overrides
  • [ ] URLs omit the scheme-default port
  • [ ] ADVERTISED_HTTP_PORT option
  • [ ] Port election module
  • [ ] kolibri configure setup runs the election
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • The configure flag is kolibri configure setup --preferred-port N, and passing it is the "explicit request"; a separate subcommand would change only the CLI surface.
  • An earlier election's pin counts as explicit, so re-election needs HTTP_PORT removed first; overriding elected pins needs a marker distinguishing them from user pins.
  • Neither port bindable: pin nothing, warn, exit 0; failing would abort kolibri-server's set -e postinst.
  • Occupant naming is Linux-only (procfs); Windows/macOS report "busy" unnamed — Windows naming would add GetExtendedTcpTable.
  • Unprivileged runs cannot read other users' /proc/<pid>/fd, so root/www-data nginx goes unnamed; naming those needs the socket uid from /proc/net/tcp.
  • Option name ADVERTISED_HTTP_PORT (env KOLIBRI_ADVERTISED_HTTP_PORT); the kolibri-server follow-up issue must use the same name.
  • KolibriInstance.base_url keeps :80; dropping it would change stored NetworkLocation.base_url identity for peers.
  • Election ignores ADVERTISED_HTTP_PORT; a proxied install configured before its proxy starts could pin 80 unless it sets HTTP_PORT.
  • A fresh install started with kolibri start alone never elects and stays on unpinned 8080; electing there means moving election into initialize() with app gating.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Oct 21 '26 23:10 rtibblesbot