Gregg Wonderly wrote:
On Jul 7, 2012, at 8:02 AM, Peter Firmstone wrote:

These doAs methods in this case cannot elevate Permission, they can reduce 
Permission to that which the Subject has in common with other code on the 
stack, but it cannot be used by code to gain privilege if it uses a custom 
DomainCombiner that extends SubjectDomainCombiner.

Would this be an acceptable compromise?

In future, we can look at other tools to assist with simplifying security, such 
as static bytecode analysis or FindBugs perhaps.

When I am using remote code, I either trust it by source, or don't, and can assert that trust by 
granting AllPermission for the URL, or not.  Adding local resource access to a proxies code base, 
is usually limited to network access, but sometimes file access for certain UIs which, for example, 
have images which my caching URLHandler will store on disk.  That access to local resources, 
whether through Subject grant, or blanket permission is what matters for using a services 
ServiceUI.  When I use a services proxy for interaction, I've always used JAAS login services to 
gain access, via PAM login services on Linux and other PAM supporting OSes using JNI mechanisms.  
Thus, there is a Subject created which has a set of Principals that my LoginModule creates in the 
form of a "user" and any "groups" that the user is a member of.

In the services, I always use Subject.doAs with those subjects, and could use 
user or group based permission grants in my policy.  But, in the end, I never 
found that to be needed, and I instead, grant permissions to the codebase at 
the appropriate granularity (never granting to or using a client side codebase 
jar).

The authorization framework that I've mention here, before, is then used to do 
role based control of how the API is used on the server, by the calls into that 
environment from the client.  I have a InvocationHandler that I insert to do 
the Subject.doAs() on the server side.  So, when the user authenticates with 
the server, I get a Subject.  I do Subject.doAs() to create an instance of the 
InvocationHandler (which holds a reference to the Subject), and the exported 
smart proxy instance, which is returned to the client.

When a Subject asserts some kind of client local controls, it could provide 
some new functionality as you illustrated. In the case of network access 
control, or other local resource access, it could allow you to limit access to 
those resources, or to extend access in particular ways with a dynamic policy 
grant, on the client.

I crafted some code in that direction at one point.  It allowed the jar to have 
a list of permissions in it, that it wished to have granted, and I was trying 
to decide what the right interface would be, to allowing the client software to 
talk to the user about these permissions.  In a sense, this was along the lines 
of Java WebStart kinds of thoughts.  My ServiceUI desktop has a code flow at 
the point that the UI is activated, that it could obviously do a resource query 
into the jar, find the requested accesses, and prompt the user to grant them.

Conversely, you want to limit permissions by asserting a domain controlled by 
the Subject, that would provide whatever access you granted to the Subject in 
that domain/policty.  So, at the time that a client UI is first activated, you 
could use information about it being an uncontrolled codebase to trigger the 
assertion of the Subject controlled domain.

What I think we need to focus on, are these two mechanisms (grant to client 
thread/Subject jar requested permissions and limit of client thread to already 
asserted Subject based domain) and the obvious fact that it's really about 
asserting control into the client execution environment.  We need to work on 
how we'd decide that needed to happen, and then think about whether it's just 
Subjects we want to assert, and whether we need to include the Privileged forms 
or not.

Gregg Wonderly
I've spent some time pondering the issue of running as a Subject in the presence of untrusted code.

I've realised that the Privileged forms are also required, to allow a context to be saved and run in an executor thread as an example. But since Jini Security also allows preservation of the context ClassLoader or anything else for that matter, by utilising a Policy or SecurityManager that implements SecurityContextSource, I'd like to use SecurityContext in place of AccessControlContext. AggregatePolicyProvider implements it to preserve the context class loader. Other than SecurityContext, the functionality would be similar to Subject.doAsPrivileged.

It is possible using the existing Subject.doAsPrivileged methods, to get the current context, then from within a privileged action call Subject.doAsPrivileged with the context previously retrieved. In this case the Subjects Principals are only injected into the privileged domain of the calling code, excluding domains from the previously retrieved context. The issue is of course when a trusted domain calls Subject.doAsPrivileged, it may already have AllPermission or have privileges, so additional principals are unlikely to grant additional privilege. If there is untrusted code in assignedDomains, it won't cause security issues, since the Principals are not injected into assigned or inherited domains, only the current context, which in this case will be the privileged callers domain.

Available privileges are limited to the intersection of Permissions in each domain, if only trusted code is present on the Thread stack, the only way to restrict permission of the Subject will be to restrict permission of trusted privileged code. This is however complex and difficult for developers to comprehend. Separation of concerns between Principals and CodeSource is easier to comprehend. Rather than grant to CodeSource and Principals, make separate grants for each, this ensures that a Subject has no more privileges than specified by grants to that Subjects Principals.

Many Jini services also use Subject.doAsPrivileged, to start a service with only one ProtectionDomain on the stack, injected with Server Principals.

Since Gregg hasn't utilised traditional jvm style Permissions for Principals, there is no possibility of elevating privileges when calling Subject.doAs, so granting "doAs" to untrusted code doesn't present any security risk in Gregg's use case.

The proposed doAs methods don't elevate privileges, on the contrary they may narrow privilege and hence aren't a security risk if called in the presence of untrusted code, unlike Subject.doAs, which will throw a SecurityException.

Providing an alternative to Subject.doAs would also be useful in the case where a service allows clients to hand back another remote object, allowing remote code (to which we don't want to grant privilege) to run on the server, while multiple client Subjects (represented by threads) interact with each other in the presence of untrusted proxy code in the same jvm.

But we must always be very careful not to deserialise in a privileged context, regardless of whether the new methods are used, otherwise DownloadPermission can be easily circumvented.

The use case here is for Internet based services, we need to assure administrators that running downloaded code is no less secure than using a web browser, otherwise an administrator would likely disable the functionality.

I'll commit an example implementation shortly, this may be removed in future, but it might be useful in explaining what I'm trying to achieve.

Also it's worth noting the Policy implementation can provide support, so changes to Subject Principals are effective immediately, leading to a much more programmer friendly JAAS.

Regards,

Peter.

Reply via email to