1
0
Fork 0

Add token and identifier

This commit is contained in:
Florian RICHER 2023-01-31 17:35:21 +01:00
parent 115855ac75
commit f8a03bc18a
No known key found for this signature in database
GPG key ID: 6BF27BF8A1E71623
5 changed files with 27 additions and 23 deletions

View file

@ -8,4 +8,4 @@
- `docker build . -t gateway` - `docker build . -t gateway`
- `docker run -p 22:22 gateway` - `docker run -p 22:22 gateway`
- `ssh test@localhost "{\"command\": \"/bin/bash\", \"envs\": {}, \"args\": []}"` - `ssh test@localhost "{\"identifier\": \"project_env\", \"token\": \"token\", \"command\": \"/bin/bash\", \"envs\": {}, \"args\": []}"`

View file

@ -13,8 +13,9 @@ message AuthorizeRequest {
// identifier of the project // identifier of the project
string identifier = 1; string identifier = 1;
// ssh_keys from ssh agent // ssh_keys from ssh agent
string public_ssh_keys = 2; string token = 2;
// command? // command like /bin/bash
string command = 3;
} }
enum AuthorizationStatus { enum AuthorizationStatus {
@ -26,7 +27,6 @@ message AuthorizeResponse {
AuthorizationStatus status = 1; AuthorizationStatus status = 1;
string error_message = 2; string error_message = 2;
string session_uuid = 3; string session_uuid = 3;
string log_file = 4;
} }
message TerminateRequest { message TerminateRequest {

View file

@ -2,7 +2,7 @@
pub mod client; pub mod client;
use libcommand::internal::{AuthorizeRequest, AuthorizeResponse}; use libcommand::internal::{AuthorizationStatus, AuthorizeRequest, AuthorizeResponse};
use tonic::Response; use tonic::Response;
#[cfg(unix)] #[cfg(unix)]
@ -11,23 +11,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let arg = std::env::args() let arg = std::env::args()
.skip(1) .skip(1)
.last().unwrap(); .last().unwrap();
let mut command : std::process::Command = serde_json::from_str::<libcommand::Command>(&arg) let command_arg : libcommand::Command = serde_json::from_str::<libcommand::Command>(&arg)
.unwrap() .unwrap();
.into();
let mut client = client::connect().await?; let mut client = client::connect().await?;
let request = tonic::Request::new(AuthorizeRequest { let request = tonic::Request::new(AuthorizeRequest {
identifier: "Tonic".into(), identifier: command_arg.identifier.clone(),
public_ssh_keys: "Tonic".into(), token: command_arg.token.clone(),
command: command_arg.command.clone()
}); });
let response : Response<AuthorizeResponse> = client.authorize(request).await?; let response : Response<AuthorizeResponse> = client.authorize(request).await?;
println!("RESPONSE={:?}", response); if AuthorizationStatus::from_i32(response.get_ref().status) == Some(AuthorizationStatus::Authorized) {
let mut command : std::process::Command = command_arg.into();
let mut child = command.spawn().unwrap(); let mut child = command.spawn().unwrap();
child.wait().unwrap(); child.wait().unwrap();
} else {
eprintln!("Permission denied");
}
Ok(()) Ok(())
} }

View file

@ -6,7 +6,7 @@ use tonic::{Request, Response, Status};
use libcommand::internal::{ use libcommand::internal::{
unix_server::Unix, unix_server::Unix,
AuthorizeRequest, AuthorizeResponse, TerminateRequest, TerminateResponse AuthorizeRequest, AuthorizeResponse, AuthorizationStatus, TerminateRequest, TerminateResponse, TerminateStatus
}; };
#[derive(Default)] #[derive(Default)]
@ -24,10 +24,9 @@ impl Unix for DaemonServer {
println!("Got a request {:?} with info {:?}", request, conn_info); println!("Got a request {:?} with info {:?}", request, conn_info);
} }
let reply = libcommand::internal::AuthorizeResponse { let reply = AuthorizeResponse {
status: libcommand::internal::AuthorizationStatus::Authorized.into(), status: AuthorizationStatus::Authorized.into(),
error_message: "".into(), error_message: "".into(),
log_file: "".into(),
session_uuid: "".into() session_uuid: "".into()
}; };
Ok(Response::new(reply)) Ok(Response::new(reply))
@ -43,8 +42,8 @@ impl Unix for DaemonServer {
println!("Got a request {:?} with info {:?}", request, conn_info); println!("Got a request {:?} with info {:?}", request, conn_info);
} }
let reply = libcommand::internal::TerminateResponse { let reply = TerminateResponse {
status: libcommand::internal::TerminateStatus::Ok.into(), status: TerminateStatus::Ok.into(),
error_message: "".into(), error_message: "".into(),
}; };
Ok(Response::new(reply)) Ok(Response::new(reply))

View file

@ -9,9 +9,11 @@ pub mod internal {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Command { pub struct Command {
command: String, pub identifier: String,
envs: HashMap<String, String>, pub token: String,
args: Vec<String> pub command: String,
pub envs: HashMap<String, String>,
pub args: Vec<String>
} }
impl Into<std::process::Command> for Command { impl Into<std::process::Command> for Command {