You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Mike Müller <mi...@mysign.ch> on 2014/03/16 20:54:09 UTC

[RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Hi

As I worked on SLING-3435 [1] and added some more tests I noticed that
Even if resourceaccesssecurity is installed as a bundle the two implementing 
classes ApplicationResourceAccessSecurityImpl (for application context) and 
ProviderResourceAccessSecurityImpl (for provider context) are only registered
if there is at least one ResourceAccessGate registered for the appropriate context.
The implementation of ResourceResolver itself only checks if there is an implementation
for ResourceAccessSecurity registered. If no such service is available, ResourceResolver
grants access for all operations. That means, even if a ResourceProvider implementation 
sets the useResourceAccessSecurity flag to true, access will be granted if no 
ResourceAccessGate is registered for the provider context.

I think this should be changed, because it makes resourceaccesssecurity somewhat weak.
Imagine we do have a Mongo ResourceProvider with the useResourceAccessSecurity flag 
set to true and we even have installed the resourceaccesssecurity bundle. Now 
we either forgot to install also a ResourceAccessGate implementation or the bundle 
containing the gate is not started properly. With the actual behavour access will be 
granted on all resources from Mongo ResourceProvider for all operations.
Even if the bundle with our ResourceAccessGate implementation is started correctly
But not the resourceaccesssecurity bundle we do have the same problem.
It think this is wrong in terms of security.

I suggest we should do the following:
- If a provider sets useResourceAccessSecurity flag to true we do not grant access to any
Resource from this provider (for any operation) if ResourceAccessSecurity for the provider 
context can't be found.

Furthermore the implementation of the ResourceAccessSecurity for the provider context
does not behave like the one for the application context: If we for example check the
read access for a resource the implementation calls all ResourceAccessGates till a gate
is found which grants read access. That's correct but only done in the provider context.
In the application context the implementation also calls all ResourceAccessGates till a
gate is found which grants read access. But if no gate is found which grants read access
and there's also no gate which denies access (returns GateResult.DONTCARE), access
will be granted. This seems wrong in terms of security. The two implementations for
provider context and application context should behave the same. With the only difference
that ResourceResolver will ignore the application context if the service could not be 
found.

WDYT?

Best regards
mike

[1] https://issues.apache.org/jira/browse/SLING-3435

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Marius Petria <mp...@adobe.com>.
I think the actual problem might be in the implementation of ProviderHandler. getReadableResource. The applicationsecurityservice should apply its restrictions to the already secured resource (returnValue) rather than on the initial resource. That way any constraint imposed by the providersecurityservice will be taken into account.

Marius



[1] https://github.com/apache/sling/blob/838ec33748f6cb5eb21d9dd0d8106adecc001f97/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ProviderHandler.java#L176




> -----Original Message-----
> From: Mike Müller [mailto:mikedev@mysign.ch]
> Sent: Monday, March 17, 2014 5:38 PM
> To: dev@sling.apache.org
> Subject: RE: [RT] Make ResourceAccessSecurity always restrict access if
> installed and no ResourceAccessGate present
> 
> Hi
> 
> I think this is insecure by design and not correct:
> The problem is not, that we do grant access if no ResourceAccessGate is
> registered for application context. The problem is, that we grant access also
> if there is a ResourceAccessGate registered for application level but does
> return GateResult.DONTCARE. In this case no access should be granted as we
> do on provider context.
> To see that actual wrong implementation in action have a look at the
> integration Test in
> SecuredProviderResourceAccessSecurityTest#testUpdateDeniedUpdateAllow
> edRead:
> Here only READ is granted but not UPDATE. But because there are also
> registered ResourceAccessGates for application levels the access would be
> granted for update anyway if no application ResourceAccessGate denies
> updates (per default they only return GateResult.DONTCARE).
> There's no disadvantage if we do not grant access if no ResourceAccessGate
> returns GateResult.GRANT. Because in the case if no ResourceAccessGate is
> defined we do not have a registered ResourceAccessSecurity service for the
> application level.
> So IMHO we definitively have to change this behavour to act similar as in the
> provider context.
> 
> Best regards
> mike
> 
> > -----Original Message-----
> > From: Carsten Ziegeler [mailto:cziegeler@apache.org]
> > Sent: Monday, March 17, 2014 3:35 PM
> > To: dev@sling.apache.org
> > Subject: Re: [RT] Make ResourceAccessSecurity always restrict access
> > if installed and no ResourceAccessGate present
> >
> > Yes, I think my first answer was wrong (Note to myself, don't answer
> > mails after long distance travels...) and you're right. The difference
> > between provider and application type is exactly that.
> > If there is no provider RAS and the provider does not declare to
> > require one, the resource is visible. Same with application type, but
> > also if application RAS is there but doesn't restrcit it.
> >
> > Carsten
> >
> >
> > 2014-03-17 3:09 GMT-07:00 Marius Petria <mp...@adobe.com>:
> >
> > > > > Furthermore the implementation of the ResourceAccessSecurity for
> > > > > the provider context does not behave like the one for the
> > > > > application
> > > > > context: If we for example check the read access for a resource
> > > > > the implementation calls all ResourceAccessGates till a gate is
> > > > > found which grants read access. That's correct but only done in
> > > > > the provider context.
> > > > > In the application context the implementation also calls all
> > > > > ResourceAccessGates till a gate is found which grants read access.
> > > > > But if no gate is found which grants read access and there's
> > > > > also no gate which denies access (returns GateResult.DONTCARE),
> > > > > access will be granted. This seems wrong in terms of security.
> > > > > The two implementations for provider context and application
> > > > > context should behave the same. With the only difference that
> > > > > ResourceResolver will ignore the application context if the
> > > > > service could
> > not be found.
> > >
> > > I thought the difference in defaults between application scoped
> > > access security and provider scoped is intended.
> > > Provider scoped access security is requested by the resource
> > > provider itself using USE_RESOURCE_ACCESS_SECURITY, so it makes
> > > sense to deny access if no gate is present because the provider
> > > really cares about
> > security.
> > >
> > > However, the application scoped access security is requested by the
> > > one that installs a gate, so it should only restrict access if the
> > > gate is present, as the provider does not really care about security.
> > >
> > > Or, am I understanding it wrong?
> > >
> > > Marius
> > >
> > >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Marius Petria <mp...@adobe.com>.
I created an issue to fix the initial problem encountered by Mike [1]. 

The issue was that an explicit application scoped gate was needed to deny update access even if the access was denied by a provider scoped gate. That problem was captured in a test [2].

WDYT?

Marius

[1] https://issues.apache.org/jira/browse/SLING-3458
[2] https://github.com/apache/sling/blob/trunk/bundles/resourceaccesssecurity/it/src/test/java/org/apache/sling/resourceaccesssecurity/it/SecuredProviderResourceAccessSecurityTest.java#L103



RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Mike Müller <mi...@mysign.ch>.
...snipsnap
> 
> Ok, I see your point and yes, partially this is related to the name
> "DONTCARE". I'm fine with renaming it to CANTDECIDE and then implementing
> it the way you suggest :)
> 
> Regards
> Carsten

