You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Sylvain Leroux <sl...@wanadoo.fr> on 2009/08/17 14:25:37 UTC

Using security manager to grant permission to db stored procedures

Hi everybody,

I have a db stored procedure that should send an e-mail on certain 
events. This procedure should open a socket to an SMTP server.

But, when Derby runs under security manager (using Derby 10.5.1.1), the 
default security policy does not allow that.

The obvious solution is to write a custom policy file having a rule like:
 > grant codebase "file:///path/to/db/jar/APP/MailHelper.jar" {
 >     permission java.net.SocketPermission  "*:25", "connect"
 > }

/But/, db stored JAR a copied to the db/jar/APP folder with trailing 
"magic number" (?) like: "MailHelper.jar.G1230379179336".


So here are my questions:
1) Should I use the full JAR name 'MailHelper.jar.G1230379179336' as 
codebase in my "grant" rule?
2) Under which circumstances the trailing "G1230379179336" will change?
3) Is setting a security policy on per stored-db JAR basis a supported 
feature or not?

Considering the later, all the docs I found on the internet regarding 
this subject where a little bit "fuzzy" or out-dated.  As an example, 
http://db.apache.org/derby/binaries/jta-WE15.pdf expressively states 
that "SQL Functions and Procedures must [...] have permission for action 
granted to their code base - *Currently not possible for jar files 
stored in db*". In the other hand the doc is 3 years old...


Thanks in advance for your time,
Sylvain Leroux
-- 
Website: http://www.chicoree.fr

Re: Using security manager to grant permission to db stored procedures

Posted by Sylvain Leroux <sl...@wanadoo.fr>.
Hi Rick,

And thanks for this answer.

To close that subject, I must say that I wasn't able to set the required 
privilege using neither of the rules:

 > grant codebase "${derby.install.url}derby.jar" {
 >     permission java.net.SocketPermission  "*:25", "connect"
 > }
 > grant codebase "${derby.install.url}derbynet.jar" {
 >     permission java.net.SocketPermission  "*:25", "connect"
 > }

The only one that does the trick was:
 > grant {
 >     permission java.net.SocketPermission  "*:25", "connect"
 > }
But, this will allow any class from any JAR directly or indirectly 
loaded in the JVM to send mail...

 > So I have created DERBY-4354 to track this issue. Feel free to
 > vote for this issue--that will improve its chances of being considered
 > for a future feature release.
I will do!

Sylvain
-- 
Website: http://www.chicoree.fr

Re: Using security manager to grant permission to db stored procedures

Posted by Rick Hillegas <Ri...@Sun.COM>.
Sylvain Leroux wrote:
> Sylvain Leroux a écrit :
>> 1) Should I use the full JAR name 'MailHelper.jar.G1230379179336' as
>>  codebase in my "grant" rule?
>
> I failed to mention that the following rule does not seem to work:
>> grant codebase  
>> "file:///path/to/db/jar/APP/MailHelper.jar.G1230379179336" {
>>     permission java.net.SocketPermission  "*:25", "connect"
>> }
>
> Sylvain
>
>
Hi Sylvain,

I am not aware of any work that has been done to make it possible to 
grant java security privileges to user-coded jar files that are stored 
in the database. I also cannot find an existing enhancement request for 
this. So I have created DERBY-4354 to track this issue. Feel free to 
vote for this issue--that will improve its chances of being considered 
for a future feature release.

Thanks,
-Rick

Re: Using security manager to grant permission to db stored procedures

Posted by Sylvain Leroux <sl...@wanadoo.fr>.
Sylvain Leroux a écrit :
> 1) Should I use the full JAR name 'MailHelper.jar.G1230379179336' as
>  codebase in my "grant" rule?

I failed to mention that the following rule does not seem to work:
> grant codebase  "file:///path/to/db/jar/APP/MailHelper.jar.G1230379179336" {
>     permission java.net.SocketPermission  "*:25", "connect"
> }

Sylvain


-- 
Website: http://www.chicoree.fr