1 2 3 4 Previous Next 116 Replies Latest reply on Nov 28, 2008 3:21 PM by anil.saldhana Go to original post
      • 15. Re: VFS Permissions - JBMICROCONT-149

         

        "adrian@jboss.org" wrote:

        An alternative solution is to change the way the VFSClassLoaderPolicy determines
        the code source. i.e. instead of returning the vfs url we could hack it to return
        a normal url.

        ...

        An alternative solution would be to allow you to specify the codeSourceURL to use
        for the classloader as a parameter when you create it.


        I just tried a third alternative which is to delay the installation of the policy and
        security manager and make it run in new security.xml bootstrap file.

        This does work, I've committed it, obviously haven't enabled it by default
        so committing it isn't a problem. :-)

        To enable it change conf/bootstrap.xml
         <url>classloader.xml</url>
        + <url>security.xml</url>
         <url>aop.xml</url>
        


        But there's some issues that need resolving.

        1) POLICY FILE

        You need to create a proper security policy file. The one I added
        in server/xxx/conf/java.policy gives everybody all permissions.

        I got as far as this:

        grant codebase "file:/home/ejort/development/jboss-head/build/output/jboss-5.0.0.GA/bin/run.jar" {
         permission java.security.AllPermission;
        };
        
        grant codebase "file:/home/ejort/development/jboss-head/build/output/jboss-5.0.0.GA/lib/-" {
         permission java.security.AllPermission;
        };
        
        grant codebase "vfszip:/home/ejort/development/jboss-head/build/output/jboss-5.0.0.GA/lib/-" {
         permission java.security.AllPermission;
        };
        


        But there's other code in deployers and deploy that needs to have
        the AllPermission. The default policy also needs defining to have
        sensible rights.

        2) The above shows an annoying feature.
        We access things in JBOSS_HOME/lib using both the file: and vfszip urls
        depending on whether the jars are loaded by the NoAnnotationURLClassLoader
        or a VFSClassLoaderPolicy.

        3) I could change the file: urls above to use the system properties,
        but not the vfszip url. We don't have system properties for the vfs versions
        of the urls.

        4) There's some issue at shutdown where I try to uninstall the security manager
        that I haven't investigated.

        19:37:51,453 WARN [StartStopLifecycleAction] Error during stop for SecurityPolicy
        java.security.AccessControlException: access denied (java.lang.RuntimePermission setSecurityManager)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
         at java.security.AccessController.checkPermission(AccessController.java:427)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.System.setSecurityManager0(System.java:253)
         at java.lang.System.setSecurityManager(System.java:245)
         at org.jboss.system.server.security.SecurityPolicy.stop(SecurityPolicy.java:97)
        


        I guess the shutdown hooks run with different rights so it needs to be a
        privileged block?

        • 16. Re: VFS Permissions - JBMICROCONT-149

          The actual implementation is fairly trivial

          public class SecurityPolicy
          {
           /** Whether to install the security manager */
           private SecurityManager securityManager;
          
           /** The policy url */
           private URL policyURL;
          
           /**
           * Get the securityManager.
           *
           * @return the securityManager.
           */
           public SecurityManager getSecurityManager()
           {
           return securityManager;
           }
          
           /**
           * Set the securityManager.
           *
           * @param securityManager the securityManager.
           */
           public void setSecurityManager(SecurityManager securityManager)
           {
           this.securityManager = securityManager;
           }
          
           /**
           * Get the policyURL.
           *
           * @return the policyURL.
           */
           public URL getPolicyURL()
           {
           return policyURL;
           }
          
           /**
           * Set the policyURL.
           *
           * @param policyURL the policyURL.
           */
           public void setPolicyURL(URL policyURL)
           {
           this.policyURL = policyURL;
           }
          
           @Start
           public void start()
           {
           if (policyURL != null)
           System.setProperty("java.security.policy", policyURL.toExternalForm());
           Policy.getPolicy().refresh();
          
           if (securityManager != null)
           System.setSecurityManager(securityManager);
           }
          
           public void stop()
           {
           if (securityManager != null)
           System.setSecurityManager(null);
           }
          }
          


          with xml config
           <bean name="SecurityPolicy" class="org.jboss.system.server.security.SecurityPolicy">
           <property name="securityManager"><javabean xmlns="urn:jboss:javabean:2.0" class="java.lang.SecurityManager"/></property>
           <property name="policyURL">${jboss.server.config.url}/java.policy</property>
           </bean>
          


          I guess for management purposes, it would be better to have the policies
          defined directly in that xml using our own policy implementation?
          e.g. being able change policies from the profile service or management console?

          • 17. Re: VFS Permissions - JBMICROCONT-149
            dmlloyd

             

            "adrian@jboss.org" wrote:
            I guess the shutdown hooks run with different rights so it needs to be a privileged block?


            If you make the stop() method run privileged, won't you make it kind of easy to defeat the security manager (by simply undeploying the bean, or even just getting the bean by name, or creating an instance of it, and manually calling stop() on it from hostile code)?

            Just trying to think if there's a way to get at that. Probably the shutdown hook is the one that should be using the privileged block - or is that what you meant?

            • 18. Re: VFS Permissions - JBMICROCONT-149

              NOTE: The above java.policy gets passed the aop problem you had Anil
              but then fails on the binding manager because I hadn't given any permissions
              to the service binding manager that lives in the shared libs (currently server/lib)

              19:37:49,508 ERROR [AbstractKernelController] Error installing to Start: name=SystemPropertyBinder state=Create
              java.security.AccessControlException: access denied (java.util.PropertyPermission jboss.messaging.connector.bisocket.port write)
               at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
               at java.security.AccessController.checkPermission(AccessController.java:427)
               at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
               at java.lang.System.setProperty(System.java:699)
               at org.jboss.services.binding.SystemPropertyBinder$1.run(SystemPropertyBinder.java:68)
               at java.security.AccessController.doPrivileged(Native Method)
               at org.jboss.services.binding.SystemPropertyBinder.start(SystemPropertyBinder.java:64)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
               at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
               at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
               at org.jboss.kernel.plugins.dependency.DispatchJoinPoint.run(DispatchJoinPoint.java:47)
               at java.security.AccessController.doPrivileged(Native Method)
               at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:54)
              


              Which brings up the question whether the bootstrap files should be looking
              at the shared lib folder and if so whether we should move more jars
              from /lib into it.

              • 19. Re: VFS Permissions - JBMICROCONT-149

                 

                "david.lloyd@jboss.com" wrote:

                If you make the stop() method run privileged, won't you make it kind of easy to defeat the security manager (by simply undeploying the bean, or even just getting the bean by name, or creating an instance of it, and manually calling stop() on it from hostile code)?


                That's a different issue. We already said that we need a permission
                within the MC that controls who can inject/install what into what or who can
                invoke on what through the kernel bus.

                Currently there's no fine-grained permission, only one big permission
                on whether you can access the kernel(controller).

                Ales do you have a JIRA for that? Or have you already done it without me
                noticing as usual? ;-)

                • 20. Re: VFS Permissions - JBMICROCONT-149
                  anil.saldhana

                  Adrian, why were the aop classes having the issue they had with the current approach that we have?

                  • 21. Re: VFS Permissions - JBMICROCONT-149
                    anil.saldhana

                     

                    "anil.saldhana@jboss.com" wrote:
                    Adrian, why were the aop classes having the issue they had with the current approach that we have?


                    scratch that. Never mind.

                    • 22. Re: VFS Permissions - JBMICROCONT-149
                      alesj

                       

                      "adrian@jboss.org" wrote:

                      Ales do you have a JIRA for that? Or have you already done it without me
                      noticing as usual? ;-)

                      Nope. Forgot about it. :-)

                      Can you go ahead and create it,
                      describing a bit what needs to be done,
                      and I'll make sure it gets in before 2.0.0.GA.

                      • 23. Re: VFS Permissions - JBMICROCONT-149
                        anil.saldhana

                        Can you folks retrofit ClassLoaderPolicy, VFSClassLoaderPolicy to take in the settings from the system property (java.security.debug which can have entries such as:

                         - access print all checkPermission results
                         - jar print jar verification information
                         - policy print policy information
                         - scl print permissions assigned by the SecureClassLoader
                        
                        The access option has the following sub-options:
                         - stack include stack trace
                         - domain dump all domains in context
                         - failure dump the stack and domain that did not have permission before throwing the exception
                        
                        For example, to print all checkPermission results and trace all domains in context, set java.security.debug to access,stack. To trace access failures, set it to access,failure.
                        


                        I was looking at this source file:
                        http://anonsvn.jboss.org/repos/jbossas/projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java

                        Additionally, the getProtectionDomain method was supposed to handle certificates with a todo of JBMICROCONT-182 (which has been completed)
                        https://jira.jboss.org/jira/browse/JBMICROCONT-182

                        So I created subtasks for this:

                        https://jira.jboss.org/jira/browse/JBMICROCONT-381
                        https://jira.jboss.org/jira/browse/JBMICROCONT-382

                        Ales, can I know how this classloader policy is being installed? I could not figure out from the xmls in the conf directory.

                        • 24. Re: VFS Permissions - JBMICROCONT-149
                          anil.saldhana

                          Adrian, your alternative approach of "security.xml" coming after "classloading.xml" is just one approach. But we really need to support the traditional approach of starting jboss with a security manager.

                          -Djava.security.manager


                          • 25. Re: VFS Permissions - JBMICROCONT-149
                            anil.saldhana

                            Adrian, have you explored the possibility of overriding CodeSource class to create something like VFSCodeSource that is added in the VFSClassLoaderPolicy->getProtectionDomain method?

                            The key method that always gets called by the JDK is the codesource->imples method.
                            http://java.sun.com/j2se/1.5.0/docs/api/java/security/CodeSource.html#implies(java.security.CodeSource)

                            at least in the Policy->getPermissions(CodeSource) method.
                            http://java.sun.com/j2se/1.5.0/docs/api/java/security/Policy.html#getPermissions(java.security.CodeSource)

                            • 26. Re: VFS Permissions - JBMICROCONT-149
                              anil.saldhana

                              The customized CodeSource is not going to work. The default policy file implementation usage of URL (to get the URLConnection's permission) is a problem.

                              • 27. Re: VFS Permissions - JBMICROCONT-149
                                anil.saldhana

                                With the current setup, the protection domain that is failing is:

                                ProtectionDomain (vfszip:/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/lib/jboss-aop-asintegration-core.jar <no signer certificates>)
                                 null
                                 <no principals>
                                 java.security.Permissions@12910b0b (
                                 (java.net.SocketPermission * connect,resolve)
                                 (java.lang.RuntimePermission getClassLoader)
                                 (java.lang.RuntimePermission accessClassInPackage.*)
                                 (java.lang.RuntimePermission org.jboss.security.SecurityAssociation.getSubject)
                                 (java.lang.RuntimePermission queuePrintJob)
                                 (java.lang.RuntimePermission getProtectionDomain)
                                 (java.util.PropertyPermission * read)
                                 (javax.management.MBeanServerPermission findMBeanServer)
                                 (javax.management.MBeanPermission org.jboss.mx.modelmbean.XMBean#*[JMImplementation:type=MBeanRegistry] *)
                                 (javax.management.MBeanPermission org.jboss.security.plugins.JaasSecurityManagerService#*[jboss.security:service=JaasSecurityManager] invoke)
                                 (javax.management.MBeanPermission org.jboss.security.plugins.AuthorizationManagerService#*[jboss.security:service=AuthorizationManager] invoke)
                                 (javax.management.MBeanPermission org.jboss.security.auth.login.XMLLoginConfig#*[jboss.security:service=XMLLoginConfig] invoke)
                                 (javax.security.auth.AuthPermission createLoginContext.*)
                                 (javax.security.auth.AuthPermission getLoginConfiguration)
                                 (java.io.FilePermission file:/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/bin/../server/default/tmp/- read)
                                 (java.io.FilePermission file:/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/server/default/tmp/- read)
                                 (java.security.SecurityPermission getPolicy)
                                )
                                
                                


                                I tried the protocol handler approach to apply the vfszip handler. No luck.

                                • 28. Re: VFS Permissions - JBMICROCONT-149
                                  anil.saldhana

                                  The following is happening:

                                  FilePermission fp = new FilePermission(
                                   "file:/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/server/default/tmp/-",
                                   "read");
                                   FilePermission fq = new FilePermission(
                                   "file:/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/server/default/tmp/aopdynclasses",
                                   "read");
                                  
                                   assertTrue(fp.implies(fq));
                                  
                                   FilePermission fr = new FilePermission(
                                   "/home/anil/jboss-5.0/jboss-head/build/output/jboss-5.0.0.GA/server/default/tmp/aopdynclasses",
                                   "read");
                                  
                                   assertFalse(fp.implies(fr));
                                  


                                  The assigned permission from the policy file is "fp" with the protocol to be "file:".

                                  The security manager is checking for a File Permission with the protocol stripped out and just with the path (equivalent to fr).

                                  Any vfs urls in the security policy file are rejected.

                                  • 29. Re: VFS Permissions - JBMICROCONT-149
                                    anil.saldhana

                                    Additionally, when we create the codesource url in the vfs classloading policy, we can register a URL handler. Handlers can be provided in the URL constructor.

                                    I am trying out all available options and then choose the best approach by the coming week.

                                    1 2 3 4 Previous Next