Metadata-Version: 2.4
Name: podbench
Version: 0.1.0b2
Summary: debugging container for kubernetes pods
Author-email: Giles Knap <gilesknap@gmail.com>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "{}"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright {yyyy} {name of copyright owner}
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: GitHub, https://github.com/gilesknap/podbench
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typer>=0.12
Dynamic: license-file

[![CI](https://github.com/gilesknap/podbench/actions/workflows/ci.yml/badge.svg)](https://github.com/gilesknap/podbench/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/gilesknap/podbench/branch/main/graph/badge.svg)](https://codecov.io/gh/gilesknap/podbench)

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

# podbench

**A development seat — editor, gdb, a Python inner loop — inside a Kubernetes
pod, reached over nothing but your kubeconfig.**

podbench launches a debug container into a running pod (or into a sacrificial
clone of one), tunnels ssh through `kubectl exec`, and hands you the config
stanza that VS Code Remote-SSH needs. There is no port-forward to babysit, no
pod IP to reach, no file sync and no traffic interception: the editor is already
inside the cluster.

```
              laptop
     VS Code · Remote-SSH · kubectl
                 |
                 |  ssh over kubectl exec (API server only)
                 |
  +--------------+--------------------------------------+
  |  pod                                                 |
  |                                                      |
  |  +----------------------+  +----------------------+  |
  |  | app container        |  | podbench             |  |
  |  |                      |  |                      |  |
  |  | workload process     |  | sshd · vscode-server |  |
  |  |   (maybe distroless) |  | gdb · git · uv       |  |
  |  | fs visible at        |  |                      |  |
  |  |   /proc/<pid>/root   |  |                      |  |
  |  +----------------------+  +----------------------+  |
  |                                                      |
  |  shared: PID namespace (via the target)              |
  |          network namespace (always)                  |
  +------------------------------------------------------+
```

Two artefacts: a debug **container image** (`ghcr.io/gilesknap/podbench`) and a
**launcher you never have to install** — `uvx podbench` runs it straight from
PyPI, uses your kubeconfig, and puts nothing on your `PATH`.

| | Observe mode | Iterate mode |
|---|---|---|
| Command | `uvx podbench attach pod/foo` | `uvx podbench dev pod/foo` |
| What it does | adds an ephemeral container to the **live** pod | authors a **sacrificial clone** with the app idled and podbench as a real sidecar |
| Built for | distroless targets with no shell of their own; gdb against the running workload | edit → relaunch → see the change through the Service |
| Resources | shares the workload's limits, **cannot reserve its own** | has its own memory and ephemeral-storage requests |
| Risk to the workload | real — see below | none by default; the origin pod is never touched. `--cutover` moves Service traffic, and is opt-in |

## Run it

The launcher's **only runtime dependency is its CLI**, so `uvx` resolves and
runs it in one cold start, with nothing installed and nothing on your `PATH`
afterwards (uv does keep the environment in its own cache, so an unpinned
`uvx podbench` reuses that version until you ask for `podbench@latest`).
Everything it does to a cluster goes through `kubectl`; there is no client
library:

```
$ uvx podbench --version
$ uvx podbench list
no podbench containers in namespace default
```

**That will not resolve until the first PyPI release** — the name is not
published yet — so until then, run it from git instead, here and everywhere
below:

```
$ uvx --from git+https://github.com/gilesknap/podbench podbench list
```

Once published, pin it with `uvx podbench@1.0.0 <verb>`, or put it on `PATH`
permanently with `uv tool install podbench` if you would rather type `podbench`.
It is the same program either way.

Full prerequisites, cluster-side RBAC and the one-time ssh `Include` line — the
only thing that does outlive the command — are in the *Installation* tutorial.

## Observe mode in one command

```
$ uvx podbench attach pod/web-7d9f8c5b4-x2k9p -n demo
```

podbench walks a capability ladder, lands the best seat the cluster will admit,
runs its probe **inside the container it just created** and prints what that
seat can actually do:

```
seat        demo/web-7d9f8c5b4-x2k9p[podbench-1]  (new)
target      web
rung        full - root + CAP_SYS_PTRACE (live attach)
ladder
  full      landed   admitted by the API server and the kubelet
supports
  [x] live attach (gdb -p <pid>)
  [x] read-only inspect (/proc/<pid>/root, maps, environ)
  [ ] iterate (edit, relaunch, verify through the Service)
      attach shares a live pod, where killing PID 1 restarts the container...
  [x] seat (editor, shell, git)
measured
  verdict     live attach available
  blocker     none
  node        node02
  yama        absent (no Yama LSM on this node - not the same as scope 0)
  uids        seat 0, target 0

ssh config written to ~/.podbench/config.d/demo-web-7d9f8c5b4-x2k9p.conf
add this to ~/.ssh/config once:  Include ~/.podbench/config.d/*.conf
then:  ssh podbench-demo-web-7d9f8c5b4-x2k9p
```

Then **Remote-SSH: Connect to Host…** in VS Code and pick that alias.

## Iterate mode in one command

```
$ uvx podbench dev api-5f6c9b7d8-qz4tn -n demo --port 8080
$ kubectl -n demo exec -it api-5f6c9b7d8-qz4tn-podbench -c podbench -- bash
# podbench dev-bootstrap --repo https://github.com/you/api
# podbench run --port 8080 -- python -m api
```

Edit in VS Code, re-run `podbench run`, and the change is live on the pod IP.
Measured end to end: **1.18 s** per edit → relaunch → verified-through-the-Service
cycle.

---

## Read this before you attach to a live pod

These are not fine print. Each one has bitten a spike on a real cluster.

### 1. On a live pod, podbench can get your workload OOM-killed

**This is the biggest footgun.** An ephemeral container may not declare
`resources` at all — the field is rejected outright — so in Observe mode
podbench shares the workload's memory and ephemeral-storage limits and **cannot
reserve its own**. Measured working set of a VS Code session:

| | amd64 | arm64 |
|---|---|---|
| vscode-server, extracted | 680.8 MiB | 638.3 MiB |
| `ms-vscode.cpptools` | 330 MiB | 261 MiB |
| server idle RSS | ~97 MiB | ~92 MiB |
| **realistic footprint** | **1.1–1.3 GB of node disk** | |

Two ways that hurts:

* **Memory.** Exceed the pod's memory limit and the kernel OOM-kills something
  in the pod cgroup. It killed the ephemeral container in testing, but there is
  no guarantee it picks podbench rather than your workload — and **an OOM
  inside an ephemeral container is unrecoverable**: it cannot be restarted, and
  a replacement comes up with a completely fresh rootfs (server, extensions and
  host keys gone).
* **Ephemeral storage.** The debug container's writes count against the pod's
  ephemeral-storage limit. Exceed it and the kubelet **evicts the whole pod**,
  workload included. 2 GB is a realistic facility default; the numbers above
  fill most of it.

What to do about it:

* **Iterate mode is immune.** `podbench dev` authors the pod itself, so the
  sidecar carries its own memory and ephemeral-storage requests and a workspace
  volume. Anything heavier than looking belongs in a dev pod.
* **Observe mode manages it by staying slim** — a cockpit, not a workshop. Read
  the target's files through the sysroot, fetch symbols over debuginfod, install
  as few extensions as you can live with.
* **`attach --resize 6Gi`** raises the target container's memory limit in place
  before attaching. It is opt-in because it is only lightly proven: one k3s
  version, one pod, never against a `LimitRange`, a `ResourceQuota`, or a
  controller that would fight the change.

### 2. `SYS_PTRACE` is outside the Pod Security Standards, so refusal is normal

gdb *attach* needs `CAP_SYS_PTRACE`, which is in neither the **baseline** nor
the **restricted** allowed-capability list. Being refused is a mainstream
scenario, not an error state, so podbench treats it as one: it walks a ladder
with exactly two valid rungs and lands the best one the cluster admits.

| Rung | Shape | What you get |
|---|---|---|
| **full** | `runAsUser: 0` **and** `capabilities.add: [SYS_PTRACE]` | live attach to the workload's processes |
| **degraded** | the **target's own UID**, `drop: [ALL]`, `runAsNonRoot`, `RuntimeDefault` seccomp | `/proc/<pid>/root`, `maps`, `environ`; full source-level debugging of processes gdb starts itself |
| *(seat)* | whatever is admitted | editor, shell, git |

There is deliberately no rung in between. `capabilities.add: [SYS_PTRACE]` on a
container with a non-zero `runAsUser` is a **silent no-op** — the capability
lands in the bounding set only, `CapEff` stays `0`, the pod is admitted, the
container runs and ptrace fails with a bare `EPERM`. podbench refuses to author
that combination rather than tell you that you have live attach when you do not.

Even on the full rung, attach can still be denied — by Yama's `ptrace_scope`,
by seccomp, or by AppArmor, all of which are **per node** and none of which can
be cached cluster-wide. All four subsystems refuse with the same `EPERM`, so
podbench probes and **names the blocker** instead of leaving you an errno.
See the *Security model* explanation for the RBAC verbs and the
admission-policy escape hatch.

### 3. Ephemeral containers are permanent

They cannot be removed, restarted or edited. Every attach appends a container to
the pod spec for the rest of the pod's life, and a name once used is **burnt**
until the pod dies. So:

* `attach` **reconnects** to a running podbench container by default. `--new`
  appends another one; use it only when you mean it.
* Nothing may live only in the debug container's writable layer. The host key,
  the authorized keys and the sshd config are rebuilt on every start, and
  re-bootstrapping after a pod restart (~6 s) is the documented reconnect path,
  not a surprise.
* A pod restart mints a **new ssh host key**. podbench manages its own
  `known_hosts` keyed on the pod UID rather than shipping
  `StrictHostKeyChecking no`.

### 4. A dev pod never joins a Service by accident

`podbench dev` does not copy the origin's Service-selector labels unless you
pass `--take-traffic`, and `--cutover` (which repoints a Service exclusively at
the dev pod) records the original selector for an exact restore. Silently
joining a production Service is a foot-cannon; it is always opt-in.

## What is proven, and what is not

Five spikes ran against a real 6-node k3s cluster and all passed; they are kept
verbatim in the docs, along with the
*Phase 0 gate report* that is the empirical basis for most of the non-obvious behaviour here. Where
the design brief and that report disagree, the report wins.

Known-unproven, stated plainly:

* **No real VS Code GUI client has connected yet.** The transport was verified
  at the protocol level (HTTP 200 + WebSocket `101` through `ssh -L`) and the
  server was driven headlessly. Every RSS figure above is a **lower bound**; no
  extension host or language server has been measured.
* **Source provisioning for Observe mode is an open design problem.** Debian's
  debuginfod serves symbols but **not** sources, and `set sysroot` does not
  cover source lookup at all. See the
  *Debug with gdb* how-to for where sources
  actually come from.
* **In-place pod resize is lightly proven** — see `--resize` above.
* **Patch mode has never been run against a cluster.** The workflow exists
  (`podbench patch init|apply|status|consolidate`, and `patch --print-values`
  for the chart snippet) and is unit-tested, but every one of those tests drives
  a temp directory and a fake `kubectl`. `attach --mount` now puts the claim
  into the seat at the application's own mountPath, so the workflow is
  reachable end to end — but reachable is not the same as demonstrated.

What            | Where
:---:           | :---:
Source          | <https://github.com/gilesknap/podbench>
Launcher        | <https://pypi.org/project/podbench> (not published yet)
Image           | `ghcr.io/gilesknap/podbench`
Chart           | `oci://ghcr.io/gilesknap/charts/podbench`
Documentation   | <https://gilesknap.github.io/podbench>
Releases        | <https://github.com/gilesknap/podbench/releases>

<!-- README only content. Anything below this line won't be included in index.md -->

## Documentation

See <https://gilesknap.github.io/podbench> for the full documentation.

* Tutorials — [installation](docs/tutorials/installation.md),
  [your first session](docs/tutorials/first-session.md)
* How-to — [attach to a pod](docs/how-to/attach-to-a-pod.md),
  [debug with gdb](docs/how-to/debug-with-gdb.md),
  [iterate on Python](docs/how-to/iterate-on-python.md),
  [VS Code Remote-SSH](docs/how-to/vscode-remote-ssh.md),
  [the container image](docs/how-to/run-container.md)
* Reference — [CLI](docs/reference/cli.md)
* Explanations — [architecture](docs/explanations/architecture.md),
  [security](docs/explanations/security.md),
  [design brief](docs/explanations/design-brief.md),
  [Phase 0 report](docs/explanations/spikes/phase0-report.md)
