Skip to content

Version exchange and logging #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: release/1.5-alpha
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 93 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ homepage = "https://github.com/DefGuard/proxy"
repository = "https://github.com/DefGuard/proxy"

[dependencies]
defguard_version = { path = "../defguard/crates/defguard_version" }
# base `axum` deps
axum = { version = "0.7", features = ["macros", "tracing"] }
axum-client-ip = "0.6"
Expand Down Expand Up @@ -44,6 +45,7 @@ tower_governor = "0.4"
rust-embed = { version = "8.5", features = ["include-exclude"] }
mime_guess = "2.0"
base64 = "0.22.1"
tonic-middleware = "0.2"

[build-dependencies]
tonic-build = { version = "0.12" }
Expand Down
5 changes: 5 additions & 0 deletions src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
},
};

use defguard_version::version_info_from_metadata;
use tokio::sync::{mpsc, oneshot};
use tokio_stream::wrappers::UnboundedReceiverStream;
use tonic::{Request, Response, Status, Streaming};
Expand Down Expand Up @@ -98,6 +99,10 @@ impl proxy_server::Proxy for ProxyServer {
error!("Failed to determine client address for request: {request:?}");
return Err(Status::internal("Failed to determine client address"));
};
let (version, info) = version_info_from_metadata(request.metadata());
let span =
tracing::info_span!("core_bidi_stream", core_version = version, core_info = info,);
let _guard = span.enter();
info!("Defguard Core gRPC client connected from: {address}");

let (tx, rx) = mpsc::unbounded_channel();
Expand Down
9 changes: 8 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use axum::{
};
use axum_extra::extract::cookie::Key;
use clap::crate_version;
use defguard_version::server::DefguardVersionServerMiddleware;
use serde::Serialize;
use tokio::{net::TcpListener, task::JoinSet};
use tonic::transport::{Identity, Server, ServerTlsConfig};
use tonic_middleware::MiddlewareFor;
use tower_governor::{
governor::GovernorConfigBuilder, key_extractor::SmartIpKeyExtractor, GovernorLayer,
};
Expand All @@ -33,6 +35,7 @@ use crate::{
grpc::ProxyServer,
handlers::{desktop_client_mfa, enrollment, password_reset, polling},
proto::proxy_server,
VERSION,
};

pub(crate) static ENROLLMENT_COOKIE_NAME: &str = "defguard_proxy";
Expand Down Expand Up @@ -162,8 +165,12 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
} else {
Server::builder()
};
let versioned_server = MiddlewareFor::new(
proxy_server::ProxyServer::new(grpc_server),
DefguardVersionServerMiddleware::new(VERSION)?,
);
builder
.add_service(proxy_server::ProxyServer::new(grpc_server))
.add_service(versioned_server)
.serve(addr)
.await
.context("Error running gRPC server")
Expand Down
Loading
Loading