You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Mike Matrigali <mi...@sbcglobal.net> on 2007/07/09 22:49:24 UTC

what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

I am hoping to get a discussion going on how the right way to fix these
issues.  As I understand it the ability to read/write files is currently
inherited from derby.jar where the import/export system procedures
currently reside.  The problem is that this means the they can be used
to bypass the normal database level read/write access to derby system
files: property files, database files, log files, temp files.  As dan
has pointed out I believe the current policy files may allow in one
database but access files in a completely different database so the
scope of the files is larger than just the current database.

I don't know much about security manager possibilities so maybe someone
who knows can point the way.

Some approaches:
1) try to code access privileges in the routines themselves, that is 
separate from java security manager.  Basically
    disallow access to derby files by adding code logic to determine if 
the files being read/written are derby files.  This is not too hard to 
do if you
    only want to disallow under the current database subtree, but gets
    harder under any derby subtree.
    So I think this approach  would check for files named:
    derby.properties
    system.properties
    log/log*.dat
    log/log.ctrl
    log/logmirror.ctrl
    seg0/*.dat

    I think temporary files also, and I think they can be anywhere.


2) Is it possible to temporarily give up a set of granted security 
privileges in a class and get them again on the way out?  Basically
import only wants the write derby access privilege and export only
wants the read derby access privilege.

3) Could the routines be moved into a separate jar that would get a 
different set of security manager privileges?

4) we could get rid of the current interfaces all together and change
to require streams rather than files for the user files.  This may be
a lot slower and does raise backward compatibility issues.  The point
of import/export is to allow easy/fast bulk load/unload, so doesn't 
really solve the issue.

Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Daniel John Debrunner <dj...@apache.org>.
Mike Matrigali wrote:
> I am hoping to get a discussion going on how the right way to fix these
> issues.  As I understand it the ability to read/write files is currently
> inherited from derby.jar where the import/export system procedures
> currently reside.  The problem is that this means the they can be used
> to bypass the normal database level read/write access to derby system
> files: property files, database files, log files, temp files.  As dan
> has pointed out I believe the current policy files may allow in one
> database but access files in a completely different database so the
> scope of the files is larger than just the current database.
> 
> I don't know much about security manager possibilities so maybe someone
> who knows can point the way.
> 
> Some approaches:
> 1) try to code access privileges in the routines themselves, that is 
> separate from java security manager.  Basically
>    disallow access to derby files by adding code logic to determine if 
> the files being read/written are derby files.  This is not too hard to 
> do if you
>    only want to disallow under the current database subtree, but gets
>    harder under any derby subtree.
>    So I think this approach  would check for files named:
>    derby.properties
>    system.properties
>    log/log*.dat
>    log/log.ctrl
>    log/logmirror.ctrl
>    seg0/*.dat
> 
>    I think temporary files also, and I think they can be anywhere.

I like the above approach, simple but likely covers most of situations. 
The list would need to include jar/*.jar. I also think you mean 
service.properties and not system.properties.


A "right" Java fix might be to introduce new Derby permissions for 
import and export. Then derby.jar would need to be granted those 
permissions in order to import/export. The permissions could use 
java.io.FilePermission (write for Export, read for Import).

Dan.



Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Rick Hillegas <Ri...@Sun.COM>.
Mike Matrigali wrote:
> Another approach might be to just disallow import/export on files that
> are under system home.  This might be a backward compatibility issue.
> If compatibility were an overriding issue then we could just do this in
> 10.3 for blob/clob import/export leaving the possible holes that already
> exist in 10.2.
>
> Mike Matrigali wrote:
>> I am hoping to get a discussion going on how the right way to fix these
>> issues.  As I understand it the ability to read/write files is currently
>> inherited from derby.jar where the import/export system procedures
>> currently reside.  The problem is that this means the they can be used
>> to bypass the normal database level read/write access to derby system
>> files: property files, database files, log files, temp files.  As dan
>> has pointed out I believe the current policy files may allow in one
>> database but access files in a completely different database so the
>> scope of the files is larger than just the current database.
>>
>> I don't know much about security manager possibilities so maybe someone
>> who knows can point the way.
>>
>> Some approaches:
>> 1) try to code access privileges in the routines themselves, that is 
>> separate from java security manager.  Basically
>>    disallow access to derby files by adding code logic to determine 
>> if the files being read/written are derby files.  This is not too 
>> hard to do if you
>>    only want to disallow under the current database subtree, but gets
>>    harder under any derby subtree.
>>    So I think this approach  would check for files named:
>>    derby.properties
>>    system.properties
>>    log/log*.dat
>>    log/log.ctrl
>>    log/logmirror.ctrl
>>    seg0/*.dat
>>
>>    I think temporary files also, and I think they can be anywhere.
>>
>>
>> 2) Is it possible to temporarily give up a set of granted security 
>> privileges in a class and get them again on the way out?  Basically
>> import only wants the write derby access privilege and export only
>> wants the read derby access privilege.
>>
>> 3) Could the routines be moved into a separate jar that would get a 
>> different set of security manager privileges?
>>
>> 4) we could get rid of the current interfaces all together and change
>> to require streams rather than files for the user files.  This may be
>> a lot slower and does raise backward compatibility issues.  The point
>> of import/export is to allow easy/fast bulk load/unload, so doesn't 
>> really solve the issue.
>>
5) Martin is adding system privileges (DERBY-2109) as part of 10.4. He 
has already checked in a DatabasePermission class. It should be possible 
to define new kinds of DatabasePermissions which restrict 
import/export/backup/restore to specific subdirectories. So, for 
instance, the customer could add the following permission to the server 
policy file. This permission would prevent Mike from exporting anywhere 
outside his home directory tree:


    grant principal org.apache.derby.authentication.DatabasePrincipal 
"mikem@mikesDB"
    {
      permission org.apache.derby.security.DatabasePermission 
"directory:/usr/home/mikem/-" "export";
    };

Regards,
-Rick



Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Mike Matrigali <mi...@sbcglobal.net>.
Another approach might be to just disallow import/export on files that
are under system home.  This might be a backward compatibility issue.
If compatibility were an overriding issue then we could just do this in
10.3 for blob/clob import/export leaving the possible holes that already
exist in 10.2.

Mike Matrigali wrote:
> I am hoping to get a discussion going on how the right way to fix these
> issues.  As I understand it the ability to read/write files is currently
> inherited from derby.jar where the import/export system procedures
> currently reside.  The problem is that this means the they can be used
> to bypass the normal database level read/write access to derby system
> files: property files, database files, log files, temp files.  As dan
> has pointed out I believe the current policy files may allow in one
> database but access files in a completely different database so the
> scope of the files is larger than just the current database.
> 
> I don't know much about security manager possibilities so maybe someone
> who knows can point the way.
> 
> Some approaches:
> 1) try to code access privileges in the routines themselves, that is 
> separate from java security manager.  Basically
>    disallow access to derby files by adding code logic to determine if 
> the files being read/written are derby files.  This is not too hard to 
> do if you
>    only want to disallow under the current database subtree, but gets
>    harder under any derby subtree.
>    So I think this approach  would check for files named:
>    derby.properties
>    system.properties
>    log/log*.dat
>    log/log.ctrl
>    log/logmirror.ctrl
>    seg0/*.dat
> 
>    I think temporary files also, and I think they can be anywhere.
> 
> 
> 2) Is it possible to temporarily give up a set of granted security 
> privileges in a class and get them again on the way out?  Basically
> import only wants the write derby access privilege and export only
> wants the read derby access privilege.
> 
> 3) Could the routines be moved into a separate jar that would get a 
> different set of security manager privileges?
> 
> 4) we could get rid of the current interfaces all together and change
> to require streams rather than files for the user files.  This may be
> a lot slower and does raise backward compatibility issues.  The point
> of import/export is to allow easy/fast bulk load/unload, so doesn't 
> really solve the issue.
> 

Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Mike Matrigali <mi...@sbcglobal.net>.
I am not planning on working on this other than participating in the
discussion.  My take on this issue is that it is a serious issue that
affects both 10.2 and 10.3.  Personally I would not hold up 10.3 release
waiting on the fix unless someone actively is working on it.

Myrna van Lunteren wrote:
> To jump in...Mike, are you intending to fix this? In the foreseeable 
> future?
> (If you are, then maybe it *is* worth holding the release waiting for it).
> 
> Myrna
> 

Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Myrna van Lunteren <m....@gmail.com>.
To jump in...Mike, are you intending to fix this? In the foreseeable future?
(If you are, then maybe it *is* worth holding the release waiting for it).

Myrna

Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Oystein Grovlen - Sun Norway <Oy...@Sun.COM>.
Bryan Pendleton wrote:
>> 1) try to code access privileges in the routines themselves, that is 
>> separate from java security manager.  Basically
>>    disallow access to derby files by adding code logic to determine if 
>> the files being read/written are derby files. 
> 
> Instead of trying to write this "negative" logic, figuring out
> what files *oughtn't* to be written to, perhaps it would be
> easier to specify things the other way, and change import/export
> so that they are only capable of reading-from/writing-to a
> new, well-known location, which is certain not to contain any
> other files of importance.
> 
> That is, for each database, we define a new "import/export scratch space",
> whose location defaults to something reasonable but can be configured
> on a database-by-database basis if necessary, and import only ever
> looks for files in that directory, and export only ever writes files
> to that directory.

I had the same thoughts as you, Bryan, but I guess this will introduce 
incompatibilities for existing users who currently gets to decide where 
the exported data should be written.

-- 
Øystein

Re: what is the right way to fix the import/export security issues (DERBY-2436, DERBY-2437)?

Posted by Bryan Pendleton <bp...@amberpoint.com>.
> 1) try to code access privileges in the routines themselves, that is 
> separate from java security manager.  Basically
>    disallow access to derby files by adding code logic to determine if 
> the files being read/written are derby files. 

Instead of trying to write this "negative" logic, figuring out
what files *oughtn't* to be written to, perhaps it would be
easier to specify things the other way, and change import/export
so that they are only capable of reading-from/writing-to a
new, well-known location, which is certain not to contain any
other files of importance.

That is, for each database, we define a new "import/export scratch space",
whose location defaults to something reasonable but can be configured
on a database-by-database basis if necessary, and import only ever
looks for files in that directory, and export only ever writes files
to that directory.

thanks,

bryan