fix(dgw): separate credential injection runtime - #1900
fix(dgw): separate credential injection runtime#1900irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 10 commits into
Conversation
604d476 to
4d54764
Compare
4d54764 to
3e9b3b6
Compare
3e9b3b6 to
751129f
Compare
| enforce_credential_injection_enabled(jti, conf.debug.enable_unstable)?; | ||
|
|
||
| let kdc = credentials.kdc_for(jti).map_err(credential_injection_resolve_error)?; | ||
| let kdc = synthetic_kdc_registry |
There was a problem hiding this comment.
Now everything the KDC Proxy need is in the synthetic_kdc_registry, there's no need for KDC handler to read provisioning store anymore.
More semantically clear
There was a problem hiding this comment.
Pull request overview
Refactors RDP credential injection by separating provisioning, synthetic KDC registration, and CredSSP orchestration.
Changes:
- Splits RDP proxy and CredSSP logic into dedicated modules.
- Replaces
CredentialServicewith a one-shot provisioning store and live KDC registry. - Updates all connection and API paths to use the new architecture.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
devolutions-gateway/src/service.rs |
Initializes and wires the new stores. |
devolutions-gateway/src/rdp_proxy/mod.rs |
Adds RDP handshake and TLS orchestration. |
devolutions-gateway/src/rdp_proxy/credssp.rs |
Encapsulates CredSSP MITM behavior. |
devolutions-gateway/src/rdp_proxy.rs |
Removes the former monolithic proxy. |
devolutions-gateway/src/rd_clean_path.rs |
Integrates new credential-injection state. |
devolutions-gateway/src/provisioning.rs |
Makes provisioning retrieval one-shot. |
devolutions-gateway/src/ngrok.rs |
Updates state wiring. |
devolutions-gateway/src/listener.rs |
Updates TCP client construction. |
devolutions-gateway/src/lib.rs |
Replaces credential-service state fields. |
devolutions-gateway/src/generic_client.rs |
Builds session-scoped credential injection. |
devolutions-gateway/src/credential_injection.rs |
Adds credential and synthetic KDC runtime. |
devolutions-gateway/src/credential_injection_kdc.rs |
Removes the previous combined service. |
devolutions-gateway/src/api/rdp.rs |
Passes new state into RDP handling. |
devolutions-gateway/src/api/preflight.rs |
Writes directly to provisioning storage. |
devolutions-gateway/src/api/kdc_proxy.rs |
Resolves only live registered KDCs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dcf1ce4 to
7c1a9ba
Compare
7881ed0 to
45839d6
Compare
45839d6 to
53726c5
Compare
53726c5 to
f815e99
Compare
f815e99 to
866675e
Compare
866675e to
63e17d0
Compare
Benoît Cortier (CBenoit)
left a comment
There was a problem hiding this comment.
Warning
Automated review. Human insight is required, especially to resolve the conflicting SPN assumptions described below.
Requesting changes on this stacked delta (chore/regenerate-openapi-provisioning -> refactor/rdp-proxy-credssp-extract).
-
Blocking - the existing SPN regression thread remains unresolved.
credential_injection.rs:222,260,351,416now derives the synthetic-KDC service hostname from the association token'sdst_hst. The base branch deliberately usedconf.hostnameafter merged fix #1856, and this PR deletesservice_kdc_for_uses_gateway_hostname_for_spn, the regression test that pinned that behavior. The author has supplied contrary product-path evidence in the existing thread, so this needs a human protocol decision rather than another automated guess. Whichever hostname is correct must be explicit, tested with different Gateway and destination hostnames, and described as a behavior change if #1856 is intentionally being reversed. -
The new one-shot store changes observable retry behavior without documenting it.
ProvisioningStore::take(provisioning.rs:143-197) removes credentials and connection options before target connection, TLS, or CredSSP can succeed (generic_client.rs:158-197,rd_clean_path.rs:490-580). A transient failure consumes the data, and a retry inside the advertised TTL can silently fall through to non-injected forwarding. This conflicts with the currenttime_to_livewording inopenapi.rs:396-400("Minimum persistence duration") and is not a behavior-preservingrefactor:. Either retain entries across failed attempts, or document the single-use contract in OpenAPI/PR history and make skipped injection explicit instead of silently falling back. -
The CredSSP enclosure is incomplete and leaves two orchestration implementations.
credssp.rs:73-153owns both CredSSP legs, Connect Confirm interception, leftover flushing, and forwarding, butrd_clean_path.rs:551-634open-codes the same sequence.rdp_proxy/mod.rs:12-14then re-exports three internals solely to sustain that duplicate path. BuildCredsspSession/PreparedCredsspfrom RDCleanPath too and callrun; that removes roughly 80 duplicated lines and makes the stated module boundary real. -
generic_clientdestructively reads entries it does not use. Atgeneric_client.rs:157-160,takeruns beforeentry.mapping.is_some(), so an RDP connection consumes a token-onlyprovision-tokenentry and discards it. Match the safer RDCleanPath shape: checkhas_mappingfirst, thentakeonly for the injection path. -
Protocol gating was duplicated while its regression coverage was deleted. The two-flag condition is repeated at
generic_client.rs:162andrd_clean_path.rs:495, while the prior flag-matrix test was removed. The empty test module atrdp_proxy/mod.rs:274-278incorrectly claims protocol selection remains covered. Centralize the predicate, restore the opt-in matrix test, and remove the empty scaffolding. -
The kitchen metaphor makes the new boundaries harder to learn.
credential_injection.rs:1-5,101,108,205,524-531andrd_clean_path.rs:668-669require readers to translate "supermarket/groceries/chef/dish/pass window" back intoProvisioningStore,ProvisioningEntry, preparation, and live KDC registration. Use those technical terms directly; this module's purpose is separation of concerns, so it should not introduce a second vocabulary for them.
Non-blocking cleanup: CredentialInjectionKdcResolveError no longer has a discriminating consumer (credential_injection.rs:55-72), so its four variants and duplicated pre-return warnings should either regain a matching caller or collapse to contextual anyhow errors. Also capitalize the newly added log messages and terminate sentence comments per repository conventions.
Note
LLM-assisted content (no human feedback).
63e17d0 to
79b523d
Compare
79b523d to
350ada2
Compare
Split rdp_proxy CredSSP into its own module. Delete CredentialService: DgwState holds ProvisioningStore + SyntheticKdcRegistry. from_provisioned builds PreparedCredentialInjection; register_if_kerberos publishes. take() consumes groceries once. Synthetic KDC keeps only fake-KDC runtime; credentials and target_kdc stay on the dish.
Authorize CleanPath tokens before one-shot take, use a registry-wide generation counter, and replace bare clippy allow with expect. SPN remains association-token dst_hst for client-facing CredSSP.
350ada2 to
77d3c4c
Compare
Use association dst_hst for synthetic KDC SPN and target-leg Kerberos hostname instead of conf.hostname. Route RDCleanPath through CredsspSession, peek before one-shot take, and document checkout TTL. Issue: DGW review #1900 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the preinstalled WiX toolset until Chocolatey successfully installs the pinned version. Retry transient feed failures, validate candle.exe, and expose WIXSHARP_WIXDIR so installer builds cannot continue with an empty WiX path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Implementation notes:
Note Human-tuned, LLM-assisted content. |
Keep PR #1900 scoped to the Gateway provisioning and CredSSP refactor. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep consumed credential mappings visible until their original expiry so a reused JTI fails explicitly instead of silently falling back to ordinary forwarding. Centralize atomic checkout and CredSSP orchestration, preserve token-only provisioning, and simplify KDC error handling. Record the one-shot contract in PR history without regenerating unchanged OpenAPI artifacts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Describe time_to_live as the first-checkout window for credential-injection mappings and state that failed attempts require re-provisioning. Regenerate the published specification and clients. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
State that supported credential-injection clients retain association dst_hst as their logical TERMSRV service name even when the transport endpoint is a Gateway listener. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Final review follow-up:
Additional cleanup: removed the unused typed KDC resolve error, centralized checkout validation, kept generation-guarded KDC leases for explicit same-JTI re-provision overlap, and regenerated OpenAPI artifacts. Validation: full workspace Clippy; workspace lib/bin/test targets plus colliding examples run separately; generated .NET client build; 22-case DVLS matrix, including live NTLM and Kerberos CredSSP over RDCleanPath. Note Human-tuned, LLM-assisted content. |
Restore the pre-existing provisioning TTL wording and generated artifacts. The OpenAPI documentation update was outside the requested PR scope. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Benoît Cortier (@CBenoit), ready for review Note Human-tuned, LLM-assisted content. |
Separates pending provisioning data from the live credential-injection runtime so each handler owns the session state it consumes and the KDC proxy resolves only active synthetic KDC registrations.
Credential injection uses the association token's dynamic
dst_hstfor the client-facingTERMSRVSPN and target-side Kerberos hostname. Supported clients retain that logical destination when connecting through a Gateway listener; clients that derive the SPN from the Gateway transport hostname are outside the unstable Kerberos credential-injection contract.Provisioned injection mappings are checked out atomically and consumed once. Reused JTIs fail explicitly instead of silently downgrading to ordinary forwarding, and callers must re-provision after a failed attempt.
Both generic RDP and RDCleanPath use the same CredSSP session orchestration and centralized Kerberos opt-in decision.
Issue: DVLS-14697