-
Notifications
You must be signed in to change notification settings - Fork 46
feat: Configuration for disabling authorization token passthrough #336
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### feat: Configuration for disabling authorization token passthrough - @swcollard PR #336 | ||
|
|
||
| A new optional new MCP Server configuration parameter, `transport.auth.disable_auth_token_passthrough`, which is `false` by default, that when true, will no longer pass through validated Auth tokens to the GraphQL API. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,8 @@ async fn main() -> anyhow::Result<()> { | |
| .then(|| config.graphos.graph_ref()) | ||
| .transpose()?; | ||
|
|
||
| let transport = config.transport.clone(); | ||
|
|
||
| Ok(Server::builder() | ||
| .transport(config.transport) | ||
| .schema_source(schema_source) | ||
|
|
@@ -125,6 +127,15 @@ async fn main() -> anyhow::Result<()> { | |
| .mutation_mode(config.overrides.mutation_mode) | ||
| .disable_type_description(config.overrides.disable_type_description) | ||
| .disable_schema_description(config.overrides.disable_schema_description) | ||
| .disable_auth_token_passthrough(match transport { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we shorten this a bit via: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't quite get this syntax working? I think the match needs the enum name so it can pull the auth values from the struct. And the compiler isn't smart enough to pull it as an 'else' case? |
||
| apollo_mcp_server::server::Transport::Stdio => false, | ||
| apollo_mcp_server::server::Transport::SSE { auth, .. } => auth | ||
| .map(|a| a.disable_auth_token_passthrough) | ||
| .unwrap_or(false), | ||
| apollo_mcp_server::server::Transport::StreamableHttp { auth, .. } => auth | ||
| .map(|a| a.disable_auth_token_passthrough) | ||
| .unwrap_or(false), | ||
| }) | ||
| .custom_scalar_map( | ||
| config | ||
| .custom_scalars | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ pub(super) struct Running { | |
| pub(super) mutation_mode: MutationMode, | ||
| pub(super) disable_type_description: bool, | ||
| pub(super) disable_schema_description: bool, | ||
| pub(super) disable_auth_token_passthrough: bool, | ||
| pub(super) health_check: Option<HealthCheck>, | ||
| } | ||
|
|
||
|
|
@@ -211,7 +212,9 @@ impl ServerHandler for Running { | |
| let mut headers = self.headers.clone(); | ||
| if let Some(axum_parts) = context.extensions.get::<axum::http::request::Parts>() { | ||
| // Optionally extract the validated token and propagate it to upstream servers if present | ||
| if let Some(token) = axum_parts.extensions.get::<ValidToken>() { | ||
| if !self.disable_auth_token_passthrough | ||
| && let Some(token) = axum_parts.extensions.get::<ValidToken>() | ||
| { | ||
|
Comment on lines
+215
to
+217
|
||
| headers.typed_insert(token.deref().clone()); | ||
| } | ||
|
|
||
|
|
@@ -242,7 +245,9 @@ impl ServerHandler for Running { | |
| let mut headers = self.headers.clone(); | ||
| if let Some(axum_parts) = context.extensions.get::<axum::http::request::Parts>() { | ||
| // Optionally extract the validated token and propagate it to upstream servers if present | ||
| if let Some(token) = axum_parts.extensions.get::<ValidToken>() { | ||
| if !self.disable_auth_token_passthrough | ||
| && let Some(token) = axum_parts.extensions.get::<ValidToken>() | ||
| { | ||
| headers.typed_insert(token.deref().clone()); | ||
| } | ||
|
|
||
|
|
@@ -355,6 +360,7 @@ mod tests { | |
| mutation_mode: MutationMode::None, | ||
| disable_type_description: false, | ||
| disable_schema_description: false, | ||
| disable_auth_token_passthrough: false, | ||
| health_check: None, | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
config.transportis being cloned unnecessarily. Since it's moved into the builder on line 115, you can use the clonedtransportvariable instead of cloning again.