Okay, created SLING-3462.

Best regards
mike

Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Carsten Ziegeler <cz...@apache.org>.
Ok, I see your point and yes, partially this is related to the name
"DONTCARE". I'm fine with renaming it to CANTDECIDE and then implementing
it the way you suggest :)

Regards
Carsten


2014-03-18 0:48 GMT-07:00 Mike Müller <mi...@mysign.ch>:

> > 2014-03-17 8:38 GMT-07:00 Mike Müller <mi...@mysign.ch>:
> >
> > > Hi
> > >
> > > I think this is insecure by design and not correct:
> > > The problem is not, that we do grant access if no ResourceAccessGate is
> > > registered for application context. The problem is, that we grant
> access
> > > also if there is a ResourceAccessGate registered for application level
> but
> > > does return GateResult.DONTCARE. In this case no access should be
> granted
> > > as we do on provider context.
> > > To see that actual wrong implementation in action have a look at the
> > > integration
> > > Test in
> > >
> SecuredProviderResourceAccessSecurityTest#testUpdateDeniedUpdateAllowedRead:
> > > Here only READ is granted but not UPDATE. But because there are also
> > > registered
> > > ResourceAccessGates for application levels the access would be granted
> for
> > > update anyway if no application ResourceAccessGate denies updates (per
> > > default
> > > they only return GateResult.DONTCARE).
> > > There's no disadvantage if we do not grant access if no
> ResourceAccessGate
> > > returns GateResult.GRANT. Because in the case if no ResourceAccessGate
> is
> > > defined we do not have a registered ResourceAccessSecurity service for
> > > the application level.
> > > So IMHO we definitively have to change this behavour to act similar as
> in
> > > the
> > > provider context.
> > >
> > >
> > ah, thanks, got it now. I think either way is a little bit strange. I
> guess
> > we all agree that if there is no application RAG, the resource is
> > accessible (leaving out the provider RAG for now).
> > Then you add an application RAG which say "DONTCARE" and out of the
> sudden,
> > the resource is not visible anymore. This seems a little bit
> contradicting
> > the term "DONTCARE". I think DONTCARE means you get the same result as if
> > this check wasn't done and in the case of the application RAG that's
> acess
> > is granted.
> >
> > Regards
> > Carsten
>
>
> I think in this case the concept of DONTCARE is not clear. DONTCARE
> doesn't mean
> GRANT, it rather means "I can't decide". So if a RAG returns DONTCARE that
> means
> NOT if nobody else handles the resource we can grant access. Maybe it's
> easier to
> understand why this third answer (beside GRANT and DENY) should be
> possible at
> all, here's a use case:
> Think of a LockdownGate which locks down the whole site and only allows
> access to
> logged in users. To do that we implement a RAG with a canReadMethod like
> this
>
>     public GateResult canRead(Resource resource) {
>         if (resource.getResourceResolver().getUserID() != null  && !
> resource.getResourceResolver().getUserID().equals("anonymous") )
>         {
>             return GateResult.DONTCARE;
>         }
>         else
>         {
>             return GateResult.DENIED;
>         }
>     }
>
> and register the RAG with the property finaloperations=read.
> This ensures that not logged in users do not have read access. But it also
> ensures
> that logged in users do not have more access than before the registration
> of the
> LockdownGate because with the returning DONTCARE the gate delegates giving
> access here to the other existing gates. If no other gate grants access
> the logged
> in user will not have additional access because of the LockdownGate, which
> is
> what we really want. To allow access would be wrong.
>
> We do exactly that with provider context RAGs so it would be wrong to do
> something
> else in the application context. The only difference between these two is,
> that without
> any RAG registered for the provider context access will be denied (because
> the resource
> provider asked for with the setted flag). In application context access
> will be granted without
> any RAG registered for application context (because in this case maybe you
> do not want
> to use ResourceAccessSecurity). But as soon as a RAG is registered we do
> that because we
> want to control the access and the registered RAGs have to grant access
> explicitly.
>
> Maybe it would make sense to rename the DONTCARE to CANTDECIDE which would
> explain the mechanism better.
>
> Best regards
> mike
>



