14 Commits

Author SHA1 Message Date
brotoskyj 740e2924fa Added documentation to .pyi file for history_logging function
Build and Release / build-linux (push) Failing after 2s
Build and Release / build-windows (push) Failing after 3s
Build and Release / release (push) Has been skipped
2025-10-30 16:33:17 -04:00
brotoskyj e7702c5fdd Successful Implementation of history_logging
Build and Release / build-linux (push) Failing after 6s
Build and Release / build-windows (push) Failing after 5s
Build and Release / release (push) Has been skipped
2025-10-30 16:23:10 -04:00
brotoskyj 6285b574a6 Added info
Build and Release / build-linux (push) Failing after 9s
Build and Release / build-windows (push) Failing after 9s
Build and Release / release (push) Has been skipped
2025-10-20 17:16:14 -04:00
brotoskyj 99501fcc9d Reintroduced actions
Build and Release / build-linux (push) Failing after 3s
Build and Release / build-windows (push) Failing after 4s
Build and Release / release (push) Has been skipped
2025-10-20 17:13:31 -04:00
brotoskyj cd70a0219a Added Break System Packages
Build and Release / build-windows (push) Failing after 3s
Build and Release / build-linux (push) Failing after 46s
Build and Release / release (push) Has been skipped
2025-10-20 17:10:09 -04:00
brotoskyj d328a91a29 Removed SUDO
Build and Release / build-windows (push) Failing after 3s
Build and Release / build-linux (push) Failing after 47s
Build and Release / release (push) Has been skipped
2025-10-20 17:08:21 -04:00
brotoskyj f38d742019 Added curl
Build and Release / build-linux (push) Failing after 2s
Build and Release / build-windows (push) Failing after 3s
Build and Release / release (push) Has been skipped
2025-10-20 17:07:46 -04:00
brotoskyj 8b257d424b Using Custom Actions
Build and Release / build-linux (push) Failing after 3s
Build and Release / build-windows (push) Failing after 3s
Build and Release / release (push) Has been skipped
2025-10-20 17:06:50 -04:00
brotoskyj 9e8b953ddf I forgot how to do this
Build and Release / build-linux (push) Failing after 22s
Build and Release / build-windows (push) Failing after 21s
Build and Release / release (push) Has been skipped
2025-10-20 17:02:06 -04:00
brotoskyj 635986ef90 Added file for testing 2025-10-20 17:00:54 -04:00
brotoskyj efc8577c22 Testing Runner 2025-10-20 17:00:17 -04:00
brotoskyj e700550391 Removed unnecessary class from .pyi 2025-10-20 16:53:11 -04:00
brotoskyj fd63ecbd1a Redid build.sh and removed files 2025-10-20 16:52:08 -04:00
brotoskyj 63a0da47a4 Random Test 2025-10-20 15:52:34 -04:00
9 changed files with 1900 additions and 3 deletions
+98
View File
@@ -0,0 +1,98 @@
name: Build and Release
on:
push:
branches:
- master
jobs:
build-linux:
runs-on: debian-bookworm
steps:
- uses: actions/checkout@v5
with:
repository: 'brotoskyj/AirlockLibs'
token: ${{RUNNER_TOKEN}}
- name: Install Rust + Python + maturin
run: |
apt-get update && apt-get install -y python3 python3-pip curl node
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
pip3 install maturin --break-system-packages
- name: Build Linux Wheel
run: |
source $HOME/.cargo/env
maturin build --release --interpreter python3
- name: Upload Linux wheel
uses: actions/upload-artifact@v4
with:
name: wheel-linux
path: target/wheels/*.whl
build-windows:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Docker
run: |
sudo apt-get update && sudo apt-get install -y docker.io
- name: Build Windows Wheel with maturin in cross container
run: |
docker run --rm -v $PWD:/project -w /project ghcr.io/cross-rs/x86_64-pc-windows-gnu \
bash -c "pip3 install maturin && maturin build --release --target x86_64-pc-windows-gnu"
- name: Upload Windows wheel
uses: actions/upload-artifact@v4
with:
name: wheel-windows
path: target/wheels/*win_amd64.whl
release:
needs: [build-linux, build-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: wheel-linux
path: dist/
- uses: actions/download-artifact@v4
with:
name: wheel-windows
path: dist/
- name: Get Version
id: version
run: |
version=$(grep '^version' Cargo.toml | head -n1 | cut -d'"' -f2)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Generate changelog from commits
id: changelog
run: |
log=$(git log --pretty=format:"- %s (%h)" $(git describe --tags --abbrev=0)..HEAD)
echo "$log" > changes.md
echo "log<<EOF" >> "$GITHUB_OUTPUT"
echo "$log" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create Gitea Release
uses: https://gitea.com/actions/create-release@v1
with:
tag: v${{ steps.version.outputs.version }}
title: Release v${{ steps.version.outputs.version }}
note: ${{ steps.changelog.outputs.log }}
env:
RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }}
- name: Upload release assets
uses: https://gitea.com/actions/upload-release-asset@v1
with:
tag: v${{ steps.version.outputs.version }}
file: dist/*.whl
env:
RUNNER_TOKEN: ${{ secrets.RUNNER_TOKEN }}
+2
View File
@@ -1 +1,3 @@
/target
build.sh
pythontest.py
Generated
+1582
View File
File diff suppressed because it is too large Load Diff
+19 -1
View File
@@ -7,4 +7,22 @@ edition = "2024"
crate-type = ["cdylib"]
[dependencies]
pyo3 = "0.27.0"
pyo3 = { version = "0.27.0", features = ["extension-module", "generate-import-lib"] }
reqwest = { version = "0.12.24", features = ["json", "native-tls"] }
serde = "1.0.228"
serde-pyobject = "0.8.0"
serde_json = "1.0.145"
tokio = { version = "1.48.0", features = ["full"] }
[package.metadata.maturin]
generate-abi-stubs = true
[profile.release]
opt-level = "z"
lto = "fat"
debug = false
codegen-units = 1
panic = 'abort'
strip = true
debug-assertions = false
overflow-checks = false
+87
View File
@@ -0,0 +1,87 @@
from typing import Dict, List, Optional
def pull_policy_exec_histories(self, type: List[str], checkpoint: str, policy: List[str]) -> str:
"""Retrieve execution history logs."""
def api(AirlockAPIWrapper):
"""
An implementation of the python AirlockAPIWrapper class to pass Python data into Rust
Parameters
----------
base_url : str
(Required) Base URL of the Airlock API, this should be in your .env file.
api_key : str
(Required) API Key for your profile in airlock, this should be in your credential manager.
headers : {"X-APIKey": self.api_key}
```def __init__(self, base_url: str, api_key: str):
self.base_url = base_ur.rstrip("/")
self.api_key = api_key
self.headers = {"X-APIKey": self.api_key}
```
"""
def history_logging(
api,
exec_types: str,
checkpoint_number: str,
policy_names: str,
) -> List[Dict[str, Any]]:
"""
Query execution history logs from the Airlock API.
Parameters
----------
exec_types : str
A JSON-style string list of execution types to retrieve.
Example: "[3,5,8]"
- 0 = Trusted Execution
- 1 = Blocked Execution
- 2 = Untrusted Execution [Audit]
- 3 = Untrusted Execution [OTP]
- 5 = Trusted Publisher Execution
- 8 = Trusted Process Execution
(etc.)
checkpoint_number : str
The checkpoint ID. Used to fetch results after a certain event.
Example: "601d275487bacb01e3470713"
policy_names : str
A comma-separated or JSON-style list of policy group names.
Example: "Apple Mac" or "["Apple Mac", "Servers London"]"
Returns
-------
List[Dict[str, Any]]
A list of dictionaries, where each dictionary represents an
execution history record. Each record can include fields like:
- checkpoint: str
- type: int
- username: str
- hostname: str
- filename: str
- ppolicy: str
- policyname: str
- policyver: str
- commandline: str
- publisher: str
- pprocess: str
- gprocess: str
- sha256: str
- datetime: str
- ip: str
- localip: str
Raises
------
RuntimeError
If the request fails or the response cannot be parsed.
Example
-------
>>> histories = await airlock_libs.history_logging("[3,5,8]", "601d275487bacb01e3470713", "Apple Mac")
>>> print(histories[0]["filename"])
'chrome.exe'
"""
...
+1
View File
@@ -0,0 +1 @@
+4 -2
View File
@@ -1,11 +1,13 @@
use pyo3::prelude::*;
mod chunkinator;
mod services;
#[pymodule]
fn python_ext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
fn airlock_libs(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(double, py)?)?;
m.add_function(wrap_pyfunction!(services::history_logging, py)?)?;
Ok(())
}
#[pyfunction]
fn double(x: usize) -> usize {
x * 2
}
}
+107
View File
@@ -0,0 +1,107 @@
use std::str::FromStr;
use pyo3::{
prelude::*,
types::{PyDict, PyList, PyString},
};
use reqwest::{
Client,
header::{HeaderMap, HeaderName, HeaderValue},
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_pyobject::to_pyobject;
#[derive(Debug, Deserialize, Serialize)]
struct ApiResponse {
error: String,
response: ExecHistories,
}
#[derive(Debug, Deserialize, Serialize)]
struct ExecHistories {
exechistories: Vec<Group>,
}
#[derive(Debug, Deserialize, Serialize)]
struct Group {
checkpoint: String,
#[serde(rename = "type")]
exectype: u8,
username: String,
hostname: String,
netdomain: String,
filename: String,
ppolicy: String,
policyname: String,
policyver: String,
commandline: String,
publisher: String,
pprocess: String,
gprocess: String,
sha256: String,
datetime: String,
md5: String,
sha128: String,
sha384: String,
sha512: String,
ip: String,
localip: String,
}
#[tokio::main]
#[pyfunction]
pub async fn history_logging(
py: Python<'_>,
py_self: Py<PyAny>,
exec_types: String,
checkpoint_number: String,
policy_names: String,
) -> Py<PyList> {
let base_url = py_self.getattr(py, "base_url").unwrap().to_string();
let headers = py_self.getattr(py, "headers").unwrap().to_string();
let headers_replace = headers.replace('\'', "\"");
let parsed: Value = serde_json::from_str(&headers_replace.as_str()).unwrap();
let mut header_map = HeaderMap::new();
if let Some(obj) = parsed.as_object() {
for (key, value) in obj {
if let Some(v) = value.as_str() {
let val = HeaderValue::from_str(v).unwrap();
header_map.insert(HeaderName::from_str("X-APIKey").unwrap(), val);
}
}
}
let payload = format!(
r#"{{
"type": {},
"checkpoint": "{}",
"policy": ["{}"]
}}"#,
exec_types, checkpoint_number, policy_names
);
let client = Client::builder()
.danger_accept_invalid_certs(true)
.default_headers(header_map)
.timeout(std::time::Duration::from_secs(30))
.build()
.unwrap();
let res = client
.post(format!("{}/v1/logging/exechistories", base_url))
.body(payload)
.send()
.await;
match res {
Ok(res) => {
let first_response: ApiResponse = serde_json::from_str(&res.text().await.unwrap())
.expect("Failed to Parse JSON - Rust Lib");
let py_any: Py<PyAny> = serde_pyobject::to_pyobject(py, &first_response.response.exechistories)
.unwrap().into();
py_any.extract(py).unwrap()
}
Err(res) => {
let first_response = res.to_string();
let py_any: Py<PyAny> = serde_pyobject::to_pyobject(py, &first_response)
.unwrap()
.into();
let py_list: Py<PyList> = py_any.extract(py).unwrap();
return py_list;
}
}
}
View File