Search |
||
JavaDB End-to-End Security![]()
Tue, 2007-03-20
JavaDB end to end securityMasoud Kalali JavaDB, as an open source and pure Java relational database, provides several features that make it suitable for embedded and network server mode. One of these features is JavaDB mechanisms to make it secure on several levels. If you are going to build an application using JavaDB and security is important, then this article is for you. These are the steps that we should follow to make JavaDB work with an acceptable level of security.
Before we dig into each of these subjects, you need to have JavaDB installed in your environment. We will use OpenDS Which is a pure Java open source LDAP server for authentication purpose. I will talk about each of the above items and in the same time give you detail instructions to address it using JavaDB provided features. Database EncryptionFirst let's see what we have when we create a database in JavaDB. A JavaDB database is usually a directory containing some data files, transaction logs, and a database configuration file, service.properties. The JavaDB database directory is portable and anyone can copy a JavaDB database and boot it up using another JavaDB instance and take a look into its data. But there are some mechanisms that protect our database from any kind of external unauthorized access. A JavaDB database can be encrypted on hard disk and thus not be useable until decrypted. Decryption is only possible using a single key or password, which is provided during database creation. OK, let's see how we can encrypt our database and then how we can connect to this encrypted database. As I mentioned earlier encryption happens during database creation time. You may already know that we can create a database by supplying extra attributes in JDBC connection string. To demonstrate our steps, I will use IJ, which is the JavaDB command line tool for database administration and development. Start the JavaDB network server and then run the ij CLI and execute the following commands one after another. I should say that during this article we will use NetworkServerControl script to start and stop network server. You can start network server by passing a start as a command line argument to start JavaDB.
The first command, You can see three attribute inside the connection string which you may not be familiar with.
Now we have an encrypted database and we need to connect to this database from our java application, how does the code that connects to this encrypted database will look like? It is quite simple: you just need to include the bootPassword attribute in your connection string. Something like:
That's it; you have a connection to your encrypted database. Beware that once you boot a database (i.e., you've made a first connection with a boot password) it will be open for connections even without bootPassword. So shut down the database as soon as you have finished your work with it. The following code snippet shows how you can shut down a database from within your application.
If you try to connect to database without bootPassword attribute, you will get an error message. Using encryption, you protect your database against any external unauthorized access by anyone who do not know the bootpassword. Connection authenticationAs a second concern I am going to talk about connection authentication. A JavaDB database or server is open for connections with full access to all database server resources. A database developer can configure it to authenticate users that are trying to connect to a database on the server. Until you try to configure it to your specific needs, JavaDB is a zero-administration RDBMS. But configuring JavaDB to perform authentication is very simple and nearly a zero-cost configuration. The JavaDB network server is configurable using a standard properties file, named derby.properties, which can simply be placed inside the JavaDB bin directory. There are dozens of configuration parameters we can put in this properties file, but for now we are just going to use a few of them. JavaDB can authenticate users in three ways in addition to its default no-authorization behavior:
Each of the above mechanisms has its own strengths and weaknesses; in the next few paragraphs you will see how easily you can configure JavaDB to perform authentication against an external LDAP like OpenDS. So before we continue, you need to setup and start your OpenDS directory server. OpenDS is a pure Java open-source directory server with many features that could be used to build an enterprise application. The OpenDS installation is straightforward: just launch the QuickSetup JNLP (Java Web Start) installer, and follow the installation steps to set up your directory server. Having installed OpenDS, I will describe the test data which you will import into your directory server storage to test JavaDB authentication. Our test data is a standard LDIF file, which you can find in the resources section. You can import it into OpenDS using its shell script named import-ldif .
By executing the above command in the OpenDS bin directory, you can import the sample data into your directory server storage. Make sure that OpenDS is not running when you want to import data into its storage; otherwise you will receive an error message indicating that the import utility cannot acquire a lock over storage. If you browse OpenDS storage using an LDAP browser like LDAP Studio, you will find four entries under dc=example,dc=com. These entries are the users that we will use during next parts of this article. The user names are jhallett, mchrysta, thardy, and tquist; passwords are same as respective userids. To activate the authentication we need to add a property in the derby.properties file. So, create a text file and save it in JavaDB_home/bin as derby.properties, open the file and add the following line to it.
This property alone tells JavaDB to authenticate users whom try to connect to JavaDB but it does not define any source for authenticating users' credentials. Therefore we should define a source that JavaDB should use to authenticate users against. Here is what we should add in order to define a source of authentication:
It is not mandatory to add all of the above properties, but it is a good practice to include the last two, since they will limit the search scope for usernames during authentication. Ab explanation about each of those attribute can be found in the JavaDB documentation. Now, restart the JavaDB network server and let's try to connect to our secArticle database as in the previous step, to what we will get when we try it. Open an ij session and execute the following commands.
Now let's provide a correct username and password; we can use any of the 4 users that we added to our OpenDS storage in the previous section.
And this time you should be able to connect to the database without any problem. SQL authorizationNow we have authentication present in the deployment, what about authorization? Activating JavaDB SQL authorization is very simple; just open derby.properties and add some entries which ask JavaDB to apply SQL authorization. The lines you need to add are as follows:
These two properties enforce SQL authorization, for any database created from now on. But what about our already-created database? What we can do to enable SQL authorization in them? Fortunately, we just need to execute a system function to set SQL authorization for an already-created database. So, open an IJ session, connect to our sample database, and execute the following command.
Now, our database has SQL authorization capability, but the network server needs to be restarted before we can use this feature. Restart the network server and continue. Then open an ij session, connect to the database with the tquis user, and create a table.
Executing the above commands will create a table in TQUIST schema, with table owner tquist who has full privileges over this table. The last command will end the current session. Now to check whether our table is safe or not connect to database with another user and try to insert some data into that table.
The above error indicate that our user has no permission to perform an insert on TQUIST.sec_art_table. In the next code snippetm we connect to database as user tquist and grant some permission to jhallett.
Now jhallett has insert privileges on TQUIST.sec_art_table. You can try inserting statement again to make sure that it works fine. Other implemented and supported privileges can be found in the JavaDB documentation. Securing environmentThe Java Security manager and policy definition is a mechanism that allows one to define and apply specific policies over execution of specific code and JVM access to some potentially risky resources like sockets, files, etc. By default when you install the JRE or JDK, there is no restriction and all permissions are granted to standard extensions.
At the JVM level, we can have one default policy implementation which will apply on all users of that JRE. We can also define per-user policy files to apply specific policies for certain users. There are multiple ways that we could apply policies to the JVMm but the most popular one is using policy files which we pass to the
When you are starting the JavaDB network server, you can activate the Java security manager and pass a policy file to the
JVM to use when it is running. To achieve this you can either edit the
NetworkServerControl shell file (a
You just need to change the middle line to:
As I said a policy file is a plain text file, so create a text file and save it as JavaDB.policy in the JavaDB bin directory. Now add the following snippet to it.
In the above policy description we grant some permissions to all jar files and classes placed in lib folder; permissions are as follow:
By default JavaDB network server will listen on localhost, but we can pass an -h AN_IP_ADDRESS argynebt to NetworkServerControl in order to configure it to listen on other IP addresses. Now imagine that your JavaDB is open for incoming connections from the Internet; you can simply limit incoming connections to your JavaDB network server by providing a list of permitted address in a policy file, as we have done in our sample policy file. ConclusionJavaDB as an open source, pure Java database, can play an important role in future Java applications, especially for small applications that do not need a huge list of expensive features that are available in commercial RDBMS's. Security is a major concern to the software development industry and JavaDB provides an acceptable set of features to make your small database secure. Some questions that you may face during this article:
Resources»
Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|