Projects STRLCPY ebpfguard Commits d98f78bf
🤬
  • ■ ■ ■ ■ ■ ■
    README.md
     1 +[![Workflow Status](https://github.com/deepfence/guardity/workflows/build-test/badge.svg)](https://github.com/deepfence/guardity/actions?query=workflow)
     2 + 
    1 3  # guardity
    2 4   
    3 5  **Guardity** is a library for managing Linux security policies. It is based on
    skipped 61 lines
    65 67   
    66 68  Then run our example policy program with:
    67 69   
    68  -```rust
     70 +```bash
    69 71  $ RUST_LOG=info cargo xtask run --example file_open -- --path-to-deny /tmp/test
    70 72  ```
    71 73   
    skipped 9 lines
    81 83   
    82 84  The policy application should show logs like:
    83 85   
    84  -```rust
     86 +```bash
    85 87  [2023-04-22T20:51:01Z INFO file_open] file_open: pid=3001 subject=980333 path=9632
    86 88  [2023-04-22T20:51:03Z INFO file_open] file_open: pid=3010 subject=980298 path=9633
    87 89  ```
    skipped 26 lines
    114 116   
    115 117  eBPF programs inside guardity-ebpf directory are licensed under
    116 118  [GNU General Public License, version 2](https://github.com/deepfence/guardity/blob/main/guardity-ebpf/LICENSE).
    117  - 
  • ■ ■ ■ ■ ■ ■
    README.tpl
     1 +[![Workflow Status](https://github.com/deepfence/guardity/workflows/build-test/badge.svg)](https://github.com/deepfence/guardity/actions?query=workflow)
     2 + 
     3 +# {{crate}}
     4 + 
     5 +{{readme}}
     6 + 
     7 +## License
     8 + 
     9 +Guardity's userspace part is licensed under
     10 +[Apache License, version 2.0](https://github.com/deepfence/guardity/blob/main/LICENSE).
     11 + 
     12 +eBPF programs inside guardity-ebpf directory are licensed under
     13 +[GNU General Public License, version 2](https://github.com/deepfence/guardity/blob/main/guardity-ebpf/LICENSE).
     14 + 
  • ■ ■ ■ ■ ■
    guardity/src/lib.rs
    skipped 62 lines
    63 63  //!
    64 64  //! Then run our example policy program with:
    65 65  //!
    66  -//! ```
     66 +//! ```bash
    67 67  //! $ RUST_LOG=info cargo xtask run --example file_open -- --path-to-deny /tmp/test
    68 68  //! ```
    69 69  //!
    skipped 9 lines
    79 79  //!
    80 80  //! The policy application should show logs like:
    81 81  //!
    82  -//! ```
     82 +//! ```bash
    83 83  //! [2023-04-22T20:51:01Z INFO file_open] file_open: pid=3001 subject=980333 path=9632
    84 84  //! [2023-04-22T20:51:03Z INFO file_open] file_open: pid=3010 subject=980298 path=9633
    85 85  //! ```
    skipped 18 lines
    104 104  //! ```bash
    105 105  //! $ cargo xtask run --example cli -- policy add --path examples/cli/policy.yaml
    106 106  //! ```
    107  -//!
    108  -//! # License
    109  -//!
    110  -//! Guardity's userspace part is licensed under
    111  -//! [Apache License, version 2.0](https://github.com/deepfence/guardity/blob/main/LICENSE).
    112  -//!
    113  -//! eBPF programs inside guardity-ebpf directory are licensed under
    114  -//! [GNU General Public License, version 2](https://github.com/deepfence/guardity/blob/main/guardity-ebpf/LICENSE).
    115 107   
    116 108  use std::path::Path;
    117 109   
    skipped 20 lines
    138 130   ///
    139 131   /// # Example
    140 132   ///
    141  - /// ```rust
     133 + /// ```no_run
    142 134   /// use guardity::PolicyManager;
    143 135   /// use std::path::Path;
    144 136   ///
    skipped 212 lines
  • ■ ■ ■ ■ ■
    xtask/Cargo.toml
    skipped 5 lines
    6 6  [dependencies]
    7 7  anyhow = "1"
    8 8  aya-tool = { git = "https://github.com/aya-rs/aya", branch = "main" }
     9 +cargo-readme = "3.2.0"
    9 10  clap = { version = "4.1", features = ["derive"] }
    10 11   
  • ■ ■ ■ ■ ■ ■
    xtask/src/generate_readme.rs
     1 +use std::{env::current_dir, fs::File};
     2 + 
     3 +use clap::Parser;
     4 + 
     5 +#[derive(Debug, Parser)]
     6 +pub struct Options {
     7 + /// Do not overwrite the README.md file, just check whether it is up to date.
     8 + #[clap(long, default_value_t = false)]
     9 + check: bool,
     10 +}
     11 + 
     12 +pub fn generate_readme(opts: Options) -> anyhow::Result<()> {
     13 + let project_root = current_dir()?.join("guardity");
     14 + let mut source = File::open("guardity/src/lib.rs")?;
     15 + let mut template = File::open("README.tpl")?;
     16 + 
     17 + let content = cargo_readme::generate_readme(
     18 + project_root.as_path(),
     19 + &mut source,
     20 + Some(&mut template),
     21 + true,
     22 + true,
     23 + true,
     24 + true,
     25 + )
     26 + .map_err(|e| anyhow::anyhow!(e))?;
     27 + 
     28 + if opts.check {
     29 + let readme = std::fs::read_to_string("README.md")?;
     30 + if readme != content {
     31 + anyhow::bail!("README.md is not up to date");
     32 + }
     33 + } else {
     34 + std::fs::write("README.md", content)?;
     35 + }
     36 + 
     37 + Ok(())
     38 +}
     39 + 
  • ■ ■ ■ ■ ■ ■
    xtask/src/main.rs
    1 1  mod build_ebpf;
     2 +mod generate_readme;
    2 3  mod run;
    3 4   
    4 5  use std::process::exit;
    skipped 9 lines
    14 15  #[derive(Debug, Parser)]
    15 16  enum Command {
    16 17   BuildEbpf(build_ebpf::Options),
     18 + GenerateReadme(generate_readme::Options),
    17 19   Run(run::Options),
    18 20  }
    19 21   
    20 22  fn main() {
    21 23   let opts = Options::parse();
    22 24   
    23  - use Command::*;
    24 25   let ret = match opts.command {
    25  - BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
    26  - Run(opts) => run::run(opts),
     26 + Command::BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
     27 + Command::GenerateReadme(opts) => generate_readme::generate_readme(opts),
     28 + Command::Run(opts) => run::run(opts),
    27 29   };
    28 30   
    29 31   if let Err(e) = ret {
    skipped 5 lines
Please wait...
Page is in error, reload to recover