Skip to content

[JENKINS-38831] Add support for credential tracking in SecretBuildWrapper and BindingStep#27

Merged
jglick merged 3 commits into
jenkinsci:masterfrom
iwarapter:master
Nov 1, 2016
Merged

[JENKINS-38831] Add support for credential tracking in SecretBuildWrapper and BindingStep#27
jglick merged 3 commits into
jenkinsci:masterfrom
iwarapter:master

Conversation

@iwarapter

@iwarapter iwarapter commented Oct 18, 2016

Copy link
Copy Markdown
Contributor

@iwarapter

Copy link
Copy Markdown
Contributor Author

This is currently setup to track the instances of builds using the credential, would we want this to be that granular or do we just want the Job?

@jglick jglick changed the title JENKINS-38831 add support for credential tracking in SecretBuildWrapp… [JENKINS-38831] Add support for credential tracking in SecretBuildWrapper and BindingStep Oct 24, 2016

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Binary-incompatible, which is easily fixed I think; otherwise looks LGTM.


/** Type token. */
protected abstract Class<C> type();
public abstract Class<C> type();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Binary-incompatible for external implementations, I think.

Probably solvable by adding a public final method to MultiBinding to set up the tracking.

unbinders.add(environment.getUnbinder());
overrides.putAll(environment.getValues());
IdCredentials id = CredentialsProvider.findCredentialById(binding.getCredentialsId(), binding.type(), run);
CredentialsProvider.track(run, id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps also desirable to call track(Node, Credentials). (For BindingStep, just inject a Node; for SecretBuildWrapper, use the method on AbstractBuild IIRC.) @stephenc any guidance?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So track(Node, C) is to track when the credential is used to launch that node. Not the case here. We already have tracking between the Run and the Node(s) it ran on.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, not in the case of Pipeline builds generally, but I see your point—track(Node, Credentials) is irrelevant here. I will file a PR to fix the Javadoc.

@stephenc stephenc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🐛 the intent is that tracking should be done at the point of lookup not by doing a second lookup

MultiBinding.MultiEnvironment environment = binding.bind(run, workspace, launcher, listener);
unbinders.add(environment.getUnbinder());
overrides.putAll(environment.getValues());
IdCredentials id = CredentialsProvider.findCredentialById(binding.getCredentialsId(), binding.type(), run);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ugh! The tracking should be done when the credential is actually looked up... not by doing a second look up... as that second look-up may trigger a second logged call to an external credentials management system. Much better if we can have it as part of the binding... May require a thread local to capture the Run context

final List<MultiBinding.MultiEnvironment> m = new ArrayList<MultiBinding.MultiEnvironment>();
for (MultiBinding binding : bindings) {
m.add(binding.bind(build, build.getWorkspace(), launcher, listener));
IdCredentials id = CredentialsProvider.findCredentialById(binding.getCredentialsId(), binding.type(), build);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ugh! Please no... one lookup only

@iwarapter

Copy link
Copy Markdown
Contributor Author

@jglick @stephenc thanks for your feedback, this should fix all the issues i believe.

@stephenc stephenc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm

@iwarapter

Copy link
Copy Markdown
Contributor Author

The jenkins hook seems to be stuck, can someone give it a kick :)

@iwarapter

Copy link
Copy Markdown
Contributor Author

Is there anything else needed for this PR?

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Buglet regarding timing of track call, otherwise good.

import hudson.model.Descriptor;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please revert and use explicit imports.

*/
protected final @Nonnull C getCredentials(@Nonnull Run<?,?> build) throws IOException {
IdCredentials cred = CredentialsProvider.findCredentialById(credentialsId, IdCredentials.class, build);
CredentialsProvider.track(build, cred);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better moved to the if block that returns a value.


import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, please retain explicit imports.

@iwarapter

Copy link
Copy Markdown
Contributor Author

@jglick updated from feedback.

@jglick
jglick merged commit 737a0f7 into jenkinsci:master Nov 1, 2016
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.

3 participants