From b9c111962fd1ee274fd74090c81154cfc8272bf8 Mon Sep 17 00:00:00 2001 From: Nikita Kalyanov <44959448+nikitakalyanov@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:23:51 +0300 Subject: [PATCH] pass JWT to management API (#5151) support authentication with JWT from env for proxy calls to mgmt API --- proxy/src/console/provider/neon.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/proxy/src/console/provider/neon.rs b/proxy/src/console/provider/neon.rs index 3f4cee6e34..3322d5a5be 100644 --- a/proxy/src/console/provider/neon.rs +++ b/proxy/src/console/provider/neon.rs @@ -16,12 +16,21 @@ use tracing::{error, info, info_span, warn, Instrument}; pub struct Api { endpoint: http::Endpoint, caches: &'static ApiCaches, + jwt: String, } impl Api { /// Construct an API object containing the auth parameters. pub fn new(endpoint: http::Endpoint, caches: &'static ApiCaches) -> Self { - Self { endpoint, caches } + let jwt: String = match std::env::var("NEON_PROXY_TO_CONTROLPLANE_TOKEN") { + Ok(v) => v, + Err(_) => "".to_string(), + }; + Self { + endpoint, + caches, + jwt, + } } pub fn url(&self) -> &str { @@ -39,6 +48,7 @@ impl Api { .endpoint .get("proxy_get_role_secret") .header("X-Request-ID", &request_id) + .header("Authorization", &self.jwt) .query(&[("session_id", extra.session_id)]) .query(&[ ("application_name", extra.application_name), @@ -83,6 +93,7 @@ impl Api { .endpoint .get("proxy_wake_compute") .header("X-Request-ID", &request_id) + .header("Authorization", &self.jwt) .query(&[("session_id", extra.session_id)]) .query(&[ ("application_name", extra.application_name),