Skip to content

Commit

Permalink
feat(vine): add keycloak support
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Jul 16, 2024
1 parent fcd3321 commit 430d373
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions crates/vine/api/src/user_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum UserAuthResponse {
box_name: Option<String>,
box_quota_bindings: Vec<UserBoxQuotaBindingSpec<UserBoxQuotaSpec>>,
user: UserSpec,
user_name: String,
},
Error(UserAuthError),
}
Expand Down
3 changes: 2 additions & 1 deletion crates/vine/plugin/src/routes/desktop/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use actix_web::{
};
use ark_core::result::Result;
use kube::Client;
use tracing::{instrument, Level};
use tracing::{instrument, warn, Level};
use vine_api::user_session::{UserSessionCommandBatch, UserSessionMetadata};
use vine_rbac::auth::AuthUserSession;
use vine_session::batch::{BatchCommandArgs, BatchCommandUsers};
Expand All @@ -27,6 +27,7 @@ pub async fn post_exec_broadcast(
.await
.and_then(|metadata| metadata.assert_admin())
{
warn!("{error}");
return HttpResponse::from(Result::<()>::Err(error.to_string()));
};

Expand Down
7 changes: 5 additions & 2 deletions crates/vine/plugin/src/routes/desktop/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use actix_web::{
};
use ark_core::result::Result;
use kube::Client;
use tracing::{instrument, Level};
use tracing::{instrument, warn, Level};
use vine_api::user_session::{UserSessionCommand, UserSessionRef};
use vine_rbac::auth::{AuthUserSession, AuthUserSessionRef};
use vine_session::exec::SessionExecExt;
Expand All @@ -23,7 +23,10 @@ pub async fn post_exec(
.and_then(|session| session.try_into_ark_session())
{
Ok(session) => session,
Err(error) => return HttpResponse::from(Result::<()>::Err(error.to_string())),
Err(error) => {
warn!("{error}");
return HttpResponse::from(Result::<()>::Err(error.to_string()));
}
};

let result = session.exec_without_tty(kube, command).await.map(|_| ());
Expand Down
3 changes: 2 additions & 1 deletion crates/vine/plugin/src/routes/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use actix_web::{get, web::Data, HttpRequest, HttpResponse, Responder};
use ark_api::SessionRef;
use ark_core::result::Result;
use kube::Client;
use tracing::{instrument, Level};
use tracing::{instrument, warn, Level};
use vine_api::user_session::UserSessionMetadata;
use vine_rbac::auth::AuthUserSession;
use vine_session::exec::SessionExec;
Expand All @@ -15,6 +15,7 @@ pub async fn list(request: HttpRequest, kube: Data<Client>) -> impl Responder {
.await
.and_then(|metadata| metadata.assert_admin())
{
warn!("{error}");
return HttpResponse::from(Result::<()>::Err(error.to_string()));
};

Expand Down
28 changes: 17 additions & 11 deletions crates/vine/rbac/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,26 @@ impl AuthUserSession for UserSessionMetadata {
let user_name = get_user_name_with_timestamp(request, now)
.map_err(|error| anyhow!("failed to get user name: {error}"))?;

let role = get_user_role(client, &user_name, now)
.await
.map_err(|error| anyhow!("failed to get user role: {error}"))?;

execute_with_timestamp(client, &user_name, now)
.await
.and_then(|response| match response {
UserAuthResponse::Accept { box_name, user, .. } => Ok(Self {
match execute_with_timestamp(client, &user_name, now).await? {
UserAuthResponse::Accept {
box_name,
user,
user_name,
..
} => {
let role = get_user_role(client, &user_name, now)
.await
.map_err(|error| anyhow!("failed to get user role: {error}"))?;

Ok(Self {
box_name,
role,
user,
user_name,
}),
UserAuthResponse::Error(error) => bail!("failed to auth user: {error}"),
})
})
}
UserAuthResponse::Error(error) => bail!("failed to auth user: {error}"),
}
}
}

Expand Down Expand Up @@ -436,6 +441,7 @@ async fn execute_with_timestamp(
box_name,
box_quota_bindings,
user: user.spec,
user_name,
})
}

Expand Down

0 comments on commit 430d373

Please sign in to comment.