-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-72611] Forbid editing credentials ID #502
Conversation
@@ -323,6 +323,14 @@ private synchronized boolean removeCredentials(@NonNull Domain domain, @NonNull | |||
private synchronized boolean updateCredentials(@NonNull Domain domain, @NonNull Credentials current, | |||
@NonNull Credentials replacement) throws IOException { | |||
checkPermission(CredentialsProvider.UPDATE); | |||
|
|||
// See IdCredentials.Helper#equals. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR
credentials-plugin/src/main/java/com/cloudbees/plugins/credentials/common/IdCredentials.java
Lines 50 to 85 in cf0a900
/** | |
* The contract implementations of {@link #equals(Object)} and {@link #hashCode()} that implementations of | |
* this class must use as the basis for equality tests and as the hash code. | |
* | |
* @since 1.6 | |
*/ | |
final class Helpers { | |
/** | |
* Standard {@link #equals(Object)} implementation. | |
* | |
* @param self the {@code this} reference. | |
* @param o the other object. | |
* @return true if equal. | |
*/ | |
public static boolean equals(IdCredentials self, Object o) { | |
if (self == o) { | |
return true; | |
} | |
if (!(o instanceof IdCredentials)) { | |
return false; | |
} | |
IdCredentials that = (IdCredentials) o; | |
return self.getId().equals(that.getId()); | |
} | |
/** | |
* The standard {@link #hashCode()} implementation. | |
* | |
* @param self the {@code this} reference. | |
* @return the hash code. | |
*/ | |
public static int hashCode(IdCredentials self) { | |
return self.getId().hashCode(); | |
} |
credentials-plugin/src/main/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials.java
Lines 116 to 130 in cf0a900
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public final int hashCode() { | |
return IdCredentials.Helpers.hashCode(this); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public final boolean equals(Object o) { | |
return IdCredentials.Helpers.equals(this, o); | |
} |
Hello, this created a compatibility issue with |
|
||
// See IdCredentials.Helper#equals. | ||
// Note: We probably should not assume that all credentials are IdCredentials. We also do this a few lines below in list.indexOf(current) call. | ||
// If this one breaks, that one breaks as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how so - the list is of type Credentials
not IdCredentials
so that would not break with a big bad angry jenkins.
At worst it would not find current
, as the list would use equals
and it is up to current credential may have been correctly obtained by it's name or otherwise in the code path.
@jtnord What concrete
https://github.com/jenkinsci/plain-credentials-plugin/blob/ce8710821f17a043d91b448cf19b8568935d0167/src/test/java/org/jenkinsci/plugins/plaincredentials/BaseTest.java#L107? That just sounds like a meaningless test. |
for example -> https://github.com/jenkinsci/loadfocus-jmeter-load-testing-integration-plugin/blob/d2d2af5b0af276932dfb6c8191d3bb13791d6bc7/src/main/java/com/loadfocus/jenkins/impl/LoadCredentialImpl.java there may be companies with other implementations.
Nope this works :)
credentials-plugin/src/main/java/com/cloudbees/plugins/credentials/CredentialsStoreAction.java Lines 744 to 748 in 7eb51b3
you get a dummy ID based on the index in the list. For update and delete. A plugin can perfectly ask for any credential of Type X for domain F and get the list IDs are the future (or the now) but they are not /currently/ mandatory.
|
Hmm https://github.com/jenkinsci/loadfocus-jmeter-load-testing-integration-plugin/blob/d2d2af5b0af276932dfb6c8191d3bb13791d6bc7/src/main/java/com/loadfocus/jenkins/LoadCredential.java#L13 looks like it was meant to extend
Are there some examples of this? I can only think of cases where config includes a 🤷 anyway I guess it should be simple enough to fix things up to just ignore non- |
yes - we only need to do the comparison if one or other of the credentials is an
if we want to kill non ID based credentials and cleanup the code then I am ok with doing that in a PR that is clearly saying "remove support for obsolete implementations of Credentials" so long as it is just doing that, and we also fixup the knwon fallout (which is not huge but there is some). |
https://issues.jenkins.io/browse/JENKINS-72611
Testing done
Tested interactively, made sure that two credentials cannot have the same ID.
Submitter checklist