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

Various improvements for the webconsole plugin #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rombert
Copy link
Contributor

@rombert rombert commented Aug 5, 2022

No description provided.

rombert added 3 commits August 5, 2022 11:34
- allow the path to be empty, but not null
- return a more informative message if no mappings are found
… a map/resolve call

- extend the form to optionally accept a user to impersonate
- use the resolver of the current user as a basis for impersonation
- make sure that we don't accidentally generate imports from the auth.core and jcr.resource bundles,
  they are only used for the constant values, which are inlined.
@rombert rombert requested review from kwin and cziegeler August 5, 2022 11:31
Copy link
Contributor

@cziegeler cziegeler left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 6, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

2.1% 2.1% Coverage
0.0% 0.0% Duplication

Copy link
Member

@kwin kwin left a comment

Choose a reason for hiding this comment

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

LGTM overall, just some minor remarks to better handle some edge cases.

pw.println("' class='input' size='50'>");
pw.println("' class='input' size='20'>");
pw.print("User (optional)");
pw.print("<input type='text' name='" + ATTR_USER + "' value='");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a hint that this does only work/has an effect on resources resolved by the JCR resource provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.


// resolver is set by the auth.core bundle in case of successful authentication, so it should
// always be there
Object resolverAttribute = request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this rather be based on service resource resolver as well to make it work with all web console security providers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean that we should try to create an additional mapping for the console using a service user that has impersonation rights?

Copy link
Member

@kwin kwin Aug 8, 2022

Choose a reason for hiding this comment

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

Just try to get a resourceresolver based on the service one and the user is to impersonate. The one returned as request attribute might not have the according rights

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I try to set up impersonation based on the existing resolver (

resolver = resolverFactory.getServiceResourceResolver(this.resolverFactory.getServiceUserAuthenticationInfo("console"));
) I get back

Test Failure: org.apache.sling.api.resource.LoginException: Impersonation not allowed.

Copy link
Member

@kwin kwin Aug 9, 2022

Choose a reason for hiding this comment

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

You need to adjust privileges of the underlying technical user: https://jackrabbit.apache.org/oak/docs/security/authentication/default.html#impersonation

Copy link
Contributor Author

@rombert rombert Aug 9, 2022

Choose a reason for hiding this comment

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

Looking at the Oak implementation, I see that impersonation works if either:

  • the impersonator is an admin
  • the impersonator is included in the rep:impersonators property of the impersonated user

https://github.com/apache/jackrabbit-oak/blob/a90566744551246535f65c2aefc5a44fd5275490/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ImpersonationImpl.java#L125-L146

I am not sure if either of these is possible or desirable for a service user. Do you see another way?

Copy link
Member

@kwin kwin Aug 9, 2022

Choose a reason for hiding this comment

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

Actually the user needs to be "admin", just being member of the administrators group is IMHO not enough. I don't think that there is an option yet for a user to enable him to impersonate as anyone else. Might be a good extension though for Oak.
The same limitation applies to the user doing the webconsole request (in case the Sling Webconsole Security provider is used), so in fact this option does only work for admin with all other users.
Therefore I would suggest to use a new administrative resource resolver with impersonation and whitelist the usage accordingly.


Map<String, Object> authenticationInfo = new HashMap<>();
authenticationInfo.put(ResourceResolverFactory.USER_IMPERSONATION, user);
authenticationInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, currentResolver.adaptTo(Session.class));
Copy link
Member

Choose a reason for hiding this comment

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

This adaptTo may return null in case JCR resource provider is not used, a null check is necessary here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The import of JCR packages is optional, I assume the above code does not work if the JCR bundle is not installed?
We should keep that dependency as optional and not require JCR api to be installed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two issues to discuss here

  1. The javax.jcr import is already optional - https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/78/files#diff-6d1033f3cc4642b36cd395cf203fdc2d963f51e46cb1949508765a9756743c45R2 . I think that a NoClassDefFoundError will be thrown from the method, then caught at . This should not affect the path where impersonation is not used. Do we need to handle this in some other way, e.g. using the bundle class loader to dynamically load the class definition?
  2. The adaptTo call can return null nonetheless and I will take it into acount

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad, I didn't read the full code. You are right, that this will work. And just to be sure I gave it a test run in a sling application that does not have the jcr api and except for impersonation, everything works

// always be there
Object resolverAttribute = request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
if ( !(resolverAttribute instanceof ResourceResolver) ) {
throw new IllegalArgumentException("No " + ResourceResolver.class.getSimpleName() + " found in request, unable to proceed with impersonation");
Copy link
Contributor

@cziegeler cziegeler Aug 8, 2022

Choose a reason for hiding this comment

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

It is a common case if the web console is not using the Sling authentication provider that the request attribute is not set. In that case, it currently displays:
Test Failure: java.lang.IllegalArgumentException: No ResourceResolver found in request, unable to proceed with impersonation
I think it would be good if just the message without the exception type would be displayed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kwin suggested that we use an admin resolver instead (and include the bundle in the allow list ). If we would stop looking up the ResourceResolver in the request attribute, would it solve this issue?

#78 (comment)

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 not really a fan of adding another case for using an admin resource resolver, especially not in the web console

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

2.1% 2.1% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 5, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

2.1% 2.1% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link

sonarqubecloud bot commented Feb 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions

2.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

1 similar comment
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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