Skip to content

Commit 877e1e8

Browse files
committed
allow other users to read git's authorized_keys
1 parent b720398 commit 877e1e8

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

.github/workflows/system.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: uv sync
2121
- name: Set up commit0
2222
run: uv run commit0 setup simpy
23-
- name: Setup
23+
- name: Build docker images
2424
run: uv run commit0 build simpy
2525
- name: Get tests
2626
run: uv run commit0 get-tests simpy

commit0/harness/run_pytest_ids.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,19 @@ def main(
9696
context.write_test_output(test_output, timed_out)
9797
print(test_output)
9898
except EvaluationError as e:
99-
error_msg = traceback.format_exc()
100-
logger.info(error_msg)
101-
print(e)
99+
error_msg = (
100+
f"Error in running pytest for {repo}: {e}\n"
101+
f"{traceback.format_exc()}\n"
102+
f"Check ({log_file}) for more information."
103+
)
104+
raise EvaluationError(repo, error_msg, logger)
102105
except Exception as e:
103106
error_msg = (
104-
f"Error in running pytest for {spec.repo}: {e}\n"
107+
f"General error: {e}\n"
105108
f"{traceback.format_exc()}\n"
106-
# f"Check ({logger.log_file}) for more information."
109+
f"Check ({log_file}) for more information."
107110
)
108-
logger.error(error_msg)
109-
import os
110-
os.system(f"cat {log_file}")
111+
raise RuntimeError(error_msg)
111112
return str(log_dir)
112113

113114

commit0/harness/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,25 @@ def handle_command(command: str, description: str, logger: logging.Logger) -> No
8888

8989
def setup_git(logger: logging.Logger) -> None:
9090
"""Sets up the 'git' user with appropriate shell settings, .ssh directory, and git-shell as login shell."""
91+
handle_command(
92+
'sudo adduser --disabled-password --gecos "" git', "adds git user", logger
93+
)
94+
95+
# Get git user's home directory dynamically
96+
git_home_command = "getent passwd git | cut -d: -f6"
97+
stdout, stderr, exit_code = run_command(git_home_command)
98+
if exit_code != 0:
99+
raise RuntimeError(f"Error getting git user's home directory: {stderr}")
100+
git_home = stdout.strip() # Extract and trim the home directory
101+
102+
# Commands to be executed
91103
commands = [
92-
('sudo adduser --disabled-password --gecos "" git', "adds git user"),
104+
(f"sudo chmod 755 {git_home}", "make home of git viewable by others"),
93105
(
94-
"sudo -u git bash -c 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 666 ~/.ssh/authorized_keys'",
106+
f"sudo sh -c 'mkdir -p {git_home}/.ssh && chmod 755 {git_home}/.ssh && touch {git_home}/.ssh/authorized_keys && chmod 666 {git_home}/.ssh/authorized_keys'",
95107
"sets up .ssh directory for git",
96108
),
97-
("sudo touch /etc/shells", "creates /etc/shells if it doesn't exists yet"),
109+
("sudo touch /etc/shells", "creates /etc/shells if it doesn't exist yet"),
98110
("cat /etc/shells", "views available shells"),
99111
(
100112
"sudo sh -c 'which git-shell >> /etc/shells'",
@@ -106,6 +118,7 @@ def setup_git(logger: logging.Logger) -> None:
106118
),
107119
]
108120

121+
# Execute each command
109122
for command, description in commands:
110123
handle_command(command, description, logger)
111124

0 commit comments

Comments
 (0)