@gresearch/marimohub-compute-armada 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,414 @@
1
+ # marimohub-compute-armada
2
+
3
+ A [marimohub](https://github.com/marimo-team/marimohub) compute adapter that runs
4
+ notebook kernels as [Armada](https://armadaproject.io/) jobs.
5
+
6
+ Loaded through marimohub's external adapter library mode (`apiVersion: 1`), so it
7
+ needs no changes to marimohub itself.
8
+
9
+ ## Status
10
+
11
+ Released on npm as
12
+ [`@gresearch/marimohub-compute-armada`](https://www.npmjs.com/package/@gresearch/marimohub-compute-armada):
13
+ the adapter bundle, and the kernel agent as static Linux binaries for amd64 and arm64 with a
14
+ Dockerfile that turns them into the agent image. No image is published; the agent image goes
15
+ into a registry your worker clusters pull from, built from the package without a Go
16
+ toolchain (see [From the npm package](#from-the-npm-package)). Each release is also a GitHub
17
+ release with the same files and build attestations; [CHANGELOG.md](CHANGELOG.md) lists what
18
+ changed.
19
+
20
+ To build from source instead, see [Deployment](#deployment);
21
+ [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) walks through a full run against a local kind
22
+ cluster.
23
+
24
+ ## How it works
25
+
26
+ Armada is a batch meta-scheduler: you submit a job to a queue and it places the pod
27
+ on one of many Kubernetes clusters. Its API has no exec, and it exists to keep cluster
28
+ credentials away from the tools that use it. Each kernel session becomes one Armada
29
+ job.
30
+
31
+ Because Armada cannot run commands in a pod, the kernel container runs a small
32
+ **agent** as PID 1 (`agent/`, a static Go binary) instead of `sleep infinity`. It
33
+ listens on a second port next to marimo's and runs the commands marimohub sends it.
34
+ Armada exposes both ports and reports both addresses, so the adapter reaches the pod
35
+ with an address Armada handed it and a token minted for that one pod, and holds no
36
+ Kubernetes credential of any kind.
37
+
38
+ The adapter is two halves: **placement** (`src/armada.ts`) submits the job and follows
39
+ its events, and the **control channel** (`src/channel.ts`) talks to the agent.
40
+ Everything above that is ordinary shell commands. The full picture, with diagrams, is
41
+ in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
42
+
43
+ ## Configuration
44
+
45
+ | Variable | Required | Description |
46
+ | ------------------------------------ | -------- | ----------------------------------------------------- |
47
+ | `ARMADA_URL` | yes | Armada REST API base URL |
48
+ | `ARMADA_QUEUE` | yes | Queue jobs are submitted to |
49
+ | `ARMADA_AGENT_IMAGE` | yes | Kernel agent image, run as the init container |
50
+ | `ARMADA_AGENT_TOKEN_SECRET` | yes | Key agent tokens derive from; 32+ chars, shared |
51
+ | `MARIMOHUB_COMPUTE_IMAGE` | no | Kernel image, first of the list (default marimo's) |
52
+ | `ARMADA_NAMESPACE` | no | Pod namespace (default `default`) |
53
+ | `ARMADA_LOOKOUT_URL` | no | Lookout base URL; enables `listActive` reconciliation |
54
+ | `ARMADA_PRIORITY_CLASS` | no | Use a non-preemptible class for interactive sessions |
55
+ | `ARMADA_KERNEL_PORT` | no | Port marimo serves on (default `2718`) |
56
+ | `ARMADA_AGENT_PORT` | no | Port the agent listens on (default `8718`) |
57
+ | `ARMADA_IMAGE_PULL_SECRETS` | no | Comma-separated secret names for private registries |
58
+ | `ARMADA_RUN_AS_USER` | no | Pod `securityContext.runAsUser`, a uid |
59
+ | `ARMADA_RUN_AS_GROUP` | no | Pod `securityContext.runAsGroup`, a gid |
60
+ | `ARMADA_FS_GROUP` | no | Pod `securityContext.fsGroup`; owns the agent volume |
61
+ | `ARMADA_COMMAND_MAX_SECONDS` | no | Backstop for one exec (default `21600`, `0` off) |
62
+ | `ARMADA_EXPOSE` | no | `nodeport` (default) or `ingress`, for both ports |
63
+ | `ARMADA_INGRESS_TLS` | no | `true` (default) or `false`; ingress only |
64
+ | `ARMADA_INGRESS_CERT_NAME` | no | TLS secret name prefix (default `<namespace>-`) |
65
+ | `ARMADA_INGRESS_ANNOTATIONS` | no | JSON object put on every job's Ingress |
66
+ | `ARMADA_POD_LABELS` | no | JSON object of labels put on every kernel pod |
67
+ | `ARMADA_POD_ANNOTATIONS` | no | JSON object of annotations put on every kernel pod |
68
+ | `ARMADA_QUEUE_BY_USER` | no | JSON object, marimohub user id to queue |
69
+ | `ARMADA_QUEUE_BY_PROJECT` | no | JSON object, marimohub project id to queue |
70
+ | `ARMADA_GPU_NODE_SELECTORS` | no | JSON object, GPU type to node selector; enables GPUs |
71
+ | `MARIMOHUB_COMPUTE_SANDBOX_HOSTNAME` | no | Public kernel hostname |
72
+ | `ARMADA_AUTH_USERNAME` | no | Basic auth, set with the password |
73
+ | `ARMADA_AUTH_PASSWORD` | no | Basic auth, set with the username |
74
+ | `ARMADA_AUTH_TOKEN` | no | Bearer token, for example from OIDC |
75
+ | `ARMADA_AUTH_TOKEN_FILE` | no | Bearer token file, re-read on every request |
76
+
77
+ Configuration is validated at startup, so a missing variable stops marimohub from
78
+ booting rather than failing at the first session.
79
+
80
+ `MARIMOHUB_COMPUTE_IMAGE` defaults to `ghcr.io/marimo-team/marimo-sandbox:latest`, marimo's
81
+ own kernel image, as marimohub's kubernetes adapter defaults its own. It is public and amd64.
82
+ `ARMADA_AGENT_IMAGE` has no default because the image is not published: build it from the
83
+ npm package's `dist/agent` or from `agent/`, and push it where the worker nodes pull from
84
+ (see Deployment). The agent port is exposed the same way as the kernel port, so whatever
85
+ reaches one reaches the other.
86
+
87
+ `ARMADA_AGENT_TOKEN_SECRET` is the key each sandbox's agent token is derived from, with
88
+ the sandbox id. Generate it once (`openssl rand -hex 32`) and give every marimohub process
89
+ running the adapter the same value: marimohub stops and snapshots a session through
90
+ whichever process gets there, and a process with a different secret is refused by the
91
+ pod. Changing it cuts every running session off from its agent, so their edits can no
92
+ longer be saved; rotate it when no sessions are running. The same holds once for the
93
+ upgrade that introduced it: pods started by an earlier version carry a random token no
94
+ process can derive, so upgrade with no sessions running, or expect those sessions' last
95
+ edits to be lost when they end.
96
+
97
+ Both images are pulled by the worker cluster, never by marimohub, so a private registry
98
+ needs a credential the cluster holds: `ARMADA_IMAGE_PULL_SECRETS` names one or more
99
+ secrets in `ARMADA_NAMESPACE`, and every pod lists them as `imagePullSecrets`. A secret's
100
+ registry host must match the image reference's host exactly (`ghcr.io` is not
101
+ `https://ghcr.io/v2/`); a mismatch does not fail at startup, it surfaces later as
102
+ `ImagePullBackOff` on the pod.
103
+
104
+ A cluster may run an admission policy that rejects a pod which does not say who it runs
105
+ as (the failure is literally `runAsUser not specified`). `ARMADA_RUN_AS_USER`,
106
+ `ARMADA_RUN_AS_GROUP` and `ARMADA_FS_GROUP` fill the pod-level `securityContext`, so the
107
+ init container that copies the agent runs with the same ids as the kernel. None has a
108
+ default: a guessed uid is wrong on every cluster that does not need one, and which uid a
109
+ kernel image tolerates is a property of that image. `ARMADA_FS_GROUP` matters as much as
110
+ `ARMADA_RUN_AS_USER`: the agent's volume is an `emptyDir`, mounted root-owned, so a
111
+ non-root user cannot have the agent written into it unless the volume is group-owned by
112
+ a group the pod runs with. Without `fsGroup`, the init container's `agent install` fails
113
+ with a permission error before the kernel ever starts.
114
+
115
+ `ARMADA_EXPOSE` decides how those two ports are reached. `nodeport` asks Armada for a
116
+ NodePort service: plaintext HTTP on the cluster's own network, which is what a local
117
+ cluster offers with nothing installed and is enough when marimohub runs beside it in
118
+ `proxy` exposure. `ingress` asks for an Ingress instead: one hostname per port, named by
119
+ the executor's `podDefaults.ingress.hostnameSuffix`, served over HTTPS by the cluster's
120
+ ingress controller. Armada's Ingress names no class, so the cluster needs a default
121
+ IngressClass or an annotation naming one; the executor's suffix must be a wildcard DNS
122
+ record for the controller; and the TLS secret, `<namespace>-` (or
123
+ `ARMADA_INGRESS_CERT_NAME`) plus the executor's `certNameSuffix`, must hold a wildcard
124
+ certificate for `*.<namespace>.<suffix>` that marimohub trusts (`NODE_EXTRA_CA_CERTS` for
125
+ a private CA). `ARMADA_INGRESS_ANNOTATIONS` lands on every job's Ingress: a source
126
+ allowlist for the agent's hostname, or a longer websocket read timeout, go there. It is
127
+ part of the submission, so everyone with Lookout access reads it (see
128
+ [What Armada shows everyone](#what-armada-shows-everyone)).
129
+
130
+ `ARMADA_POD_LABELS` and `ARMADA_POD_ANNOTATIONS` tag every kernel pod with fixed values,
131
+ for cost allocation, admission policies or `kubectl -l`. Armada copies them from the job
132
+ onto the pod, and Lookout shows the annotations. Armada does not check them at submit, so
133
+ the adapter applies Kubernetes' rules at startup: a key or a label value the cluster would
134
+ refuse stops marimohub rather than failing every session. Keys starting with `armada_` or
135
+ `armadaproject.io/`, and `marimohub/sandbox`, are reserved. The pod's Service and Ingress
136
+ do not get these labels. Both are public to everyone with Lookout access, so neither may
137
+ hold a credential (see [What Armada shows everyone](#what-armada-shows-everyone)).
138
+
139
+ ```bash
140
+ ARMADA_POD_LABELS='{"team": "quant", "example.com/cost-center": "cc-1234"}'
141
+ ARMADA_POD_ANNOTATIONS='{"example.com/contact": "quant@example.com"}'
142
+ ```
143
+
144
+ `ARMADA_QUEUE` takes every sandbox unless its owner maps elsewhere. Armada computes fair
145
+ share and priority per queue, so a queue per team or per user is how tenants are told
146
+ apart. `ARMADA_QUEUE_BY_USER` and `ARMADA_QUEUE_BY_PROJECT` map marimohub ids to queue
147
+ names, the user's entry winning; every queue named must already exist, with permissions
148
+ for the configured credential. marimohub names the owner on the calls where it holds a
149
+ session record (marimohub#301, released in 0.4.0), and the owner places a sandbox that does
150
+ not exist yet. For one that does, the queue it is in is the answer whatever the map says
151
+ today: the adapter remembers it, takes it from Lookout during `listActive`, and asks
152
+ Lookout by job set for a sandbox it has never seen, since marimohub addresses sandboxes by
153
+ id alone on several paths. A queue map therefore requires `ARMADA_LOOKOUT_URL`, and a
154
+ call Lookout cannot answer fails rather than guesses; marimohub retries it.
155
+
156
+ Compute profiles (`MARIMOHUB_COMPUTE_PROFILES`, marimohub 0.4.13 onwards) let editors
157
+ pick hardware per notebook: when creating it, later through "Change compute profile", or
158
+ for one edit session. The adapter tells marimohub it applies them, and a profile's CPU
159
+ and memory become the kernel container's requests and limits, which Armada requires to
160
+ be equal. So a kernel that outgrows its profile's memory is OOM-killed, and every session
161
+ is charged its full profile against the queue's fair share, idle or not. Offer a short
162
+ list of sizes rather than one large default. Users can only pick when
163
+ `MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors`.
164
+
165
+ ```bash
166
+ MARIMOHUB_COMPUTE_PROFILES='small:cpu=1;mem=4Gi,large:cpu=4;mem=32Gi,a100:cpu=8;mem=64Gi;gpu=A100'
167
+ MARIMOHUB_COMPUTE_PROFILE_OVERRIDE=editors
168
+ ARMADA_GPU_NODE_SELECTORS='{"A100": {"nvidia.com/gpu.product": "NVIDIA-A100-SXM4-80GB"}}'
169
+ ```
170
+
171
+ A profile's GPU count becomes an `nvidia.com/gpu` request. Its type is placement, so
172
+ GPU profiles are only on when `ARMADA_GPU_NODE_SELECTORS` maps every type the profiles
173
+ name to a `nodeSelector`; without the map, marimohub drops the GPUs from every profile
174
+ and says so at startup, and a type the map misses stops startup. The label values are
175
+ the cluster's (`kubectl get nodes -L nvidia.com/gpu.product`), and every label used must
176
+ be in each executor's `kubernetes.trackedNodeLabels`: the scheduler only sees tracked
177
+ labels, so a selector on any other stays queued for good.
178
+
179
+ Session surfaces (VS Code or OpenCode inside the sandbox, `MARIMOHUB_SURFACES`) need a
180
+ port each next to the kernel's. The adapter reads marimohub's own `MARIMOHUB_SURFACES`
181
+ and `MARIMOHUB_SURFACE_<ID>_PORT` settings, declares those ports on every pod so Armada
182
+ exposes them like the kernel's, and advertises `multiPort` exactly then. A surface port
183
+ may not be the agent's. The kernel image must ship the surface's binary.
184
+
185
+ `ARMADA_LOOKOUT_URL` gates a capability: set it and the adapter advertises
186
+ `listActive`, which marimohub's reconciler uses to enumerate live sandboxes after a
187
+ restart. Leave it unset and reconciliation is a clean no-op.
188
+
189
+ Configure at most one auth mechanism. With none, no `Authorization` header is sent,
190
+ which is what a server running `anonymousAuth: true` expects. Prefer
191
+ `ARMADA_AUTH_TOKEN_FILE` for anything that rotates: it is read per request.
192
+
193
+ ## What Armada shows everyone
194
+
195
+ Armada keeps every job submission and serves it back whole: its API returns the pod spec,
196
+ and Lookout shows the submission to everyone who can open the job. Once submitted, nothing
197
+ takes it back. Treat every value below as readable by everyone with Lookout access, for
198
+ good, and never put a credential in one. The two tables are the whole submission
199
+ (`src/armada.ts` builds it, `src/podspec.ts` the pod spec in it).
200
+
201
+ What configuration decides:
202
+
203
+ | In the submission | Comes from |
204
+ | ----------------------- | -------------------------------------------------------------------------------- |
205
+ | Queue and namespace | `ARMADA_QUEUE` (or the owner's entry in `ARMADA_QUEUE_BY_*`), `ARMADA_NAMESPACE` |
206
+ | Kernel and agent images | `MARIMOHUB_COMPUTE_IMAGE` (the one marimohub asks for), `ARMADA_AGENT_IMAGE` |
207
+ | Pod labels | `ARMADA_POD_LABELS` |
208
+ | Pod annotations | `ARMADA_POD_ANNOTATIONS` |
209
+ | Exposure | `ARMADA_EXPOSE`: a NodePort service or an Ingress |
210
+ | Ingress settings | `ARMADA_INGRESS_TLS`, `ARMADA_INGRESS_CERT_NAME`, `ARMADA_INGRESS_ANNOTATIONS` |
211
+ | Ports | `ARMADA_KERNEL_PORT`, `ARMADA_AGENT_PORT`, `MARIMOHUB_SURFACE_<ID>_PORT` |
212
+ | Surfaces | `MARIMOHUB_SURFACES`, which picks the surfaces whose ports are declared |
213
+ | Resources | The compute profile's CPU, memory and GPU count, else 1 CPU and `2Gi` |
214
+ | Node selector | `ARMADA_GPU_NODE_SELECTORS`, the entry for the profile's GPU type |
215
+ | Priority class | `ARMADA_PRIORITY_CLASS` |
216
+ | Pull secrets | `ARMADA_IMAGE_PULL_SECRETS`, the secret names only |
217
+ | Pod security context | `ARMADA_RUN_AS_USER`, `ARMADA_RUN_AS_GROUP`, `ARMADA_FS_GROUP` |
218
+ | Deadline | marimohub's session lifetime, else `ARMADA_KERNEL_MAX_LIFETIME_SECONDS` |
219
+
220
+ What the adapter fixes:
221
+
222
+ | In the submission | Value |
223
+ | --------------------------------------- | ------------------------------------------------------------------------- |
224
+ | Job set id, client id, external job URI | The sandbox id |
225
+ | Annotations | `armadaproject.io/failFast: "true"`, `marimohub/sandbox` set to the queue |
226
+ | One pod environment variable | `MH_AGENT_TOKEN_SHA256`, the SHA-256 of the agent token, never the token |
227
+ | Pod lifecycle | Restart policy `Never`, a 30s grace period |
228
+ | Agent install | The `mh-agent` volume and the init container that copies the agent in |
229
+ | Init container resources | `100m` CPU and `64Mi` memory |
230
+ | Container commands | `/agent install …` and `/mh-agent/agent --port <ARMADA_AGENT_PORT>` |
231
+ | Ingress service | `useClusterIP: true` |
232
+
233
+ Every configured value is copied in as written. The adapter checks each one's shape,
234
+ such as a valid label key or a nonblank name, and nothing more: it cannot tell a
235
+ credential from any other string. The free-form maps are where one is most likely to be
236
+ pasted: `ARMADA_POD_ANNOTATIONS`, `ARMADA_INGRESS_ANNOTATIONS`, and `ARMADA_POD_LABELS`
237
+ within the label character set. Some ingress annotations invite a credential: an
238
+ ingress-nginx `configuration-snippet` that sets an `Authorization` header, or an `auth-url`
239
+ with a key in its query string. Name a Kubernetes Secret instead
240
+ (`nginx.ingress.kubernetes.io/auth-secret`), the way `ARMADA_IMAGE_PULL_SECRETS` does for
241
+ registries.
242
+
243
+ No variable sets an environment variable on the pod, by design: a value set that way is
244
+ in the spec. `ARMADA_AGENT_TOKEN_SECRET`, the agent tokens and the `ARMADA_AUTH_*`
245
+ credentials never enter a submission; the auth credentials only ever travel as an
246
+ `Authorization` header to Armada and Lookout.
247
+
248
+ Notebook users cannot put anything in a submission: they pick a compute profile and an
249
+ image from lists the operator wrote. The credentials they give marimohub for an
250
+ integration, such as a database password or a cloud key, become the session's environment,
251
+ which the adapter hands to the pod through the agent, as `export` statements in front of
252
+ each command. So those credentials:
253
+
254
+ - stay out of the submission and out of Lookout;
255
+ - cross the cluster network as plain HTTP, readable by anyone who can watch it. The agent
256
+ speaks only HTTP, so under `ARMADA_EXPOSE=nodeport` the whole way is plaintext, and
257
+ under `ingress` with TLS only the hop from marimohub to the ingress controller is
258
+ encrypted: the controller forwards to the pod in plaintext;
259
+ - are visible to every process in the kernel container, as on any marimohub backend;
260
+ - never appear in the adapter's own error messages. Those name the command marimohub
261
+ asked for at most, never the `export` statements put in front of it, so a credential
262
+ written into the command itself would still show.
263
+
264
+ What a notebook prints stays out of Lookout as well. The kernel's output goes to a log file
265
+ inside the pod and command output goes back over the agent, so the container log, which is
266
+ what Lookout's log view shows, holds only the agent's own lines.
267
+
268
+ Before a deployment goes live, walk whoever sets these variables through this section. The
269
+ adapter keeps the credentials it handles out of the submission; it cannot stop a person
270
+ typing one into a variable that is public by design.
271
+
272
+ ## Deployment
273
+
274
+ ```bash
275
+ bun run build
276
+ docker build --platform linux/amd64 -t <registry>/marimohub-armada:<tag> .
277
+ docker build --platform linux/amd64 -t <registry>/marimohub-kernel-agent:<tag> agent
278
+ ```
279
+
280
+ Two images:
281
+
282
+ - **marimohub with the adapter baked in.** The stock marimohub image plus one `COPY`
283
+ of the bundle, with `MARIMOHUB_COMPUTE_BACKEND=library` and
284
+ `MARIMOHUB_COMPUTE_LIBRARY` preset. Armada settings come from the runtime
285
+ environment, not the image. `--platform linux/amd64` is required on Apple Silicon:
286
+ the upstream image ships no arm64 variant.
287
+ - **The agent.** A few megabytes, pushed to a registry the worker clusters can pull
288
+ from and named in `ARMADA_AGENT_IMAGE`. Build it for the architecture of the worker
289
+ nodes (or both, with `buildx`); it runs there, not where marimohub runs.
290
+
291
+ The agent authenticates every request with a per-session token whose hash travels in
292
+ the pod spec; the token is derived from `ARMADA_AGENT_TOKEN_SECRET`, so that secret is
293
+ what guards every agent. It is exposed exactly as the kernel port is: over a NodePort that is
294
+ plaintext HTTP on the cluster network, over an ingress it is a public HTTPS hostname.
295
+ Restrict the ingress to marimohub's egress address in the latter case, through
296
+ `ARMADA_INGRESS_ANNOTATIONS` or the executor's cluster-wide ingress annotations.
297
+
298
+ The kernel port is not guarded by the agent token. marimo checks a token of its own,
299
+ which marimohub mints per session, and only when `MARIMOHUB_SANDBOX_AUTH=on`. Its default
300
+ is `off`, which starts marimo with `--no-token`: anyone who can reach a kernel's address
301
+ then has a live editor in that pod. Set `MARIMOHUB_SANDBOX_AUTH=on`, as both scripts in
302
+ `dev/` do. [ARCHITECTURE.md](docs/ARCHITECTURE.md#two-tokens) explains which code sends and
303
+ checks each token.
304
+
305
+ The surface ports (`MARIMOHUB_SURFACES`) have no token under either setting: marimohub starts
306
+ VS Code and OpenCode without authentication, so each one is open to anyone who can reach its
307
+ address. Enable surfaces only where the cluster network keeps everyone but marimohub away
308
+ from the kernel pods.
309
+
310
+ ### From the npm package
311
+
312
+ The package carries everything this adapter adds: `dist/index.js`, the bundle marimohub
313
+ loads, and `dist/agent`, the agent for both worker architectures with its Dockerfile and
314
+ checksums. Install it anywhere; nothing in it runs on install.
315
+
316
+ ```bash
317
+ npm install --prefix /opt/marimohub-armada @gresearch/marimohub-compute-armada@<version>
318
+ PKG=/opt/marimohub-armada/node_modules/@gresearch/marimohub-compute-armada
319
+
320
+ # The agent image, into a registry the worker clusters pull from. Nothing runs in the
321
+ # build, so either architecture builds on any host without emulation.
322
+ docker buildx build --platform linux/amd64,linux/arm64 --push \
323
+ -t <registry>/marimohub-kernel-agent:<version> "$PKG/dist/agent"
324
+ export ARMADA_AGENT_IMAGE=<registry>/marimohub-kernel-agent:<version>
325
+
326
+ # The adapter, from where it was installed, or copied into the marimohub image as the
327
+ # Dockerfile does.
328
+ export MARIMOHUB_COMPUTE_LIBRARY="$PKG/dist/index.js"
329
+ ```
330
+
331
+ Tag the agent image with the package version and upgrade both together: an adapter can
332
+ call an agent route that an older agent does not have. To check where the files came from,
333
+ `npm audit signatures` verifies the package's provenance, and
334
+ `gh attestation verify "$PKG/dist/agent/linux-amd64/agent" --repo G-Research/marimohub-compute-armada`
335
+ verifies a binary against the attestation of the release that built it.
336
+
337
+ ### Without the marimohub image
338
+
339
+ Each marimohub release also ships `marimohub-linux-x64`, a standalone server binary for
340
+ x86-64 Linux hosts with no Node installed. It loads the adapter the same way the image
341
+ does, so the Dockerfile is optional: put the bundle somewhere on the host and point the
342
+ binary at it. The agent image is still needed, since it runs in the cluster.
343
+
344
+ ```bash
345
+ # The bundle: one self-contained file, built with `bun run build`.
346
+ sudo install -D dist/index.js /etc/marimohub/compute.mjs
347
+
348
+ # The binary, at the release the Dockerfile names, checked against its published hash.
349
+ V=0.4.13
350
+ curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64"
351
+ curl -fsSLO "https://github.com/marimo-team/marimohub/releases/download/v$V/marimohub-linux-x64.sha256"
352
+ sha256sum -c marimohub-linux-x64.sha256
353
+ sudo install marimohub-linux-x64 /usr/local/bin/marimohub
354
+
355
+ # marimohub's own settings (storage, auth, exposure) as documented upstream, then:
356
+ export MARIMOHUB_COMPUTE_BACKEND=library
357
+ export MARIMOHUB_COMPUTE_LIBRARY=/etc/marimohub/compute.mjs
358
+ export ARMADA_URL=https://armada.example.com
359
+ export ARMADA_QUEUE=marimohub
360
+ # The agent image runs in the cluster in front of each kernel; it is the one
361
+ # thing you push yourself. The kernel image defaults to the one marimo publishes.
362
+ export ARMADA_AGENT_IMAGE=<registry>/marimohub-kernel-agent:<tag>
363
+ # The key agent tokens derive from: generated once, then kept, because every
364
+ # process running the adapter needs the same one, across restarts too.
365
+ [ -f ~/.config/marimohub/agent-token-secret ] ||
366
+ (umask 077 && mkdir -p ~/.config/marimohub && openssl rand -hex 32 >~/.config/marimohub/agent-token-secret)
367
+ export ARMADA_AGENT_TOKEN_SECRET="$(cat ~/.config/marimohub/agent-token-secret)"
368
+ marimohub
369
+ ```
370
+
371
+ The path in `MARIMOHUB_COMPUTE_LIBRARY` must be absolute. On first start the binary
372
+ unpacks its bundled files to `~/.cache/marimohub-sea/<build-id>` (or
373
+ `MARIMOHUB_SEA_CACHE_DIR`); the directory has to be owned by the running user and not
374
+ reachable through a directory other users can write, so give a service account a home or
375
+ a cache directory of its own. See marimohub's deployment docs for the rest. A bad Armada
376
+ setting fails at startup here too, with the variable named.
377
+
378
+ The kernel image, `MARIMOHUB_COMPUTE_IMAGE`, is `ghcr.io/marimo-team/marimo-sandbox:latest`
379
+ unless set: marimo's own, public and amd64, with `latest-vscode`, `latest-opencode` and
380
+ `latest-tools` variants for session surfaces. Any cluster whose nodes can pull from
381
+ GitHub's registry can leave it alone; nothing about it is specific to this adapter. Set
382
+ it to your own build of marimohub's `examples/sandbox-image` when the nodes are arm64,
383
+ cannot reach the internet, or you want a pinned marimo.
384
+
385
+ The agent image is the one thing this adapter adds to the cluster, so it is the one
386
+ thing you must build and push. A real Armada cluster pulls from a registry its
387
+ executors can reach. A local kind cluster needs no registry: a kind node can be handed
388
+ an image straight from your Docker daemon.
389
+
390
+ ```bash
391
+ docker build -t marimohub-kernel-agent:local agent
392
+ kind load docker-image marimohub-kernel-agent:local --name armada
393
+ export ARMADA_AGENT_IMAGE=marimohub-kernel-agent:local
394
+ ```
395
+
396
+ `dev/run-native.sh` scripts the local arrangement end to end, including the load; see
397
+ [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md), which also covers the case where
398
+ `kind load` trips over a multi-platform image.
399
+
400
+ Verified against `ghcr.io/marimo-team/marimohub:0.4.2`, the release the adapter interface
401
+ is transcribed from; everything added since 0.3.12 is optional, so that release loads it too.
402
+
403
+ ## Documentation
404
+
405
+ - [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): the three systems, the agent, and
406
+ how one session flows through them.
407
+ - [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md): toolchain, checks, running the whole
408
+ thing locally, and what to update when you change something.
409
+ - [docs/DECISIONS.md](docs/DECISIONS.md): why the adapter is shaped the way it is, with
410
+ the evidence cited against the pinned Armada release, and what is left to a deployment.
411
+
412
+ ## License
413
+
414
+ Copyright 2026 G-Research. Apache-2.0, see [LICENSE](LICENSE).
@@ -0,0 +1,14 @@
1
+ # The kernel agent image from the prebuilt binaries in the npm package, the same
2
+ # image agent/Dockerfile builds from source. It ships as dist/agent/Dockerfile next
3
+ # to linux-amd64/ and linux-arm64/, so that directory is the build context:
4
+ #
5
+ # docker buildx build --platform linux/amd64,linux/arm64 --push \
6
+ # -t <registry>/marimohub-kernel-agent:<version> \
7
+ # node_modules/@gresearch/marimohub-compute-armada/dist/agent
8
+ #
9
+ # Nothing runs during the build, so a platform other than the host's needs no
10
+ # emulation.
11
+ FROM scratch
12
+ ARG TARGETARCH
13
+ COPY linux-${TARGETARCH}/agent /agent
14
+ ENTRYPOINT ["/agent"]
@@ -0,0 +1,2 @@
1
+ 75a9771888aae62ceaeba21ad82c6fe65237ffbc92ec4bfdc352ef8495f53b9c linux-amd64/agent
2
+ 84b31f2e150ac110c3184aaaedce6cd77a0063d6d8c58e50dc98928f2b0d3e04 linux-arm64/agent
Binary file
Binary file