Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323347

Summary: jmxPermissions.vbs sets no permissions
Product: [RT] Virgo Reporter: Hristo Iliev <hsiliev>
Component: unknownAssignee: Glyn Normington <glyn.normington>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eliasbalasis, glyn.normington, zteve.powell
Version: unspecified   
Target Milestone: 2.1.0.M05-incubation   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 326140    
Attachments:
Description Flags
Fixed VBScript
none
cacls replacement for the VB script none

Description Hristo Iliev CLA 2010-08-23 03:07:58 EDT
Build Identifier: 2.1.0.M03-incubation

After unzip of virgo the files often have Everyone (local or domain user). Running Virgo invokes jmxPermissions.vbs which does not set any permissions for org.eclipse.virgo.kernel.jmxremote.access.properties since the current user is not part of the ACL list. 

The problematic code seems to be:
	For Each ace in objSecurityDescriptor.DACL
		If ace.Trustee.Name = WshNetwork.UserName Then
			Set specificAce(0) = ace
		End If
	Next

The Trustee.Name=Everyone, while UserName=<domain or local user>

Perhaps a check if the user is included in a group could fix the issue. Unfortunately I don't have much experience with VBS, so my assumptions above may be wrong.

Reproducible: Always

Steps to Reproduce:
1. Unzip Virgo
2. Run startup.bat
Comment 1 Steve Powell CLA 2010-08-23 10:35:24 EDT
We currently have a vbs which is Windows platform sensitive (and is a nightmare to maintain).
This may be a Windows 7 specific problem -- we do not test on the W7 platform (yet).  Can you identify the platform upon which you detect this problem, please?
Comment 2 Hristo Iliev CLA 2010-08-23 11:27:10 EDT
I tested this also on Windows XP and Vista and the problem is present there also.

