Skip to content

[JENKINS-75184] CredentialsMatcher fail with ECR Security Token #977

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

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsMatcher;
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
import hudson.util.Secret;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -56,15 +57,19 @@ public boolean matches(Credentials item) {
return false;
}

if (item.getClass().getName().equals("com.cloudbees.jenkins.plugins.amazonecr.AmazonECSRegistryCredential")) {
return false;
}

try {
UsernamePasswordCredentials usernamePasswordCredential = ((UsernamePasswordCredentials) item);
String username = usernamePasswordCredential.getUsername();
String password;
try {
password = Secret.toString(usernamePasswordCredential.getPassword());
} catch (Exception e) {
// JENKINS-75184
return false;
}

boolean isEMail = username.contains(".") && username.contains("@");
boolean validSecretLength = usernamePasswordCredential.getPassword().getPlainText().length() == CLIENT_SECRET_LENGTH;
boolean validSecretLength = password.length() == CLIENT_SECRET_LENGTH;
boolean validKeyLength = username.length() == CLIENT_KEY_LENGTH;

return !isEMail && validKeyLength && validSecretLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@

UsernamePasswordCredentials usernamePasswordCredential = ((UsernamePasswordCredentials) item);
String username = usernamePasswordCredential.getUsername();
String password = Secret.toString(usernamePasswordCredential.getPassword());
String password;
try {
password = Secret.toString(usernamePasswordCredential.getPassword());
} catch (Exception e) {
// JENKINS-75184
return false;

Check warning on line 59 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/credentials/BitbucketUsernamePasswordCredentialMatcher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 57-59 are not covered by tests
}
return StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password);
}
}
Loading