Skip to content

Commit

Permalink
Update Jupyter UI (#225)
Browse files Browse the repository at this point in the history
* Updating notebooks (autorun + skiping init cell)

* adding /lab support for jupyter

* updating jupyter version

* enabling init_cell by default

* updating bootstrap script

* PR comments
  • Loading branch information
jt-dd authored Jul 18, 2024
1 parent 5fce5b6 commit 265f490
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 285 deletions.
2 changes: 2 additions & 0 deletions deployments/kubehound/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- jupyter
ports:
- "127.0.0.1:8888:8888"
- "127.0.0.1:8889:8889"
networks:
- kubenet
labels:
Expand All @@ -45,6 +46,7 @@ services:
- kubeui_data:/root/notebooks/shared
environment:
- NOTEBOOK_PASSWORD=admin
- GRAPH_NOTEBOOK_SSL=False

ui-invana-engine:
image: invanalabs/invana-engine:latest
Expand Down
33 changes: 5 additions & 28 deletions deployments/kubehound/notebook/BlueTeam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,17 @@
"source": [
"## Initial Setup\n",
"\n",
"Connect to the kubegraph server by running the cell below"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
" \"traversal_source\": \"g\",\n",
" \"username\": \"\",\n",
" \"password\": \"\",\n",
" \"message_serializer\": \"graphsonv3\"\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Connection is being initated directly from the docker using the env vars `GRAPH_NOTEBOOK_HOST` and `GRAPH_NOTEBOOK_PORT`. To overwrite it you can use the magic `%%graph_notebook_config` [details here](https://github.com/aws/graph-notebook/tree/main/additional-databases/gremlin-server#connecting-to-a-local-gremlin-server-from-jupyter).\n",
"\n",
"Now set the appearance customizations for the notebook. You can see a guide on possible options [here](https://github.com/aws/graph-notebook/blob/623d43827f798c33125219e8f45ad1b6e5b29513/src/graph_notebook/notebooks/01-Neptune-Database/02-Visualization/Grouping-and-Appearance-Customization-Gremlin.ipynb#L680)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"init_cell": true
},
"outputs": [],
"source": [
"%%graph_notebook_vis_options\n",
Expand Down
68 changes: 51 additions & 17 deletions deployments/kubehound/notebook/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,109 @@
# This Dockerfile is a tailored version of https://github.com/aws/graph-notebook under APACHE 2 LICENCE

FROM amazonlinux:2
FROM amazonlinux:2022

# Notebook Port
EXPOSE 8888
# Lab Port
EXPOSE 8889
USER root

# May need to be set to `pipargs=' -i https://pypi.tuna.tsinghua.edu.cn/simple '` for china regions
ENV pipargs=""
ENV WORKING_DIR="/root"
ENV WORKING_DIR="/kubehound"
ENV NOTEBOOK_DIR="${WORKING_DIR}/notebooks"
ENV NODE_VERSION=14.x
ENV EXAMPLE_NOTEBOOK_DIR="${NOTEBOOK_DIR}/kubehound_presets"
ENV NODE_VERSION=14
ENV PYTHON_VERSION=3.10
ENV GRAPH_NOTEBOOK_AUTH_MODE="DEFAULT"
ENV GRAPH_NOTEBOOK_HOST="kubegraph"
ENV GRAPH_NOTEBOOK_PROXY_PORT="8192"
ENV GRAPH_NOTEBOOK_PROXY_HOST=""
ENV GRAPH_NOTEBOOK_PORT="8182"
ENV NEPTUNE_LOAD_FROM_S3_ROLE_ARN=""
ENV AWS_REGION="us-east-1"
ENV NOTEBOOK_PORT="8888"
ENV LAB_PORT="8889"
ENV GRAPH_NOTEBOOK_SSL="True"
ENV NOTEBOOK_PASSWORD="admin"
ENV PROVIDE_EXAMPLES=0

# "when the SIGTERM signal is sent to the docker process, it immediately quits and all established connections are closed"
# "graceful stop is triggered when the SIGUSR1 signal is sent to the docker process"
STOPSIGNAL SIGUSR1

ENV GID 1000
ENV UID 1000

# Update the package list, install sudo, create a non-root user, and grant password-less sudo permissions
RUN yum update -y && \
yum install -y sudo shadow-utils && \
/usr/sbin/groupadd --gid $GID nonroot && \
adduser --uid $UID --gid $GID --system nonroot -m && \
echo 'nonroot ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

RUN mkdir -p "${WORKING_DIR}" && \
mkdir -p "${NOTEBOOK_DIR}" && \
mkdir -p "${EXAMPLE_NOTEBOOK_DIR}" && \
chown -R nonroot:nonroot "${WORKING_DIR}" && \
# Yum Update and install dependencies
yum update -y && \
yum install tar gzip git amazon-linux-extras which -y && \
yum install tar gzip git findutils -y && \
# Install NPM/Node
curl --silent --location https://rpm.nodesource.com/setup_${NODE_VERSION} | bash - && \
yum install nodejs -y && \
npm install -g opencollective && \
# Install Python 3.8
amazon-linux-extras install python3.8 -y && \
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && \
. ~/.nvm/nvm.sh && \
nvm install ${NODE_VERSION} && \
# Install Python
yum install python${PYTHON_VERSION} -y && \
# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 && \
echo 'Using python version:' && \
python3 --version && \
python3 -m ensurepip --upgrade && \
python3 -m venv /tmp/venv && \
python${PYTHON_VERSION} --version && \
python${PYTHON_VERSION} -m ensurepip --upgrade && \
python${PYTHON_VERSION} -m venv /tmp/venv && \
source /tmp/venv/bin/activate && \
cd "${WORKING_DIR}" && \
# Clone the repo and install python dependencies
git clone https://github.com/aws/graph-notebook && \
cd "${WORKING_DIR}/graph-notebook" && \
chown -R nonroot:nonroot "${WORKING_DIR}/graph-notebook" && \
pip3 install --upgrade pip setuptools wheel && \
pip3 install twine==3.7.1 && \
pip3 install -r requirements.txt && \
pip3 install --upgrade 'jupyter-server<2.0.0' && \
pip3 install "jupyterlab>=3,<4" && \
pip3 install jupyter_contrib_nbextensions && \
pip3 install jupyter_nbextensions_configurator && \
# Build the package
python3 setup.py sdist bdist_wheel && \
# install the copied repo
pip3 install . && \
# copy premade starter notebooks
cd "${WORKING_DIR}/graph-notebook" && \
jupyter contrib nbextension install --system --debug && \
jupyter nbextension enable --py --sys-prefix graph_notebook.widgets && \
jupyter nbextensions_configurator enable --system # can be skipped for notebook >=5.3 && \
# This allows for the `.ipython` to be set
python -m graph_notebook.start_jupyterlab --jupyter-dir "${NOTEBOOK_DIR}" && \
deactivate && \
# Cleanup
yum clean all && \
yum remove wget tar git -y && \
rm -rf /var/cache/yum && \
rm -rf "${WORKING_DIR}/graph-notebook" && \
rm -rf /root/.cache && \
rm -rf /root/.npm/_cacache && \
rm -rf /usr/share
cd /usr/share && \
rm -r $(ls -A | grep -v terminfo)

# Set the non-root user as the default user
USER nonroot

ADD --chown=nonroot:nonroot *.ipynb ${EXAMPLE_NOTEBOOK_DIR}/

ADD *.ipynb ${NOTEBOOK_DIR}/
# Adding support for init_cell - allow cell to be run on startup of the notebook
# Command not working jupyter nbextension enable --system init_cell && \
ADD --chown=nonroot:nonroot notebook.json /home/nonroot/.jupyter/nbconfig/notebook.json

ADD ./service.sh /usr/bin/service.sh
ADD --chown=nonroot:nonroot ./service.sh /usr/bin/service.sh
RUN chmod +x /usr/bin/service.sh

ENTRYPOINT [ "bash","-c","service.sh" ]
33 changes: 5 additions & 28 deletions deployments/kubehound/notebook/KindCluster_Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,17 @@
"source": [
"## Initial Setup\n",
"\n",
"Connect to the kubegraph server by running the cell below"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
" \"traversal_source\": \"g\",\n",
" \"username\": \"\",\n",
" \"password\": \"\",\n",
" \"message_serializer\": \"graphsonv3\"\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Connection is being initated directly from the docker using the env vars `GRAPH_NOTEBOOK_HOST` and `GRAPH_NOTEBOOK_PORT`. To overwrite it you can use the magic `%%graph_notebook_config` [details here](https://github.com/aws/graph-notebook/tree/main/additional-databases/gremlin-server#connecting-to-a-local-gremlin-server-from-jupyter).\n",
"\n",
"Now set the appearance customizations for the notebook. You can see a guide on possible options [here](https://github.com/aws/graph-notebook/blob/623d43827f798c33125219e8f45ad1b6e5b29513/src/graph_notebook/notebooks/01-Neptune-Database/02-Visualization/Grouping-and-Appearance-Customization-Gremlin.ipynb#L680)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"init_cell": true
},
"outputs": [],
"source": [
"%%graph_notebook_vis_options\n",
Expand Down
33 changes: 5 additions & 28 deletions deployments/kubehound/notebook/KubeHound.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,17 @@
"source": [
"## Initial Setup\n",
"\n",
"Connect to the kubegraph server by running the cell below"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%graph_notebook_config\n",
"{\n",
" \"host\": \"kubegraph\",\n",
" \"port\": 8182,\n",
" \"ssl\": false,\n",
" \"gremlin\": {\n",
" \"traversal_source\": \"g\",\n",
" \"username\": \"\",\n",
" \"password\": \"\",\n",
" \"message_serializer\": \"graphsonv3\"\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Connection is being initated directly from the docker using the env vars `GRAPH_NOTEBOOK_HOST` and `GRAPH_NOTEBOOK_PORT`. To overwrite it you can use the magic `%%graph_notebook_config` [details here](https://github.com/aws/graph-notebook/tree/main/additional-databases/gremlin-server#connecting-to-a-local-gremlin-server-from-jupyter).\n",
"\n",
"Now set the appearance customizations for the notebook. You can see a guide on possible options [here](https://github.com/aws/graph-notebook/blob/623d43827f798c33125219e8f45ad1b6e5b29513/src/graph_notebook/notebooks/01-Neptune-Database/02-Visualization/Grouping-and-Appearance-Customization-Gremlin.ipynb#L680)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"init_cell": true
},
"outputs": [],
"source": [
"%%graph_notebook_vis_options\n",
Expand Down
Loading

0 comments on commit 265f490

Please sign in to comment.