-- 
Carsten Ziegeler
cziegeler@apache.org

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Mike Müller <mi...@mysign.ch>.
> From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org]
> Subject: Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present
> 
> Hi,
> 
> On Tue, Mar 18, 2014 at 8:48 AM, Mike Müller <mi...@mysign.ch> wrote:
> >... Maybe it would make sense to rename the DONTCARE to CANTDECIDE which would
> > explain the mechanism better....
> 
> I'm only half-following those discussions - do we have a single place
> which explains how the RAG works?
> 
> As this stuff has security implications it would be nice to make sure
> we can get and review the complete picture somewhere.
> 
> Unless there's something already I'd suggest a new page under
> http://sling.apache.org/documentation/bundles.html which acts as the
> documentation for this feature once it's ready. For now that can be
> marked DRAFT while things are still in flux - or maybe start a draft
> at https://cwiki.apache.org/confluence/display/SLING

Good point.
+1
I will do a first draft, created SLING-3461.

Best regards
mike

Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Mar 18, 2014 at 8:48 AM, Mike Müller <mi...@mysign.ch> wrote:
>... Maybe it would make sense to rename the DONTCARE to CANTDECIDE which would
> explain the mechanism better....

I'm only half-following those discussions - do we have a single place
which explains how the RAG works?

As this stuff has security implications it would be nice to make sure
we can get and review the complete picture somewhere.

