Repository navigation
BOX-661: Use one Router host helper with env and config override - #2498
Draft
booker-keeper wants to merge 17 commits into
Draft
booker-keeper wants to merge 17 commits into
booker-keeper wants to merge 17 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_targetis the one source of the Router location.get_router_hostandget_router_baseuse it.KROUTER_URL. It acceptshost[: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.ROUTER_HOST. Only thekeeper_dagconnection classes read it.router_hostsin the Commander config (params.config). It maps a server to ahost[:port]or an https URL without a path.routerUrlfrom the server key reply of a self-managed host.connect.<vault host>, for Keeper cloud hosts only.connect.<host>. If the server publishes norouterUrl, Commander raisesRouterHostError. The user can setKROUTER_URLorrouter_hosts.rest_api.parse_router_urlvalidatesrouterUrl. The value must behttps://<host>[:port]with no path. An invalid value is logged and ignored.KROUTER_URL,ROUTER_HOST,router_hostsentry orrouterUrlraisesRouterHostError. The error names its source. It is aCommandError, so the CLI prints a message and no traceback.router_hostsentry does not fall back toconnect.<host>. One invalid entry fails the lookup for every server._), an IPv4 address, or a bracketed IPv6 address. The port must be 1-65535.router_helper.get_router_url,api.execute_router_rest, thekeeper_dagconnection classes andpam tunnel diagnoseuse the helper.pam gateway listpassesRouterHostErrorthrough. It does not log it as an unhandled error.pam tunnel diagnosesplitshost:portand probes the port. The default port is 443.secureparameter ofget_router_baseis removed.ROUTER_URLinexecute_router_restis unchanged.region_redirectreply from a non-cloud host raisesKeeperApiError('server_redirect_refused'). The client does not follow it. Keeper cloud hosts still follow the redirect.is_keeper_cloud_hostnormalizes IDN host names and accepts IPv6 correctly.pam tunnel diagnoserecords aRouterHostErroras a failed check. It strips the brackets of a bare IPv6 Router host.routerUrlgives an error that says so.REGION_REDIRECTfrom a custom host (refuse_redirect_on_custom_host), as forregion_redirect.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.is_up_to_date_versionmakes 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 casespamcommands fail (Commander issue 2490, SMK issue 839).KROUTER_URLdoes 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
routerUrlfield 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
routerUrl: https://github.com/Keeper-Security/smk/blob/main/docs/reference/server-public-key-contract.mdkeeper-smksets: https://github.com/Keeper-Security/smk/blob/main/docs/reference/commander.mdconnect.<SMK_SERVICE_DOMAIN>endpoint: https://github.com/Keeper-Security/smk/blob/main/docs/reference/pam-connections.mdrouter_hosts,routerUrlor the redirect refusal yet. Follow-up: add them.How it was verified
CI checks on the current head, all passing:
test-with-pytest (3.9): SUCCESStest-with-pytest (3.14): SUCCESSCodeQL: SUCCESSAnalyze (python): SUCCESSSocket Security: Pull Request Alerts: SUCCESSSocket Security: Project Report: SUCCESSUnit 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.pypass.Tests in the diff:
unit-tests/test_router_host.py(new): precedence, invalid values,router_hosts,routerUrldiscovery, legacyKROUTER_URLshapes,pam tunnel diagnoseport 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.pyand twounit-tests/pam/test_dag_layer_b_*files: small updates to match the helper.Unverified:
routerUrldiscovery against a real self-managed server.pam tunnel diagnosewith a self-managed host that publishes norouterUrl.Merge risk
The PR conflicts at file level with open PRs #2013, #2014, #2143, #2212, #2412 and #2444. Rebase before any merge.