From 56f53d5e21e5044041c910f98f5eb2c5fd7fce2b Mon Sep 17 00:00:00 2001 From: Matthias Lucas Jaros Date: Wed, 22 Oct 2025 10:12:07 +0200 Subject: - Added also info logging for successful attempts - merge info and error logs - Fix log being overwritten with every entry --- src/env | 2 +- src/init | 4 ++-- src/run | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/env b/src/env index 2269b13..1efd7b5 100644 --- a/src/env +++ b/src/env @@ -2,4 +2,4 @@ set _REPO_PERMISSIONS_FILE /etc/repo-permissions set _REPO_VALIDATION_REGEX "((?:\/[a-zA-Z0-9_-]+)+.git)" set _GIT_VALIDATION_REGEX "^(git-(?:upload-pack|receive-pack|upload-archive)) '$_REPO_VALIDATION_REGEX'\$" set _GIT_SUDO_GROUP gitsudo -set LOG /var/log/error.txt +set _LOG /var/log/run.txt diff --git a/src/init b/src/init index 619c97e..d02c19a 100755 --- a/src/init +++ b/src/init @@ -140,7 +140,7 @@ for repoConfig in $repos setupRepo "$repoConfig" end -# create writable log file -touch $LOG && chmod 777 $LOG +# create writable log file for run script +touch $_LOG && chmod 777 $_LOG runSSHDaemon diff --git a/src/run b/src/run index 5b18bc8..4e95098 100755 --- a/src/run +++ b/src/run @@ -8,7 +8,7 @@ set -l currentUser (whoami) set -l matcher (string match -r -g $_GIT_VALIDATION_REGEX -- "$argv") if test (count $matcher) -ne 2 # there should be two groups otherwise something is wrong - echo "$(date -Is): DENY bad_format user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG + echo "$(date -Is): DENY bad_format user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$_LOG exit 1 end @@ -22,16 +22,19 @@ set -l repoDir /(string join -n '/' srv repos (string split '/' $repo)) # check repo jail in /srv/repos if not string match -r -q -- "/srv/repos/.*" "(realpath $repoDir)" # something is for sure wrong here - echo "$(date -Is): DENY jail_escape user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG + echo "$(date -Is): DENY jail_escape user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>>$_LOG exit 2 end # check for permissions if not cat $_REPO_PERMISSIONS_FILE | grep -q -E "^$repoDir:$currentUser\$" # something is for sure wrong here - echo "$(date -Is): DENY no_permissions user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>$LOG + echo "$(date -Is): DENY no_permissions user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>>$_LOG exit 1 end +# info logging +echo "$(date -Is): ALLOW user=$currentUser ip=$SSH_CONNECTION argv=$argv" &>>$_LOG + # execute parsed git command /usr/bin/sudo -u git /usr/bin/git-shell -c "$gitCommand '$repoDir'" -- cgit v1.3.1