Skip to content

Commit 4f72c44

Browse files
authored
[JENKINS-73923] Add javadoc for SSH host key verification strategies (jenkinsci#1237)
https://issues.jenkins.io/browse/JENKINS-73923 notes that https://jenkins.io/doc/developer/extensions/git-client/ has no documentation. It says "This extension point has no Javadoc documentation". Provide the documentation for the extension point and the four implementations of the extension point so that extension point documentation will include documentation after the next release of the git client plugin. Much of the text is copied from the README or derived from the text in the README. Testing done Checked that the Javadoc renders as expected in Chrome.
1 parent f02b158 commit 4f72c44

File tree

6 files changed

+101
-1
lines changed

6 files changed

+101
-1
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ By default, Git Client plugin uses the "Known hosts file" strategy to verify all
102102
Host key verification strategies include:
103103

104104
Accept first connection::
105-
Remembers the first host key encountered for each git server and requires that the same host key must be use for later access.
105+
Remembers the first host key encountered for each git server and requires that the same host key must be used for later access.
106106
This is usually the most convenient setting for administrators while still providing ssh host key verification
107107

108108
Known hosts file::

src/main/java/org/jenkinsci/plugins/gitclient/verifier/AcceptFirstConnectionStrategy.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
import hudson.model.Descriptor;
66
import org.kohsuke.stapler.DataBoundConstructor;
77

8+
/**
9+
* Accept known hosts strategy for the {@link SshHostKeyVerificationStrategy host key verification strategy extension point}.
10+
*
11+
* <p>Remembers the first host key encountered for each git server and requires that the same host key must be used for later access.
12+
* This is usually the most convenient setting for administrators while still providing ssh host key verification
13+
*/
814
public class AcceptFirstConnectionStrategy extends SshHostKeyVerificationStrategy<AcceptFirstConnectionVerifier> {
915

16+
/**
17+
* Creates a secure shell host key verification strategy that accepts known hosts on first connection.
18+
* Remembers the first host key encountered for each git server and requires that the same host key must be used for later access.
19+
*/
1020
@DataBoundConstructor
1121
public AcceptFirstConnectionStrategy() {
1222
// stapler needs @DataBoundConstructor
1323
}
1424

25+
/** {@inheritDoc} */
1526
@Override
1627
public AcceptFirstConnectionVerifier getVerifier() {
1728
return new AcceptFirstConnectionVerifier();

src/main/java/org/jenkinsci/plugins/gitclient/verifier/KnownHostsFileVerificationStrategy.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
import hudson.model.Descriptor;
66
import org.kohsuke.stapler.DataBoundConstructor;
77

8+
/**
9+
* Known hosts strategy for the {@link SshHostKeyVerificationStrategy host key verification strategy extension point}.
10+
*
11+
* <p>Uses the existing 'known_hosts' file on the controller and on the agent.
12+
* This assumes the administrator has already configured this file on the controller and on all agents
13+
*/
814
public class KnownHostsFileVerificationStrategy extends SshHostKeyVerificationStrategy<KnownHostsFileVerifier> {
915

16+
/**
17+
* Creates a secure shell host key verification strategy that uses the existing 'known_hosts' file on the controller and on the agent.
18+
* This assumes the administrator has already configured this file on the controller and on all agents
19+
*/
1020
@DataBoundConstructor
1121
public KnownHostsFileVerificationStrategy() {
1222
// stapler needs @DataBoundConstructor
1323
}
1424

25+
/** {@inheritDoc} */
1526
@Override
1627
public KnownHostsFileVerifier getVerifier() {
1728
return new KnownHostsFileVerifier();

src/main/java/org/jenkinsci/plugins/gitclient/verifier/ManuallyProvidedKeyVerificationStrategy.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,36 @@
88
import org.kohsuke.stapler.DataBoundConstructor;
99
import org.kohsuke.stapler.QueryParameter;
1010

11+
/**
12+
* Manually provided host key strategy for the {@link SshHostKeyVerificationStrategy host key verification strategy extension point}.
13+
*
14+
* <p>Provides a form field where the administrator inserts the host keys for the git repository servers.
15+
* This works well when a small set of repository servers meet the needs of most users
16+
*/
1117
public class ManuallyProvidedKeyVerificationStrategy
1218
extends SshHostKeyVerificationStrategy<ManuallyProvidedKeyVerifier> {
1319

1420
private final String approvedHostKeys;
1521

22+
/**
23+
* Creates a secure shell host key verification strategy that uses the host keys provided by the Jenkins administrator.
24+
* This works well when a small set of repository servers meet the needs of most users
25+
*/
1626
@DataBoundConstructor
1727
public ManuallyProvidedKeyVerificationStrategy(String approvedHostKeys) {
1828
this.approvedHostKeys = approvedHostKeys.trim();
1929
}
2030

31+
/** {@inheritDoc} */
2132
@Override
2233
public ManuallyProvidedKeyVerifier getVerifier() {
2334
return new ManuallyProvidedKeyVerifier(approvedHostKeys);
2435
}
2536

37+
/**
38+
* Returns the approved host keys.
39+
* @return approved host keys
40+
*/
2641
public String getApprovedHostKeys() {
2742
return approvedHostKeys;
2843
}
@@ -42,6 +57,7 @@ public FormValidation doCheckApprovedHostKeys(@QueryParameter String approvedHos
4257
}
4358
}
4459

60+
/** {@inheritDoc} */
4561
@Override
4662
public boolean equals(Object o) {
4763
if (this == o) {
@@ -54,6 +70,7 @@ public boolean equals(Object o) {
5470
return Objects.equals(approvedHostKeys, that.approvedHostKeys);
5571
}
5672

73+
/** {@inheritDoc} */
5774
@Override
5875
public int hashCode() {
5976
return Objects.hash(approvedHostKeys);

src/main/java/org/jenkinsci/plugins/gitclient/verifier/NoHostKeyVerifier.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
55
import java.util.logging.Logger;
66
import org.eclipse.jgit.transport.sshd.ServerKeyDatabase;
77

8+
/**
9+
* Disable all host key verification by the {@link SshHostKeyVerificationStrategy host key verification strategy extension point}.
10+
*
11+
* <p>Disables all verification of ssh host keys.
12+
* <strong>Not recommended</strong> because it provides no protection from "man-in-the-middle" attacks
13+
*/
814
public class NoHostKeyVerifier extends HostKeyVerifierFactory {
915

1016
private static final Logger LOGGER = Logger.getLogger(NoHostKeyVerifier.class.getName());
1117

18+
/**
19+
* Creates a secure shell host key verification strategy that performs no host key verification.
20+
* <strong>Not recommended</strong> because it provides no protection from "man-in-the-middle" attacks.
21+
*/
1222
@Override
1323
public AbstractCliGitHostKeyVerifier forCliGit(TaskListener listener) {
1424
return tempKnownHosts -> "-o StrictHostKeyChecking=no";

src/main/java/org/jenkinsci/plugins/gitclient/verifier/SshHostKeyVerificationStrategy.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,72 @@
88
import jenkins.model.Jenkins;
99
import org.apache.commons.lang.StringUtils;
1010

11+
/**
12+
* Secure shell host key verification strategy extension point for SSH connections from the git client plugin.
13+
* Secure shell (ssh) host key verification protects an SSH client from a
14+
* <a href="https://superuser.com/questions/1657387/how-does-host-key-checking-prevent-man-in-the-middle-attack">man in the middle attack</a>.
15+
*
16+
* <p>Host key verifications strategies allow the Jenkins administrator
17+
* to choose the level of host key verification that will be
18+
* performed.
19+
*
20+
* <p>Host key verification strategies include:
21+
*
22+
* <dl>
23+
* <dt>{@link AcceptFirstConnectionStrategy Accept first connection}</dt>
24+
* <dd>
25+
* Remembers the first host key encountered for each git server and requires that the same host key must be used for later access.
26+
* This is usually the most convenient setting for administrators while still providing ssh host key verification
27+
* </dd>
28+
*
29+
* <dt>{@link KnownHostsFileVerificationStrategy Known hosts file}</dt>
30+
* <dd>
31+
* Uses the existing 'known_hosts' file on the controller and on the agent.
32+
* This assumes the administrator has already configured this file on the controller and on all agents
33+
* </dd>
34+
*
35+
* <dt>{@link ManuallyProvidedKeyVerifier Manually provided keys}</dt>
36+
* <dd>
37+
* Provides a form field where the administrator inserts the host keys for the git repository servers.
38+
* This works well when a small set of repository servers meet the needs of most users
39+
* </dd>
40+
*
41+
* <dt>{@link NoHostKeyVerificationStrategy No verification}</dt>
42+
* <dd>
43+
* Disables all verification of ssh host keys.
44+
* <strong>Not recommended</strong> because it provides no protection from "man-in-the-middle" attacks
45+
* </dd>
46+
* </dl>
47+
*
48+
* Configure the host key verification strategy from "Manage Jenkins" / "Security" / "Git Host Key Verification Configuration".
49+
* More details are available in the <a href="https://plugins.jenkins.io/git-client/#plugin-content-ssh-host-key-verification">plugin documentation</a>.
50+
*/
1151
public abstract class SshHostKeyVerificationStrategy<T extends HostKeyVerifierFactory>
1252
extends AbstractDescribableImpl<SshHostKeyVerificationStrategy<T>> implements ExtensionPoint {
1353

54+
/** Default path to the known hosts file for the current user. */
1455
public static final String KNOWN_HOSTS_DEFAULT =
1556
Path.of(System.getProperty("user.home"), ".ssh", "known_hosts").toString();
57+
1658
private static final String JGIT_KNOWN_HOSTS_PROPERTY =
1759
SshHostKeyVerificationStrategy.class.getName() + ".jgit_known_hosts_file";
1860
private static final String JGIT_KNOWN_HOSTS_FILE_PATH =
1961
StringUtils.defaultIfBlank(System.getProperty(JGIT_KNOWN_HOSTS_PROPERTY), KNOWN_HOSTS_DEFAULT);
62+
/** JGit known hosts file path for the current user.
63+
* Uses the {@link #KNOWN_HOSTS_DEFAULT default path} to the known hosts file for the current user
64+
* unless the <code>JGIT_KNOWN_HOSTS_PROPERTY</code> property is
65+
* set.
66+
*/
2067
public static final File JGIT_KNOWN_HOSTS_FILE = new File(JGIT_KNOWN_HOSTS_FILE_PATH);
2168

2269
@Override
2370
public Descriptor<SshHostKeyVerificationStrategy<T>> getDescriptor() {
2471
return (Descriptor<SshHostKeyVerificationStrategy<T>>) Jenkins.get().getDescriptorOrDie(getClass());
2572
}
2673

74+
/**
75+
* Returns the ssh host key verifier for this strategy.
76+
* @return ssh host key verifier for this strategy.
77+
*/
2778
public abstract T getVerifier();
2879
}

0 commit comments

Comments
 (0)