This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict which ports a workload is allowed to use
- Don't allow ports outside of a specific range. - Don't allow ports already in use by another running workload. - Prevent users listening on too many ports. - Fetch Enarx.toml from drawbridge to determine which ports it will use. Signed-off-by: Nicholas Farshidmehr <[email protected]>
- Loading branch information
1 parent
ae678ea
commit 278b8a9
Showing
8 changed files
with
308 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-FileCopyrightText: 2022 Profian Inc. <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
use crate::jobs::Job; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct Data { | ||
job: Option<Job>, | ||
} | ||
|
||
impl Data { | ||
pub fn new(job: Option<Job>) -> Self { | ||
Self { job } | ||
} | ||
|
||
pub fn job(&self) -> &Option<Job> { | ||
&self.job | ||
} | ||
|
||
pub fn job_mut(&mut self) -> Option<&mut Job> { | ||
self.job.as_mut() | ||
} | ||
|
||
pub async fn kill_job(&mut self) { | ||
if let Some(job) = &mut self.job { | ||
job.kill().await; | ||
} | ||
|
||
self.job = None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// SPDX-FileCopyrightText: 2022 Profian Inc. <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
use crate::ports; | ||
|
||
use std::process::Stdio; | ||
use std::str::FromStr; | ||
use std::sync::atomic::AtomicUsize; | ||
|
@@ -47,11 +52,16 @@ pub struct Job { | |
slug: Option<String>, | ||
wasm: Option<NamedTempFile>, | ||
toml: Option<NamedTempFile>, | ||
reserved_ports: Vec<u16>, | ||
} | ||
|
||
impl Drop for Job { | ||
fn drop(&mut self) { | ||
COUNT.fetch_sub(1, Ordering::SeqCst); | ||
|
||
if !self.reserved_ports.is_empty() { | ||
error!("a job was not cleaned up correctly"); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -66,6 +76,7 @@ impl Job { | |
slug: Option<String>, | ||
wasm: Option<NamedTempFile>, | ||
toml: Option<NamedTempFile>, | ||
reserved_ports: Vec<u16>, | ||
) -> Result<Self, Response> { | ||
let workload_type = WorkloadType::from_str(&workload_type).map_err(|e| { | ||
debug!("Failed to parse workload type: {e}"); | ||
|
@@ -122,6 +133,7 @@ impl Job { | |
slug, | ||
wasm, | ||
toml, | ||
reserved_ports, | ||
}) | ||
} | ||
|
||
|
@@ -131,4 +143,10 @@ impl Job { | |
Standard::Error => self.exec.stderr.as_mut().unwrap().read(buffer).await, | ||
} | ||
} | ||
|
||
pub async fn kill(&mut self) { | ||
let _ = self.exec.kill().await; | ||
ports::free(&self.reserved_ports).await; | ||
self.reserved_ports.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.