Skip to content

feat(docker): configurable host bind address for kg-api and kg-web - #547

Open
theja0143 wants to merge 1 commit into
aaronsb:mainfrom
theja0143:feat/configurable-host-bind-address
Open

feat(docker): configurable host bind address for kg-api and kg-web#547
theja0143 wants to merge 1 commit into
aaronsb:mainfrom
theja0143:feat/configurable-host-bind-address

Conversation

@theja0143

Copy link
Copy Markdown

Problem

#502 bound postgres (5432) and garage (3900/3903) to 127.0.0.1, on the rationale that the API and operator reach them over the docker network, so the host publish is only for local tooling.

kg-api (8000) and kg-web (3000) were left on 0.0.0.0 — and reasonably so. Unlike postgres and garage, they are browser-facing, and may legitimately need to be reachable from another machine. Hard-coding them to loopback would break that, which I assume is exactly why #502 stopped where it did.

But that leaves single-box installs — a local dev setup, or WSL, where the browser and the API share a host — publishing an API and a web UI on every interface, with no way to opt out short of patching docker-compose.yml. That patch then collides on every pull, and resolving the collision the wrong way silently re-widens the ports again.

Change

Make the bind address configurable instead of choosing for the operator:

- "${KG_API_BIND:-0.0.0.0}:8000:8000"  # API endpoint
- "${KG_WEB_BIND:-0.0.0.0}:3000:80"    # Web UI

The default is 0.0.0.0 — current behaviour, unchanged. Nothing breaks for anyone who needs off-box access. Operators who don't can set KG_API_BIND=127.0.0.1 / KG_WEB_BIND=127.0.0.1 in .env and get the same treatment #502 gave the backend services.

The ${VAR:-default} idiom is already used ~19 times in this compose file, so this doesn't introduce a new pattern.

Verification

Via docker compose -f docker/docker-compose.yml config:

env kg-api host_ip kg-web host_ip postgres / garage
unset (default) 0.0.0.0 0.0.0.0 127.0.0.1
KG_API_BIND=127.0.0.1 KG_WEB_BIND=127.0.0.1 127.0.0.1 127.0.0.1 127.0.0.1

So the default path resolves byte-for-byte to today's behaviour, and the opt-in brings all five published ports onto loopback.

Also

New Host Port Bind Addresses section in .env.example documenting both knobs and stating the default explicitly.


Context, in the interest of being upfront: I run this project as a local, loopback-only knowledge substrate for another codebase, and have been carrying a local patch that hard-binds these two ports. This PR is the upstream-shaped version of that patch — configurable rather than imposed — so I can drop the local carry. Happy to adjust naming (KG_API_BIND vs something else) or drop the .env.example prose if you'd rather keep it lean.

aaronsb#502 bound postgres (5432) and garage (3900/3903) to 127.0.0.1, on the
rationale that the API and operator reach them over the docker network and the
host publish is only for local tooling. kg-api (8000) and kg-web (3000) were
left on 0.0.0.0 — reasonably so: unlike postgres and garage, they are
browser-facing and may legitimately need to be reachable off-box, so a hard
loopback would break that.

But that leaves single-box installs (a local dev setup, or WSL, where the
browser and the API share a host) publishing an API and a web UI on every
interface with no way to opt out short of patching the compose file — which then
collides on every pull.

So make the bind address configurable rather than choosing for the operator:

    - "${KG_API_BIND:-0.0.0.0}:8000:8000"
    - "${KG_WEB_BIND:-0.0.0.0}:3000:80"

The default is 0.0.0.0 — current behaviour, byte-for-byte unchanged, nothing
breaks for anyone who does need LAN access. Operators who don't can set
KG_API_BIND=127.0.0.1 / KG_WEB_BIND=127.0.0.1 in .env and get the same treatment
aaronsb#502 gave the backend services. The ${VAR:-default} idiom is already used
throughout this compose file.

Verified with `docker compose config`:
  * unset          -> kg-api/kg-web host_ip 0.0.0.0   (postgres/garage 127.0.0.1)
  * both = 127.0.0.1 -> all five services host_ip 127.0.0.1

Documented under a new "Host Port Bind Addresses" section in .env.example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant