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

[JEP-227] Replace Acegi Security with Spring Security & upgrade Spring Framework #4848

Merged
merged 168 commits into from
Nov 6, 2020

Conversation

jglick
Copy link
Member

@jglick jglick commented Jul 15, 2020

JEP-227

Proposed changelog entries

  • Jenkins now uses Spring Security rather than its predecessor, Acegi Security. Other bundled Spring libraries are also updated.

Proposed upgrade guidelines

https://www.jenkins.io/blog/2020/11/10/spring-xstream/

See the compatibility table.

Desired reviewers

@jenkinsci/core

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are correct
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

looks like a good approach

@jglick

This comment has been minimized.

@res0nance res0nance added the work-in-progress The PR is under active development, not ready to the final review label Jul 20, 2020
core/src/main/java/hudson/ExpressionFactory2.java Outdated Show resolved Hide resolved
@@ -578,7 +578,7 @@ public Object get() {
// so that we invoke them before derived class one. This isn't specified in JSR-250 but implemented
// this way in Spring and what most developers would expect to happen.

final Set<Class> interfaces = ClassUtils.getAllInterfacesAsSet(instance);
final Set<Class<?>> interfaces = ClassUtils.getAllInterfacesAsSet(instance);
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a signature change in Spring.

// we just authenticate anonymous users as such,
// so that later authorization can reject them if so configured
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("anonymous");
AuthenticationManager authenticationManager = new ProviderManager(authenticator, rmap, aap);
Copy link
Member Author

Choose a reason for hiding this comment

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

Just translating the Groovy into equivalent Java.

import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;

public class PrincipalSid implements Sid {
Copy link
Member Author

Choose a reason for hiding this comment

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

Reimplementing these from scratch. Only used from SidAcl.

Copy link
Member

Choose a reason for hiding this comment

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

and cloudbees/bluesteel -> TeamSecurity.java (which is not using SidACL in that class but underlying more it it is). (not sure you saw that or not)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ought to be compatible AFAICT.

*
* @author Kohsuke Kawaguchi
*/
public class BindAuthenticator2 extends BindAuthenticator {
Copy link
Member Author

Choose a reason for hiding this comment

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

Seems to have been unused, and I do not want to depend on Spring Security modules for LDAP here; belongs in the ldap plugin only.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correction: was used by the ldap plugin, and should have been there all along (see 9b4cd99 & 32cba8f). Correcting in jenkinsci/ldap-plugin@a5267e6.

* @deprecated TODO replacement
*/
@Deprecated
public interface UserDetailsService extends org.springframework.security.core.userdetails.UserDetailsService {}
Copy link
Member Author

Choose a reason for hiding this comment

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

Might just get deleted, TBD.

@jvz
Copy link
Member

jvz commented Nov 4, 2020

I'll do one last review today, @timja.

Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

LGTM. Tested this as part of the compatibility testing efforts on various plugins. We already discussed the pervasive 2 suffix and how it should be helpful for developers to update their API usages.

LOGGER.log(Level.FINE, "Login attempt failed", failed);
/* TODO this information appears to have been deliberately removed from Spring Security:
Authentication auth = failed.getAuthentication();
if (auth != null) {
SecurityListener.fireFailedToLogIn(auth.getName());
Copy link
Member

Choose a reason for hiding this comment

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

I'd kind of like to get more data exposed in audit-log-plugin, though that doesn't appear to listen for this event yet. It is listening for login and logout events, though, so it would make sense to support.

}
};

// TODO can we instead use BCryptPasswordEncoder from Spring Security, which has its own copy of BCrypt so we could drop the special library?
Copy link
Member

Choose a reason for hiding this comment

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

I think so. BouncyCastle provides BCrypt, too, so it's not like a separate library was needed in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot use BouncyCastle from core, though.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose it shouldn't matter for this case, then, since Spring Security already includes a BCrypt implementation in its own dependencies like you mentioned in the comment here. Does this limitation include for remoting? That'd be annoying if the only way to support TLS 1.3 connections there is to use Java 11 or customizing your classpath manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you are talking about. BouncyCastle is bundled only in a wrapper plugin for use by other plugins.

Copy link
Member

Choose a reason for hiding this comment

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

BouncyCastle has JSSE glue to support TLS 1.3 in older JDKs than 11. Classes like SSLContext call into that which is the usual class for handling TLS code in Java.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, do not know anything about it. Off topic I suppose. The point here is that for now I kept the existing behavior of using our own bundled jBCrypt, but now that Spring Security also bundles their own copy, we could consider switching to that and dropping our dep. I did not attempt to do so here because the format uses by BCryptPasswordEncoder does not match that of existing saved passwords in Jenkins, so we would need to do more work.

import java.util.logging.Logger;
import org.acegisecurity.acls.sid.GrantedAuthoritySid;
import org.acegisecurity.acls.sid.PrincipalSid;
import org.acegisecurity.acls.sid.Sid;
Copy link
Member

Choose a reason for hiding this comment

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

Should spring-security-acl be blocked as a dependency then?

@@ -69,6 +69,7 @@ for(j = 0; j < jdks.size(); j++) {
allowEmptyArchive: true, // in case we forgot to reincrementalify
fingerprint: true
}
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, includes: 'japicmp.html', keepAll: false, reportDir: 'core/target/japicmp', reportFiles: 'japicmp.html', reportName: 'API compatibility', reportTitles: 'japicmp report'])
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to merge this in?

Copy link
Member Author

Choose a reason for hiding this comment

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

<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<version>0.14.4-20200728.214757-1</version> <!-- TODO https://github.com/siom79/japicmp/pull/266 -->
Copy link
Member

Choose a reason for hiding this comment

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

Similarly doesn't look like something we want to merge in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is OK because this is only used in a profile we active in CI, so if my PR never gets picked up we can either drop this profile, or use the last mojo release which will work for most purposes (just not complex library replacements like is done here).

Happy to remove it if you are uneasy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with leaving it. I actually ran the profile and examined the results. If Daniel is concerned, though, I readily accept the removal.

@jvz jvz mentioned this pull request Nov 6, 2020
6 tasks
@jeffret-b jeffret-b merged commit a9ca5ef into jenkinsci:master Nov 6, 2020
@jglick jglick deleted the spring-5303 branch November 6, 2020 18:33
jglick added a commit to jglick/jenkins.io that referenced this pull request Nov 6, 2020

public static void setProtectedFieldValue(String protectedField, Object object, Object newValue) {
try {
org.apache.commons.lang.reflect.FieldUtils.writeField(object, protectedField, newValue, true);
Copy link
Member Author

Choose a reason for hiding this comment

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

see #5105

@@ -67,7 +67,6 @@
import jenkins.util.io.OnMaster;
import net.sf.json.JSONObject;

import org.acegisecurity.Authentication;
Copy link
Member

Choose a reason for hiding this comment

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

@timja
Copy link
Member

timja commented Mar 22, 2021

@jglick / @jvz looks like the credentials API needs updating? https://github.com/jenkinsci/credentials-plugin/blob/3a603dec20412ccce754d9cbbd835d890ca06ee5/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java#L517

It takes the acegi security Authentication as a parameter and I can't avoid a deprecation warning in my plugin because of this.

@jglick
Copy link
Member Author

jglick commented Mar 22, 2021

It could be updated, sure.

@jglick jglick mentioned this pull request Jan 14, 2022
@basil basil mentioned this pull request Mar 13, 2022
11 tasks
Vlatombe added a commit to Vlatombe/credentials-plugin that referenced this pull request Oct 23, 2023
This is the implementation of
jenkinsci/jenkins#4848 for Credentials API. This
will allow consumers of the credentials API to remove references to
deprecated acegi APIs.
Vlatombe added a commit to Vlatombe/credentials-plugin that referenced this pull request Oct 23, 2023
This is the implementation of
jenkinsci/jenkins#4848 for Credentials API. This
will allow consumers of the credentials API to remove references to
deprecated acegi APIs.
Vlatombe added a commit to Vlatombe/credentials-plugin that referenced this pull request Oct 23, 2023
This is the implementation of
jenkinsci/jenkins#4848 for Credentials API. This
will allow consumers of the credentials API to remove references to
deprecated acegi APIs.
jglick pushed a commit to jenkinsci/credentials-plugin that referenced this pull request Oct 27, 2023
…APIs (#490)

* [JEP-227] Replace Acegi Security with Spring Security APIs

This is the implementation of
jenkinsci/jenkins#4848 for Credentials API. This
will allow consumers of the credentials API to remove references to
deprecated acegi APIs.

* Fix spotbugs issues

* Fix reviews

* Rename methods appropriately

* Fixup some javadocs.

* Remove unused method.

* Forgot to remove usages.

* Remove CredentialsProvider#getCredentials2(Class, ItemGroup, Authentication) in favor of CredentialsProvider#getCredentials2(Class, ItemGroup, Authentication, List)

* Fix a few null checks while we are here.

* Restore a method I deleted by mistake.

* Add tests for new signatures

* Rename *2 methods to *InItem/*InItemGroup to avoid ambiguous signatures

* Update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file developer Changes which impact plugin developers major-rfe For changelog: Major enhancement. Will be highlighted on the top plugin-api-changes Changes the API of Jenkins available for use in plugins. ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback removed This PR removes a feature or a public API squash-merge-me Unclean or useless commit history, should be merged only with squash-merge upgrade-guide-needed This changes might be breaking in rare circumstances, an entry in the LTS upgrade guide is needed
Projects
None yet
9 participants