I guess that this may be due to the domain configuration on my machines (Everyone domain group).
Comment 3 Steve Powell CLA 2010-08-24 04:20:19 EDT
(In reply to comment #2)
Thank you Hristo.

This will be looked at in the next week or so, when our vbs/windows expert returns from the antipodes.
Comment 4 Hristo Iliev CLA 2010-08-25 11:39:47 EDT
Just for the record - on a Windows machine outside a domain the script works OK. 

The jmx.properties file however has only one permissions and this is exactly the user that's trying to run Virgo.
Comment 5 Hristo Iliev CLA 2010-08-27 12:05:06 EDT
I just tried to workaround the issue with a check for the groups:

	Set objUser = GetObject("WinNT://" & WshNetwork.UserDomain & "/" & WshNetwork.UserName)

	Dim specificAce(0)
	i = 0
	For Each ace in objSecurityDescriptor.DACL
		If ace.Trustee.Name = WshNetwork.UserName Then
			Set specificAce(i) = ace
			WScript.Echo "Username = " & ace.Trustee.Name
			i = i + 1
			Continue
		End If
	    For Each oGroup in objUser.Groups
		    WScript.Echo "   Trustee = " & ace.Trustee.Name
			WScript.Echo "   Group   = " & oGroup.name
			If ace.Trustee.name = oGroup.name Then
				Set specificAce(i) = ace
				WScript.Echo "Username = " & ace.Trustee.Name
				i = i + 1
			End If
		Next
	Next

This doesn't seem to work since the group Everyone is not in the list of groups. This may happen if ActiveDirectory or some other user store is in use - I cannot tell the exact reason.

Therefore as a solution I can propose the explicit setting of ACL to the one of the user that starts Virgo. In the end this is the purpose of the script. 

The problem of the current approach is that the desired ACL may not be present in the ACL list of the jmx properties file. There can be ACL for Everyone, Administrators or whatever group is set, but the user ACL may be absent. Therefore the script will just wipe out the ACL list which actually causes the problem.
Comment 6 Elias Balasis CLA 2010-09-02 10:23:47 EDT
I am verifying behaviour on Windows 7

Using virgo-web-server-2.1.0.M03-incubation

org.eclipse.virgo.kernel.jmxremote.access.properties after running startup.bat (implicitly jxjPermissions.vbs) has no permissions and startup script fails with following error message

Error: Exception thrown by the agent : java.io.FileNotFoundException: ...\config\org.eclipse.virgo.kernel.jmxremote.access.properties (Access is denied)

I detected easily that indeed code in jmxPermissions.vbs is responsible but don't know how to fix it

Tried to modify jmxPermissions.vbs by altering the following section


Dim files(0)
files(0) = "org.eclipse.virgo.kernel.jmxremote.access.properties"

For Each file In files
	updateInheritance(configFolder & file)
	updateOwnership(configFolder & file)
	updatePermissions(configFolder & file)
Next 

tried to place in remarks combinations of update... calls. finally server started but failed to access via http://localhost:8080. still, log reported tomcat started on port 8080

I hope this helps

I will meanwhile try to discover a way to make jmxPermissions.vbs to work on as many versions of windows as possible
I suspect WMI calls differ among different versions of Windows and Windows 7 is obviously a totally new case
Comment 7 Elias Balasis CLA 2010-09-02 10:52:26 EDT
Found something.

On Windows 7 there are no instances of classes Win32_LogicalFileSecuritySetting
(referenced in jmxPermissions.vbs)

Used Microsoft "WMI Tools" to discover (WMI CIM Studio and WMI Object Browser)

Trying to find alternative method plus a way to determine Windows version and act accordingly...
Comment 8 Elias Balasis CLA 2010-09-02 11:07:39 EDT
More observations

Placed in remarks the "updateInheritance" and "updatePermissions" calls in jmxPermissions.vbs

Server started normally and file org.eclipse.virgo.kernel.jmxremote.access.propertie permissions remained unaffected

"updateInheritance" and "updatePermissions" calls make use of WMI "Win32_LogicalFileSecuritySetting" instance which does not exist in Windows 7
assumption on "Win32_LogicalFileSecuritySetting" was correct for Windows 7

Suspecting this could be a workaround for Windows 7
(not the best one however, still alternative to "Win32_LogicalFileSecuritySetting" plus O/S version check is required)

failure to access http://localhost:8080 in "comment 6" was invalid, please ignore. Had to be typed as http://127.0.0.1:8080 instead (for unknown reasons)
Comment 9 Hristo Iliev CLA 2010-09-07 04:43:47 EDT
As far as I was able to debug the issue the problem lies in the Sub:
   updatePermissions(configFolder & file)

Commenting this sub seems to solve the problem on the affected systems.

Perhaps changing the call for Windows 7 will do, but please note that I had the same problem on Vista. 

If you have a patch I can test it on XP, Vista and 7 in the domain configuration that caused the problem.

What do you think of the idea to set explicit ACL? To me it looks better than cycling through all users and expecting that the current one will be already there (which proved to be false expectation).
Comment 10 Glyn Normington CLA 2010-09-07 04:57:57 EDT
Thanks Hristo. Chris is back tomorrow and will respond in due course, email backlog permitting.
Comment 11 Glyn Normington CLA 2010-09-20 05:31:26 EDT
We will investigate the feasibility of fixing this robustly for 2.1.0. If this cannot be done, we will document a workaround and look to fix this post 2.1.0.
Comment 12 Glyn Normington CLA 2010-09-23 07:19:11 EDT
The best compromise we could come up with was to tolerate the situation described in this bug and not attempt to set the file permissions in that case but to issue a warning instead and continue launching.

If we can identify suitable robust/portable VBScript to create an ACE from scratch for the current user, we could use this instead of the current technique of searching for a suitable ACE in the file's permissions. However, we are not aware of such a VBScript technique which will work reliably across all Windows platforms.

This will be fixed in the next milestone, but if you would like to try it out, I'll attach the updated script which needs to replace the one in the bin directory.
Comment 13 Glyn Normington CLA 2010-09-23 07:19:42 EDT
Created attachment 179447 [details]
Fixed VBScript
Comment 14 Hristo Iliev CLA 2010-09-23 07:46:40 EDT
Created attachment 179448 [details]
cacls replacement for the VB script

We can replace the VBS with 2 commands:

	takeown /F "%CONFIG_DIR%\org.eclipse.virgo.kernel.jmxremote.access.properties" > nul
	echo Y| cacls "%CONFIG_DIR%\org.eclipse.virgo.kernel.jmxremote.access.properties" /G "%USERDOMAIN%\%USERNAME%":F > nul


The drawback from this approach is that the "takeown" does not exist in Windows XP and an error message is produced. Of course "takeown" can be removed since the main change here is the use of "cacls" command.

I tested this approach on Windows XP and Windows 7. It works ok with domain users and also does restricts the access to the current user only (as expected)
Comment 15 Glyn Normington CLA 2010-09-23 08:47:28 EDT
(In reply to comment #14)
> Created an attachment (id=179448) [details]
> cacls replacement for the VB script

Thanks Hristo. This change is a little more radical, perhaps risky, than my workaround. We'll review it and get back to you.
Comment 16 Hristo Iliev CLA 2010-09-23 08:59:55 EDT
(In reply to comment #13)
> Created an attachment (id=179447) [details]
> Fixed VBScript

I tested the workaround and Virgo was able to start without touching the properties.
Comment 17 Glyn Normington CLA 2010-09-23 09:12:49 EDT
(In reply to comment #15)
> (In reply to comment #14)
> > Created an attachment (id=179448) [details] [details]
> > cacls replacement for the VB script
> 
> Thanks Hristo. This change is a little more radical, perhaps risky, than my
> workaround. We'll review it and get back to you.

It turns out we used to use cacls but got burned. https://issuetracker.springsource.com/browse/DMS-456 shows a major weakness in cacls and prompted us to write the VBScript.
Comment 18 Hristo Iliev CLA 2010-09-23 09:29:06 EDT
I agree - cacls is not usable. 

Perhaps we can try a hybrid approach then:
- if icacls is available then we can use it - it overcomes the issue with echo by providing an /Y switch
- if only cacls is on the system we can fallback to the VBS

In this way the jmx properties will be protected at least on the newer Windows systems (2003 SP2, Vista, 7, 2008 ...).

If older versions (2000, XP) are targeted then xcacls can be used as it also provides /Y switch
Comment 19 Glyn Normington CLA 2010-09-23 09:47:33 EDT
(In reply to comment #18)
> I agree - cacls is not usable. 
> 
> Perhaps we can try a hybrid approach then:
> - if icacls is available then we can use it - it overcomes the issue with echo
> by providing an /Y switch
> - if only cacls is on the system we can fallback to the VBS
> 
> In this way the jmx properties will be protected at least on the newer Windows
> systems (2003 SP2, Vista, 7, 2008 ...).
> 
> If older versions (2000, XP) are targeted then xcacls can be used as it also
> provides /Y switch

It might be possible to get this kind of hybrid scheme to work, but I wouldn't relish the testing as it sounds like the execution path would vary depending on the Windows platform.

Anyway, IMO such an approach is too risky for 2.1.0 as we'd want it to have plenty of time to "bed in", i.e. for users to try it and raise feedback.

Can we agree to stick with the current workaround for 2.1.0 and revisit alternatives post 2.1.0 (possibly under a new enhancement bug for clarity)?
Comment 20 Hristo Iliev CLA 2010-09-23 09:57:08 EDT
(In reply to comment #19)
> (In reply to comment #18)
> > I agree - cacls is not usable. 
> > 
> > Perhaps we can try a hybrid approach then:
> > - if icacls is available then we can use it - it overcomes the issue with echo
> > by providing an /Y switch
> > - if only cacls is on the system we can fallback to the VBS
> > 
> > In this way the jmx properties will be protected at least on the newer Windows
> > systems (2003 SP2, Vista, 7, 2008 ...).
> > 
> > If older versions (2000, XP) are targeted then xcacls can be used as it also
> > provides /Y switch
> 
> It might be possible to get this kind of hybrid scheme to work, but I wouldn't
> relish the testing as it sounds like the execution path would vary depending on
> the Windows platform.
> 
> Anyway, IMO such an approach is too risky for 2.1.0 as we'd want it to have
> plenty of time to "bed in", i.e. for users to try it and raise feedback.
> 
> Can we agree to stick with the current workaround for 2.1.0 and revisit
> alternatives post 2.1.0 (possibly under a new enhancement bug for clarity)?

Sure - 2.1.0 is prio 1. Let's leave the acl modifications for the next versions so we can have enough time to experiment and get feedback.

Perhaps we can just describe the steps needed to secure the jmx properties file . Can the current troubleshooting page be reused for this purpose?
Comment 21 Glyn Normington CLA 2010-09-24 04:34:15 EDT
(In reply to comment #20)
> Sure - 2.1.0 is prio 1. Let's leave the acl modifications for the next versions
> so we can have enough time to experiment and get feedback.

Agreed.

> 
> Perhaps we can just describe the steps needed to secure the jmx properties file
> . Can the current troubleshooting page be reused for this purpose?

Yes that sounds good. I am not aware of the necessary steps, so if you are, please could you update the wiki or provide text here that we could use. Thanks.
Comment 22 Hristo Iliev CLA 2010-09-24 09:03:35 EDT
(In reply to comment #21)
> (In reply to comment #20)
> > Sure - 2.1.0 is prio 1. Let's leave the acl modifications for the next versions
> > so we can have enough time to experiment and get feedback.
> 
> Agreed.
> 
> > 
> > Perhaps we can just describe the steps needed to secure the jmx properties file
> > . Can the current troubleshooting page be reused for this purpose?
> 
> Yes that sounds good. I am not aware of the necessary steps, so if you are,
> please could you update the wiki or provide text here that we could use.
> Thanks.

I updated the Windows troubleshooting section in the documentation. The patch is attached to bug 326140
Comment 23 Glyn Normington CLA 2010-09-27 08:34:36 EDT
RC1 is planned instead of milestone 5.
Comment 24 Glyn Normington CLA 2010-09-27 08:36:54 EDT
Closing now that documentation is in place. A new bug will be required for a later release if it is necessary to replace the VBScript with cacls etc.
Comment 25 Steve Powell CLA 2010-10-19 16:45:40 EDT
If you're gonna close it, then close it!
Comment 26 Glyn Normington CLA 2010-10-20 04:09:26 EDT
Well spotted!