-
Notifications
You must be signed in to change notification settings - Fork 157
fix(jupyter): bind notebook services to loopback by default #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Edd88-pixel
wants to merge
5
commits into
coder:main
Choose a base branch
from
Edd88-pixel:fix/jupyter-loopback-bind-585
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed43ffe
fix(jupyter): bind notebook services to loopback
Edd88-pixel b0f2d2c
Merge remote-tracking branch 'origin/main' into fix/jupyter-loopback-…
Edd88-pixel cdd85dc
fix(jupyter): address review feedback
Edd88-pixel 98d1856
fix(jupyter): satisfy README validation
Edd88-pixel 77db73e
test(jupyter-notebook): remove outdated NotebookApp assertions
Edd88-pixel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { describe, expect, it, setDefaultTimeout } from "bun:test"; | ||
| import { | ||
| execContainer, | ||
| findResourceInstance, | ||
| readFileContainer, | ||
| removeContainer, | ||
| runContainer, | ||
| runTerraformApply, | ||
| runTerraformInit, | ||
| testRequiredVariables, | ||
| writeFileContainer, | ||
| } from "~test"; | ||
|
|
||
| setDefaultTimeout(30_000); | ||
|
|
||
| describe("jupyter-notebook", async () => { | ||
| await runTerraformInit(import.meta.dir); | ||
|
|
||
| testRequiredVariables(import.meta.dir, { | ||
| agent_id: "foo", | ||
| }); | ||
|
|
||
| it("binds to loopback by default", async () => { | ||
| const state = await runTerraformApply(import.meta.dir, { | ||
| agent_id: "foo", | ||
| }); | ||
| const script = findResourceInstance(state, "coder_script").script; | ||
|
|
||
| expect(script).toContain("--ServerApp.ip='127.0.0.1'"); | ||
| expect(script).not.toContain("0.0.0.0"); | ||
| expect(script).not.toContain("--ServerApp.ip='*'"); | ||
| expect(script).toContain("--ServerApp.allow_remote_access=True"); | ||
|
|
||
| const id = await runContainer("alpine"); | ||
| try { | ||
| await execContainer(id, ["mkdir", "-p", "/root/.local/bin"]); | ||
| await writeFileContainer( | ||
| id, | ||
| "/root/.local/bin/jupyter-notebook", | ||
| "#!/bin/sh\nprintf '%s\\n' \"$@\" > /tmp/jupyter-args\n", | ||
| ); | ||
| await execContainer(id, [ | ||
| "chmod", | ||
| "755", | ||
| "/root/.local/bin/jupyter-notebook", | ||
| ]); | ||
| const result = await execContainer( | ||
| id, | ||
| ["sh", "-c", script], | ||
| [ | ||
| "--env", | ||
| "PATH=/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", | ||
| ], | ||
| ); | ||
| expect(result.exitCode).toBe(0); | ||
| const args = await readFileContainer(id, "/tmp/jupyter-args"); | ||
| expect(args).toContain("--ServerApp.ip=127.0.0.1"); | ||
| expect(args).toContain("--ServerApp.allow_remote_access=True"); | ||
| } finally { | ||
| await removeContainer(id); | ||
| } | ||
| }); | ||
|
|
||
| it("renders an explicit external host", async () => { | ||
| const state = await runTerraformApply(import.meta.dir, { | ||
| agent_id: "foo", | ||
| host: "0.0.0.0", | ||
| }); | ||
| const script = findResourceInstance(state, "coder_script").script; | ||
| expect(script).toContain("--ServerApp.ip='0.0.0.0'"); | ||
| expect(script).toContain("--ServerApp.allow_remote_access=True"); | ||
| }); | ||
|
|
||
| it("renders an IPv6 loopback host", async () => { | ||
| const state = await runTerraformApply(import.meta.dir, { | ||
| agent_id: "foo", | ||
| host: "::1", | ||
| }); | ||
| const script = findResourceInstance(state, "coder_script").script; | ||
| expect(script).toContain("--ServerApp.ip='::1'"); | ||
| }); | ||
|
|
||
| for (const unsafeHost of [ | ||
| "127.0.0.1; touch /tmp/injected", | ||
| "127.0.0.1 $(id)", | ||
| "127.0.0.1`id`", | ||
| "127.0.0.1'quoted", | ||
| ]) { | ||
| it(`rejects unsafe host ${JSON.stringify(unsafeHost)}`, async () => { | ||
| const apply = runTerraformApply(import.meta.dir, { | ||
| agent_id: "foo", | ||
| host: unsafeHost, | ||
| }); | ||
| await expect(apply).rejects.toThrow("host must contain only"); | ||
| }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| run "secure_defaults" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| agent_id = "test-agent-id" | ||
| } | ||
|
|
||
| assert { | ||
| condition = var.host == "127.0.0.1" | ||
| error_message = "host must default to 127.0.0.1" | ||
| } | ||
|
|
||
| assert { | ||
| condition = strcontains(coder_script.jupyter-notebook.script, "--ServerApp.ip='127.0.0.1'") | ||
| error_message = "the default script must bind Jupyter Notebook to 127.0.0.1" | ||
| } | ||
|
|
||
| assert { | ||
| condition = strcontains(coder_script.jupyter-notebook.script, "--ServerApp.allow_remote_access=True") | ||
| error_message = "the script must allow requests forwarded by the Coder application proxy" | ||
| } | ||
|
|
||
| assert { | ||
| condition = !strcontains(coder_script.jupyter-notebook.script, "0.0.0.0") && !strcontains(coder_script.jupyter-notebook.script, "--ServerApp.ip='*'") | ||
| error_message = "the default script must not bind Jupyter Notebook to all interfaces" | ||
| } | ||
|
|
||
| assert { | ||
| condition = coder_app.jupyter-notebook.url == "http://localhost:19999" | ||
| error_message = "the default Coder application URL must remain unchanged" | ||
| } | ||
| } | ||
|
|
||
| run "explicit_external_host" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| agent_id = "test-agent-id" | ||
| host = "0.0.0.0" | ||
| } | ||
|
|
||
| assert { | ||
| condition = strcontains(coder_script.jupyter-notebook.script, "--ServerApp.ip='0.0.0.0'") | ||
| error_message = "the script must render an explicitly configured host" | ||
| } | ||
| } | ||
|
|
||
| run "ipv6_loopback_host" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| agent_id = "test-agent-id" | ||
| host = "::1" | ||
| } | ||
|
|
||
| assert { | ||
| condition = strcontains(coder_script.jupyter-notebook.script, "--ServerApp.ip='::1'") | ||
| error_message = "the script must render an IPv6 loopback host" | ||
| } | ||
| } | ||
|
|
||
| run "unsafe_host_rejected" { | ||
| command = plan | ||
|
|
||
| variables { | ||
| agent_id = "test-agent-id" | ||
| host = "127.0.0.1; touch /tmp/injected" | ||
| } | ||
|
|
||
| expect_failures = [ | ||
| var.host, | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.