Skip to content

Commit 6e68237

Browse files
authored
feat(doctor): ensure lima ssh credentials have correct permissions (#206)
1 parent ce9fab4 commit 6e68237

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

devenv/checks/colimaSsh.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import sys
5+
6+
from devenv import constants
7+
from devenv.lib import proc
8+
from devenv.lib_check.types import checker
9+
from devenv.lib_check.types import fixer
10+
11+
tags: set[str] = {"builtin"}
12+
name = "colima ssh credentials should only be owner rw"
13+
14+
15+
def only_owner_can_rw(path: str) -> bool:
16+
mode = os.stat(path).st_mode & 0o777
17+
return mode == 0o400 or mode == 0o600
18+
19+
20+
@checker
21+
def check() -> tuple[bool, str]:
22+
lima_ssh_creds = f"{constants.home}/.colima/_lima/_config/user"
23+
24+
if not only_owner_can_rw(lima_ssh_creds):
25+
return (
26+
False,
27+
f"Permission bits on {lima_ssh_creds} are too permissive; colima startup will hang on waiting for ssh",
28+
)
29+
30+
return True, ""
31+
32+
33+
@fixer
34+
def fix() -> tuple[bool, str]:
35+
lima_ssh_creds = f"{constants.home}/.colima/_lima/_config/user"
36+
37+
os.chmod(lima_ssh_creds, 0o600)
38+
39+
try:
40+
proc.run((sys.executable, "-P", "-m", "devenv", "colima", "start"))
41+
except RuntimeError as e:
42+
return (
43+
False,
44+
f"""Failed to start colima: {e}
45+
46+
47+
========================================================================================
48+
You might want to share the last 100 lines of colima's stderr log in #discuss-dev-infra:
49+
50+
`tail -n 100 ~/.colima/_lima/colima/ha.stderr.log`
51+
""",
52+
)
53+
54+
return True, ""

0 commit comments

Comments
 (0)