Hey folks.
On Thu, 2015-02-19 at 07:49 +0530, Sitaram Chamarty wrote:
> it's nothing to do with gitolite; sshd tries to run whatever command it
> is supposed to run with $SHELL -c <your command>.
Ah thanks :) ... of course... how could I just forget ^^
Nevertheless, I feel a bit bad about this, i.e. having a user which I
must allow for SSH and which might thus be an entry point into the
system should anything be accidentally misconfigured (e.g. when someone
changes has password authentication enabled, a password set for the git
user... or maybe when the path for authorized_keys is changed in ssh)
Some ideas that came up my mind:
1) I guess just a shell that accepts any command to be executed with
sh(1) compatbile "-c" would work and you don't need bash in specific,
right?
So making things a tiny bit better would be to advise people to
use /bin/sh as shell - on e.g. Debian system this is dash,.. far less
code, far tricky bash hacks... less likely to have security exploits.
2) Even better, can't you provide a dummy shell that handles "-c", e.g.
add -c to /usr/share/gitolite3/gitolite-shell .
When gitolite-shell is invoked with -c, then make sure that *only*
gitolite's commands (i.e. what you set in commands="..." in
authorized_keys) are executed and immediately exit if something else was
given by ssh.
That would be a simple fuse to prevent "normal" shell access to the
gitolite user (and thus all repos), just in case anyone does something
stupid with his ~git/.ssh/authorized_keys or whatever).
3) ~git/.ssh/authorized_keys
Maybe it makes sense to add "no-user-rc" in addition to all lines? Or
perhaps make it configurable, whether it should be added or not (just in
case someone really uses it for whatever).
4) Restrictions at the sshd_config level using Match blocks and options
allowed therein[0].
So maybe one could come up with a recommendation for such Match block
that users can/should use with the git/gitolite users, but which doesn't
break any things.
My first idea would have been something like:
------------------------------------------------------------------------------------------------------------
Match User git,otherGitolitUser,...
#for the user “git” used with Gitolite
Match User git
#Note: Gitolite via SSH must only be used with the public key authentication method, therefore the following completely disables all others. However, the former isn’t explicitily ena
bled here, but rather “inherited” from the “global” configuration.
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no
RhostsRSAAuthentication no
HostbasedAuthentication no
HostbasedUsesNameFromPacketOnly no
KerberosAuthentication no
GSSAPIAuthentication no
RSAAuthentication no
###PubkeyAuthentication yes
AuthenticationMethods publickey
#Note: As of now, Gitolite doesn’t make use of an “authorized keys command”. It could have been “inherited” from the “global” configuration, therefore the following disables it explicitly.
AuthorizedKeysCommand none
AuthorizedKeysCommandUser invalid
#Note: Gitolite always expects the authorized keys to be found at “~/.ssh/authorized_keys”. A different value could have been “inherited” from the “global” configuration, therefore the following sets it explicitly.
AuthorizedKeysFile .ssh/authorized_keys
#Note: The following makes sure that it is really the user “git” which is used and that it isn’t an “alias for root” (in other words: any user name having the user ID 0).
AllowUsers git
PermitRootLogin no
#Note: The following restricts miscellaneous things which shouldn’t be necessary for respectively used with git or Gitolite.
PermitTTY no
AllowAgentForwarding no
PermitUserRC no
AcceptEnv LANG LC_ALL LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME
AllowStreamLocalForwarding no
StreamLocalBindMask 0777
StreamLocalBindUnlink no
AllowTcpForwarding no
PermitOpen none
PermitTunnel no
X11Forwarding no
X11UseLocalhost yes
GatewayPorts no
#Note: The following effectively forbids SSH channel multiplexing, which might have security implications (simplified: further channels “inherit” some parameters from the initiating one) if allowed.
MaxSessions 1
------------------------------------------------------------------------------------------------------------
Gitolite seems to still work with this correctly, at least at a first
glance.
So maybe you can include this in the documentation/recommendations on
how to set it up?
a) Any ideas whether git / gitolite makes use of LANG / LC_* env vars?
b) Do you think it's feasible to run gitolite inside a ChrootDirectory
(which ssh supports via that option)?
If you have questions thereon or further ideas for appropriate
hardening, that would be great :)
5) Using authorized keys command
That might be something interesting for gitolite to use/support in
future versions (but I don't know enough of its internals to tell
whether or not)
There's the authorized keys command:
AuthorizedKeysCommand /bin/foo
AuthorizedKeysCommandUser git
which can as of now be only used to get the authorized keys for a used.
But in future versions this:
https://bugzilla.mindrot.org/show_bug.cgi?id=2081
will be implemented, and so you might determine the right command="" via
the AuthorizedKeysCommand as well.
Maybe this helps to make access control easier.
Cheers,
Chris.
[0] As of OpenSSH 6.7 these options are allowed:
AcceptEnv, AllowAgentForwarding, AllowGroups, AllowTcpForwarding,
AllowUsers, AuthenticationMethods, AuthorizedKeysCommand,
AuthorizedKeysCommandUser, AuthorizedKeysFile, AuthorizedPrincipalsFile,
Banner, ChrootDirectory, DenyGroups, DenyUsers, ForceCommand,
GatewayPorts, GSSAPIAuthentication, HostbasedAuthentication,
HostbasedUsesNameFromPacketOnly, KbdInteractiveAuthentication,
KerberosAuthentication, MaxAuthTries, MaxSessions,
PasswordAuthentication, PermitEmptyPasswords, PermitOpen,
PermitRootLogin, PermitTTY, PermitTunnel, PermitUserRC,
PubkeyAuthentication, RekeyLimit, RhostsRSAAuthentication,
RSAAuthentication, X11DisplayOffset, X11Forwarding and X11UseLocalHost
And as far as I understand, also these: IPQoS, RevokedKeys,
StreamLocalBindMask, StreamLocalBindUnlink and TrustedUserCAKeys (see
https://bugzilla.mindrot.org/show_bug.cgi?id=2353)