Skip to content

Commit 52869d4

Browse files
authored
Merge pull request #6 from fzs/sshAuthMethods
Set list of offered SSH authentication methods.
2 parents d0d6278 + 51e70f4 commit 52869d4

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

src/main/distrib/data/defaults.properties

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,25 @@ git.sshKeysManager = com.gitblit.transport.ssh.FileKeyManager
138138
# SINCE 1.5.0
139139
git.sshKeysFolder= ${baseFolder}/ssh
140140

141-
# Use Kerberos5 (GSS) authentication
141+
142+
# Authentication methods offered by the SSH server.
143+
# Space separated list of authentication method names that the
144+
# server shall offer. The default is "publickey password".
142145
#
143-
# SINCE 1.7.0
144-
git.sshWithKrb5 = false
146+
# Valid authentication method names are:
147+
# publickey - authenticate with SSH public key
148+
# password - authenticate with username, password
149+
# keyboard-interactive - currently synonym to 'password'
150+
# gssapi-with-mic - GSS API Kerberos 5 authentication
151+
#
152+
# This setting obsoletes the "git.sshWithKrb5" setting. To enable
153+
# Kerberos5 (GSS) authentication, add 'gssapi-with-mic' to the list.
154+
#
155+
# SINCE 1.9.0
156+
# RESTART REQUIRED
157+
# SPACE-DELIMITED
158+
git.sshAuthenticationMethods = publickey password
159+
145160

146161
# The path to a Kerberos 5 keytab.
147162
#

src/main/java/com/gitblit/transport/ssh/SshDaemon.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.security.KeyPair;
2424
import java.security.KeyPairGenerator;
2525
import java.text.MessageFormat;
26+
import java.util.List;
2627
import java.util.concurrent.atomic.AtomicBoolean;
2728

2829
import org.apache.sshd.common.io.IoServiceFactoryFactory;
@@ -55,6 +56,13 @@ public class SshDaemon {
5556

5657
private final Logger log = LoggerFactory.getLogger(SshDaemon.class);
5758

59+
private static final String AUTH_PUBLICKEY = "publickey";
60+
private static final String AUTH_PASSWORD = "password";
61+
private static final String AUTH_KBD_INTERACTIVE = "keyboard-interactive";
62+
private static final String AUTH_GSSAPI = "gssapi-with-mic";
63+
64+
65+
5866
public static enum SshSessionBackend {
5967
MINA, NIO2
6068
}
@@ -97,9 +105,6 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
97105
FileKeyPairProvider hostKeyPairProvider = new FileKeyPairProvider();
98106
hostKeyPairProvider.setFiles(new String [] { rsaKeyStore.getPath(), dsaKeyStore.getPath(), dsaKeyStore.getPath() });
99107

100-
// Client public key authenticator
101-
SshKeyAuthenticator keyAuthenticator =
102-
new SshKeyAuthenticator(gitblit.getPublicKeyManager(), gitblit);
103108

104109
// Configure the preferred SSHD backend
105110
String sshBackendStr = settings.getString(Keys.git.sshBackend,
@@ -125,11 +130,34 @@ public SshDaemon(IGitblit gitblit, WorkQueue workQueue) {
125130
sshd.setPort(addr.getPort());
126131
sshd.setHost(addr.getHostName());
127132
sshd.setKeyPairProvider(hostKeyPairProvider);
128-
sshd.setPublickeyAuthenticator(new CachingPublicKeyAuthenticator(keyAuthenticator));
129-
sshd.setPasswordAuthenticator(new UsernamePasswordAuthenticator(gitblit));
130-
if (settings.getBoolean(Keys.git.sshWithKrb5, false)) {
133+
134+
List<String> authMethods = settings.getStrings(Keys.git.sshAuthenticationMethods);
135+
if (authMethods.isEmpty()) {
136+
authMethods.add(AUTH_PUBLICKEY);
137+
authMethods.add(AUTH_PASSWORD);
138+
}
139+
// Keep backward compatibility with old setting files that use the git.sshWithKrb5 setting.
140+
if (settings.getBoolean("git.sshWithKrb5", false) && !authMethods.contains(AUTH_GSSAPI)) {
141+
authMethods.add(AUTH_GSSAPI);
142+
log.warn("git.sshWithKrb5 is obsolete!");
143+
log.warn("Please add {} to {} in gitblit.properties!", AUTH_GSSAPI, Keys.git.sshAuthenticationMethods);
144+
settings.overrideSetting(Keys.git.sshAuthenticationMethods,
145+
settings.getString(Keys.git.sshAuthenticationMethods, AUTH_PUBLICKEY + " " + AUTH_PASSWORD) + " " + AUTH_GSSAPI);
146+
}
147+
if (authMethods.contains(AUTH_PUBLICKEY)) {
148+
SshKeyAuthenticator keyAuthenticator = new SshKeyAuthenticator(gitblit.getPublicKeyManager(), gitblit);
149+
sshd.setPublickeyAuthenticator(new CachingPublicKeyAuthenticator(keyAuthenticator));
150+
log.info("SSH: adding public key authentication method.");
151+
}
152+
if (authMethods.contains(AUTH_PASSWORD) || authMethods.contains(AUTH_KBD_INTERACTIVE)) {
153+
sshd.setPasswordAuthenticator(new UsernamePasswordAuthenticator(gitblit));
154+
log.info("SSH: adding password authentication method.");
155+
}
156+
if (authMethods.contains(AUTH_GSSAPI)) {
131157
sshd.setGSSAuthenticator(new SshKrbAuthenticator(settings, gitblit));
158+
log.info("SSH: adding GSSAPI authentication method.");
132159
}
160+
133161
sshd.setSessionFactory(new SshServerSessionFactory());
134162
sshd.setFileSystemFactory(new DisabledFilesystemFactory());
135163
sshd.setTcpipForwardingFilter(new NonForwardingFilter());

0 commit comments

Comments
 (0)