Skip to content

Commit e1b5b9b

Browse files
refactor(dgw): CredSSP enclosure, supermarket store, thin synthetic KDC
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.
1 parent 50d4e0f commit e1b5b9b

15 files changed

Lines changed: 1647 additions & 1863 deletions

‎devolutions-gateway/src/api/kdc_proxy.rs‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use picky_krb::messages::KdcProxyMessage;
55
use uuid::Uuid;
66

77
use crate::DgwState;
8-
use crate::credential_injection_kdc::{
9-
CredentialInjectionKdcInterception, CredentialInjectionKdcRequest, CredentialInjectionKdcResolveError,
10-
kdc_proxy_message_realm,
8+
use crate::credential_injection::{
9+
CredentialInjectionKdcInterception, CredentialInjectionKdcRequest, kdc_proxy_message_realm,
1110
};
1211
use crate::extract::KdcToken;
1312
use crate::http::HttpError;
@@ -22,7 +21,7 @@ pub fn make_router<S>(state: DgwState) -> Router<S> {
2221
async fn kdc_proxy(
2322
State(DgwState {
2423
conf_handle,
25-
credentials,
24+
synthetic_kdc_registry,
2625
agent_tunnel_handle,
2726
..
2827
}): State<DgwState>,
@@ -47,7 +46,9 @@ async fn kdc_proxy(
4746
KdcDestination::Inject { jti } => {
4847
enforce_credential_injection_enabled(jti, conf.debug.enable_unstable)?;
4948

50-
let kdc = credentials.kdc_for(jti).map_err(credential_injection_resolve_error)?;
49+
let kdc = synthetic_kdc_registry
50+
.get(jti)
51+
.ok_or_else(|| HttpError::bad_request().msg("no live synthetic KDC published for this session"))?;
5152

5253
debug!(
5354
jti = %kdc.jti(),
@@ -92,17 +93,6 @@ async fn kdc_proxy(
9293
}
9394
}
9495

95-
fn credential_injection_resolve_error(error: CredentialInjectionKdcResolveError) -> HttpError {
96-
match error {
97-
CredentialInjectionKdcResolveError::BuildKdcConfig { .. } => HttpError::internal()
98-
.with_msg("credential-injection KDC could not be initialized")
99-
.build(error),
100-
_ => HttpError::bad_request()
101-
.with_msg("credential-injection state is not available")
102-
.build(error),
103-
}
104-
}
105-
10696
// Forwards the request to the real KDC indicated by the token (or by the debug override) and
10797
// returns the response wrapped as a `KdcProxyMessage`.
10898
//

‎devolutions-gateway/src/api/preflight.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use uuid::Uuid;
1111

1212
use crate::DgwState;
1313
use crate::config::Conf;
14-
use crate::credential_injection_kdc::CredentialService;
1514
use crate::extract::PreflightScope;
1615
use crate::http::HttpError;
17-
use crate::provisioning::InsertError;
16+
use crate::provisioning::{InsertError, ProvisioningStore};
1817
use crate::session::SessionMessageSender;
1918

2019
const OP_GET_VERSION: &str = "get-version";
@@ -204,7 +203,7 @@ pub(super) async fn post_preflight(
204203
State(DgwState {
205204
conf_handle,
206205
sessions,
207-
credentials,
206+
provisioning,
208207
..
209208
}): State<DgwState>,
210209
_scope: PreflightScope,
@@ -231,13 +230,13 @@ pub(super) async fn post_preflight(
231230
let outputs = outputs.clone();
232231
let conf = conf_handle.get_conf();
233232
let sessions = sessions.clone();
234-
let credentials = credentials.clone();
233+
let provisioning = provisioning.clone();
235234

236235
async move {
237236
let operation_id = operation.id;
238237
trace!(%operation.id, "Process preflight operation");
239238

240-
if let Err(error) = handle_operation(operation, &outputs, &conf, &sessions, &credentials).await {
239+
if let Err(error) = handle_operation(operation, &outputs, &conf, &sessions, &provisioning).await {
241240
outputs.push(PreflightOutput {
242241
operation_id,
243242
kind: PreflightOutputKind::Alert {
@@ -264,7 +263,7 @@ async fn handle_operation(
264263
outputs: &Outputs,
265264
conf: &Conf,
266265
sessions: &SessionMessageSender,
267-
credentials: &CredentialService,
266+
provisioning: &ProvisioningStore,
268267
) -> Result<(), PreflightError> {
269268
match operation.kind.as_str() {
270269
OP_GET_VERSION => outputs.push(PreflightOutput {
@@ -355,7 +354,7 @@ async fn handle_operation(
355354
})?;
356355
}
357356

358-
let replaced = credentials
357+
let replaced = provisioning
359358
.insert_credentials(token, mapping, time_to_live)
360359
.inspect_err(|error| warn!(%operation.id, error = format!("{error:#}"), "Failed to insert credentials"))
361360
.map_err(|error| match error {
@@ -397,7 +396,7 @@ async fn handle_operation(
397396
PreflightError::new(PreflightAlertStatus::InvalidParams, format!("invalid token: {error:#}"))
398397
})?;
399398

400-
let replaced = credentials.insert_connection_options(jti, connection_options, time_to_live);
399+
let replaced = provisioning.insert_connection_options(jti, connection_options, time_to_live);
401400

402401
if replaced {
403402
outputs.push(PreflightOutput {

‎devolutions-gateway/src/api/rdp.rs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub async fn handler(
2525
subscriber_tx,
2626
recordings,
2727
shutdown_signal,
28-
credentials,
28+
provisioning,
29+
synthetic_kdc_registry,
2930
agent_tunnel_handle,
3031
..
3132
}): State<DgwState>,
@@ -46,7 +47,8 @@ pub async fn handler(
4647
subscriber_tx,
4748
recordings.active_recordings,
4849
source_addr,
49-
credentials,
50+
provisioning,
51+
synthetic_kdc_registry,
5052
agent_tunnel_handle,
5153
)
5254
.instrument(span)
@@ -66,7 +68,8 @@ async fn handle_socket(
6668
subscriber_tx: SubscriberSender,
6769
active_recordings: Arc<ActiveRecordings>,
6870
source_addr: SocketAddr,
69-
credentials: crate::credential_injection_kdc::CredentialService,
71+
provisioning: crate::provisioning::ProvisioningStore,
72+
synthetic_kdc_registry: crate::credential_injection::SyntheticKdcRegistry,
7073
agent_tunnel_handle: Option<Arc<agent_tunnel::AgentTunnelHandle>>,
7174
) {
7275
let (stream, close_handle) = crate::ws::handle(
@@ -84,7 +87,8 @@ async fn handle_socket(
8487
sessions,
8588
subscriber_tx,
8689
&active_recordings,
87-
&credentials,
90+
&provisioning,
91+
&synthetic_kdc_registry,
8892
agent_tunnel_handle,
8993
)
9094
.await;

0 commit comments

Comments
 (0)