gotoni 0.1.0__tar.gz

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.
gotoni-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: gotoni
3
+ Version: 0.1.0
4
+ Summary: A helper package to easily add SSH support to Modal apps.
5
+ Author: Alessio Toniolo
6
+ Project-URL: Homepage, https://github.com/alessiotoniolo/gotoni
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: modal
10
+
11
+ # gotoni (Python Package)
12
+
13
+ A Python package providing utilities to easily inject an SSH daemon into [Modal](https://modal.com/) images and securely connect to running containers.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ cd python
19
+ pip install -e .
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ import modal
26
+ import gotoni
27
+
28
+ # 1. Add SSH into your Modal Image
29
+ image = modal.Image.debian_slim().pip_install("fastapi")
30
+ image = gotoni.add_ssh(image, key_path="~/.ssh/id_rsa.pub")
31
+
32
+ app = modal.App("my-ssh-app", image=image)
33
+
34
+ # 2. Start the SSH daemon in a modal function
35
+ @app.function(timeout=3600)
36
+ def debug_session():
37
+ # This will print the SSH command to your terminal and block for the duration of the timeout
38
+ gotoni.start_ssh(port=2222, timeout=3600)
39
+ ```
gotoni-0.1.0/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # gotoni (Python Package)
2
+
3
+ A Python package providing utilities to easily inject an SSH daemon into [Modal](https://modal.com/) images and securely connect to running containers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ cd python
9
+ pip install -e .
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ import modal
16
+ import gotoni
17
+
18
+ # 1. Add SSH into your Modal Image
19
+ image = modal.Image.debian_slim().pip_install("fastapi")
20
+ image = gotoni.add_ssh(image, key_path="~/.ssh/id_rsa.pub")
21
+
22
+ app = modal.App("my-ssh-app", image=image)
23
+
24
+ # 2. Start the SSH daemon in a modal function
25
+ @app.function(timeout=3600)
26
+ def debug_session():
27
+ # This will print the SSH command to your terminal and block for the duration of the timeout
28
+ gotoni.start_ssh(port=2222, timeout=3600)
29
+ ```
@@ -0,0 +1,71 @@
1
+ import subprocess
2
+ import time
3
+ import modal
4
+
5
+ def add_ssh(image: modal.Image, key_path: str = "~/.ssh/id_rsa.pub") -> modal.Image:
6
+ """
7
+ Modifies a Modal image to configure an SSH daemon, allowing secure remote access.
8
+
9
+ This function performs the following setup steps on the provided modal.Image:
10
+ 1. Installs the 'openssh-server' package via apt.
11
+ 2. Generates host keys using 'ssh-keygen -A'.
12
+ 3. Modifies '/etc/ssh/sshd_config' to:
13
+ - Allow root login ('PermitRootLogin yes').
14
+ - Enable public key authentication ('PubkeyAuthentication yes').
15
+ - Disable password authentication ('PasswordAuthentication no').
16
+ 4. Copies the specified local SSH public key to the container's '/root/.ssh/authorized_keys'.
17
+ 5. Sets strict permissions (chmod 600) on the 'authorized_keys' file to ensure SSH accepts it.
18
+
19
+ Args:
20
+ image (modal.Image): The base Modal image to modify.
21
+ key_path (str): The path to your local public SSH key.
22
+ Defaults to "~/.ssh/id_rsa.pub".
23
+
24
+ Returns:
25
+ modal.Image: The updated Modal image with the SSH daemon and keys configured.
26
+ """
27
+ return (
28
+ image
29
+ .apt_install("openssh-server")
30
+ .run_commands(
31
+ "ssh-keygen -A",
32
+ r"sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config",
33
+ r"sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config",
34
+ r"sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config",
35
+ )
36
+ .add_local_file(key_path, "/root/.ssh/authorized_keys", copy=True)
37
+ .run_commands("chmod 600 /root/.ssh/authorized_keys")
38
+ )
39
+
40
+
41
+ def start_ssh(port: int = 2222, timeout: int = 3600):
42
+ """
43
+ Starts the SSH daemon in the Modal container and sets up a port forward to the user's local machine.
44
+
45
+ This function should be called inside your Modal function when you want to block and keep
46
+ the container alive for an SSH session. It performs these actions:
47
+ 1. Spawns the SSH daemon subprocess: `/usr/sbin/sshd -D -e -p <port>`.
48
+ 2. Uses `modal.forward` to expose the chosen port over an unencrypted Modal tunnel.
49
+ 3. Prints out the exact `ssh` command the user can copy and paste into their local
50
+ terminal or IDE to connect to the container.
51
+ 4. Blocks execution (sleeps) for the specified `timeout` duration to keep the container running.
52
+
53
+ Args:
54
+ port (int): The port on which the SSH daemon will listen inside the container.
55
+ Defaults to 2222.
56
+ timeout (int): The number of seconds to keep the container running and the tunnel open.
57
+ Defaults to 3600 (1 hour).
58
+ """
59
+ # Start the SSH daemon in the background
60
+ subprocess.Popen(["/usr/sbin/sshd", "-D", "-e", "-p", str(port)])
61
+
62
+ # Expose via Modal tunnel
63
+ with modal.forward(port=port, unencrypted=True) as tunnel:
64
+ host, tunnel_port = tunnel.tcp_socket
65
+ print(f"\n=======================================================")
66
+ print(f" SSH into container using command:")
67
+ print(f" ssh -p {tunnel_port} root@{host}")
68
+ print(f"=======================================================\n")
69
+
70
+ # Block to keep the container alive and tunnel active
71
+ time.sleep(timeout)
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: gotoni
3
+ Version: 0.1.0
4
+ Summary: A helper package to easily add SSH support to Modal apps.
5
+ Author: Alessio Toniolo
6
+ Project-URL: Homepage, https://github.com/alessiotoniolo/gotoni
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: modal
10
+
11
+ # gotoni (Python Package)
12
+
13
+ A Python package providing utilities to easily inject an SSH daemon into [Modal](https://modal.com/) images and securely connect to running containers.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ cd python
19
+ pip install -e .
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ import modal
26
+ import gotoni
27
+
28
+ # 1. Add SSH into your Modal Image
29
+ image = modal.Image.debian_slim().pip_install("fastapi")
30
+ image = gotoni.add_ssh(image, key_path="~/.ssh/id_rsa.pub")
31
+
32
+ app = modal.App("my-ssh-app", image=image)
33
+
34
+ # 2. Start the SSH daemon in a modal function
35
+ @app.function(timeout=3600)
36
+ def debug_session():
37
+ # This will print the SSH command to your terminal and block for the duration of the timeout
38
+ gotoni.start_ssh(port=2222, timeout=3600)
39
+ ```
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ gotoni/__init__.py
4
+ gotoni.egg-info/PKG-INFO
5
+ gotoni.egg-info/SOURCES.txt
6
+ gotoni.egg-info/dependency_links.txt
7
+ gotoni.egg-info/requires.txt
8
+ gotoni.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ modal
@@ -0,0 +1 @@
1
+ gotoni
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gotoni"
7
+ version = "0.1.0"
8
+ description = "A helper package to easily add SSH support to Modal apps."
9
+ readme = "README.md"
10
+ authors = [
11
+ { name="Alessio Toniolo" }
12
+ ]
13
+ requires-python = ">=3.8"
14
+ dependencies = [
15
+ "modal"
16
+ ]
17
+
18
+ [project.urls]
19
+ "Homepage" = "https://github.com/alessiotoniolo/gotoni"
gotoni-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+