commit 820ae68a15081e859ebcbecbb97da54115789927
parent c83014e724dc454e611e270b9f4054fdbd00472f
Author: Antoine A <>
Date: Tue, 24 Nov 2026 13:21:11 +0100
common: wire gateway endpoints disabled by default
Diffstat:
12 files changed, 150 insertions(+), 47 deletions(-)
diff --git a/adapters/taler-cyclos/src/api.rs b/adapters/taler-cyclos/src/api.rs
@@ -433,7 +433,7 @@ mod test {
use taler_api::{
Serve,
api::TalerRouter as _,
- config::{ApiCfg, AuthCfg},
+ config::{ApiCfg, AuthCfg, WireGatewayCfg},
db::TypeHelper as _,
subject::{IncomingKey, OutgoingSubject},
};
@@ -483,8 +483,9 @@ mod test {
root: CompactString::const_new("localhost"),
currency: Currency::TEST,
serve: Serve::Systemd,
- wire_gateway: Some(ApiCfg {
+ wire_gateway: Some(WireGatewayCfg {
auth: AuthCfg::None,
+ enable_admin_endpoints: true,
}),
revenue: Some(ApiCfg {
auth: AuthCfg::None,
diff --git a/adapters/taler-cyclos/src/config.rs b/adapters/taler-cyclos/src/config.rs
@@ -19,7 +19,7 @@ use std::time::Duration;
use compact_str::{CompactString, format_compact};
use taler_api::{
Serve,
- config::{ApiCfg, DbCfg},
+ config::{ApiCfg, DbCfg, WireGatewayCfg},
};
use taler_common::{
config::{CfgErr, Config},
@@ -102,7 +102,7 @@ pub struct ServeCfg {
pub currency: Currency,
pub root: CompactString,
pub serve: Serve,
- pub wire_gateway: Option<ApiCfg>,
+ pub wire_gateway: Option<WireGatewayCfg>,
pub revenue: Option<ApiCfg>,
pub observability: Option<ApiCfg>,
}
@@ -116,7 +116,7 @@ impl ServeCfg {
let serve = Serve::parse(&s)?;
- let wire_gateway = ApiCfg::parse(cfg.section("cyclos-httpd-wire-gateway-api"))?;
+ let wire_gateway = WireGatewayCfg::parse(cfg.section("cyclos-httpd-wire-gateway-api"))?;
let revenue = ApiCfg::parse(cfg.section("cyclos-httpd-revenue-api"))?;
let observability = ApiCfg::parse(cfg.section("cyclos-httpd-observability-api"))?;
diff --git a/adapters/taler-cyclos/src/lib.rs b/adapters/taler-cyclos/src/lib.rs
@@ -53,7 +53,7 @@ async fn build_router(cfg: &ServeCfg, pool: PgPool) -> Router {
let mut router = Router::new();
if let Some(cfg) = &cfg.wire_gateway {
router = router
- .wire_gateway(api.clone(), cfg.auth.method())
+ .wire_gateway(api.clone(), cfg)
.prepared_transfer(api.clone());
}
if let Some(cfg) = &cfg.revenue {
diff --git a/adapters/taler-magnet-bank/src/api.rs b/adapters/taler-magnet-bank/src/api.rs
@@ -412,7 +412,7 @@ mod test {
use taler_api::{
Serve,
api::TalerRouter as _,
- config::{ApiCfg, AuthCfg},
+ config::{ApiCfg, AuthCfg, WireGatewayCfg},
db::TypeHelper as _,
subject::{IncomingKey, OutgoingSubject},
};
@@ -460,8 +460,9 @@ mod test {
let cfg = ServeCfg {
payto: PAYTO.clone(),
serve: Serve::Systemd,
- wire_gateway: Some(ApiCfg {
+ wire_gateway: Some(WireGatewayCfg {
auth: AuthCfg::None,
+ enable_admin_endpoints: true,
}),
revenue: Some(ApiCfg {
auth: AuthCfg::None,
diff --git a/adapters/taler-magnet-bank/src/config.rs b/adapters/taler-magnet-bank/src/config.rs
@@ -19,7 +19,7 @@ use std::time::Duration;
use jiff::civil::Date;
use taler_api::{
Serve,
- config::{ApiCfg, DbCfg},
+ config::{ApiCfg, DbCfg, WireGatewayCfg},
};
use taler_common::{
config::{CfgErr, Config},
@@ -45,7 +45,7 @@ pub fn parse_account_payto(cfg: &Config) -> Result<FullHuPayto, CfgErr> {
pub struct ServeCfg {
pub payto: FullHuPayto,
pub serve: Serve,
- pub wire_gateway: Option<ApiCfg>,
+ pub wire_gateway: Option<WireGatewayCfg>,
pub revenue: Option<ApiCfg>,
pub observability: Option<ApiCfg>,
}
@@ -58,7 +58,8 @@ impl ServeCfg {
let serve = Serve::parse(&s)?;
- let wire_gateway = ApiCfg::parse(cfg.section("magnet-bank-httpd-wire-gateway-api"))?;
+ let wire_gateway =
+ WireGatewayCfg::parse(cfg.section("magnet-bank-httpd-wire-gateway-api"))?;
let revenue = ApiCfg::parse(cfg.section("magnet-bank-httpd-revenue-api"))?;
let observability = ApiCfg::parse(cfg.section("cyclos-httpd-observability-api"))?;
diff --git a/adapters/taler-magnet-bank/src/lib.rs b/adapters/taler-magnet-bank/src/lib.rs
@@ -51,7 +51,7 @@ async fn build_router(cfg: &ServeCfg, pool: PgPool) -> Router {
let mut router = Router::new();
if let Some(cfg) = &cfg.wire_gateway {
router = router
- .wire_gateway(api.clone(), cfg.auth.method())
+ .wire_gateway(api.clone(), cfg)
.prepared_transfer(api.clone());
}
if let Some(cfg) = &cfg.revenue {
diff --git a/adapters/taler-wise/src/api.rs b/adapters/taler-wise/src/api.rs
@@ -40,7 +40,7 @@ use taler_api::{
TalerApi, TalerRouter as _, observability::Observability, prepared::PreparedTransfer,
revenue::Revenue, wire::WireGateway,
},
- config::ApiCfg,
+ config::{ApiCfg, WireGatewayCfg},
error::{ApiResult, failure_code, not_implemented},
subject::{IncomingKey, fmt_in_subject},
};
@@ -78,7 +78,7 @@ pub async fn start(
balances: Vec<WiseBalance>,
key: ParsedPublicKey,
profile_id: u64,
- wire_gateway: &Option<ApiCfg>,
+ wire_gateway: &Option<WireGatewayCfg>,
revenue: &Option<ApiCfg>,
observability: &Option<ApiCfg>,
) -> Router {
@@ -122,7 +122,7 @@ pub async fn start(
let mut balance_router = Router::new();
if let Some(cfg) = wire_gateway {
balance_router = balance_router
- .wire_gateway(api.clone(), cfg.auth.method())
+ .wire_gateway(api.clone(), cfg)
.prepared_transfer(api.clone());
}
if let Some(cfg) = revenue {
@@ -508,7 +508,7 @@ mod test {
use sqlx::PgPool;
use taler_api::{
api::TalerRouter as _,
- config::{ApiCfg, AuthCfg},
+ config::{ApiCfg, AuthCfg, WireGatewayCfg},
subject::IncomingKey,
};
use taler_common::{
@@ -563,8 +563,9 @@ mod test {
balances,
ApiEnv::sandbox.public_key(),
7,
- &Some(ApiCfg {
+ &Some(WireGatewayCfg {
auth: AuthCfg::None,
+ enable_admin_endpoints: true,
}),
&Some(ApiCfg {
auth: AuthCfg::None,
diff --git a/adapters/taler-wise/src/config.rs b/adapters/taler-wise/src/config.rs
@@ -21,7 +21,7 @@ use compact_str::CompactString;
use http::HeaderValue;
use taler_api::{
Serve,
- config::{ApiCfg, DbCfg},
+ config::{ApiCfg, DbCfg, WireGatewayCfg},
};
use taler_common::{
config::{CfgErr, Config, Section},
@@ -185,7 +185,7 @@ pub struct ServeCfg {
pub name: CompactString,
pub serve: Serve,
pub balances: Vec<WiseBalance>,
- pub wire_gateway: Option<ApiCfg>,
+ pub wire_gateway: Option<WireGatewayCfg>,
pub revenue: Option<ApiCfg>,
pub observability: Option<ApiCfg>,
}
@@ -198,7 +198,7 @@ impl ServeCfg {
profile_id: s.number("PROFILE_ID").require()?,
name: s.cstr("NAME").require()?,
serve: Serve::parse(&cfg.section("wise-httpd"))?,
- wire_gateway: ApiCfg::parse(cfg.section("wise-httpd-wire-gateway-api"))?,
+ wire_gateway: WireGatewayCfg::parse(cfg.section("wise-httpd-wire-gateway-api"))?,
revenue: ApiCfg::parse(cfg.section("wise-httpd-revenue-api"))?,
observability: ApiCfg::parse(cfg.section("wise-httpd-observability-api"))?,
balances: balances(cfg)?,
diff --git a/common/taler-api/src/api.rs b/common/taler-api/src/api.rs
@@ -44,6 +44,7 @@ use crate::{
Listener, Serve,
api::{observability::Observability, prepared::PreparedTransfer},
auth::{AuthMethod, AuthMiddlewareState},
+ config::WireGatewayCfg,
error::{ApiResult, LoggedError, failure, failure_code},
};
@@ -92,7 +93,7 @@ impl<S: Send + Clone + Sync + 'static> RouterUtils for Router<S> {
}
pub trait TalerRouter {
- fn wire_gateway<T: WireGateway>(self, api: Arc<T>, auth: AuthMethod) -> Self;
+ fn wire_gateway<T: WireGateway>(self, api: Arc<T>, cfg: &WireGatewayCfg) -> Self;
fn prepared_transfer<T: PreparedTransfer>(self, api: Arc<T>) -> Self;
fn revenue<T: Revenue>(self, api: Arc<T>, auth: AuthMethod) -> Self;
fn observability<T: Observability>(self, api: Arc<T>, auth: AuthMethod) -> Self;
@@ -105,8 +106,8 @@ pub trait TalerRouter {
}
impl TalerRouter for Router {
- fn wire_gateway<T: WireGateway>(self, api: Arc<T>, auth: AuthMethod) -> Self {
- self.nest("/taler-wire-gateway", wire::router(api, auth))
+ fn wire_gateway<T: WireGateway>(self, api: Arc<T>, cfg: &WireGatewayCfg) -> Self {
+ self.nest("/taler-wire-gateway", wire::router(api, cfg))
}
fn prepared_transfer<T: PreparedTransfer>(self, api: Arc<T>) -> Self {
diff --git a/common/taler-api/src/api/wire.rs b/common/taler-api/src/api/wire.rs
@@ -40,9 +40,9 @@ use taler_common::{
use super::TalerApi;
use crate::{
api::{RouterUtils as _, Validation, check_currency},
- auth::AuthMethod,
+ config::WireGatewayCfg,
constants::WIRE_GATEWAY_API_VERSION,
- error::{ApiResult, bad_request, failure_code, failure_status},
+ error::{ApiResult, bad_request, failure, failure_code, failure_status},
extract::{Path, Query, Req},
};
@@ -134,7 +134,20 @@ impl Validation for AddMappedRequest {
}
}
-pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router {
+pub fn router<I: WireGateway>(state: Arc<I>, cfg: &WireGatewayCfg) -> Router {
+ let admin_route = |handler| {
+ if cfg.enable_admin_endpoints {
+ handler
+ } else {
+ post(async || {
+ failure(
+ ErrorCode::GENERIC_FEATURE_NOT_IMPLEMENTED,
+ "Wire Gateway admin endpoints are disabled (ENABLE_ADMIN_ENDPOINTS = NO).",
+ )
+ })
+ }
+ };
+
Router::new()
.route(
"/transfer",
@@ -197,45 +210,45 @@ pub fn router<I: WireGateway>(state: Arc<I>, auth: AuthMethod) -> Router {
),
)
.route(
+ "/account/check",
+ get(
+ async |State(state): State<Arc<I>>, Query(params): Query<AccountParams>| match state
+ .account_check(params)
+ .await?
+ {
+ Some(it) => Ok(Json(it)),
+ None => Err(failure_code(ErrorCode::BANK_UNKNOWN_ACCOUNT)),
+ },
+ ),
+ )
+ .route(
"/admin/add-incoming",
- post(
+ admin_route(post(
async |State(state): State<Arc<I>>, Req(req): Req<AddIncomingRequest>| {
req.check(&state.currency())?;
ApiResult::Ok(Json(state.add_incoming_reserve(req).await?))
},
- ),
+ )),
)
.route(
"/admin/add-kycauth",
- post(
+ admin_route(post(
async |State(state): State<Arc<I>>, Req(req): Req<AddKycauthRequest>| {
req.check(&state.currency())?;
ApiResult::Ok(Json(state.add_incoming_kyc(req).await?))
},
- ),
+ )),
)
.route(
"/admin/add-mapped",
- post(
+ admin_route(post(
async |State(state): State<Arc<I>>, Req(req): Req<AddMappedRequest>| {
req.check(&state.currency())?;
ApiResult::Ok(Json(state.add_incoming_mapped(req).await?))
},
- ),
- )
- .route(
- "/account/check",
- get(
- async |State(state): State<Arc<I>>, Query(params): Query<AccountParams>| match state
- .account_check(params)
- .await?
- {
- Some(it) => Ok(Json(it)),
- None => Err(failure_code(ErrorCode::BANK_UNKNOWN_ACCOUNT)),
- },
- ),
+ )),
)
- .auth(auth, "taler-wire-gateway")
+ .auth(cfg.auth.method(), "taler-wire-gateway")
.route(
"/config",
get(async |State(state): State<Arc<I>>| {
diff --git a/common/taler-api/src/config.rs b/common/taler-api/src/config.rs
@@ -96,6 +96,25 @@ impl ApiCfg {
}
}
+/// Wire Gateway API configuration
+pub struct WireGatewayCfg {
+ pub auth: AuthCfg,
+ pub enable_admin_endpoints: bool,
+}
+
+impl WireGatewayCfg {
+ pub fn parse(s: Section) -> Result<Option<Self>, CfgErr> {
+ let enable_admin_endpoints = s.boolean("ENABLE_ADMIN_ENDPOINTS");
+ let Some(ApiCfg { auth }) = ApiCfg::parse(s)? else {
+ return Ok(None);
+ };
+ Ok(Some(Self {
+ auth,
+ enable_admin_endpoints: enable_admin_endpoints.default(false)?,
+ }))
+ }
+}
+
impl Serve {
pub fn parse(s: &Section) -> Result<Self, CfgErr> {
map_config!(s, "serve", "SERVE",
diff --git a/common/taler-api/src/test.rs b/common/taler-api/src/test.rs
@@ -27,11 +27,12 @@ use serde_json::json;
use sqlx::{PgPool, Row as _, postgres::PgRow};
use taler_common::{
api::{
- HashCode, ShortHashCode,
+ ErrorDetail, HashCode, ShortHashCode,
prepared::PreparedTransferConfig,
revenue::RevenueConfig,
wire::{TransferRequest, TransferResponse, TransferState, WireConfig},
},
+ config::Config,
db::IncomingType,
error_code::ErrorCode,
types::{
@@ -55,6 +56,7 @@ use tokio::sync::watch::Sender;
use crate::{
api::TalerRouter,
auth::AuthMethod,
+ config::{AuthCfg, WireGatewayCfg},
constants::SAFE_BODY_LENGTH,
db::TypeHelper as _,
test::{api::TestApi, db::notification_listener},
@@ -88,7 +90,13 @@ fn test_api(pool: PgPool, currency: Currency) -> Router {
));
let state = Arc::new(wg);
Router::new()
- .wire_gateway(state.clone(), AuthMethod::None)
+ .wire_gateway(
+ state.clone(),
+ &WireGatewayCfg {
+ auth: AuthCfg::None,
+ enable_admin_endpoints: true,
+ },
+ )
.prepared_transfer(state.clone())
.revenue(state.clone(), AuthMethod::None)
.observability(state, AuthMethod::None)
@@ -99,6 +107,64 @@ async fn setup(db: &PgPool) -> Router {
}
#[tokio::test]
+async fn wire_gateway_admin_endpoints_are_opt_in() {
+ let api = Arc::new(TestApi::new(
+ "EUR".parse().unwrap(),
+ PgPool::connect_lazy("postgres:///unused").unwrap(),
+ Sender::new(0),
+ Sender::new(0),
+ PAYTO.clone(),
+ ));
+ for (option, expected) in [
+ ("", StatusCode::NOT_IMPLEMENTED),
+ ("ENABLE_ADMIN_ENDPOINTS = NO", StatusCode::NOT_IMPLEMENTED),
+ (
+ "# Whether to enable the admin operations\nENABLE_ADMIN_ENDPOINTS = YES",
+ StatusCode::BAD_REQUEST,
+ ),
+ ] {
+ let config = Config::from_mem(&format!(
+ "[wire-gateway]\nENABLED = YES\nAUTH_METHOD = bearer\nTOKEN = test\n{option}\n"
+ ))
+ .unwrap();
+ let cfg = WireGatewayCfg::parse(config.section("wire-gateway"))
+ .unwrap()
+ .unwrap();
+ let server = Router::new()
+ .wire_gateway(api.clone(), &cfg)
+ .finalize()
+ .prefix("/taler-wire-gateway");
+
+ server.get("/config").await.assert_ok();
+ server
+ .post("/admin/unknown")
+ .await
+ .assert_error(ErrorCode::GENERIC_ENDPOINT_UNKNOWN);
+ for path in [
+ "/admin/add-incoming",
+ "/admin/add-kycauth",
+ "/admin/add-mapped",
+ ] {
+ server
+ .post(path)
+ .await
+ .assert_error(ErrorCode::GENERIC_UNAUTHORIZED);
+ let response = server
+ .post(path)
+ .header(header::AUTHORIZATION, "Bearer test")
+ .json(json!({}))
+ .await;
+ response.assert_status(expected);
+ if expected == StatusCode::NOT_IMPLEMENTED {
+ response.assert_error(ErrorCode::GENERIC_FEATURE_NOT_IMPLEMENTED);
+ let error: ErrorDetail = response.json_parse();
+ assert!(error.hint.unwrap().contains("ENABLE_ADMIN_ENDPOINTS = NO"));
+ }
+ }
+ }
+}
+
+#[tokio::test]
async fn options_requests() {
use axum::{
body::Body,