Unless there's something already I'd suggest a new page under
http://sling.apache.org/documentation/bundles.html which acts as the
documentation for this feature once it's ready. For now that can be
marked DRAFT while things are still in flux - or maybe start a draft
at https://cwiki.apache.org/confluence/display/SLING

-Bertrand

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Mike Müller <mi...@mysign.ch>.
> 2014-03-17 8:38 GMT-07:00 Mike Müller <mi...@mysign.ch>:
> 
> > Hi
> >
> > I think this is insecure by design and not correct:
> > The problem is not, that we do grant access if no ResourceAccessGate is
> > registered for application context. The problem is, that we grant access
> > also if there is a ResourceAccessGate registered for application level but
> > does return GateResult.DONTCARE. In this case no access should be granted
> > as we do on provider context.
> > To see that actual wrong implementation in action have a look at the
> > integration
> > Test in
> > SecuredProviderResourceAccessSecurityTest#testUpdateDeniedUpdateAllowedRead:
> > Here only READ is granted but not UPDATE. But because there are also
> > registered
> > ResourceAccessGates for application levels the access would be granted for
> > update anyway if no application ResourceAccessGate denies updates (per
> > default
> > they only return GateResult.DONTCARE).
> > There's no disadvantage if we do not grant access if no ResourceAccessGate
> > returns GateResult.GRANT. Because in the case if no ResourceAccessGate is
> > defined we do not have a registered ResourceAccessSecurity service for
> > the application level.
> > So IMHO we definitively have to change this behavour to act similar as in
> > the
> > provider context.
> >
> >
> ah, thanks, got it now. I think either way is a little bit strange. I guess
> we all agree that if there is no application RAG, the resource is
> accessible (leaving out the provider RAG for now).
> Then you add an application RAG which say "DONTCARE" and out of the sudden,
> the resource is not visible anymore. This seems a little bit contradicting
> the term "DONTCARE". I think DONTCARE means you get the same result as if
> this check wasn't done and in the case of the application RAG that's acess
> is granted.
> 
> Regards
> Carsten


I think in this case the concept of DONTCARE is not clear. DONTCARE doesn't mean
GRANT, it rather means "I can't decide". So if a RAG returns DONTCARE that means
NOT if nobody else handles the resource we can grant access. Maybe it's easier to
understand why this third answer (beside GRANT and DENY) should be possible at
all, here's a use case:
Think of a LockdownGate which locks down the whole site and only allows access to 
logged in users. To do that we implement a RAG with a canReadMethod like this

    public GateResult canRead(Resource resource) {
        if (resource.getResourceResolver().getUserID() != null  && ! resource.getResourceResolver().getUserID().equals("anonymous") )
        {
            return GateResult.DONTCARE;
        }
        else
        {
            return GateResult.DENIED;
        }
    }

and register the RAG with the property finaloperations=read.
This ensures that not logged in users do not have read access. But it also ensures
that logged in users do not have more access than before the registration of the
LockdownGate because with the returning DONTCARE the gate delegates giving
access here to the other existing gates. If no other gate grants access the logged
in user will not have additional access because of the LockdownGate, which is
what we really want. To allow access would be wrong.

We do exactly that with provider context RAGs so it would be wrong to do something
else in the application context. The only difference between these two is, that without
any RAG registered for the provider context access will be denied (because the resource
provider asked for with the setted flag). In application context access will be granted without
any RAG registered for application context (because in this case maybe you do not want
to use ResourceAccessSecurity). But as soon as a RAG is registered we do that because we
want to control the access and the registered RAGs have to grant access explicitly.

Maybe it would make sense to rename the DONTCARE to CANTDECIDE which would 
explain the mechanism better.

Best regards
mike

Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi


2014-03-17 8:38 GMT-07:00 Mike Müller <mi...@mysign.ch>:

> Hi
>
> I think this is insecure by design and not correct:
> The problem is not, that we do grant access if no ResourceAccessGate is
> registered for application context. The problem is, that we grant access
> also if there is a ResourceAccessGate registered for application level but
> does return GateResult.DONTCARE. In this case no access should be granted
> as we do on provider context.
> To see that actual wrong implementation in action have a look at the
> integration
> Test in
> SecuredProviderResourceAccessSecurityTest#testUpdateDeniedUpdateAllowedRead:
> Here only READ is granted but not UPDATE. But because there are also
> registered
> ResourceAccessGates for application levels the access would be granted for
> update anyway if no application ResourceAccessGate denies updates (per
> default
> they only return GateResult.DONTCARE).
> There's no disadvantage if we do not grant access if no ResourceAccessGate
> returns GateResult.GRANT. Because in the case if no ResourceAccessGate is
> defined we do not have a registered ResourceAccessSecurity service for
> the application level.
> So IMHO we definitively have to change this behavour to act similar as in
> the
> provider context.
>
>
ah, thanks, got it now. I think either way is a little bit strange. I guess
we all agree that if there is no application RAG, the resource is
accessible (leaving out the provider RAG for now).
Then you add an application RAG which say "DONTCARE" and out of the sudden,
the resource is not visible anymore. This seems a little bit contradicting
the term "DONTCARE". I think DONTCARE means you get the same result as if
this check wasn't done and in the case of the application RAG that's acess
is granted.

Regards
Carsten



> Best regards
> mike
>
> > -----Original Message-----
> > From: Carsten Ziegeler [mailto:cziegeler@apache.org]
> > Sent: Monday, March 17, 2014 3:35 PM
> > To: dev@sling.apache.org
> > Subject: Re: [RT] Make ResourceAccessSecurity always restrict access if
> > installed and no ResourceAccessGate present
> >
> > Yes, I think my first answer was wrong (Note to myself, don't answer
> mails
> > after long distance travels...) and you're right. The difference between
> > provider and application type is exactly that.
> > If there is no provider RAS and the provider does not declare to require
> one,
> > the resource is visible. Same with application type, but also if
> application RAS
> > is there but doesn't restrcit it.
> >
> > Carsten
> >
> >
> > 2014-03-17 3:09 GMT-07:00 Marius Petria <mp...@adobe.com>:
> >
> > > > > Furthermore the implementation of the ResourceAccessSecurity for
> > > > > the provider context does not behave like the one for the
> > > > > application
> > > > > context: If we for example check the read access for a resource
> > > > > the implementation calls all ResourceAccessGates till a gate is
> > > > > found which grants read access. That's correct but only done in
> > > > > the provider context.
> > > > > In the application context the implementation also calls all
> > > > > ResourceAccessGates till a gate is found which grants read access.
> > > > > But if no gate is found which grants read access and there's also
> > > > > no gate which denies access (returns GateResult.DONTCARE), access
> > > > > will be granted. This seems wrong in terms of security. The two
> > > > > implementations for provider context and application context
> > > > > should behave the same. With the only difference that
> > > > > ResourceResolver will ignore the application context if the
> service could
> > not be found.
> > >
> > > I thought the difference in defaults between application scoped access
> > > security and provider scoped is intended.
> > > Provider scoped access security is requested by the resource provider
> > > itself using USE_RESOURCE_ACCESS_SECURITY, so it makes sense to deny
> > > access if no gate is present because the provider really cares about
> > security.
> > >
> > > However, the application scoped access security is requested by the
> > > one that installs a gate, so it should only restrict access if the
> > > gate is present, as the provider does not really care about security.
> > >
> > > Or, am I understanding it wrong?
> > >
> > > Marius
> > >
> > >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
>



-- 
Carsten Ziegeler
cziegeler@apache.org

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Mike Müller <mi...@mysign.ch>.
Hi

I think this is insecure by design and not correct:
The problem is not, that we do grant access if no ResourceAccessGate is
registered for application context. The problem is, that we grant access
also if there is a ResourceAccessGate registered for application level but
does return GateResult.DONTCARE. In this case no access should be granted
as we do on provider context.
To see that actual wrong implementation in action have a look at the integration
Test in SecuredProviderResourceAccessSecurityTest#testUpdateDeniedUpdateAllowedRead:
Here only READ is granted but not UPDATE. But because there are also registered
ResourceAccessGates for application levels the access would be granted for
update anyway if no application ResourceAccessGate denies updates (per default
they only return GateResult.DONTCARE).
There's no disadvantage if we do not grant access if no ResourceAccessGate
returns GateResult.GRANT. Because in the case if no ResourceAccessGate is
defined we do not have a registered ResourceAccessSecurity service for
the application level.
So IMHO we definitively have to change this behavour to act similar as in the
provider context.

Best regards
mike

> -----Original Message-----
> From: Carsten Ziegeler [mailto:cziegeler@apache.org]
> Sent: Monday, March 17, 2014 3:35 PM
> To: dev@sling.apache.org
> Subject: Re: [RT] Make ResourceAccessSecurity always restrict access if
> installed and no ResourceAccessGate present
> 
> Yes, I think my first answer was wrong (Note to myself, don't answer mails
> after long distance travels...) and you're right. The difference between
> provider and application type is exactly that.
> If there is no provider RAS and the provider does not declare to require one,
> the resource is visible. Same with application type, but also if application RAS
> is there but doesn't restrcit it.
> 
> Carsten
> 
> 
> 2014-03-17 3:09 GMT-07:00 Marius Petria <mp...@adobe.com>:
> 
> > > > Furthermore the implementation of the ResourceAccessSecurity for
> > > > the provider context does not behave like the one for the
> > > > application
> > > > context: If we for example check the read access for a resource
> > > > the implementation calls all ResourceAccessGates till a gate is
> > > > found which grants read access. That's correct but only done in
> > > > the provider context.
> > > > In the application context the implementation also calls all
> > > > ResourceAccessGates till a gate is found which grants read access.
> > > > But if no gate is found which grants read access and there's also
> > > > no gate which denies access (returns GateResult.DONTCARE), access
> > > > will be granted. This seems wrong in terms of security. The two
> > > > implementations for provider context and application context
> > > > should behave the same. With the only difference that
> > > > ResourceResolver will ignore the application context if the service could
> not be found.
> >
> > I thought the difference in defaults between application scoped access
> > security and provider scoped is intended.
> > Provider scoped access security is requested by the resource provider
> > itself using USE_RESOURCE_ACCESS_SECURITY, so it makes sense to deny
> > access if no gate is present because the provider really cares about
> security.
> >
> > However, the application scoped access security is requested by the
> > one that installs a gate, so it should only restrict access if the
> > gate is present, as the provider does not really care about security.
> >
> > Or, am I understanding it wrong?
> >
> > Marius
> >
> >
> 
> 
> --
> Carsten Ziegeler
> cziegeler@apache.org

Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Carsten Ziegeler <cz...@apache.org>.
Yes, I think my first answer was wrong (Note to myself, don't answer mails
after long distance travels...)
and you're right. The difference between provider and application type is
exactly that.
If there is no provider RAS and the provider does not declare to require
one, the resource is visible. Same with application type, but also if
application RAS is there but doesn't restrcit it.

Carsten


2014-03-17 3:09 GMT-07:00 Marius Petria <mp...@adobe.com>:

