Provide configuration option to disable reverse DNS lookup

Adds gerrit.disableReverseDnsLookup configuration option to disable
reverse DNS lookup during audit log entry creation for identified user.
By default this option is set to 'false'.
Setting this option to 'true' would improve push time from host without
reverse DNS entry. Currently JVM will wait for 5s until it gives up
reverse resolution, this can be bypassed by changing this new
configuration option.

Based on input from old mail thread[1]

[1]
https://groups.google.com/d/msg/repo-discuss/pqq4I0-hiUY/ZmaXA0oWvbwJ

Change-Id: I13247799e2a2e8793b3c35d9fffb8f2c069e5ce0
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
Dariusz Luksza
2014-08-20 09:38:09 +02:00
committed by David Pursehouse
parent bcf97bd354
commit 45ee73ef9d
9 changed files with 116 additions and 16 deletions

View File

@@ -1502,6 +1502,12 @@ Defaults to "Report Bug".
Default change screen UI to direct users to. Valid values are
`OLD_UI` and `CHANGE_SCREEN2`. Default is `CHANGE_SCREEN2`.
[[gerrit.disableReverseDnsLookup]]gerrit.disableReverseDnsLookup::
+
Disables reverse DNS lookup during computing ref log entry for identified user.
+
Defaults to false.
[[gitweb]]
=== Section gitweb

View File

@@ -32,6 +32,8 @@ import com.google.gerrit.server.cache.h2.DefaultCacheFactory;
import com.google.gerrit.server.change.ChangeKindCacheImpl;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
import com.google.gerrit.server.config.DisableReverseDnsLookup;
import com.google.gerrit.server.config.DisableReverseDnsLookupProvider;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.git.ChangeCache;
import com.google.gerrit.server.git.TagCache;
@@ -81,6 +83,8 @@ public class BatchProgramModule extends FactoryModule {
.toProvider(CommentLinkProvider.class).in(SINGLETON);
bind(String.class).annotatedWith(CanonicalWebUrl.class)
.toProvider(CanonicalWebUrlProvider.class);
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON);
bind(IdentifiedUser.class)
.toProvider(Providers.<IdentifiedUser> of(null));
bind(CurrentUser.class).to(IdentifiedUser.class);

View File

