geyser: check `x-token` for health service too (#359)
This commit is contained in:
parent
13f8df264c
commit
bc9da4fe01
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -14,11 +14,18 @@ The minor version will be incremented upon a breaking change and the patch versi
|
|||
|
||||
### Features
|
||||
|
||||
- geyser: add compression option to config ([#356](https://github.com/rpcpool/yellowstone-grpc/pull/356))
|
||||
- geyser: add `x-endpoint` to `subscriptions_total` ([#358](https://github.com/rpcpool/yellowstone-grpc/pull/358))
|
||||
|
||||
### Breaking
|
||||
|
||||
## 2024-06-07
|
||||
|
||||
- yellowstone-grpc-geyser-1.15.0+solana.1.17.33
|
||||
|
||||
### Features
|
||||
|
||||
- geyser: add compression option to config ([#356](https://github.com/rpcpool/yellowstone-grpc/pull/356))
|
||||
- geyser: add `x-endpoint` to metric `subscriptions_total` ([#358](https://github.com/rpcpool/yellowstone-grpc/pull/358))
|
||||
- geyser: check `x-token` for health service too ([#359](https://github.com/rpcpool/yellowstone-grpc/pull/359))
|
||||
|
||||
## 2024-06-05
|
||||
|
||||
- yellowstone-grpc-geyser-1.14.4+solana.1.17.33
|
||||
|
|
|
@ -5210,7 +5210,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "yellowstone-grpc-geyser"
|
||||
version = "1.14.4+solana.1.17.33"
|
||||
version = "1.15.0+solana.1.17.33"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.21.7",
|
||||
|
|
|
@ -3,7 +3,7 @@ resolver = "2"
|
|||
members = [
|
||||
"examples/rust", # 1.13.0+solana.1.17.33
|
||||
"yellowstone-grpc-client", # 1.15.0+solana.1.17.33
|
||||
"yellowstone-grpc-geyser", # 1.14.4+solana.1.17.33
|
||||
"yellowstone-grpc-geyser", # 1.15.0+solana.1.17.33
|
||||
"yellowstone-grpc-proto", # 1.14.0+solana.1.17.33
|
||||
"yellowstone-grpc-tools", # 1.0.0-rc.11+solana.1.17.33
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "yellowstone-grpc-geyser"
|
||||
version = "1.14.4+solana.1.17.33"
|
||||
version = "1.15.0+solana.1.17.33"
|
||||
authors = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
description = "Yellowstone gRPC Geyser Plugin"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"channel_capacity": "100_000",
|
||||
"unary_concurrency_limit": 100,
|
||||
"unary_disabled": false,
|
||||
"x_token": null,
|
||||
"filters": {
|
||||
"accounts": {
|
||||
"max": 1,
|
||||
|
|
|
@ -34,7 +34,7 @@ use {
|
|||
},
|
||||
tokio_stream::wrappers::ReceiverStream,
|
||||
tonic::{
|
||||
service::{interceptor::InterceptedService, Interceptor},
|
||||
service::interceptor::interceptor,
|
||||
transport::{
|
||||
server::{Server, TcpIncoming},
|
||||
Identity, ServerTlsConfig,
|
||||
|
@ -790,7 +790,6 @@ impl GrpcService {
|
|||
for encoding in config.compression.send {
|
||||
service = service.send_compressed(encoding);
|
||||
}
|
||||
let service = InterceptedService::new(service, XTokenChecker::new(config.x_token));
|
||||
|
||||
// Run geyser message loop
|
||||
let (messages_tx, messages_rx) = mpsc::unbounded_channel();
|
||||
|
@ -819,6 +818,16 @@ impl GrpcService {
|
|||
|
||||
server_builder
|
||||
.http2_keepalive_interval(Some(Duration::from_secs(5)))
|
||||
.layer(interceptor(move |request: Request<()>| {
|
||||
if let Some(x_token) = &config.x_token {
|
||||
match request.metadata().get("x-token") {
|
||||
Some(token) if x_token == token => Ok(request),
|
||||
_ => Err(Status::unauthenticated("No valid auth token")),
|
||||
}
|
||||
} else {
|
||||
Ok(request)
|
||||
}
|
||||
}))
|
||||
.add_service(health_service)
|
||||
.add_service(service)
|
||||
.serve_with_incoming_shutdown(incoming, shutdown_grpc.notified())
|
||||
|
@ -1479,27 +1488,3 @@ impl Geyser for GrpcService {
|
|||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct XTokenChecker {
|
||||
x_token: Option<String>,
|
||||
}
|
||||
|
||||
impl XTokenChecker {
|
||||
const fn new(x_token: Option<String>) -> Self {
|
||||
Self { x_token }
|
||||
}
|
||||
}
|
||||
|
||||
impl Interceptor for XTokenChecker {
|
||||
fn call(&mut self, req: Request<()>) -> Result<Request<()>, Status> {
|
||||
if let Some(x_token) = &self.x_token {
|
||||
match req.metadata().get("x-token") {
|
||||
Some(t) if x_token == t => Ok(req),
|
||||
_ => Err(Status::unauthenticated("No valid auth token")),
|
||||
}
|
||||
} else {
|
||||
Ok(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue