project-polya / Design-Brochure

A repository to keep the development details of Project Polya
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

Server #1

Open SchrodingerZhu opened 4 years ago

SchrodingerZhu commented 4 years ago

The server of Project Polya is in charge of the data collection and job assignment. Basically, it has the following module:

SchrodingerZhu commented 4 years ago

we will not provide docker options now. see #2

SchrodingerZhu commented 4 years ago
{
  "systemd_nspawn": {
    "pid2": true,
    "env": [
      {
        "name": "TEXT",
        "value": "123"
      }
    ],
    "work_path": "/data",
    "syscall": [
      {
        "name": "mmap",
        "permit": true
      }
    ],
    "capacity": [],
    "capacity_drop": [],
    "no_new_privileges": false,
    "no_network": false,
    "limit": null,
    "extra_bind": [],
    "extra_bind_ro": [
      {
        "source": "testinput.txt",
        "target": "/tmp/testinput.txt"
      }
    ],
    "extra_overlay": [],
    "extra_overlay_ro": []
  },
  "firejail": {
    "timeout": {
      "hour": 0,
      "minute": 0,
      "second": 30
    },
    "syscall": [],
    "shell": "/bin/bash",
    "nice": null,
    "function": {
      "nou2f": false,
      "novideo": false,
      "no3d": false,
      "noautopulse": false,
      "nogroups": false,
      "nonewprivs": false,
      "nodvd": false,
      "nodbus": false,
      "nonet": false
    },
    "mac": null,
    "nodefault": false,
    "limit": {
      "mem_limit": 128,
      "nofile_limit": null,
      "filesize_limit": null,
      "process_limit": null,
      "sigpending_limit": null,
      "cpu_nums": null
    },
    "capacity": [],
    "capacity_drop": [],
    "with_profile": null
  },
  "notification": "the project may invoke X11",
  "max_grade": 100
}
SchrodingerZhu commented 4 years ago
use serde::*;
use std::path::PathBuf;
/// By invoke `setup` the client will first drag the image.
/// The image contains a `root.x86_64` together with other files.
/// ```
/// image.tar.lz4:
///   - root.x86_64
///   - otherfiles
/// ```
/// The image will then be untared into the `.local/tulip/image` direcotry.
/// Then it will download a config file.
///
///
#[derive(Debug, Serialize, Deserialize)]
pub struct EnvPair {
    pub name: String,
    pub value: String
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Syscall {
    pub name: String,
    pub permit: bool
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Limit {
    pub mem_limit: Option<usize>, // in MiB
    pub nofile_limit: Option<usize>,
    pub filesize_limit: Option<usize>,
    pub process_limit: Option<usize>,
    pub sigpending_limit: Option<usize>,
    pub cpu_nums: Option<usize>,

}

#[derive(Debug, Serialize, Deserialize)]
pub struct Binding {
    pub source: PathBuf,
    pub target: PathBuf
}

#[derive(Debug, Serialize, Deserialize)]
pub struct NSpawnConfig {
    pub pid2: bool,
    pub env: Vec<EnvPair>,
    pub work_path: Option<PathBuf>, // in the root
    pub syscall: Vec<Syscall>,
    pub capacity: Vec<String>,
    pub capacity_drop: Vec<String>,
    pub no_new_privileges: bool,
    pub no_network: bool,
    pub limit: Option<Limit>,
    pub extra_bind: Vec<Binding>, // relative path based on `.local/tulip/image`
    pub extra_bind_ro: Vec<Binding>, // relative path based on `.local/tulip/image`
    pub extra_overlay: Vec<Binding>, // relative path based on `.local/tulip/image`
    pub extra_overlay_ro: Vec<Binding>, // relative path based on `.local/tulip/image`
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Timeout {
    pub hour: u8,
    pub minute: u8,
    pub second: u8,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FuntionList {
    pub nou2f: bool,
    pub novideo: bool,
    pub no3d: bool,
    pub noautopulse: bool,
    pub nogroups: bool,
    pub nonewprivs: bool,
    pub nodvd: bool,
    pub nodbus: bool,
    pub nonet: bool
}

// deterministic-exit-code = true
#[derive(Debug, Serialize, Deserialize)]
pub struct FirejailConfig {
    pub timeout: Option<Timeout>,
    pub syscall: Vec<Syscall>,
    pub shell: Option<String>,
    pub nice: Option<usize>,
    pub function: FuntionList,
    pub mac: Option<String>,
    pub nodefault: bool,
    pub limit: Option<Limit>,
    pub capacity: Vec<String>,
    pub capacity_drop: Vec<String>,
    pub with_profile: Option<PathBuf> // relative path based on `.local/tulip/image`
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
    pub systemd_nspawn: NSpawnConfig,
    pub firejail: FirejailConfig,
    pub notification: String,
    pub max_grade: usize
}
SchrodingerZhu commented 4 years ago

config is adjusted. new template

{
  "systemd_nspawn": {
    "pid2": false,
    "env": [],
    "work_path": null,
    "syscall": [],
    "capacity": [],
    "capacity_drop": [],
    "no_new_privileges": false,
    "no_network": false,
    "limit": null,
    "shell": null
  },
  "firejail": {
    "timeout": null,
    "syscall": [],
    "shell": null,
    "nice": null,
    "function": {
      "nou2f": false,
      "novideo": false,
      "no3d": false,
      "noautopulse": false,
      "nogroups": false,
      "nonewprivs": false,
      "nodvd": false,
      "nodbus": false,
      "nonet": false
    },
    "mac": null,
    "dns": null,
    "nodefault": false,
    "limit": null,
    "capacity": [],
    "capacity_drop": [],
    "with_profile": null,
    "has_x": true
  },
  "notification": "",
  "max_grade": 0,
  "stdin": null,
  "extra_bind": [],
  "extra_bind_ro": [],
  "extra_overlay": [
    {
      "source": "test",
      "target": "test"
    }
  ],
  "extra_overlay_ro": []
}
SchrodingerZhu commented 4 years ago

wintersweet