> > > Furthermore the implementation of the ResourceAccessSecurity for the
> > > provider context does not behave like the one for the application
> > > context: If we for example check the read access for a resource the
> > > implementation calls all ResourceAccessGates till a gate is found
> > > which grants read access. That's correct but only done in the provider
> > > context.
> > > In the application context the implementation also calls all
> > > ResourceAccessGates till a gate is found which grants read access. But
> > > if no gate is found which grants read access and there's also no gate
> > > which denies access (returns GateResult.DONTCARE), access will be
> > > granted. This seems wrong in terms of security. The two
> > > implementations for provider context and application context should
> > > behave the same. With the only difference that ResourceResolver will
> > > ignore the application context if the service could not be found.
>
> I thought the difference in defaults between application scoped access
> security and provider scoped is intended.
> Provider scoped access security is requested by the resource provider
> itself using USE_RESOURCE_ACCESS_SECURITY, so it makes sense to deny access
> if no gate is present because the provider really cares about security.
>
> However, the application scoped access security is requested by the one
> that installs a gate, so it should only restrict access if the gate is
> present, as the provider does not really care about security.
>
> Or, am I understanding it wrong?
>
> Marius
>
>


-- 
Carsten Ziegeler
cziegeler@apache.org

RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Marius Petria <mp...@adobe.com>.
> > Furthermore the implementation of the ResourceAccessSecurity for the
> > provider context does not behave like the one for the application
> > context: If we for example check the read access for a resource the
> > implementation calls all ResourceAccessGates till a gate is found
> > which grants read access. That's correct but only done in the provider
> > context.
> > In the application context the implementation also calls all
> > ResourceAccessGates till a gate is found which grants read access. But
> > if no gate is found which grants read access and there's also no gate
> > which denies access (returns GateResult.DONTCARE), access will be
> > granted. This seems wrong in terms of security. The two
> > implementations for provider context and application context should
> > behave the same. With the only difference that ResourceResolver will
> > ignore the application context if the service could not be found.

I thought the difference in defaults between application scoped access security and provider scoped is intended.
Provider scoped access security is requested by the resource provider itself using USE_RESOURCE_ACCESS_SECURITY, so it makes sense to deny access if no gate is present because the provider really cares about security.

However, the application scoped access security is requested by the one that installs a gate, so it should only restrict access if the gate is present, as the provider does not really care about security. 

Or, am I understanding it wrong?

Marius


RE: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Mike Müller <mi...@mysign.ch>.
> the current implementation does actually this (if I read the code
> correctly) :)

Yes you're right, the implementation for this case is correct. Sorry for the
confusion...

> If useRAS is set, but no Gate available, the resource is not returned. At least
> ProviderHandler#getReadableResource does this.
> But of course if this is not the case, then you're totally right and we need to
> change this.
> 
> And I totally agree that provider and application context should behave
> similar.
> 
> Regards
> Carsten
> 
> 
> 2014-03-16 12:54 GMT-07:00 Mike Müller <mi...@mysign.ch>:
> 
> > Hi
> >
> > As I worked on SLING-3435 [1] and added some more tests I noticed that
> > Even if resourceaccesssecurity is installed as a bundle the two
> > implementing classes ApplicationResourceAccessSecurityImpl (for
> > application context) and ProviderResourceAccessSecurityImpl (for
> > provider context) are only registered if there is at least one
> > ResourceAccessGate registered for the appropriate context.
> > The implementation of ResourceResolver itself only checks if there is
> > an implementation for ResourceAccessSecurity registered. If no such
> > service is available, ResourceResolver grants access for all
> > operations. That means, even if a ResourceProvider implementation sets
> > the useResourceAccessSecurity flag to true, access will be granted if
> > no ResourceAccessGate is registered for the provider context.
> >
> > I think this should be changed, because it makes
> > resourceaccesssecurity somewhat weak.
> > Imagine we do have a Mongo ResourceProvider with the
> > useResourceAccessSecurity flag set to true and we even have installed
> > the resourceaccesssecurity bundle.
> > Now
> > we either forgot to install also a ResourceAccessGate implementation
> > or the bundle containing the gate is not started properly. With the
> > actual behavour access will be granted on all resources from Mongo
> > ResourceProvider for all operations.
> > Even if the bundle with our ResourceAccessGate implementation is
> > started correctly But not the resourceaccesssecurity bundle we do have
> > the same problem.
> > It think this is wrong in terms of security.
> >
> > I suggest we should do the following:
> > - If a provider sets useResourceAccessSecurity flag to true we do not
> > grant access to any Resource from this provider (for any operation) if
> > ResourceAccessSecurity for the provider context can't be found.
> >
> > Furthermore the implementation of the ResourceAccessSecurity for the
> > provider context does not behave like the one for the application
> > context: If we for example check the read access for a resource the
> > implementation calls all ResourceAccessGates till a gate is found
> > which grants read access. That's correct but only done in the provider
> > context.
> > In the application context the implementation also calls all
> > ResourceAccessGates till a gate is found which grants read access. But
> > if no gate is found which grants read access and there's also no gate
> > which denies access (returns GateResult.DONTCARE), access will be
> > granted. This seems wrong in terms of security. The two
> > implementations for provider context and application context should
> > behave the same. With the only difference that ResourceResolver will
> > ignore the application context if the service could not be found.
> >
> > WDYT?
> >
> > Best regards
> > mike
> >
> > [1] https://issues.apache.org/jira/browse/SLING-3435
> >
> 
> 
> 
> --
> Carsten Ziegeler
> cziegeler@apache.org

Re: [RT] Make ResourceAccessSecurity always restrict access if installed and no ResourceAccessGate present

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

the current implementation does actually this (if I read the code
correctly) :)
If useRAS is set, but no Gate available, the resource is not returned. At
least ProviderHandler#getReadableResource does this.
But of course if this is not the case, then you're totally right and we
need to change this.

And I totally agree that provider and application context should behave
similar.

Regards
Carsten


2014-03-16 12:54 GMT-07:00 Mike Müller <mi...@mysign.ch>:

> Hi
>
> As I worked on SLING-3435 [1] and added some more tests I noticed that
> Even if resourceaccesssecurity is installed as a bundle the two
> implementing
> classes ApplicationResourceAccessSecurityImpl (for application context) and
> ProviderResourceAccessSecurityImpl (for provider context) are only
> registered
> if there is at least one ResourceAccessGate registered for the appropriate
> context.
> The implementation of ResourceResolver itself only checks if there is an
> implementation
> for ResourceAccessSecurity registered. If no such service is available,
> ResourceResolver
> grants access for all operations. That means, even if a ResourceProvider
> implementation
> sets the useResourceAccessSecurity flag to true, access will be granted if
> no
> ResourceAccessGate is registered for the provider context.
>
> I think this should be changed, because it makes resourceaccesssecurity
> somewhat weak.
> Imagine we do have a Mongo ResourceProvider with the
> useResourceAccessSecurity flag
> set to true and we even have installed the resourceaccesssecurity bundle.
> Now
> we either forgot to install also a ResourceAccessGate implementation or
> the bundle
> containing the gate is not started properly. With the actual behavour
> access will be
> granted on all resources from Mongo ResourceProvider for all operations.
> Even if the bundle with our ResourceAccessGate implementation is started
> correctly
> But not the resourceaccesssecurity bundle we do have the same problem.
> It think this is wrong in terms of security.
>
> I suggest we should do the following:
> - If a provider sets useResourceAccessSecurity flag to true we do not
> grant access to any
> Resource from this provider (for any operation) if ResourceAccessSecurity
> for the provider
> context can't be found.
>
> Furthermore the implementation of the ResourceAccessSecurity for the
> provider context
> does not behave like the one for the application context: If we for
> example check the
> read access for a resource the implementation calls all
> ResourceAccessGates till a gate
> is found which grants read access. That's correct but only done in the
> provider context.
> In the application context the implementation also calls all
> ResourceAccessGates till a
> gate is found which grants read access. But if no gate is found which
> grants read access
> and there's also no gate which denies access (returns
> GateResult.DONTCARE), access
> will be granted. This seems wrong in terms of security. The two
> implementations for
> provider context and application context should behave the same. With the
> only difference
> that ResourceResolver will ignore the application context if the service
> could not be
> found.
>
> WDYT?
>
> Best regards
> mike
>
> [1] https://issues.apache.org/jira/browse/SLING-3435
>



-- 
Carsten Ziegeler
cziegeler@apache.org