refactor(dgw): CredSSP enclosure, supermarket store, thin synthetic KDC - #1900
refactor(dgw): CredSSP enclosure, supermarket store, thin synthetic KDC#1900irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 3 commits into
Conversation
604d476 to
4d54764
Compare
4d54764 to
3e9b3b6
Compare
3e9b3b6 to
751129f
Compare
| // lookup by `claims.jti` is the primary path. | ||
| if is_rdp | ||
| && let Some(entry) = credentials.get(claims.jti) | ||
| && let Some(entry) = provisioning.take(claims.jti) |
There was a problem hiding this comment.
Create credential injection from provisioning.
The analogy, as well as the mindset I'd like to use here, is that the provisioning store is like a supermarket, where each handler — for example, GenericClient here — can purchase what he wants with a jti and start preparing the meal (credential injection here).
This grants better separation of concerns, as well as better extensibility.
| let kerberos_enabled = conf.debug.enable_unstable && conf.debug.kerberos_credential_injection; | ||
| let credential_injection = | ||
| CredentialInjection::from_provisioned(claims.jti, entry, kerberos_enabled)? | ||
| .register_if_kerberos(&synthetic_kdc_registry); |
There was a problem hiding this comment.
Now the Chef 1, the generic client has done the first round of preparation, we pass it to the second chef, which is the kdc proxy hereOnce Chef 1 (GenericClient) finishes the first round of prep, the dish gets handed off to the second chef — the KDC proxy — to continue the process.
| 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.
| // lookup by `claims.jti` is the primary path. | ||
| if is_rdp | ||
| && let Some(entry) = credentials.get(claims.jti) | ||
| && let Some(entry) = provisioning.take(claims.jti) |
There was a problem hiding this comment.
Notice it's a take here, so provisioning won't be reused, one of the benifits this refactoring brings
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
As previously mentioned, the current state of KDC via provisioning is complete from a functional standpoint. However, we can see that the words
credentialandprovisionare starting to blur into each other — the boundary isn't clear, and we've been using them interchangeably, which is just bad design.I added comments to the critical lines in the PR diff; it should be clear how this makes sense from there.