mengw15 commented on code in PR #5256: URL: https://github.com/apache/texera/pull/5256#discussion_r3362187109
########## notebook-migration-service/src/main/resources/docker-compose.yml: ########## @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +name: texera-jupyter +services: + + jupyter: + build: + context: . + dockerfile: Dockerfile + container_name: texera-jupyter Review Comment: Consistency nit: `file-service/src/main/resources/docker-compose.yml` and `bin/single-node/docker-compose.yml` use `restart: unless-stopped` on every service (3/3 and 17 times respectively), plus `healthcheck:` widely (12 times in single-node, on `postgres` in file-service so `lakefs` can `depends_on: service_healthy`). This compose has neither. Adding both is cheap, matches the convention, auto-recovers Jupyter after crash / Docker daemon restart, and gives #5258's `/get-jupyter-url` health-check endpoint + any future `depends_on: jupyter: condition: service_healthy` a real target without back-filling later. Resource limits (`mem_limit` / `cpus`) aren't used anywhere in the repo, so skipping those is consistent. ########## notebook-migration-service/src/main/resources/docker-compose.yml: ########## @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +name: texera-jupyter +services: + + jupyter: + build: + context: . + dockerfile: Dockerfile + container_name: texera-jupyter + ports: + - "9100:8888" + command: > + start-notebook.sh + --NotebookApp.token='' + --NotebookApp.password='' + --NotebookApp.disable_check_xsrf=True Review Comment: The other dev-infra docker-composes in this repo (e.g., `file-service/src/main/resources/docker-compose.yml` for MinIO + Postgres + LakeFS) all set credentials on the exposed services, even if just weak defaults. This PR is the first to fully disable token + password + XSRF. I assume that's because passing a token through an iframe URL felt awkward — but Jupyter's `?token=<value>` URL-param mode is exactly what an iframe can pass through `<iframe src=...>`. Worth evaluating whether that path could keep at least token-level auth, instead of the current "anyone reachable on port 9100 can run Python" posture. ########## notebook-migration-service/src/main/resources/custom.js: ########## @@ -0,0 +1,95 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +// Use Jupyter's event system to ensure the notebook is fully loaded +require(["base/js/events"], function (events) { + events.on("kernel_ready.Kernel", function () { + + // Attach click event listener to cells + $("#notebook-container").on("click", ".cell", function (event) { + const cell = $(this); + const index = $(".cell").index(cell); + const cellContent = cell.find(".input_area").text(); + + // Get the UUID from the cell's metadata, or use "N/A" if it doesn't exist + const cellUUID = Jupyter.notebook.get_cell(index).metadata.uuid || 'N/A'; + + // Send a message to the parent window (Texera app) + window.parent.postMessage( + { action: "cellClicked", cellIndex: index, cellContent: cellContent, cellUUID: cellUUID }, + "http://localhost:4200" + ); + }); Review Comment: `events.on("kernel_ready.Kernel", ...)` fires every time a kernel becomes ready — including on kernel restart. Each restart re-runs the `$("#notebook-container").on("click", ".cell", ...)` binding, stacking another click handler on the same element. After N restarts a single cell click would post N `cellClicked` messages to the parent. Worth either guarding with a "already-bound" flag, calling `.off("click", ".cell")` before `.on(...)`, or attaching the listener once outside the `kernel_ready` callback. ########## notebook-migration-service/src/main/resources/custom.js: ########## @@ -0,0 +1,95 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +// Use Jupyter's event system to ensure the notebook is fully loaded +require(["base/js/events"], function (events) { + events.on("kernel_ready.Kernel", function () { + + // Attach click event listener to cells + $("#notebook-container").on("click", ".cell", function (event) { + const cell = $(this); + const index = $(".cell").index(cell); + const cellContent = cell.find(".input_area").text(); + + // Get the UUID from the cell's metadata, or use "N/A" if it doesn't exist + const cellUUID = Jupyter.notebook.get_cell(index).metadata.uuid || 'N/A'; + + // Send a message to the parent window (Texera app) + window.parent.postMessage( + { action: "cellClicked", cellIndex: index, cellContent: cellContent, cellUUID: cellUUID }, + "http://localhost:4200" + ); Review Comment: The Texera origin is hardcoded to `http://localhost:4200` in two places (here for `postMessage` `targetOrigin`, and at line 45 for the inbound origin check). Same for the CSP `frame-ancestors http://localhost:*` in `docker-compose.yml`. This is fine for local dev, but any deployment under a real hostname (staging, prod, codespaces, etc.) will silently drop both inbound and outbound iframe messages. **The Texera-side handler in #5263 (`JupyterPanelService.handleNotebookMessage`) already verifies origin dynamically against `notebookMigrationService.getJupyterURL()`** — so the parent side is config-driven, but the iframe side here is hardcoded. Worth aligning: env-var injection, build-time substitution, or templating from `docker-compose.yml`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