@@ -33,6 +33,7 @@ import com.google.gerrit.server.account.ListGroupMembership;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.DisableReverseDnsLookup;
import com.google.gerrit.server.group.SystemGroupBackend;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
@@ -70,6 +71,7 @@ public class IdentifiedUser extends CurrentUser {
private final Provider<String> canonicalUrl;
private final AccountCache accountCache;
private final GroupBackend groupBackend;
private final Boolean disableReverseDnsLookup;
@Inject
public GenericFactory(
@@ -77,6 +79,7 @@ public class IdentifiedUser extends CurrentUser {
AuthConfig authConfig,
@AnonymousCowardName String anonymousCowardName,
@CanonicalWebUrl Provider<String> canonicalUrl,
@DisableReverseDnsLookup Boolean disableReverseDnsLookup,
AccountCache accountCache,
GroupBackend groupBackend) {
this.capabilityControlFactory = capabilityControlFactory;
@@ -85,6 +88,7 @@ public class IdentifiedUser extends CurrentUser {
this.canonicalUrl = canonicalUrl;
this.accountCache = accountCache;
this.groupBackend = groupBackend;
this.disableReverseDnsLookup = disableReverseDnsLookup;
}
public IdentifiedUser create(final Account.Id id) {
@@ -92,22 +96,22 @@ public class IdentifiedUser extends CurrentUser {
}
public IdentifiedUser create(Provider<ReviewDb> db, Account.Id id) {
return new IdentifiedUser(capabilityControlFactory,
authConfig, anonymousCowardName, canonicalUrl, accountCache,
groupBackend, null, db, id, null);
return new IdentifiedUser(capabilityControlFactory, authConfig,
anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, null, db, id, null);
}
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
return new IdentifiedUser(capabilityControlFactory,
authConfig, anonymousCowardName, canonicalUrl, accountCache,
groupBackend, Providers.of(remotePeer), null, id, null);
return new IdentifiedUser(capabilityControlFactory, authConfig,
anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, Providers.of(remotePeer), null, id, null);
}
public CurrentUser runAs(SocketAddress remotePeer, Account.Id id,
@Nullable CurrentUser caller) {
return new IdentifiedUser(capabilityControlFactory,
authConfig, anonymousCowardName, canonicalUrl, accountCache,
groupBackend, Providers.of(remotePeer), null, id, caller);
return new IdentifiedUser(capabilityControlFactory, authConfig,
anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, Providers.of(remotePeer), null, id, caller);
}
}
@@ -125,6 +129,7 @@ public class IdentifiedUser extends CurrentUser {
private final Provider<String> canonicalUrl;
private final AccountCache accountCache;
private final GroupBackend groupBackend;
private final Boolean disableReverseDnsLookup;
private final Provider<SocketAddress> remotePeerProvider;
private final Provider<ReviewDb> dbProvider;
@@ -137,6 +142,7 @@ public class IdentifiedUser extends CurrentUser {
final @CanonicalWebUrl Provider<String> canonicalUrl,
final AccountCache accountCache,
final GroupBackend groupBackend,
final @DisableReverseDnsLookup Boolean disableReverseDnsLookup,
final @RemotePeer Provider<SocketAddress> remotePeerProvider,
final Provider<ReviewDb> dbProvider) {
@@ -146,21 +152,22 @@ public class IdentifiedUser extends CurrentUser {
this.canonicalUrl = canonicalUrl;
this.accountCache = accountCache;
this.groupBackend = groupBackend;
this.disableReverseDnsLookup = disableReverseDnsLookup;
this.remotePeerProvider = remotePeerProvider;
this.dbProvider = dbProvider;
}
public IdentifiedUser create(Account.Id id) {
return new IdentifiedUser(capabilityControlFactory,
authConfig, anonymousCowardName, canonicalUrl, accountCache,
groupBackend, remotePeerProvider, dbProvider, id, null);
return new IdentifiedUser(capabilityControlFactory, authConfig,
anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, remotePeerProvider, dbProvider, id, null);
}
public IdentifiedUser runAs(Account.Id id, CurrentUser caller) {
return new IdentifiedUser(capabilityControlFactory,
authConfig, anonymousCowardName, canonicalUrl, accountCache,
groupBackend, remotePeerProvider, dbProvider, id, caller);
return new IdentifiedUser(capabilityControlFactory, authConfig,
anonymousCowardName, canonicalUrl, accountCache, groupBackend,
disableReverseDnsLookup, remotePeerProvider, dbProvider, id, caller);
}
}
@@ -177,6 +184,7 @@ public class IdentifiedUser extends CurrentUser {
private final AuthConfig authConfig;
private final GroupBackend groupBackend;
private final String anonymousCowardName;
private final Boolean disableReverseDnsLookup;
@Nullable
private final Provider<SocketAddress> remotePeerProvider;
@@ -194,6 +202,7 @@ public class IdentifiedUser extends CurrentUser {
private Collection<AccountProjectWatch> notificationFilters;
private CurrentUser realUser;
private IdentifiedUser(
CapabilityControl.Factory capabilityControlFactory,
final AuthConfig authConfig,
@@ -201,6 +210,7 @@ public class IdentifiedUser extends CurrentUser {
final Provider<String> canonicalUrl,
final AccountCache accountCache,
final GroupBackend groupBackend,
final Boolean disableReverseDnsLookup,
@Nullable final Provider<SocketAddress> remotePeerProvider,
@Nullable final Provider<ReviewDb> dbProvider,
final Account.Id id,
@@ -211,6 +221,7 @@ public class IdentifiedUser extends CurrentUser {
this.groupBackend = groupBackend;
this.authConfig = authConfig;
this.anonymousCowardName = anonymousCowardName;
this.disableReverseDnsLookup = disableReverseDnsLookup;
this.remotePeerProvider = remotePeerProvider;
this.dbProvider = dbProvider;
this.accountId = id;
@@ -383,7 +394,7 @@ public class IdentifiedUser extends CurrentUser {
final InetSocketAddress sa = (InetSocketAddress) remotePeer;
final InetAddress in = sa.getAddress();
host = in != null ? in.getCanonicalHostName() : sa.getHostName();
host = in != null ? getHost(in) : sa.getHostName();
}
}
if (host == null || host.isEmpty()) {
@@ -444,4 +455,11 @@ public class IdentifiedUser extends CurrentUser {
public boolean isIdentifiedUser() {
return true;
}
private String getHost(final InetAddress in) {
if (Boolean.FALSE.equals(disableReverseDnsLookup)) {
return in.getCanonicalHostName();
}
return in.getHostAddress();
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2014 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.config;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.inject.BindingAnnotation;
import java.lang.annotation.Retention;
@Retention(RUNTIME)
@BindingAnnotation
public @interface DisableReverseDnsLookup {
}

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2014 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.config;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.jgit.lib.Config;
public class DisableReverseDnsLookupProvider implements Provider<Boolean> {
private final boolean disableReverseDnsLookup;
@Inject
DisableReverseDnsLookupProvider(@GerritServerConfig Config config) {
disableReverseDnsLookup =
config.getBoolean("gerrit", null, "disableReverseDnsLookup", false);
}
@Override
public Boolean get() {
return disableReverseDnsLookup;
}
}

View File

@@ -233,6 +233,8 @@ public class GerritGlobalModule extends FactoryModule {
bind(FromAddressGenerator.class).toProvider(
FromAddressGeneratorProvider.class).in(SINGLETON);
bind(WebLinks.class).toProvider(WebLinksProvider.class).in(SINGLETON);
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toProvider(DisableReverseDnsLookupProvider.class).in(SINGLETON);
bind(PatchSetInfoFactory.class);
bind(IdentifiedUser.GenericFactory.class).in(SINGLETON);

View File

@@ -55,6 +55,7 @@ import com.google.gerrit.server.config.AllUsersNameProvider;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.DisableReverseDnsLookup;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitModule;
@@ -181,6 +182,8 @@ public class CommentsTest {
.toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class)
.toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toInstance(Boolean.FALSE);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);
bind(GitReferenceUpdated.class)

View File

@@ -38,6 +38,7 @@ import com.google.gerrit.server.config.AllUsersNameProvider;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.DisableReverseDnsLookup;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
@@ -129,6 +130,8 @@ public class AbstractChangeNotesTest {
.toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class)
.toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toInstance(Boolean.FALSE);
bind(Realm.class).to(FakeRealm.class);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);

View File

@@ -46,6 +46,7 @@ import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
import com.google.gerrit.server.config.DisableReverseDnsLookup;
import com.google.gerrit.server.config.FactoryModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
@@ -269,6 +270,8 @@ public class Util {
bind(GroupBackend.class).to(SystemGroupBackend.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class)
.toProvider(CanonicalWebUrlProvider.class);
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
.toInstance(Boolean.FALSE);
bind(String.class).annotatedWith(AnonymousCowardName.class)
.toProvider(AnonymousCowardNameProvider.class);
bind(ChangeKindCache.class).to(ChangeKindCacheImpl.NoCache.class);