mirror of
https://github.com/neondatabase/neon.git
synced 2026-08-18 03:58:19 +00:00
0323bb5870
Now proxy binary accepts `--auth-backend` CLI option, which determines
auth scheme and cluster routing method. Following backends are currently
implemented:
* legacy
old method, when username ends with `@zenith` it uses md5 auth dbname as
the cluster name; otherwise, it sends a login link and waits for the console
to call back
* console
new SCRAM-based console API; uses SNI info to select the destination
cluster
* postgres
uses postgres to select auth secrets of existing roles. Useful for local
testing
* link
sends login link for all usernames
53 lines
1.7 KiB
Rust
53 lines
1.7 KiB
Rust
use crate::{compute, stream::PqStream};
|
|
use tokio::io::{AsyncRead, AsyncWrite};
|
|
use utils::pq_proto::{BeMessage as Be, BeParameterStatusMessage};
|
|
|
|
fn hello_message(redirect_uri: &str, session_id: &str) -> String {
|
|
format!(
|
|
concat![
|
|
"☀️ Welcome to Neon!\n",
|
|
"To proceed with database creation, open the following link:\n\n",
|
|
" {redirect_uri}{session_id}\n\n",
|
|
"It needs to be done once and we will send you '.pgpass' file,\n",
|
|
"which will allow you to access or create ",
|
|
"databases without opening your web browser."
|
|
],
|
|
redirect_uri = redirect_uri,
|
|
session_id = session_id,
|
|
)
|
|
}
|
|
|
|
pub fn new_psql_session_id() -> String {
|
|
hex::encode(rand::random::<[u8; 8]>())
|
|
}
|
|
|
|
pub async fn handle_user(
|
|
redirect_uri: &str,
|
|
client: &mut PqStream<impl AsyncRead + AsyncWrite + Unpin>,
|
|
) -> Result<compute::NodeInfo, crate::auth::AuthError> {
|
|
let psql_session_id = new_psql_session_id();
|
|
let greeting = hello_message(redirect_uri, &psql_session_id);
|
|
|
|
let db_info = crate::auth_backend::with_waiter(psql_session_id, |waiter| async {
|
|
// Give user a URL to spawn a new database
|
|
client
|
|
.write_message_noflush(&Be::AuthenticationOk)?
|
|
.write_message_noflush(&BeParameterStatusMessage::encoding())?
|
|
.write_message(&Be::NoticeResponse(&greeting))
|
|
.await?;
|
|
|
|
// Wait for web console response (see `mgmt`)
|
|
waiter
|
|
.await?
|
|
.map_err(crate::auth::AuthErrorImpl::auth_failed)
|
|
})
|
|
.await?;
|
|
|
|
client.write_message_noflush(&Be::NoticeResponse("Connecting to database."))?;
|
|
|
|
Ok(compute::NodeInfo {
|
|
db_info,
|
|
scram_keys: None,
|
|
})
|
|
}
|