kolibri
kolibri copied to clipboard
Configure-time port election and proxy-aware URL advertising
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_PORTskips the election entirely. - [ ] "Explicitly set" is determined via Kolibri's options machinery, which transparently proxies env vars (IIAB sets
KOLIBRI_HTTP_PORTin 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 configureflag 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/, nothttp://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 configurecommands:kolibri/utils/cli.py.- URL construction:
get_urls()inkolibri/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.
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_filestops persisting env-var overrides - [ ] URLs omit the scheme-default port
- [ ]
ADVERTISED_HTTP_PORToption - [ ] Port election module
- [ ]
kolibri configure setupruns 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_PORTremoved 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 -epostinst. - 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(envKOLIBRI_ADVERTISED_HTTP_PORT); the kolibri-server follow-up issue must use the same name. KolibriInstance.base_urlkeeps:80; dropping it would change storedNetworkLocation.base_urlidentity for peers.- Election ignores
ADVERTISED_HTTP_PORT; a proxied install configured before its proxy starts could pin 80 unless it setsHTTP_PORT. - A fresh install started with
kolibri startalone never elects and stays on unpinned 8080; electing there means moving election intoinitialize()with app gating.
Written by rtibblesbot, an LLM-based coding agent.