feat(sharing): add MARIMO_RESTRICT_SHARING env var machine-wide#9756
feat(sharing): add MARIMO_RESTRICT_SHARING env var machine-wide#9756nojaf wants to merge 2 commits into
Conversation
enforcement Injects sharing.wasm/html/molab = false as the highest-priority config override when the env var is set, so it takes precedence over any per-project or per-user config. Intended for devpod or container environments where infra admins set the variable and every notebook session inherits it without per-project configuration.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Introduces a global “restrict sharing” setting to disable external sharing options via an environment variable, and verifies the behavior with new tests.
Changes:
- Add
MARIMO_RESTRICT_SHARING(GLOBAL_SETTINGS.RESTRICT_SHARING) to globally disable sharing affordances. - Inject a highest-priority config override that forces
"sharing": {"wasm": False, "html": False, "molab": False}when enabled. - Add tests ensuring the restriction is applied and that it overrides user config.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/_config/test_manager.py | Adds test coverage for the new restrict-sharing behavior and precedence over user config. |
| marimo/_config/settings.py | Defines the new global setting RESTRICT_SHARING sourced from MARIMO_RESTRICT_SHARING. |
| marimo/_config/manager.py | Applies the sharing restriction override to config output when the global flag is enabled. |
Move the sharing restriction out of EnvConfigManager and into a final clamp at the end of MarimoConfigManager.get_config_overrides(), applied after all partials are merged. A later with_overrides() appends a partial after EnvConfigManager, so injecting in a single reader did not actually guarantee the restriction could not be re-enabled; clamping post-merge makes it unconditional and covers both get_config() and the overrides served to the frontend. Rework the tests to assert on the resolved config (overrides clamp, precedence over user config, precedence over a later with_overrides, and untouched config when the flag is off) and make the disabled case deterministic.
|
Thanks! I think that a new |
|
Thanks @dmadisetti, that makes sense. Happy to pull it out into a dedicated reader ( One nuance I want to confirm before I push: the reason it currently lives in Two ways to keep that guarantee with the cleaner reader design:
Do you have a preference? My lean is (1) since it keeps the machine-wide enforcement intent, but (2) is simpler and matches your comment most literally. Either way I'll move the logic into the new reader. |
📝 Summary
This is a follow up to #9578. That PR made the
sharing.wasm,sharing.html, andsharing.molabconfig flags control what sharing affordances the UI surfaces, and added themolabflag. During #9578 the maintainers (@mscolnick via DM) asked that theMARIMO_RESTRICT_SHARINGenv var be split out into its own PR, so this is that separate change.What changed
marimo/_config/settings.py: addRESTRICT_SHARINGtoGlobalSettings, reading theMARIMO_RESTRICT_SHARINGenv var.marimo/_config/manager.py: when the env var is set,EnvConfigManager.get_config()injectssharing = {"wasm": False, "html": False, "molab": False}.EnvConfigManageris the last (highest priority) partial inget_default_config_manager, so this override takes precedence over any per-project or per-user TOML config.tests/_config/test_manager.py: tests that the flag injects the all-false sharing config, that nothing is injected when the flag is off, and that the env override wins over a user config that explicitly enables sharing.Why we want this
The
sharing.*config flags require every project or user to opt in. In our company we run marimo in managed devpod/container environments, and there is no reliable way to ensure every user has the flag set in their own config, since users have admin access to their own environment and can edit config files.MARIMO_RESTRICT_SHARING=1lets infra admins set the restriction once at the container/pod spec level, outside the user's control, and have every notebook session inherit it without per-project configuration.Scope and honest framing
This is a UI-hiding/policy control, not a server-side security boundary. #9578 deliberately removed the server-side 403 gates (
exporting != sharing), so the sharing config only drives what the UI surfaces (the editor Share dropdown and the molab button baked into exported HTML). This env var hides those affordances machine-wide but does not block a determined user: exported HTML still embeds source and endpoints still serve code. We pair it with network egress filtering (blockingmarimo.app,molab.marimo.io,static.marimo.app) for defence in depth. Note also thatMARIMO_RESTRICT_SHARING=0as a command prefix overrides the env var for that process, so it should be set in the devpod/container spec rather than inside the container.📋 Pre-Review Checklist
✅ Merge Checklist
//cc @Light2Dark @akshayka, @dmadisetti