From 7af8f48af9ad7299bdcbcf0dfff691ff8a828165 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 9 Jun 2010 14:22:58 -0700 Subject: [PATCH] daemon: Allow httpd without sshd We now support turning off the SSHD, but leaving the HTTPD on. This matches what happens when sshd.listenAddress = off in gerrit.config, but is done much earlier in the daemon initialization. Because the SSHD has no executor threads in this setup, we cannot register the QoS filter that defers execution onto the SSHD workers. We probably don't want to flat out disable QoS here, having a way to slow down non-interactive or abusive accounts by moving them into a smaller worker pool can be very useful, but I just don't have the time to rework the QoS filter for the HTTP only case right now. Change-Id: I181acef999b1bcb3c439e26b9eec45e06cd89804 Signed-off-by: Shawn O. Pearce --- .../java/com/google/gerrit/pgm/Daemon.java | 21 +++++++------ .../google/gerrit/server/ssh/NoSshInfo.java | 29 ++++++++++++++++++ .../gerrit/server/ssh/NoSshKeyCache.java | 30 +++++++++++++++++++ .../google/gerrit/server/ssh/NoSshModule.java | 28 +++++++++++++++++ 4 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshInfo.java create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshKeyCache.java create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshModule.java diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java index 96c97b0ba1..651daa0982 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java @@ -32,6 +32,7 @@ import com.google.gerrit.server.config.CanonicalWebUrlProvider; import com.google.gerrit.server.config.GerritGlobalModule; import com.google.gerrit.server.config.MasterNodeStartup; import com.google.gerrit.server.schema.SchemaVersionCheck; +import com.google.gerrit.server.ssh.NoSshModule; import com.google.gerrit.sshd.SshModule; import com.google.gerrit.sshd.commands.MasterCommandModule; import com.google.gerrit.sshd.commands.SlaveCommandModule; @@ -114,10 +115,6 @@ public class Daemon extends SiteProgram { if (slave && httpd) { throw die("Cannot combine --slave and --enable-httpd"); } - if (httpd && !sshd) { - // TODO Support HTTP without SSH. - throw die("--enable-httpd currently requires --enable-sshd"); - } if (consoleLog) { } else { @@ -217,11 +214,15 @@ public class Daemon extends SiteProgram { private Injector createSshInjector() { final List modules = new ArrayList(); - modules.add(new SshModule()); - if (slave) { - modules.add(new SlaveCommandModule()); + if (sshd) { + modules.add(new SshModule()); + if (slave) { + modules.add(new SlaveCommandModule()); + } else { + modules.add(new MasterCommandModule()); + } } else { - modules.add(new MasterCommandModule()); + modules.add(new NoSshModule()); } return sysInjector.createChildInjector(modules); } @@ -240,7 +241,9 @@ public class Daemon extends SiteProgram { private Injector createWebInjector() { final List modules = new ArrayList(); modules.add(sshInjector.getInstance(WebModule.class)); - modules.add(sshInjector.getInstance(ProjectQoSFilter.Module.class)); + if (sshd) { + modules.add(sshInjector.getInstance(ProjectQoSFilter.Module.class)); + } return sysInjector.createChildInjector(modules); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshInfo.java new file mode 100644 index 0000000000..882181db42 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshInfo.java @@ -0,0 +1,29 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.ssh; + +import com.google.gerrit.server.ssh.SshInfo; + +import com.jcraft.jsch.HostKey; + +import java.util.Collections; +import java.util.List; + +class NoSshInfo implements SshInfo { + @Override + public List getHostKeys() { + return Collections.emptyList(); + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshKeyCache.java b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshKeyCache.java new file mode 100644 index 0000000000..ad18b3f57a --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshKeyCache.java @@ -0,0 +1,30 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.ssh; + +import com.google.gerrit.common.errors.InvalidSshKeyException; +import com.google.gerrit.reviewdb.AccountSshKey; + +class NoSshKeyCache implements SshKeyCache { + @Override + public void evict(String username) { + } + + @Override + public AccountSshKey create(AccountSshKey.Id id, String encoded) + throws InvalidSshKeyException { + throw new InvalidSshKeyException(); + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshModule.java new file mode 100644 index 0000000000..21b1a549ea --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ssh/NoSshModule.java @@ -0,0 +1,28 @@ +// Copyright (C) 2010 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.ssh; + +import com.google.inject.AbstractModule; + +/** + * Disables the SSH support by stubbing out relevant objects. + */ +public class NoSshModule extends AbstractModule { + @Override + protected void configure() { + bind(SshInfo.class).to(NoSshInfo.class); + bind(SshKeyCache.class).to(NoSshKeyCache.class); + } +}