[JENKINS-37899] RemoteGitImpl: Take a snapshot of the credentials before passing them to the git client proxy#235
Conversation
…ore passing them to the git client proxy We need to snapshot of the credentials before passing them to the git client proxy so that the credentials are snapshotted before being serialised and transferred to the build agent through Jenkins remoting.
jtnord
left a comment
There was a problem hiding this comment.
I've seen the patched code work, but am not 100% confident with the snapshot.
| /** {@inheritDoc} */ | ||
| public void addCredentials(String url, StandardCredentials credentials) { | ||
| proxy.addCredentials(url, credentials); // credentials are Serializable | ||
| proxy.addCredentials(url, CredentialsProvider.snapshot(StandardCredentials.class, credentials)); // credentials are Serializable |
There was a problem hiding this comment.
So i have seen this work - but I'm at a bit of a loss as the snapshot provider would be the first that can handle StandardCredentials and the subclass may require a more specific type.
@stephenc is this correct use of this API?
There was a problem hiding this comment.
The supplied clazz is just used to maintain the type signature.
Class bestType = null;
CredentialsSnapshotTaker bestTaker = null;
for (CredentialsSnapshotTaker taker : ExtensionList.lookup(CredentialsSnapshotTaker.class)) {
if (clazz.isAssignableFrom(taker.type()) && taker.type().isInstance(credential)) {
if (bestTaker == null || bestType.isAssignableFrom(taker.type())) {
bestTaker = taker;
bestType = taker.type();
}
}
}
if (bestTaker == null) {
return credential;
}
return clazz.cast(bestTaker.snapshot(credential));
So the best fit (with the highest ordinal in case of equivalent fits) will win.
|
🐝 |
|
@MarkEWaite I recall he was referring to using the Jenkins Acceptance Test Harness with a docker fixture for your git server, possibly adding to the existing tests |
|
I have zero recollection other than us both complaining about stuff in the basement |
|
I thought that you had described a technique available in some portion of JenkinsRule that would allow an agent (or a mock agent) to be launched and then for a job to be run on that agent. With that ability, a test might be possible which confirms that there was a problem prior to this change, and that the change has now fixed the problem. |
|
Ok I remember critiquing that tests using But there do not seem to even be any such tests then that may explain how this issue was undetected. (esp as the three tests in git-plugin are not testing credentials) |
|
You're correct that there are no tests which use |
|
Thanks @MarkEWaite |
JENKINS-37899 RemoteGitImpl: Take a snapshot of the credentials before passing them to the git client proxy.
We need to snapshot of the credentials before passing them to the git client proxy so that the credentials are snapshotted before being serialized and transferred to the build agent through Jenkins remoting.