Skip to content

Commit

Permalink
WAYK-2566: Add a way to specify association_id when we create a token…
Browse files Browse the repository at this point in the history
… via powershell + fix GET /associations endpoint to return the error if error occurred
  • Loading branch information
fdubois1 committed Aug 3, 2021
1 parent 2beacd1 commit 5064fb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
12 changes: 7 additions & 5 deletions devolutions-gateway/src/http/controllers/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ impl JetController {

#[post("/association/<association_id>")]
#[guard(AccessGuard, init_expr = r#"JetTokenType::Association"#)]
async fn create_association(&self, req: Request) -> (StatusCode, ()) {
async fn create_association(&self, req: Request) -> StatusCode {
if let Some(JetAccessTokenClaims::Association(session_token)) = req.extensions().get::<JetAccessTokenClaims>() {
let association_id = match req
.captures()
.get("association_id")
.and_then(|id| Uuid::parse_str(id).ok())
{
Some(id) => id,
None => return (StatusCode::BAD_REQUEST, ()),
None => {
return StatusCode::BAD_REQUEST;
}
};

if session_token.jet_aid != association_id {
Expand All @@ -74,7 +76,7 @@ impl JetController {
session_token.jet_aid.to_string(),
association_id
);
return (StatusCode::FORBIDDEN, ());
return StatusCode::FORBIDDEN;
}

// Controller runs by Saphir via tokio 0.2 runtime, we need to use .compat()
Expand All @@ -88,9 +90,9 @@ impl JetController {
);
start_remove_association_future(self.jet_associations.clone(), association_id).await;

(StatusCode::OK, ())
StatusCode::OK
} else {
(StatusCode::UNAUTHORIZED, ())
StatusCode::UNAUTHORIZED
}
}

Expand Down
6 changes: 0 additions & 6 deletions jet-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ pub struct JetAssociationTokenClaims {
pub creds: Option<CredsClaims>,
}

impl JetAssociationTokenClaims {
pub fn get_jet_ap(&self) -> String {
self.jet_ap.clone()
}
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum JetConnectionMode {
Expand Down
12 changes: 9 additions & 3 deletions powershell/DevolutionsGateway/Public/DGateway.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,12 @@ function New-DGatewayToken {
[DateTime] $IssuedAt, # iat

# private association claims
[string] $DestinationHost, # dst_hst
[string] $AssociationId, # jet_aid
[ValidateSet('none', 'rdp', 'wayk', 'pwsh')]
[string] $ApplicationProtocol, # jet_ap
[ValidateSet('fwd', 'rdv')]
[string] $ConnectionMode, # jet_cm
[string] $DestinationHost, # dst_hst

#private scope claims
[string] $Scope, # scope
Expand Down Expand Up @@ -695,6 +696,8 @@ function New-DGatewayToken {
}
}

$Payload | Add-Member -MemberType NoteProperty -Name 'jet_ap' -Value $ApplicationProtocol

if (-Not $ConnectionMode) {
if ($DestinationHost) {
$ConnectionMode = 'fwd'
Expand All @@ -703,12 +706,15 @@ function New-DGatewayToken {
}
}

$Payload | Add-Member -MemberType NoteProperty -Name 'jet_ap' -Value $ApplicationProtocol
$Payload | Add-Member -MemberType NoteProperty -Name 'jet_cm' -Value $ConnectionMode

if ($AssociationId) {
$Payload | Add-Member -MemberType NoteProperty -Name 'jet_aid' -Value $AssociationId
}

if ($DestinationHost) {
$Payload | Add-Member -MemberType NoteProperty -Name 'dst_hst' -Value $DestinationHost
}
}
}


Expand Down

0 comments on commit 5064fb1

Please sign in to comment.