Skip to content

[JENKINS-37899] RemoteGitImpl: Take a snapshot of the credentials before passing them to the git client proxy#235

Merged
MarkEWaite merged 1 commit intojenkinsci:masterfrom
cyrille-leclerc:JENKINS-37899
Feb 26, 2017
Merged

[JENKINS-37899] RemoteGitImpl: Take a snapshot of the credentials before passing them to the git client proxy#235
MarkEWaite merged 1 commit intojenkinsci:masterfrom
cyrille-leclerc:JENKINS-37899

Conversation

@cyrille-leclerc
Copy link
Contributor

@cyrille-leclerc cyrille-leclerc commented Feb 22, 2017

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.

…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.
@cyrille-leclerc
Copy link
Contributor Author

cc @jtnord @stephenc

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@jtnord jtnord Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@stephenc
Copy link
Member

🐝

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenc described once that there is a technique which could be used to create a test for this condition. Unfortunately, I don't recall the technique.

@stephenc, can you remind what the testing technique was that you suggested at the Jenkins World hackfest?

Copy link
Member

@jtnord jtnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐝

@jtnord
Copy link
Member

jtnord commented Feb 22, 2017

@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

@stephenc
Copy link
Member

I have zero recollection other than us both complaining about stuff in the basement

@MarkEWaite
Copy link
Contributor

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.

@stephenc
Copy link
Member

Ok I remember critiquing that tests using JenkinsRule.createOnlineSlave() might not give the correct answer as those tests still have access to the jenkins master's filesystem by virtue of running on the same machine and that might explain how you missed the issue.

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)

@MarkEWaite
Copy link
Contributor

You're correct that there are no tests which use JenkinsRule.createOnlineSlave(). There is the CredentialsTest that I created some time ago, and which I regularly use to identify working (and failing) authentication cases. The CredentialsTest does not use any remoting, and I was hoping to adapt CredentialsTest, or use createOnlineSlave to run useful remote tests.

@MarkEWaite MarkEWaite merged commit e75b299 into jenkinsci:master Feb 26, 2017
@cyrille-leclerc
Copy link
Contributor Author

Thanks @MarkEWaite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants