### Install Regorus Example Program Source: https://github.com/microsoft/regorus/blob/main/README.md Build and install the regorus example program using Cargo. This command installs the example binary from the local path. ```bash $ cargo install --example regorus --path . ``` -------------------------------- ### Install Hyperfine Source: https://github.com/microsoft/regorus/blob/main/README.md Installs the hyperfine benchmarking tool. This is a prerequisite for performance testing. ```bash $ cargo install hyperfine ``` -------------------------------- ### Install mimalloc library Source: https://github.com/microsoft/regorus/blob/main/mimalloc/mimalloc-sys/mimalloc/README.md Installs the mimalloc library and header files to /usr/local/lib and /usr/local/include. ```bash sudo make install ``` -------------------------------- ### Start Container Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-lifecycle/inputs.txt Initiates the start of a container within the Regorus system. ```APIDOC ## POST /startContainer ### Description Starts a container with the specified ID. ### Method POST ### Endpoint /startContainer ### Parameters #### Request Body - **container_id** (string) - Required - The ID of the container to start. ### Request Example { "container_id": "a3e5b029b23f8e3a63e5c231cf63688477a77f5036f249f722823eef73771098" } ``` -------------------------------- ### Install Regorus FFI Target Source: https://github.com/microsoft/regorus/blob/main/bindings/cpp/CMakeLists.txt Configures installation directories and creates an alias for the regorus_ffi target. Installs headers and CMake configuration files for package management. ```cmake include(GNUInstallDirs) set(regorus_ffi_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/regorus_ffi) set(regorus_ffi_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/regorus_ffi) set(regorus_ffi_LIBDIR ${CMAKE_INSTALL_LIBDIR}) set(regorus_ffi_BINDIR ${CMAKE_INSTALL_BINDIR}) add_library(regorus_ffi::regorus_ffi ALIAS regorus_ffi) corrosion_install(TARGETS regorus_ffi EXPORT regorus_ffi_targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) target_include_directories(regorus_ffi INTERFACE $ $ $ ) set(regorus_ffi_HEADER_FILES regorus.hpp ../ffi/regorus.ffi.hpp ) install(FILES ${regorus_ffi_HEADER_FILES} DESTINATION ${regorus_ffi_INCLUDEDIR} COMPONENT Devel ) install(EXPORT regorus_ffi_targets FILE regorus_ffi_targets.cmake NAMESPACE regorus_ffi:: DESTINATION ${regorus_ffi_CONFIGDIR} ) include(CMakePackageConfigHelpers) configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/regorus_ffiConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/regorus_ffiConfig.cmake INSTALL_DESTINATION ${regorus_ffi_CONFIGDIR} ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/regorus_ffiConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/corrosion/regorus_ffi_targetsCorrosion.cmake DESTINATION ${regorus_ffi_CONFIGDIR} ) ``` -------------------------------- ### Start Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-same-containers/inputs.txt Initiates the start of a container with the specified ID. ```APIDOC ## POST /startContainer ### Description Starts a container using its unique identifier. ### Method POST ### Endpoint /startContainer ### Parameters #### Query Parameters - **container_id** (string) - Required - The unique identifier of the container to start. ### Request Example { "container_id": "8ab188b8cbf32be40c40cbeaf26d340c100b586a9ba800fd1b3d505b735172b9" } ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example { "status": "Container started successfully" } ``` -------------------------------- ### Start Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-lifecycle/inputs.txt Initiates a new container. Requires a container ID. ```json ["ep":"StartContainerRequest",{"container_id":"45bd74c304beec46aa5a433009e3ab6703d7995c37154ebe6a0d859924ebdf67"}] ``` -------------------------------- ### Start Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/k8s-policy-pod/inputs.txt Initiates a container using its ID. This is a basic request to start an existing container. ```json ["ep":"StartContainerRequest",{"container_id":"e4bd2a97acb81f9ea31d49e21ef2675bcd8bf6883d3cd4273d6d4fb2f6fcbba2"}] ``` -------------------------------- ### Manually Install Regorusrb Gem Source: https://github.com/microsoft/regorus/blob/main/bindings/ruby/README.md Steps to manually clone the repository, build the gem, and install it locally. Use this if not using Bundler. ```bash git clone https://github.com/microsoft/regorus/ cd regorus/bindings/ruby rake && rake build # should eventually output 'regorusrb 0.1.0 built to pkg/regorusrb-0.1.0.gem.' gem install --local ./pkg/regorusrb-0.1.0.gem ``` ```bash rake build gem install --local ./pkg/regorusrb-0.1.0.gem ``` -------------------------------- ### Build Regorus Binary Size Comparison Source: https://github.com/microsoft/regorus/blob/main/README.md These commands demonstrate how to build the Regorus example binary with and without default features to observe the impact on file size. The first command builds with all default features enabled, while the second uses the --no-default-features flag. ```bash cargo build -r --example regorus; strip target/release/examples/regorus; ls -lh target/release/examples/regorus ``` ```bash cargo build -r --example regorus --no-default-features; strip target/release/examples/regorus; ls -lh target/release/examples/regorus ``` -------------------------------- ### Basic Policy Compilation and Evaluation Example Source: https://github.com/microsoft/regorus/blob/main/bindings/csharp/API.md Demonstrates how to compile a basic policy and evaluate it with different inputs. ```APIDOC ### Basic Policy Compilation and Evaluation ```csharp // Define policy modules var modules = new List { new PolicyModule("policy.rego", @" package example import rego.v1 default allow := false allow if input.user == ""admin"" ") }; // Compile the policy using var policy = Compiler.CompilePolicyWithEntrypoint("{}", modules, "data.example.allow"); // Evaluate with different inputs var result1 = policy.EvalWithInput(@"{ ""user"": ""admin"" }"); // true var result2 = policy.EvalWithInput(@"{ ""user"": ""guest"" }"); // false ``` ``` -------------------------------- ### Start Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/k8s-policy-rc/inputs.txt Initiates the execution of a previously created container. This is a fundamental step before interacting with a container's processes. ```json ["ep":"StartContainerRequest",{"container_id":"c469f18bb1c58dab6be747450b77c3321e43ba5dd26d62d19a599b82bdb0ddc5"}] ``` -------------------------------- ### OCI Configuration Example Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-many-layers/inputs.txt This snippet shows a partial OCI configuration, including version and process details. It is used for defining container runtime settings. ```json { "OCI": { "Version": "1.1.0-rc.1", "Process": { "Terminal": false, "ConsoleSize": null, "User": { "UID": 0, "GID": 0, "AdditionalGids": [ 0 ], "Username": "" }, "Args": [ "sh", "-c", "while true; do echo nginx; sleep 10; " ] } } } ``` -------------------------------- ### Compile Program with ASAN and Mimalloc Source: https://github.com/microsoft/regorus/blob/main/mimalloc/mimalloc-sys/mimalloc/README.md Example compilation command for a program linked with an ASAN-enabled mimalloc build. Ensure both the program and mimalloc are compiled with ASAN flags. ```bash clang -g -o test-wrong -Iinclude test/test-wrong.c out/debug/libmimalloc-asan-debug.a -lpthread -fsanitize=address -fsanitize-recover=address ``` -------------------------------- ### Run Test Script Source: https://github.com/microsoft/regorus/blob/main/bindings/python/building.md Execute the Python test script to verify the installation and functionality. ```bash python3 test.py ``` -------------------------------- ### Run Full Benchmark Suite Source: https://github.com/microsoft/regorus/blob/main/benches/evaluation/README.md Execute the entire benchmark suite for Regorus policy evaluation. Ensure Rust 1.70+ and Cargo are installed. ```bash cargo bench evaluation_benchmark ``` -------------------------------- ### Install wasm-pack Source: https://github.com/microsoft/regorus/blob/main/bindings/wasm/building.md Installs the wasm-pack toolchain, which is required for building Rust code to WebAssembly. ```bash cargo install wasm-pack ``` -------------------------------- ### Start ETW Tracing with WPR Source: https://github.com/microsoft/regorus/blob/main/mimalloc/mimalloc-sys/mimalloc/src/prim/windows/readme.md Use this command to start Windows Performance Recorder (WPR) profiling for mimalloc events. Ensure you are in an administrator command prompt. This profile captures allocation and free events. ```bash > wpr -start src\prim\windows\etw-mimalloc.wprp -filemode ``` -------------------------------- ### Install Python Wheel Source: https://github.com/microsoft/regorus/blob/main/bindings/python/building.md Install the generated Regorus Python wheel using pip3, forcing a reinstall to ensure the latest version is used. ```bash pip3 install ../../target/wheels/regorus*.whl --force-reinstall ``` -------------------------------- ### mimalloc Statistics Output Source: https://github.com/microsoft/regorus/blob/main/mimalloc/mimalloc-sys/mimalloc/README.md Example output showing heap statistics, memory allocation details, and process timing when MIMALLOC_SHOW_STATS is enabled. ```text 175451865205073170563711388363 = 374456281610909315237213 * 468551 heap stats: peak total freed unit normal 2: 16.4 kb 17.5 mb 17.5 mb 16 b ok normal 3: 16.3 kb 15.2 mb 15.2 mb 24 b ok normal 4: 64 b 4.6 kb 4.6 kb 32 b ok normal 5: 80 b 118.4 kb 118.4 kb 40 b ok normal 6: 48 b 48 b 48 b 48 b ok normal 17: 960 b 960 b 960 b 320 b ok heap stats: peak total freed unit normal: 33.9 kb 32.8 mb 32.8 mb 1 b ok huge: 0 b 0 b 0 b 1 b ok total: 33.9 kb 32.8 mb 32.8 mb 1 b ok malloc requested: 32.8 mb committed: 58.2 kb 58.2 kb 58.2 kb 1 b ok reserved: 2.0 mb 2.0 mb 2.0 mb 1 b ok reset: 0 b 0 b 0 b 1 b ok segments: 1 1 1 -abandoned: 0 pages: 6 6 6 -abandoned: 0 mmaps: 3 mmap fast: 0 mmap slow: 1 threads: 0 elapsed: 2.022s process: user: 1.781s, system: 0.016s, faults: 756, reclaims: 0, rss: 2.7 mb ``` -------------------------------- ### Container File System Options Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-many-layers/inputs.txt Illustrates file system options for a container, specifically for overlay read-write mounts. This configuration is part of the container's storage setup. ```json { "io.katacontainers.fs-opt.overlay-rw", "lowerdir=1b27bec068016fce230a3c9f4920d3be7251e5baada7dca3204a932cbcde27e2:c8295c80a79c2ed76e03ddb2af390ac3791b8779da798cb183fa985ce5cee1dc:cfb9fe97a1869ee9b0daae3d8cd59720cf371da568a6c14bba16d982e7092983:14f395647869a88f90a33eef50c97e82f4b981b6e20a584d51bf304967b8542c:fc7dd8614820bbafe5b6b6645e19945b4af989b662c989fd46c465fafca702f7:8d311e8e51984cabaccec1fbfcbcdd7bf52a8a978169cd20af07bbd1c3a4692a" } ``` -------------------------------- ### Regorus Java Usage Example Source: https://github.com/microsoft/regorus/blob/main/bindings/java/README.md Demonstrates how to use the Regorus Java bindings to load a policy, add data, set input, and evaluate a query. Ensure the native library and JAR are in the classpath. ```java import com.microsoft.regorus.Engine; public class Test { public static void main(String[] args) { try (Engine engine = new Engine()) { engine.addPolicy( "hello.rego", "package test\nmessage = concat(\", \", [input.message, data.message])" ); engine.addDataJson("{\"message\":\"World!\"}"); engine.setInputJson("{\"message\":\"Hello\"}"); String resJson = engine.evalQuery("data.test.message"); System.out.println(resJson); } } } ``` -------------------------------- ### Execute Process in Container Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-exec/inputs.txt Execute a process within a specified container. This example shows how to run an 'echo' command and retrieve environment variables. ```json ["ep":"ExecProcessRequest",{"container_id":"42cd455d88baf5b3d2a94fe7bdef82da5bcca78d6c2c62149724a952897bf5b6","exec_id":"56ccd0f4-1142-49a4-9732-146efca8e771","string_user":null,"process":{"Terminal":false,"ConsoleSize":null,"User":{"UID":0,"GID":0,"AdditionalGids":[0,10],"Username":""},"Args":["echo","${ISTIO_META_APP_CONTAINERS}"],"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOSTNAME=exec-test","POD_IP=10.244.0.16","SERVICE_ACCOUNT=default","POD_NAME=exec-test","POD_NAMESPACE=default","PROXY_CONFIG={}\n","ISTIO_META_POD_PORTS":[ ],"ISTIO_META_APP_CONTAINERS=serviceaclient","ISTIO_META_CLUSTER_ID=Kubernetes","ISTIO_META_NODE_NAME=aks-nodepool1-38464071-vmss000000","KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1","KUBERNETES_SERVICE_HOST=10.0.0.1","KUBERNETES_SERVICE_PORT=443","KUBERNETES_SERVICE_PORT_HTTPS=443","KUBERNETES_PORT=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP_PROTO=tcp","KUBERNETES_PORT_443_TCP_PORT=443"],"Cwd":"/","Capabilities":null,"Rlimits":[],"NoNewPrivileges":false,"ApparmorProfile":"","OOMScoreAdj":0,"SelinuxLabel":""}}] ``` ```json ["ep":"ExecProcessRequest",{"container_id":"42cd455d88baf5b3d2a94fe7bdef82da5bcca78d6c2c62149724a952897bf5b6","exec_id":"15ba4186-176e-4903-b8c9-672f676645ef","string_user":null,"process":{"Terminal":false,"ConsoleSize":null,"User":{"UID":0,"GID":0,"AdditionalGids":[0,10],"Username":""},"Args":["echo","Ready ${POD_IP}!"] ,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOSTNAME=exec-test","POD_IP=10.244.0.16","SERVICE_ACCOUNT=default","POD_NAME=exec-test","POD_NAMESPACE=default","PROXY_CONFIG={}\n","ISTIO_META_POD_PORTS":[ ],"ISTIO_META_APP_CONTAINERS=serviceaclient","ISTIO_META_CLUSTER_ID=Kubernetes","ISTIO_META_NODE_NAME=aks-nodepool1-38464071-vmss000000","KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1","KUBERNETES_SERVICE_HOST=10.0.0.1","KUBERNETES_SERVICE_PORT=443","KUBERNETES_SERVICE_PORT_HTTPS=443","KUBERNETES_PORT=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP_PROTO=tcp","KUBERNETES_PORT_443_TCP_PORT=443"],"Cwd":"/","Capabilities":null,"Rlimits":[],"NoNewPrivileges":false,"ApparmorProfile":"","OOMScoreAdj":0,"SelinuxLabel":""}}] ``` -------------------------------- ### Regorus Start Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/k8s-policy-job/inputs.txt This snippet initiates the start of a container. It requires the `container_id` to identify which container to start. This is a fundamental operation for managing container lifecycles. ```json ["ep":"StartContainerRequest",{"container_id":"92fe9b0523a4ef0e39cdd2a509bd6a13639571f50d9d7df74f6dbab37cae23fa"}] ``` -------------------------------- ### Initialize and Use Regorus Engine in Ruby Source: https://github.com/microsoft/regorus/blob/main/bindings/ruby/README.md Demonstrates how to initialize the Regorus engine, set policy version, add policies from files, load data, set input, and evaluate rules or queries. ```ruby require "regorus" engine = Regorus::Engine.new # Policy is old-style. engine.set_rego_v0(true) engine.add_policy_from_file('../../tests/aci/framework.rego') engine.add_policy_from_file('../../tests/aci/api.rego') engine.add_policy_from_file('../../tests/aci/policy.rego') # can be strings or symbols data = { metadata: { devices: { "/run/layers/p0-layer0": "1b80f120dbd88e4355d6241b519c3e25290215c469516b49dece9cf07175a766", "/run/layers/p0-layer1": "e769d7487cc314d3ee748a4440805317c19262c7acd2fdbdb0d47d2e4613a15c", "/run/layers/p0-layer2": "eb36921e1f82af46dfe248ef8f1b3afb6a5230a64181d960d10237a08cd73c79", "/run/layers/p0-layer3": "41d64cdeb347bf236b4c13b7403b633ff11f1cf94dbc7cf881a44d6da88c5156", "/run/layers/p0-layer4": "4dedae42847c704da891a28c25d32201a1ae440bce2aecccfa8e6f03b97a6a6c", "/run/layers/p0-layer5": "fe84c9d5bfddd07a2624d00333cf13c1a9c941f3a261f13ead44fc6a93bc0e7a" } } } engine.add_data(data) input = { "containerID": "container0", "layerPaths": [ "/run/layers/p0-layer0", "/run/layers/p0-layer1", "/run/layers/p0-layer2", "/run/layers/p0-layer3", "/run/layers/p0-layer4", "/run/layers/p0-layer5" ], "target": "/run/gcs/c/container0/rootfs" } engine.set_input(input) # Evaluate a specife rule rule_results = engine.eval_rule('data.framework.mount_overlay') puts rule_results # { "allowed" => true, "metadata" => [...]} # Or evalute a full policy document query_results = engine.eval_query('data.framework') puts query_results[:result][0] # Query results can can also be returned as JSON strings instead of Ruby Hash structure results_json = engine.eval_query_as_json('data.framework.mount_overlay=x') puts results_json ``` -------------------------------- ### Create Container Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/k8s-policy-rc/inputs.txt This snippet demonstrates how to create a container with specified configurations, including OCI settings, mounts, and user privileges. It's used for initializing a new container instance. ```json ["ep":"CreateContainerRequest",{"container_id":"432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e","exec_id":"432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e","string_user":null,"devices":[],"storages":[{"driver":"local","driver_options":[],"source":"local","fstype":"local","options":["mode=0777"],"mount_point":"/run/kata-containers/shared/containers/c469f18bb1c58dab6be747450b77c3321e43ba5dd26d62d19a599b82bdb0ddc5/rootfs/local/host-empty-vol"}],"OCI":{"Version":"1.1.0","Process":{"Terminal":false,"ConsoleSize":null,"User":{"UID":0,"GID":0,"AdditionalGids":[0,1,2,3,4,6,10,11,20,26,27],"Username":""},"Args":["nginx","-g","daemon off;"],"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOSTNAME=policy-rc-test-674df","NGINX_VERSION=1.15.12","KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP_PROTO=tcp","KUBERNETES_PORT_443_TCP_PORT=443","KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1","KUBERNETES_SERVICE_HOST=10.0.0.1","KUBERNETES_SERVICE_PORT=443","KUBERNETES_SERVICE_PORT_HTTPS=443","KUBERNETES_PORT=tcp://10.0.0.1:443"],"Cwd":"/","Capabilities":{"Bounding":["CAP_CHOWN","CAP_DAC_OVERRIDE","CAP_FSETID","CAP_FOWNER","CAP_MKNOD","CAP_NET_RAW","CAP_SETGID","CAP_SETUID","CAP_SETFCAP","CAP_SETPCAP","CAP_NET_BIND_SERVICE","CAP_SYS_CHROOT","CAP_KILL","CAP_AUDIT_WRITE"],"Effective":["CAP_CHOWN","CAP_DAC_OVERRIDE","CAP_FSETID","CAP_FOWNER","CAP_MKNOD","CAP_NET_RAW","CAP_SETGID","CAP_SETUID","CAP_SETFCAP","CAP_SETPCAP","CAP_NET_BIND_SERVICE","CAP_SYS_CHROOT","CAP_KILL","CAP_AUDIT_WRITE"],"Inheritable":[],"Permitted":["CAP_CHOWN","CAP_DAC_OVERRIDE","CAP_FSETID","CAP_FOWNER","CAP_MKNOD","CAP_NET_RAW","CAP_SETGID","CAP_SETUID","CAP_SETFCAP","CAP_SETPCAP","CAP_NET_BIND_SERVICE","CAP_SYS_CHROOT","CAP_KILL","CAP_AUDIT_WRITE"],"Ambient":[]},"Rlimits":[],"NoNewPrivileges":false,"ApparmorProfile":"cri-containerd.apparmor.d","OOMScoreAdj":1000,"SelinuxLabel":""},"Root":{"Path":"/run/kata-containers/shared/containers/432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e/rootfs","Readonly":false},"Hostname":"","Mounts":[{"destination":"/proc","source":"proc","type_":"proc","options":["nosuid","noexec","nodev"]},{"destination":"/dev","source":"tmpfs","type_":"tmpfs","options":["nosuid","strictatime","mode=755","size=65536k"]},{"destination":"/dev/pts","source":"devpts","type_":"devpts","options":["nosuid","noexec","newinstance","ptmxmode=0666","mode=0620","gid=5"]},{"destination":"/dev/mqueue","source":"mqueue","type_":"mqueue","options":["nosuid","noexec","nodev"]},{"destination":"/sys","source":"sysfs","type_":"sysfs","options":["nosuid","noexec","nodev","ro"]},{"destination":"/sys/fs/cgroup","source":"cgroup","type_":"cgroup","options":["nosuid","noexec","nodev","relatime","ro"]},{"destination":"/host/cache","source":"/run/kata-containers/shared/containers/c469f18bb1c58dab6be747450b77c3321e43ba5dd26d62d19a599b82bdb0ddc5/rootfs/local/host-empty-vol","type_":"local","options":["rbind","rprivate","rw"]},{"destination":"/etc/hosts","source":"/run/kata-containers/shared/containers/432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e-01336f00e960a39f-hosts","type_":"bind","options":["rbind","rprivate","rw"]},{"destination":"/dev/termination-log","source":"/run/kata-containers/shared/containers/432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e-90afc9ee3516c39f-termination-log","type_":"bind","options":["rbind","rprivate","rw"]},{"destination":"/etc/hostname","source":"/run/kata-containers/shared/containers/432a988cdb7fd4798e112d1a27a272d86e665dbfbdc4fc6937af127120b3a03e-094a24e380ead97f-hostname","type_":"bind","options":["rbind","rprivate","rw"]},{"destination":"/etc/resolv.conf","source":"/run/kata-containers/shared/containers/432a9 ``` -------------------------------- ### Install Maturin Source: https://github.com/microsoft/regorus/blob/main/bindings/python/building.md Use pipx to install Maturin, a tool for building and publishing Python packages with Rust. ```bash pipx install maturin ``` -------------------------------- ### Execute 'echo Ready ${POD_IP}!' Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-exec/inputs.txt Executes the 'echo' command to display a ready message including the container's IP address. This is useful for confirming network readiness. ```json ["ep":"ExecProcessRequest",{"container_id":"42cd455d88baf5b3d2a94fe7bdef82da5bcca78d6c2c62149724a952897bf5b6","exec_id":"30724ed8-fff6-4b60-949d-e1380ace3706","string_user":null,"process":{"Terminal":false,"ConsoleSize":null,"User":{"UID":0,"GID":0,"AdditionalGids":[0,10],"Username":""},"Args":["echo","Ready ${POD_IP}!"] ,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","HOSTNAME=exec-test","POD_IP=10.244.0.16","SERVICE_ACCOUNT=default","POD_NAME=exec-test","POD_NAMESPACE=default","PROXY_CONFIG={}\n","ISTIO_META_POD_PORTS":[ ]","ISTIO_META_APP_CONTAINERS=serviceaclient","ISTIO_META_CLUSTER_ID=Kubernetes","ISTIO_META_NODE_NAME=aks-nodepool1-38464071-vmss000000","KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1","KUBERNETES_SERVICE_HOST=10.0.0.1","KUBERNETES_SERVICE_PORT=443","KUBERNETES_SERVICE_PORT_HTTPS=443","KUBERNETES_PORT=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443","KUBERNETES_PORT_443_TCP_PROTO=tcp","KUBERNETES_PORT_443_TCP_PORT=443"],"Cwd":"/","Capabilities":null,"Rlimits":[],"NoNewPrivileges":false,"ApparmorProfile":"","OOMScoreAdj":0,"SelinuxLabel":""}}] ``` -------------------------------- ### Rego Compilation Error Example Source: https://github.com/microsoft/regorus/blob/main/docs/destructuring.md Example of a compilation error message in Rego related to variable rebinding. ```text error: var `value` used before definition below ``` -------------------------------- ### Build Python Bindings Source: https://github.com/microsoft/regorus/blob/main/bindings/python/building.md Navigate to the Python bindings directory and build the release version of the wheel, outputting to the wheels directory. ```bash cd bindings/python maturin build --release --target-dir wheels ``` -------------------------------- ### Compile and Execute Rego Policy with RVM Source: https://github.com/microsoft/regorus/blob/main/bindings/csharp/README.md Demonstrates compiling a Rego policy from modules and executing it within the RVM virtual machine. Requires Regorus SDK. ```csharp using Regorus; const string Policy = """ package demo default allow = false allow if { input.user == "alice" some role in data.roles[input.user] role == "admin" } """; const string Data = """ { \"roles\": { \"alice\": [\"admin\"] } }\n"""; const string Input = """ { \"user\": \"alice\" }\n"""; var modules = new[] { new PolicyModule("demo.rego", Policy) }; var entryPoints = new[] { "data.demo.allow" }; using var program = Program.CompileFromModules(Data, modules, entryPoints); var listing = program.GenerateListing(); using var vm = new Rvm(); vm.LoadProgram(program); vm.SetDataJson(Data); vm.SetInputJson(Input); var result = vm.Execute(); Console.WriteLine($"allow: {result}"); ``` -------------------------------- ### Install Regorus with Azure Policy Feature Source: https://github.com/microsoft/regorus/blob/main/README.md Install the Regorus CLI with the `azure_policy` cargo feature enabled. This is necessary for using Azure Policy evaluation capabilities. ```bash cargo install --example regorus --features azure_policy --path . ``` -------------------------------- ### Basic Policy Compilation and Evaluation Source: https://github.com/microsoft/regorus/blob/main/bindings/csharp/API.md Demonstrates compiling a policy with a specific entrypoint and evaluating it with different inputs. Ensure policy modules are defined correctly before compilation. ```csharp // Define policy modules var modules = new List { new PolicyModule("policy.rego", @" package example import rego.v1 default allow := false allow if input.user == ""admin"" ") }; // Compile the policy using var policy = Compiler.CompilePolicyWithEntrypoint("{}", modules, "data.example.allow"); // Evaluate with different inputs var result1 = policy.EvalWithInput(@"{ "user": "admin" }"); // true var result2 = policy.EvalWithInput(@"{ "user": "guest" }"); // false ``` -------------------------------- ### Container Operations Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-cm1/inputs.txt APIs for starting and waiting for processes within containers. ```APIDOC ## POST /StartContainerRequest ### Description Starts a container. ### Method POST ### Endpoint /StartContainerRequest ### Request Body - **container_id** (string) - Required - The ID of the container to start. ### Request Example { "container_id": "7378f298b0f0745329680eba807f4e8283813bc5d38918fb10d0b596fc7e411f" } ## POST /WaitProcessRequest ### Description Waits for a process to complete within a container. ### Method POST ### Endpoint /WaitProcessRequest ### Request Body - **container_id** (string) - Required - The ID of the container. - **exec_id** (string) - Required - The ID of the execution. ### Request Example { "container_id": "7378f298b0f0745329680eba807f4e8283813bc5d38918fb10d0b596fc7e411f", "exec_id": "7378f298b0f0745329680eba807f4e8283813bc5d38918fb10d0b596fc7e411f" } ``` -------------------------------- ### Get OOM Event Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/pod-lifecycle/inputs.txt Retrieves Out-Of-Memory (OOM) events for containers. ```APIDOC ## GET /getOOMEvent ### Description Retrieves Out-Of-Memory (OOM) events. ### Method GET ### Endpoint /getOOMEvent ### Parameters (No parameters specified in the provided text.) ### Response #### Success Response (200) (Response structure not specified in the provided text.) ``` -------------------------------- ### Fetch and Import Regorus Crate with Corrosion Source: https://github.com/microsoft/regorus/blob/main/bindings/c-nostd/CMakeLists.txt This CMake script uses FetchContent to download the Corrosion build system and then imports the Regorus FFI crate. It configures the crate for release mode, specifies the crate to build, disables default features and std support, enables custom allocator and semver features, and sets the crate type to staticlib for static linking. ```cmake cmake_minimum_required(VERSION 3.12 FATAL_ERROR) include(FetchContent) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git # Use a tag that has a fix for https://github.com/corrosion-rs/corrosion/issues/590 GIT_TAG 6be991bb34c348dfb8344be22f3606288ea5c7fd ) FetchContent_MakeAvailable(Corrosion) project("regorus-test") corrosion_import_crate( # Path to /bindings/ffi/Cargo.toml MANIFEST_PATH "../ffi/Cargo.toml" # Always build regorus in Release mode. PROFILE "release" # Only build the "regorus-ffi" crate. CRATES "regorus-ffi" # Turn off std support in regorus-ffi. NO_DEFAULT_FEATURES NO_STD # custom_allocator allows using a custom memory allocator. # To use malloc/free remove custom_allocator below. # Additionally, select specific features in regorus. # See regorus/opa_no_std FEATURES "custom_allocator,regorus/semver" LOCKED # Link statically CRATE_TYPES staticlib FLAGS --crate-type=staticlib ) ``` -------------------------------- ### Get OOM Event Request Source: https://github.com/microsoft/regorus/blob/main/tests/kata/data/k8s-policy-pod/inputs.txt Requests Out-Of-Memory (OOM) event information. This snippet is a simple request with no parameters. ```json ["ep":"GetOOMEventRequest",{}] ``` -------------------------------- ### Getting Global Fallback Execution Timer Configuration Source: https://github.com/microsoft/regorus/blob/main/docs/limits/execution_time.md Returns the currently active global fallback configuration for diagnostics. ```rust fallback_execution_timer_config() -> Option ``` -------------------------------- ### Run Program with ASAN Options Source: https://github.com/microsoft/regorus/blob/main/mimalloc/mimalloc-sys/mimalloc/README.md Execute your program with ASAN enabled, setting `verbosity` to 1 for detailed output. It's generally recommended to compile your program with ASAN enabled as well. ```bash ASAN_OPTIONS=verbosity=1 ``` -------------------------------- ### Add Regorusrb Gem to Gemfile Source: https://github.com/microsoft/regorus/blob/main/bindings/ruby/README.md Configure Bundler to build the Regorusrb gem from the remote Git repository. This is the recommended method for installation. ```ruby gem "regorusrb", git: "https://github.com/microsoft/regorus/", glob: "bindings/ruby/*.gemspec" ``` -------------------------------- ### Test Go Bindings with xtask Source: https://github.com/microsoft/regorus/blob/main/README.md Exercises language bindings for Go using the xtask CLI. This is a focused helper for testing Go integration. ```bash cargo xtask test-go ``` -------------------------------- ### Build Java Bindings Source: https://github.com/microsoft/regorus/blob/main/bindings/java/README.md Package the Java bindings into a JAR file using Maven. This command should be run after the native library has been successfully built. ```bash mvn package ```