Skip to content

BOX-661: Use one Router host helper with env and config override - #2498

Draft
booker-keeper wants to merge 17 commits into
masterfrom
fix/BOX-661-router-host
Draft

booker-keeper wants to merge 17 commits into
masterfrom
fix/BOX-661-router-host

Conversation

@booker-keeper

@booker-keeper booker-keeper commented Nov 5, 2026 •

Copy link
Copy Markdown

Jira: https://keeper.atlassian.net/browse/BOX-653
Jira: https://keeper.atlassian.net/browse/BOX-661
Requirements: https://keeper.atlassian.net/wiki/spaces/CONT/pages/5519441922

This pull request is a proof-of-concept reference for the client team. It is not ready to merge as is.

Fixes: #2490
Related: https://github.com/Keeper-Security/smk/issues/839

What changed

  • constants.get_router_target is the one source of the Router location. get_router_host and get_router_base use it.
  • The Router host comes from these sources, in this order:
    1. KROUTER_URL. It accepts host[:port], or an http, https, ws or wss URL with an optional path. The scheme the user gives sets secure or plain transport. A plaintext scheme logs a warning.
    2. ROUTER_HOST. Only the keeper_dag connection classes read it.
    3. router_hosts in the Commander config (params.config). It maps a server to a host[:port] or an https URL without a path.
    4. routerUrl from the server key reply of a self-managed host.
    5. connect.<vault host>, for Keeper cloud hosts only.
  • A self-managed host never gets a guessed connect.<host>. If the server publishes no routerUrl, Commander raises RouterHostError. The user can set KROUTER_URL or router_hosts.
  • rest_api.parse_router_url validates routerUrl. The value must be https://<host>[:port] with no path. An invalid value is logged and ignored.
  • An invalid KROUTER_URL, ROUTER_HOST, router_hosts entry or routerUrl raises RouterHostError. The error names its source. It is a CommandError, so the CLI prints a message and no traceback.
  • An invalid router_hosts entry does not fall back to connect.<host>. One invalid entry fails the lookup for every server.
  • The host check accepts a DNS name (RFC 1123 labels plus _), an IPv4 address, or a bracketed IPv6 address. The port must be 1-65535.
  • router_helper.get_router_url, api.execute_router_rest, the keeper_dag connection classes and pam tunnel diagnose use the helper.
  • pam gateway list passes RouterHostError through. It does not log it as an unhandled error.
  • pam tunnel diagnose splits host:port and probes the port. The default port is 443.
  • The unused secure parameter of get_router_base is removed.
  • ROUTER_URL in execute_router_rest is unchanged.
  • Login (BOX-653): a region_redirect reply from a non-cloud host raises KeeperApiError('server_redirect_refused'). The client does not follow it. Keeper cloud hosts still follow the redirect.
  • Cloud Router host results are unchanged.
  • is_keeper_cloud_host normalizes IDN host names and accepts IPv6 correctly.
  • pam tunnel diagnose records a RouterHostError as a failed check. It strips the brackets of a bare IPv6 Router host.
  • A user-set server key with no routerUrl gives an error that says so.
  • Login refuses the protobuf REGION_REDIRECT from a custom host (refuse_redirect_on_custom_host), as for region_redirect.
  • Mode B: after a 401 key error, a refetched key with the same key id and a different key fails with server_key_changed. The error names the host, the new key id and its SHA256 fingerprint. It says "To trust it, enter the server again: server ". The old key stays. server <host> forgets the fetched key, so the next fetch is a first use. A new key id is a key rotation and is used (contract rule 3). If the refetch finds no key, the old key stays.
  • Air gap: on a non-cloud host, is_up_to_date_version makes no GitHub request and reports up to date.

Why

Commander builds the Router host as connect.<vault host>. A self-managed deployment can serve the Router on another host. The vault host can be an IP address. In both cases pam commands fail (Commander issue 2490, SMK issue 839).

KROUTER_URL does not fix this. Some callers read it as a full URL. Other callers read it as a bare host. One helper now gives one rule to every caller.

A self-managed server can publish its Router in the server key reply. The client then needs no manual setting. A self-managed server must not send the client to another host. The client refuses such a redirect.

This change builds on merged PR #2434, which adds the self-managed server key. It reads the extra routerUrl field from the same server key reply that PR #2449 fetches. PRs #2447 and #2448 register the custom key with the KSM SDK. This PR does not change those paths.

Docs

How it was verified

CI checks on the current head, all passing:

  • test-with-pytest (3.9): SUCCESS
  • test-with-pytest (3.14): SUCCESS
  • CodeQL: SUCCESS
  • Analyze (python): SUCCESS
  • Socket Security: Pull Request Alerts: SUCCESS
  • Socket Security: Project Report: SUCCESS

Unit tests pytest unit-tests/test_router_host.py unit-tests/test_region_redirect_refusal.py unit-tests/test_self_managed_server_key.py unit-tests/pam/test_pam_tunnel.py unit-tests/test_versioning.py pass.

Tests in the diff:

  • unit-tests/test_router_host.py (new): precedence, invalid values, router_hosts, routerUrl discovery, legacy KROUTER_URL shapes, pam tunnel diagnose port split.
  • unit-tests/test_region_redirect_refusal.py (new): a custom host refuses the redirect. A cloud host follows it.
  • unit-tests/pam/test_pam_tunnel.py and two unit-tests/pam/test_dag_layer_b_* files: small updates to match the helper.

Unverified:

  • A live run on an SMK stack with the current head. Earlier live runs used older commits.
  • routerUrl discovery against a real self-managed server.
  • The redirect refusal against a real self-managed server.
  • pam tunnel diagnose with a self-managed host that publishes no routerUrl.

Merge risk

The PR conflicts at file level with open PRs #2013, #2014, #2143, #2212, #2412 and #2444. Rebase before any merge.

constants.get_router_host and get_router_base are the only source of the
Router host. KROUTER_URL accepts a bare host[:port] or an https URL. The
"router_hosts" config property sets the host per server. Cloud result is
unchanged.
…g, fail with a typed error

KROUTER_URL accepts http, https, ws, and wss URLs with an optional path
again. The scheme the user gives decides secure or plain. A plaintext
scheme logs a warning. The "router_hosts" config property stays https-only.

An invalid KROUTER_URL, ROUTER_HOST, or router_hosts entry raises
RouterHostError. It names the source and is a CommandError, so the CLI
prints a message and no traceback. An invalid router_hosts entry no
longer falls back to connect.<host>.

The helper takes the config (params.config) from the call site. The
module global and its load in __main__ are removed. ROUTER_HOST goes
through the same parser. Order: KROUTER_URL, ROUTER_HOST, router_hosts,
connect.<host>. ROUTER_URL in execute_router_rest is unchanged.

pam tunnel diagnose splits host:port and probes the port (default 443).
The unused secure parameter of get_router_base is removed.
…hrough

The host part must be an RFC 1123 DNS name, an IPv4 address, or a bracketed IPv6 address.
The port must be 1-65535. The error names KROUTER_URL, ROUTER_HOST, or router_hosts.
The gateway list commands no longer log RouterHostError as an unhandled error.

This branch has not been deployed

No deployments
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.

Use one consistent Router host override in Commander (KROUTER_URL has three shapes)

1 participant