Skip to content
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-73806] Do not allows users to authenticate with short passwords in FIPS mode #296

Conversation

BorisYaoA
Copy link
Contributor

@BorisYaoA BorisYaoA commented Sep 17, 2024

see https://issues.jenkins.io/browse/JENKINS-73806

The goal of this PR is to check that the ldap user's password is FIPS compliant (at least 14 characters).

By running a local jenkins in FIPS mode (mvn clean hpi:run -P core-oc -Djenkins.security.FIPS140.COMPLIANCE=true) I can see an angry Jenkins when the password is shorter than 14 characters in FIPS mode and the message in the logs.

Screenshot 2024-09-27 at 17 07 31

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@BorisYaoA BorisYaoA changed the title Do not allows users to authenticate with short passwords in fips mode Do not allows users to authenticate with short passwords in FIPS mode Sep 17, 2024
@BorisYaoA BorisYaoA changed the title Do not allows users to authenticate with short passwords in FIPS mode [JENKINS-73806] Do not allows users to authenticate with short passwords in FIPS mode Sep 23, 2024
@@ -411,6 +413,9 @@ public FormValidation doCheckServer(@QueryParameter String value, @QueryParamete
if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();

if(FIPS140.useCompliantAlgorithms() && managerPassword.length() < 14)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking that we are running Jenkins in FIPS mode and that the password is FIPS compliant (see https://github.com/jenkinsci/jep/tree/master/jep/237 for Jenkins FIPS support)

public class LDAPConfigurationWithFIPSTest {

@Rule
public JenkinsRule r = new JenkinsRule();
Copy link
Member

Choose a reason for hiding this comment

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

Could you use a RealJenkinsRule so that we could benefit from jenkinsci/jenkins-test-harness#829?

Copy link
Member

@fcojfernandez fcojfernandez left a comment

Choose a reason for hiding this comment

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

While the FormValidation is the way to inform the user, it won't prevent the user to click on Save button and store a non-compliant configuration. Also, with CasC you could save a unsecure configuration, so the proper fix would be:

Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

The ticket is about user passwords not being less than 14 characters. The manager password being too short is another ticket.

@fcojfernandez
Copy link
Member

Bobby is right, this PR is fixing another different issue. The fix for this ticket should be in

public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {

@@ -753,6 +754,9 @@ public SecurityComponents createSecurityComponents() {
*/
@Override
protected UserDetails authenticate2(String username, String password) throws AuthenticationException {
if(FIPS140.useCompliantAlgorithms() && (StringUtils.isBlank(password) || password.length() < 14)) {
throw new org.springframework.ldap.AuthenticationException(new javax.naming.AuthenticationException("When running in FIPS compliance mode, the password must be at least 14 characters long"));
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity, why not

Suggested change
throw new org.springframework.ldap.AuthenticationException(new javax.naming.AuthenticationException("When running in FIPS compliance mode, the password must be at least 14 characters long"));
throw new AuthenticationException("When running in FIPS compliance mode, the password must be at least 14 characters long"));

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm having this message 'AuthenticationException' is abstract; cannot be instantiated

@@ -6,6 +6,7 @@ LDAPSecurityRealm.LoginHeader=Login
LDAPSecurityRealm.AuthenticationSuccessful=Authentication: successful
LDAPSecurityRealm.AuthenticationFailed=Authentication: failed for user "{0}"
LDAPSecurityRealm.AuthenticationFailedEmptyPass=Authentication: failed for user "{0}" with empty password
LDAPSecurityRealm.AuthenticationFailedNotFipsCompliantPass=When running in FIPS compliance mode, the password must be at least 14 characters long
Copy link
Member

Choose a reason for hiding this comment

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

is it used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I will remove it

@BorisYaoA BorisYaoA requested a review from alecharp September 27, 2024 15:08
@BorisYaoA BorisYaoA marked this pull request as ready for review September 27, 2024 15:08
@BorisYaoA BorisYaoA requested review from a team as code owners September 27, 2024 15:08
@fcojfernandez fcojfernandez merged commit 387f5b3 into jenkinsci:master Sep 30, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants