Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block SSH shell access to git repositories #374

Merged
merged 13 commits into from
Sep 1, 2020

Conversation

ggwadera
Copy link
Collaborator

@ggwadera ggwadera commented Aug 28, 2020

This pull request contains changes to block shell access to the server through the SSH link used as the git repository for domains.
The access is blocked by setting up a git user account restricted to only Git-related activities through a limited shell tool called git-shell that comes with Git. Reference.

What this PR does:

  • Modify the setup.sh script to create the git user account in the myproxy group, and set the correct file permissions.

    • git user has restricted shell access through git-shell
    • adds sudoers rule so the git user can run sudo -u myproxy pm2 without password
    • disable server MOTD for the gituser so it doesn't print when someone tries to SSH into the server.
    • adds a script to print a message when someone tries to SSH into the server.
  • Modify the post-receive script so the app is started by the myproxy user instead of git.

  • Change the exec commands in /src/api/mappings.ts options to use the correct group id. (Added new helper function for this)

  • Change the authorized_keys function to save the SSH keys under the git user and with additional options.

@ggwadera ggwadera changed the title Block SSH access to git repositories Block SSH shell access to git repositories Aug 28, 2020
@@ -30,6 +30,8 @@ if [ ! -d "/home/myproxy" ] ; then
cp ./scripts/post-receive /home/myproxy/.scripts/post-receive
cp ./scripts/pre-receive /home/myproxy/.scripts/pre-receive
cp ./scripts/gitignore /home/myproxy/.scripts/.gitignore
# Disable SSH MOTD message for git user
touch /home/git/.hushlogin
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disables the MOTD sent from the server when someone tries to SSH in. For example:

$ ssh [email protected]
PTY allocation request failed on channel 0
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Sep  1 13:15:29 UTC 2020

  System load:  0.72               Users logged in:          1
  Usage of /:   18.9% of 24.06GB   IPv4 address for docker0: 172.17.0.1
  Memory usage: 48%                IPv4 address for eth0:    157.245.253.104
  Swap usage:   0%                 IPv4 address for eth0:    10.10.0.5
  Processes:    130

13 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable


fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to challenges.ggwadera.xyz closed.

Becomes:

$ ssh [email protected]
PTY allocation request failed on channel 0
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to challenges.ggwadera.xyz closed.

@songz
Copy link
Collaborator

songz commented Sep 1, 2020

everything worked out for me, running https://huevon.club/ with new server. Cannot ssh in (good security)

Screen Shot 2020-09-01 at 12 38 01 AM

@songz songz merged commit 704b582 into garageScript:master Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants