Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Conversation

@cody-wang-cb
Copy link

@cody-wang-cb cody-wang-cb commented May 7, 2025

Add authentication feature such that connecting to the proxy requires an API key if authentication is enabled.

Tested on devnet

@cody-wang-cb cody-wang-cb requested a review from danyalprout May 7, 2025 21:01
Comment on lines +164 to +175
let key_value = match api_key.clone() {
Some(key) => {
// For security, only use the first 8 chars of the API key in metrics
if key.len() > 8 {
format!("{}...", &key[0..8])
} else {
key
}
}
None => "none".to_string(),
};
counter!("websocket_proxy.connections_by_api_key", "key" => key_value).increment(1);
Copy link
Collaborator

@danyalprout danyalprout May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this I wonder if we should take in api keys in the format:

<application>:<key>,<application2>:<key2>

Then we can log out the application info, it'll make it much easier to debug issues that way too (and no need to partially leak the key)

Comment on lines +68 to +71
Router::new()
.route("/healthz", get(healthz_handler))
.route("/ws", any(websocket_handler))
.with_state(server_state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could move three of these four lines outside of conditional, and add the route for ws for the conditional.

@jowparks
Copy link
Collaborator

I tested in sepolia-alpha using the API keys from config service, did you manually apply and update to the keys? It doesn't work for me:

❯ websocat wss://sepolia-alpha-cburi/ws -v
[INFO  websocat::lints] Auto-inserting the line mode
[INFO  websocat::stdio_threaded_peer] get_stdio_peer (threaded)
[INFO  websocat::ws_client_peer] get_ws_client_peer
[INFO  websocat::net_peer] Connected to TCP ....:443
websocat: WebSocketError: WebSocketError: Received unexpected status code (404 Not Found)
websocat: error running


❯ websocat wss://sepolia-alpha-cburi/ws/{apikey} -v
[INFO  websocat::lints] Auto-inserting the line mode
[INFO  websocat::stdio_threaded_peer] get_stdio_peer (threaded)
[INFO  websocat::ws_client_peer] get_ws_client_peer
[INFO  websocat::net_peer] Connected to TCP ....:443
websocat: WebSocketError: WebSocketError: Received unexpected status code (401 Unauthorized)
websocat: error running

Comment on lines +121 to +122
#[arg(long, env, value_delimiter = ',', help = "API keys to allow")]
api_keys: Vec<String>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration will actually parse the empty --api-keys flag or API_KEYS= env var into a Vec containing a single empty string.
You'll probably want to filter out all empty strings after applying the parser/delimiter, like so:

let api_keys = args.api_keys.into_iter().filter(|key| !key.is_empty()).collect()

@danyalprout
Copy link
Collaborator

I'll fix this bug and move this PR to the flashbots rollup boost org

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants