Skip to content

add mTLS for gateway & proxy communication#2726

Open
wojcik91 wants to merge 25 commits intorelease/2.0from
mtls
Open

add mTLS for gateway & proxy communication#2726
wojcik91 wants to merge 25 commits intorelease/2.0from
mtls

Conversation

@wojcik91
Copy link
Copy Markdown
Contributor

@wojcik91 wojcik91 commented Apr 16, 2026

Generate and store core client certificates during component setup.
Those certs are then sent to the gateway/proxy along with CA cert so they can validate client identity.

Related #2695

Needs DefGuard/proto#74

@wojcik91 wojcik91 self-assigned this Apr 16, 2026
Comment thread crates/defguard_certs/src/lib.rs Outdated
Ok(cert)
}

/// Issue a Core gRPC client certificate for a specific gateway or proxy.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Issue a Core gRPC client certificate for a specific gateway or proxy.
/// Issue a Core gRPC client certificate for a specific Gateway or Edge.

Comment thread crates/defguard_certs/src/lib.rs Outdated
}
}

/// A Core gRPC client certificate issued for a specific gateway or proxy component.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A Core gRPC client certificate issued for a specific gateway or proxy component.
/// A Core gRPC client certificate issued for a specific Gateway or Edge component.

{
sqlx::query(
pub async fn mark_all_disconnected<'e, E: PgExecutor<'e>>(executor: E) -> sqlx::Result<()> {
query(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query(
query!(

let created_modified_at = created_alias_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let updated_modified_at = updated_alias_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let created_modified_at = created_destination_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let updated_modified_at = updated_destination_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let created_modified_at = created_rule_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let updated_modified_at = updated_rule_row.modified_at;

tokio::time::sleep(std::time::Duration::from_millis(2)).await;
sleep(std::time::Duration::from_millis(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

let mut results = Vec::new();
// Give the handler a brief moment to enqueue the message.
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
sleep(Duration::from_millis(50)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

async fn drain_clear_https_certs(&mut self) -> usize {
let mut results = 0;
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
sleep(Duration::from_millis(50)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

timeout(TEST_TIMEOUT, async {
while self.events_tx().receiver_count() <= initial_event_receivers {
tokio::time::sleep(Duration::from_millis(20)).await;
sleep(Duration::from_millis(20)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

}

tokio::time::sleep(Duration::from_millis(20)).await;
sleep(Duration::from_millis(20)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

}

/// Create a rustls client config that enforces the pinned component certificate serial.
/// Build a tonic [`ServerTlsConfig`] for a gateway or proxy gRPC server that enforces
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Build a tonic [`ServerTlsConfig`] for a gateway or proxy gRPC server that enforces
/// Build a tonic [`ServerTlsConfig`] for a Gateway or Edge gRPC server that enforces

@@ -0,0 +1,58 @@
//! Server-side mTLS utilities for gateway and proxy gRPC servers.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! Server-side mTLS utilities for gateway and proxy gRPC servers.
//! Server-side mTLS utilities for Gateway and Edge gRPC servers.


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


// Delay, so send_and_forget() can process the message.
tokio::time::sleep(Duration::from_secs(2)).await;
sleep(Duration::from_secs(2)).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


let shutdown_signal =
tokio::time::timeout(std::time::Duration::from_secs(1), shutdown_rx).await;
let shutdown_signal = timeout(Duration::from_secs(1), shutdown_rx).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value

assert_eq!(wizard.active_wizard, ActiveWizard::None);

let shutdown = tokio::time::timeout(std::time::Duration::from_secs(1), shutdown_rx).await;
let shutdown = timeout(Duration::from_secs(1), shutdown_rx).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value


let shutdown_signal =
tokio::time::timeout(std::time::Duration::from_secs(1), shutdown_rx).await;
let shutdown_signal = timeout(std::time::Duration::from_secs(1), shutdown_rx).await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value and just use Duration trimming std::time.

Comment thread migrations/20260414120000_[2.0.0]_core_grpc_cert.down.sql
Comment thread migrations/20260414120000_[2.0.0]_core_grpc_cert.up.sql
///
/// ```rust,ignore
/// ServiceBuilder::new()
/// .layer(tonic::service::interceptor(certificate_serial_interceptor(Some(serial))))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// .layer(tonic::service::interceptor(certificate_serial_interceptor(Some(serial))))
/// .layer(tonic::service::interceptor(certificate_serial_interceptor(serial)))

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.

3 participants