# Contributing Before submitting pull request features, please discuss them with us first by opening an issue or a discussion. We welcome new/junior/starting developers. Feel free to join to our [Slack](https://metalbear.co/slack) for help and guidance. If you would like to start working on an issue, please comment on the issue on GitHub, so that we can assign you to that issue. Make sure to take a look at the project's [style guide](STYLE.md). # Contents - [Getting Started](#getting-started) - [Debugging mirrord](#debugging-mirrord) - [New Hook Guidelines](#new-hook-guidelines) - [Compiling on macOS](#compiling-on-macos) - [Adding new target types](#adding-new-target-types) - [Testing the release workflow](#testing-the-release-workflow) - [Submitting a Pull Request](#submitting-a-pull-request) - [Architecture](#architecture) - [Release mirrord](#release-mirrord) # Getting Started The following guide details the steps to setup a local development environment for mirrord and run the E2E tests. ### Prerequisites - [GCC](https://gcc.gnu.org/) - only on Linux, GCC is needed for Go dynamic linking - [Rust](https://www.rust-lang.org/) - [NodeJS](https://nodejs.org/en/), [ExpressJS](https://expressjs.com/), [portfinder](https://www.npmjs.com/package/portfinder) - [Python (recommended 3.13+)](https://www.python.org/), [Flask](https://flask.palletsprojects.com/en/2.1.x/), [FastAPI](https://fastapi.tiangolo.com/), [Uvicorn](https://www.uvicorn.org/) - [Go](https://go.dev/) - Kubernetes Cluster (local/remote) - [Argo Rollouts CRD](https://argoproj.github.io/argo-rollouts/) - required for rollout-related E2E tests (`kubectl create namespace argo-rollouts && kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/download/v1.9.1/install.yaml`) ### Building mirrord layer and binary If you run integration or e2e tests, both are automatically built. To build it from scratch, run `cargo xtask build-layer`. The layer is at `target/debug/`. Then, build the project with `MIRRORD_LAYER_FILE=$(pwd)/target/debug/ cargo build --all`. On macOS, when you give an explicit path to the layer binary, use the universal layer at `target/universal-apple-darwin/debug/`. is OS specific: - Linux: libmirrord_layer.so - macOS: libmirrord_layer.dylib - Windows: mirrord_layer_win.dll ### Compiling Rust test binaries There are a couple rough edges which are tested with standalone Rust binaries. For more info on these, check the respective GitHub issues. `rustc` is used rather than `cargo` for faster and lighter compilation ```rust cd mirrord/layer-tests/tests/apps rustc issue1123/issue1123.rs --out-dir target rustc issue1054/issue1054.rs --out-dir target rustc issue1458/issue1458.rs --out-dir target rustc issue1458portnot53/issue1458portnot53.rs --out-dir target rustc issue2058/issue2058.rs --out-dir target rustc issue2204/issue2204.rs --out-dir target ``` ### Build Go and C test apps Both E2E and integration run tests with simple C, Go, Python and Node.js apps. C and Go need to be built before testing. ([this should be automated in the future](https://github.com/metalbear-co/mirrord/issues/982)). Build Go test apps: ```bash ./scripts/build_go_apps.sh 25 ./scripts/build_go_apps.sh 26 ./scripts/build_go_apps.sh 27 ``` Build C test apps: (script uses clang, but feel free to use another compiler); ```bash ./scripts/build_c_apps.sh ``` ### Setup a Kubernetes cluster For E2E tests and testing mirrord manually you will need a working Kubernetes cluster. A minimal cluster can be easily setup locally using either of the following: - [Minikube](https://minikube.sigs.k8s.io/) - [Docker Desktop](https://www.docker.com/products/docker-desktop/) - [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) For the ease of illustration and testing, we will conform to using Minikube for the rest of the guide. ### Minikube Download [Minikube](https://minikube.sigs.k8s.io/) Start a Minikube cluster with preferred driver. Here we will use the Docker driver. ```bash minikube start --driver=docker ``` ### Prepare a cluster Build the mirrord-agent image. Images are defined in `ci/docker-bake.hcl`. For a local development build (single platform, loaded into the local Docker daemon): ```bash PLATFORMS="linux/$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')" AGENT_TAGS=test docker buildx bake -f ci/docker-bake.hcl agent --load ``` ```bash ❯ docker images REPOSITORY TAG IMAGE ID CREATED SIZE test latest 5080c20a8222 2 hours ago 300MB ``` > **Note:** mirrord-agent is shipped as a container image as mirrord creates a job with this image, providing it with > elevated permissions on the same node as the impersonated pod. Load mirrord-agent image to Minikube. ```bash minikube image load test ``` Switch Kubernetes context to `minikube`. ```bash kubectl config get-contexts ``` ```bash kubectl config use-context minikube ``` ## E2E Tests The E2E tests create Kubernetes resources in the cluster that kubectl is configured to use and then run sample apps with the mirrord CLI. The mirrord CLI spawns an agent for the target on the cluster, and runs the test app, with the layer injected into it. Both E2E and integration tests require a mirrord binary and a layer binary. These can be provided as arguments: ```bash cargo xtask test-e2e \ --binary $(pwd)/target//debug/mirrord \ --layer $(pwd)/target//debug/ ``` ... or as environment variables: ```bash MIRRORD_TESTS_USE_BINARY=$(pwd)/target//debug/mirrord \ MIRRORD_LAYER_FILE=$(pwd)/target//debug/ \ cargo xtask test-e2e ``` For each binary, arguments have precedence over environment variables. If neither is passed in for that binary, then it is built from source: Ex1: ```bash cargo xtask test-e2e # builds both mirrord binary and layer binary from source ``` Ex2: ```bash cargo xtask test-e2e --binary # builds only layer binary from source, takes mirrord binary from arg ``` If new tests are added, decorate them with `cfg_attr` attribute macro to define what the tests target. For example, a test which only tests sanity of the ephemeral container feature should be decorated with `#[cfg_attr(not(feature = "ephemeral"), ignore)]` On Linux, running tests may exhaust a large amount of RAM and crash the machine. To prevent this, limit the number of concurrent jobs by running the command with e.g. `-j 4` If running on a laptop, you might want to pass the `--no-fail-fast` flag, as some tests can timeout. This is applicable to both integration and e2e. ### IPv6 Some tests create a single-stack IPv6 service. They can only be run on clusters with IPv6 enabled. In order to test IPv6 on a local cluster on macOS, you can use Kind: 1. `brew install kind` 2. ```shell cat >kind-config.yaml < `Summary` page) with all the test log files that could be created. ## Testing mirrord manually with a sample app. From the root directory of the mirrord repository, create a new testing deployment and service: ```bash kubectl apply -f sample/kubernetes/app.yaml ```
sample/kubernetes/app.yaml ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: py-serv-deployment labels: app: py-serv spec: replicas: 1 selector: matchLabels: app: py-serv template: metadata: labels: app: py-serv spec: containers: - name: py-serv image: ghcr.io/metalbear-co/mirrord-pytest:latest ports: - containerPort: 80 env: - name: MIRRORD_FAKE_VAR_FIRST value: mirrord.is.running - name: MIRRORD_FAKE_VAR_SECOND value: "7777" --- apiVersion: v1 kind: Service metadata: labels: app: py-serv name: py-serv spec: ports: - port: 80 protocol: TCP targetPort: 80 nodePort: 30000 selector: app: py-serv sessionAffinity: None type: NodePort ```
Verify everything was created after applying the manifest ```bash ❯ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 443/TCP 3h13m py-serv NodePort 10.96.139.36 80:30000/TCP 3h8m ❯ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE py-serv-deployment 1/1 1 1 3h8m ❯ kubectl get pods NAME READY STATUS RESTARTS AGE py-serv-deployment-ff89b5974-x9tjx 1/1 Running 0 3h8m ``` ### Build and run mirrord To build this project, you will first need a [Protocol Buffer Compiler](https://grpc.io/docs/protoc-installation/) installed. We recommend using `xtask` for building mirrord, which handles all platform-specific requirements: ```bash # Debug build for your platform (auto-detected) cargo xtask build-cli # Release build cargo xtask build-cli --release # Build for specific platform cargo xtask build-cli --release --platform macos-universal cargo xtask build-cli --release --platform linux-x86_64 ``` See [xtask/README.md](xtask/README.md) for complete documentation. **Alternative (platform-specific methods):** #### macOS ```bash scripts/build_fat_mac.sh ``` #### Linux ```bash cargo build ``` The binary is created at `./target//debug/mirrord` #### Run mirrord with a local process Sample web server - `app.js` (present at `sample/node/app.mjs` in the repository)
sample/node/app.mjs ```js import { Buffer } from "node:buffer"; import { createServer } from "net"; import { open, readFile } from "fs/promises"; async function debug_file_ops() { try { const readOnlyFile = await open("/var/log/dpkg.log", "r"); console.log(">>>>> open readOnlyFile ", readOnlyFile); let buffer = Buffer.alloc(128); let bufferResult = await readOnlyFile.read(buffer); console.log(">>>>> read readOnlyFile returned with ", bufferResult); const sampleFile = await open("/tmp/node_sample.txt", "w+"); console.log(">>>>> open file ", sampleFile); const written = await sampleFile.write("mirrord sample node"); console.log(">>>>> written ", written, " bytes to file ", sampleFile); let sampleBuffer = Buffer.alloc(32); let sampleBufferResult = await sampleFile.read(buffer); console.log(">>>>> read ", sampleBufferResult, " bytes from ", sampleFile); readOnlyFile.close(); sampleFile.close(); } catch (fail) { console.error("!!! Failed file operation with ", fail); } } // debug_file_ops(); const server = createServer(); server.on("connection", handleConnection); server.listen( { host: "localhost", port: 80, }, function () { console.log("server listening to %j", server.address()); } ); function handleConnection(conn) { var remoteAddress = conn.remoteAddress + ":" + conn.remotePort; console.log("new client connection from %s", remoteAddress); conn.on("data", onConnData); conn.once("close", onConnClose); conn.on("error", onConnError); function onConnData(d) { console.log("connection data from %s: %j", remoteAddress, d.toString()); conn.write(d); } function onConnClose() { console.log("connection from %s closed", remoteAddress); } function onConnError(err) { console.log("Connection %s error: %s", remoteAddress, err.message); } } ```
```bash MIRRORD_LOG=debug target/debug/mirrord exec -i test -l debug -c --target pod/py-serv-deployment-ff89b5974-x9tjx node sample/node/app.mjs ``` > **Note:** You need to change the pod name here to the name of the pod created on your system. ``` . . . 2022-06-30T05:14:01.592418Z DEBUG hyper::proto::h1::io: flushed 299 bytes 2022-06-30T05:14:01.657977Z DEBUG hyper::proto::h1::io: parsed 4 headers 2022-06-30T05:14:01.658075Z DEBUG hyper::proto::h1::conn: incoming body is empty 2022-06-30T05:14:01.661729Z DEBUG rustls::conn: Sending warning alert CloseNotify 2022-06-30T05:14:01.678534Z DEBUG mirrord_layer::sockets: getpeername hooked 2022-06-30T05:14:01.678638Z DEBUG mirrord_layer::sockets: getsockname hooked 2022-06-30T05:14:01.678713Z DEBUG mirrord_layer::sockets: accept hooked 2022-06-30T05:14:01.905378Z DEBUG mirrord_layer::sockets: socket called domain:30, type:1 2022-06-30T05:14:01.905639Z DEBUG mirrord_layer::sockets: bind called sockfd: 32 2022-06-30T05:14:01.905821Z DEBUG mirrord_layer::sockets: bind:port: 80 2022-06-30T05:14:01.906029Z DEBUG mirrord_layer::sockets: listen called 2022-06-30T05:14:01.906182Z DEBUG mirrord_layer::sockets: bind called sockfd: 32 2022-06-30T05:14:01.906319Z DEBUG mirrord_layer::sockets: bind: no socket found for fd: 32 2022-06-30T05:14:01.906467Z DEBUG mirrord_layer::sockets: getsockname called 2022-06-30T05:14:01.906533Z DEBUG mirrord_layer::sockets: getsockname: no socket found for fd: 32 2022-06-30T05:14:01.906852Z DEBUG mirrord_layer::sockets: listen: success 2022-06-30T05:14:01.907034Z DEBUG mirrord_layer::tcp: handle_listen -> listen Listen { fake_port: 51318, real_port: 80, ipv6: true, fd: 32, } Server listening on port 80 ``` Send traffic to the Kubernetes Pod through the service. On Linux, run the following command: ```bash curl $(minikube service py-serv --url) ``` On macOS, run the command below and keep the terminal open. ```bash minikube service py-serv --url ``` Open another terminal and send traffic with `curl` to the service URL displayed by `minikube`. Check the traffic was received by the local process ```bash . . . 2022-06-30T05:17:31.877560Z DEBUG mirrord_layer::tcp: handle_incoming_message -> message Close( TcpClose { connection_id: 0, }, ) 2022-06-30T05:17:31.877608Z DEBUG mirrord_layer::tcp_mirror: handle_close -> close TcpClose { connection_id: 0, } 2022-06-30T05:17:31.877655Z DEBUG mirrord_layer::tcp: handle_incoming_message -> handled Ok( (), ) 2022-06-30T05:17:31.878193Z WARN mirrord_layer::tcp_mirror: tcp_tunnel -> exiting due to remote stream closed! 2022-06-30T05:17:31.878255Z DEBUG mirrord_layer::tcp_mirror: tcp_tunnel -> exiting OK - GET: Request completed ``` # Debugging mirrord ## mirrord console Debugging mirrord can get hard since we're running from another app flow, so the fact we're debugging might affect the program and make it unusable/buggy (due to sharing stdout with scripts/other applications). The recommended way to do it is to use `mirrord-console`. It is a small application that receives log information from different mirrord instances and prints it, controlled via the `MIRRORD_LOG` environment variable. To use mirrord console, run it: `cargo run --bin mirrord-console --features binary` Then run mirrord with the environment variable: `MIRRORD_CONSOLE_ADDR=127.0.0.1:11233` ## Debugging the Internal Proxy (`intproxy`) To see logs from the internal proxy, use the [mirrord console](#mirrord-console). To debug it with a debugger: 1. Add ```Rust tokio::time::sleep(Duration::from_secs(20)).await; ``` to [somewhere](https://github.com/metalbear-co/mirrord/blob/fa2af7f1e77a9254fb0908be40b0dae5da53d298/mirrord/cli/src/internal_proxy.rs#L145) in the start of the intproxy code. 2. Set breakpoints in VS Code in the relevant lines of the intproxy code. 3. Build mirrord. 4. Run mirrord. 5. Attach a debugger in VS Code to the intproxy process. On macOS you can do that with `Cmd` + `Shift` + `P` -> `LLDB: Attach to Process...` -> type `intproxy` and choose the `mirrord intproxy` process. The sleep you added at the start of the intproxy is time for you to attach the debugger. ## Retrieving Agent Logs You can change the minimum severity of logs emitted by the agent by setting `agent.log_level` in the mirrord config file, for example: ```json "agent": { "log_level": "mirrord=trace" } ``` By default, the agent's pod will complete and disappear shortly after the agent exits. In order to be able to retrieve the agent's logs after it crashes, set the agent's pod's TTL to a comfortable number of seconds. This configuration can be specified either as a command line argument (`--agent-ttl`), environment variable (`MIRRORD_AGENT_TTL`), or in a configuration file: ```toml [agent] ttl = 30 ``` Then, when running with some reasonable TTL, you can retrieve the agent log like this: ```bash kubectl logs -l app=mirrord --tail=-1 | less -R ``` This will retrieve the logs from all running mirrord agents, so it is only useful when just one agent pod exists. If there are currently multiple agent pods running on your cluster, you would have to run ```bash kubectl get pods ``` and find the name of the agent pod you're interested in, then run ```bash kubectl logs | less -R ``` where you would replace `` with the name of the pod. ## Operator Isolation Marker When multiple operator instances share the same cluster, each uses an isolation marker to avoid reconciling resources created by the other. The marker is set via the `OPERATOR_ISOLATION_MARKER` environment variable and defaults to `mirrord-operator`. Its value is used as a special label on operator-managed resources (agents, copy-targets, preview sessions, etc.). Both the operator and the CLI read this env var at runtime. The CLI labels the resources it creates with the marker only when the variable is set, so to have an operator running with a custom marker pick up a session's resources, run the CLI with the same `OPERATOR_ISOLATION_MARKER`. # New Hook Guidelines Adding a feature to mirrord that introduces a new hook (file system, network) can be tricky and there are a lot of edge cases we might need to cover. In order to have a more structured approach, here's the flow you should follow when working on such a feature. 1. Start with the use case. Write an example use case of the feature, for example "App needs to read credentials from a file". 2. Write a minimal app that implements the use case - so in the case of our example, an app that reads credentials from a file. Start with either Node or Python as those are most common. 3. Figure out what functions need to be hooked in order for the behavior to be run through the mirrord-agent instead of locally. We suggest using `strace`. 4. Write a doc on how you would hook and handle the cases, for example: 1. To implement use case "App needs to read credentials from a file*" 2. I will hook `open` and `read` handling calls only with flags O_RDONLY. 3. Once `open` is called, I'll send a blocking request to the agent to open the remote file, returning the return code of the operation. 4. Create an fd using `memfd`. The result will be returned to the local app, and if successful we'll save that fd into a hashmap that matches between local fd and remote fd/identifier. 5. When `read` is called, I will check if the fd being read was previously opened by us, and if it is we'll send a blocking `read` request to the agent. The result will be sent back to the caller. 6. And so on. 5. This doc should go later on to our mirrord docs for advanced developers so people can understand how stuff works 6. After approval, you can start implementing. As part of the implementation you need to add E2E tests (in the `tests` crate). For each new hook, please test: 1. A call that should be sent to the agent. Make sure it has a result that is distinguishable from the result of performing that operation locally. 2. A call that should be bypassed. Make sure the result of the operation proves it happened locally. Please test different reasons for bypassing. E.g. for file operations, make a call with a relative path, and make a call with a path that is configured to be local. If it's easier for you, you can test bypassing in an integration test of mirrord-layer (under mirrord/layer-tests/tests). 3. If the configuration supports mappings that are relevant for this hook, add test cases with those mappings, and test that the mappings take effect correctly. E.g. for file operations test with a path mapping. # Compiling on macOS `mirrord` is cross-platform and natively supports compiling from a macOS host, with one exception: `mirrord-agent` - the component/crate that runs inside of the Kubernetes cluster. `mirrord-agent` feature-gates dependencies, modules and its entrypoint to allow compilation on macOS, but produces a binary that does nothing. To be able to properly compile and work on the code (using rust-analyzer) you need to be able to cross-compile to Linux, which requires the following steps: 1. Install the x86 Linux target ```sh rustup target add x86_64-unknown-linux-gnu ``` 2. Get a C compiler capable of targeting the `x86_64-unknown-linux-gnu` triplet Usually the builtin clang compiler can handle this, if you use GCC you'll need a custom build that targets this triplet (see [homebrew-macos-cross-toolchains](https://github.com/messense/homebrew-macos-cross-toolchains) if you use brew) 3. Tell `bindgen` which C compiler to use when building `frida-gum`, the C library we use for detour hooking: ```sh export CC_x86_64_unknown_linux_gnu=(C compiler from step 2) ``` Now you can pass the Linux target to `cargo` commands: ```sh cargo check -p mirrord-agent --target x86_64-unknown-linux-gnu ``` And tell rust-analyzer to use it: ```json "rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu" ``` This is editor specific, please check [rust-analyzer's documentation](https://rust-analyzer.github.io/book/other_editors.html) to find where to put it in your editor's configuration. # Adding new target types Adding a new target type for mirrord requires changes in: 1. `mirrord-config` crate - parsing the target from the user config; 2. `mirrord-cli` crate - verifying the user config; 3. `mirrord-kube` crate - resolving the target to the Kubernetes resource; 4. `mirrord-operator` crate - defining operator's `ClusterRole`; 5. `test` crate - testing `mirrord ls` command # Testing the release workflow The standard CI workflow runs when you open a new PR, but in some cases you'll also need to test that the release workflow works properly. From [the release workflow definition](/.github/workflows/release.yaml): > Running from workflow dispatch (AKA manual) will not publish anything. This is intended for testing changes to this flow. To test the release workflow: 1. Push your changes to a branch on the main mirrord repository (not a fork) 2. Go to [the release workflow section under the Actions tab on the mirrord repository](https://github.com/metalbear-co/mirrord/actions/workflows/release.yaml) 3. On the right of the "This workflow has a `workflow_dispatch` event trigger." banner, select the dropdown labelled "Run workflow" 4. Select the branch with your changes and run You can check the run as it progresses and download the completed artifacts from the "Summary" tab in the sidebar. ## Changing the release on macOS If you're making changes to the release and/or CI workflows for macOS specifically - for example changing how the universal binary is created, you need to update the build logic in both: - [xtask/](/xtask/) - the recommended build automation tool - [scripts/build_fat_mac.sh](/scripts/build_fat_mac.sh) - the legacy build script (still supported) The xtask approach is preferred for new development as it provides better error messages, type safety, and consistency across platforms. See [xtask/README.md](xtask/README.md) for details. # Submitting a Pull Request ## Greptile Reviews Greptile may review pull requests automatically. Authors and maintainers can apply the `no-greptile` label when an automated review is not needed, such as for a typo-only or other trivial change. Opting out of reviews that are not useful helps keep usage within the included monthly review quota. If Greptile's input becomes useful later, tag `@greptileai` in the pull request to request a review explicitly. ## Typo Checks mirrord uses [`typos`](https://github.com/crate-ci/typos) to catch typos in CI. If the pipeline fails due to a false positive (e.g. a domain-specific term, identifier, or intentional spelling), you can add an exception in the [typos configuration file](typos.toml) at the root of the repository: - **Identifiers** (variable names, type names, etc.) — add to `[default.extend-identifiers]`: ```toml [default.extend-identifiers] MyTerm = "MyTerm" ``` - **Words** (plain words in prose or strings) — add to `[default.extend-words]`: ```toml [default.extend-words] myword = "myword" ``` - **Regex patterns** (e.g. to ignore URLs or structured text) — add to `extend-ignore-re` under `[default]`: ```toml [default] extend-ignore-re = [""] ``` ## Prose Checks (Vale) mirrord uses [Vale](https://vale.sh) to enforce writing style in Markdown files and Rust doc comments. CI runs it on the Markdown files at the root of the repository, except `CHANGELOG.md`, and on every Markdown file in `changelog.d/`. To run it locally: ```bash vale . ``` If Vale reports a false positive, you have two options depending on the type of issue: - **Unknown word** (spelling error on a valid technical term) - add it to the vocabulary file at [.vale/styles/config/vocabularies/Metalbear/accept.txt](.vale/styles/config/vocabularies/Metalbear/accept.txt), one word per line. - **Wrong term** (Vale flags a correct capitalization or spelling as wrong) - add a substitution rule to [.vale/styles/Metalbear/Terms.yml](.vale/styles/Metalbear/Terms.yml): ```yaml swap: WrongForm: CorrectForm ``` - **Inline suppression** (single occurrence that shouldn't be a global exception) — wrap the text with Vale's disable/enable comments: ```markdown Text that should not be checked. ``` ## Changelog Entry Add a changelog file in `changelog.d/` named `..md` **Examples:** - `1054.changed.md` (with GitHub issue) - `+some-name.added.md` (without issue) **Identifier:** - If a GitHub issue exists, use the issue number from the public [mirrord repository](https://github.com/metalbear-co/mirrord) - Use `+some-name` if no issue exists - Don't use Linear issues or private repository issue numbers **Category** (the types in [towncrier.toml](towncrier.toml)): - `added` for new functionality - `fixed` for fixed bugs - `security` for security fixes - `deprecated` for functionality that a later release will remove - `removed` for removed functionality - `internal` for anything users don't care about, e.g. changes in tests or CI - `changed` for anything else # Architecture A high level view of mirrord. ```mermaid %%{init: {'theme': 'neutral', 'themeVariables': {'lineColor': '#f00'}}}%% graph TB ExternalTraffic["External Traffic"] subgraph mirrord["mirrord"] direction TB CLI["CLI"] Layer["Layer"] Process["User Process"] IntProxy["Internal Proxy"] CLI --> Layer Layer --> Process CLI --> IntProxy IntProxy <--> Layer end subgraph K8s["Kubernetes"] Agent["mirrord Agent"] Pod[Target Pod] CRDs[Custom Resources] end subgraph Operator["Operator (Optional)"] direction TB Manager["Resource Manager"] end IntProxy <--> |"Traffic"| Agent IntProxy <--> |"File Operations"| Agent CLI -- "Creates/Deploys" --> Agent CLI -- "Uses" --> Operator Agent <--> |"Traffic"| Pod Agent <--> |"File Operations"| Pod ExternalTraffic <--> Pod Operator -- "Manages" --> Agent Operator -- "Manages" --> CRDs classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px classDef mirrord fill:#e6f3ff,stroke:#0066cc,stroke-width:2px classDef operator fill:#ffe6e6,stroke:#cc0000,stroke-width:2px classDef k8s fill:#e6ffe6,stroke:#006600,stroke-width:2px classDef agent fill:#fff2cc,stroke:#d6b656,stroke-width:2px class mirrord mirrord class Operator operator class K8s k8s class Agent agent ``` ### Flow What a user executing their app with mirrord looks like. ```mermaid %%{init: {'theme': 'neutral', 'themeVariables': {'lineColor': '#f00'}}}%% flowchart TB Start([User starts mirrord]) --> CLI[CLI parses config & args] CLI --> Deploy[Deploy mirrord Agent] Deploy --> WaitAgent[Wait for Agent to be ready] WaitAgent --> StartProxy[Start Internal Proxy] StartProxy --> InjectLayer[Inject Layer into binary] InjectLayer --> StartBinary[Start user binary] StartBinary --> |"Layer intercepts syscalls"| Layer Layer --> |"Layer forwards intercepted calls"| IntProxy[Internal Proxy] IntProxy --> |"Proxy sends requests to agent"| Agent Agent --> |"Agent executes in pod context"| Pod[Target Pod] Pod --> |"Pod returns execution results"| Agent Agent --> |"Agent sends results back"| IntProxy IntProxy --> |"Proxy forwards results"| Layer Layer --> |"Layer returns to application"| Binary[User Binary] style Start fill:#f9f9f9,stroke:#333,stroke-width:2px style CLI fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style Deploy fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style WaitAgent fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style StartProxy fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style InjectLayer fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style Layer fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style IntProxy fill:#e6f3ff,stroke:#0066cc,stroke-width:2px style Agent fill:#fff2cc,stroke:#d6b656,stroke-width:2px style Pod fill:#e6ffe6,stroke:#006600,stroke-width:2px style Binary fill:#f9f9f9,stroke:#333,stroke-width:2px ``` # Release mirrord Releases are fully automated. Under normal circumstances no manual steps are required. ## Automated flow 1. Once daily, the [Scheduled Release workflow](/.github/workflows/scheduled-release.yaml) evaluates whether a release is due: - There is at least one entry in `changelog.d/`. - The last release is older than 7 days. 2. When both conditions are met, the [Auto Release PR workflow](/.github/workflows/auto-release-pr.yaml) opens (or updates) a PR from `releases/` to `main`. The PR: - Bumps the workspace version in `Cargo.toml` (patch bump if all changes are `fixed`/`security`/`internal`; minor bump otherwise). - Updates `Cargo.lock`. - Generates `CHANGELOG.md` by consuming the `changelog.d/` fragments. 3. Review the release PR, fix any changelog issues or typos, then merge it. 4. Merging triggers the [Release workflow](/.github/workflows/release.yaml), which: - Validates the PR came from a `releases/*` branch. - Builds all platform binaries (Linux x86\_64 / aarch64, macOS universal, Windows). - Publishes the Docker images to GHCR. - Creates the GitHub release (with tag and release notes from `CHANGELOG.md`). - Publishes to Homebrew, Chocolatey, and WinGet. - Updates the `latest` git tag and notifies the infra repository. ## Triggering a release PR manually If you don't want to wait for the daily schedule, you can trigger the [Auto Release PR workflow](/.github/workflows/auto-release-pr.yaml) directly from the [Actions tab](https://github.com/metalbear-co/mirrord/actions/workflows/auto-release-pr.yaml) using the "Run workflow" button. It will create (or update) the release PR immediately. ## Manual release If you need to create a release outside the automated flow entirely, run: ```bash ./scripts/release.sh 3.333.0 ``` Ensure there are no uncommitted changes before running the script. It will: - Create a `releases/3.333.0` branch off `main`. - Bump the workspace version in `Cargo.toml` and refresh `Cargo.lock`. - Generate the changelog with `towncrier`. - Push the branch. Open a PR from that branch to `main`, then merge it — the Release workflow will fire automatically.