Google

Using SQL Relay With Oracle8i/9i n-Tiered Authentication

Background

Ordinarily, SQL Relay logs into the database as a particular user several times and hands those sessions off to SQL Relay clients, thus avoiding the cost of connecting to and disconnecting from the database over and over. A sometimes undesirable side-effect of this approach is that it is impossible to distinguish which queries were run by which SQL Relay users from within the database since SQL Relay uses the same database user to run all queries.

Oracle n-tiered authentication provides a way around this side-effect.

If you set up a proxy role, a proxy user and a set of users that can be proxied by that proxy user in Oracle and configure SQL Relay to use the "database" authentication tier, SQL Relay users will map to Oracle users.

Setting Up Oracle

First, locate the initSID.ora file for the database. This file can be found in the $ORACLE_BASE/admin/$ORACLE_SID/pfile directory. Edit it, changing the "compatibility" parameter to a version equal to or higher than "8.1.0". Restart the database.

Next, log into the database as system and create a set of users:

CREATE USER user1 IDENTIFIED BY user1;
GRANT CREATE SESSION TO user1;
CREATE USER user2 IDENTIFIED BY user2;
GRANT CREATE SESSION TO user2;
CREATE USER user3 IDENTIFIED BY user3;
GRANT CREATE SESSION TO user3;

Now, create a proxy role and give the users access to it:

CREATE ROLE proxyrole;
GRANT proxyrole TO user1;
GRANT proxyrole TO user2;
GRANT proxyrole TO user3;

At this point, you'll need to perform grants to the proxyrole to give it whatever permissions that the users that may use it will need. Grants to roles are the performed like grants to users. For example if proxyrole needs random access to "publictable" and read access to "readonlytable":

GRANT all ON publictable TO proxyrole;
GRANT select ON readonlytable TO proxyrole;

Create a proxy user:

CREATE USER proxyuser IDENTIFIED BY proxyuser;
GRANT CREATE SESSION TO proxyuser;

Give the users access through the proxy user:

ALTER USER user1 GRANT CONNECT THROUGH proxyuser WITH ROLES proxyrole;
ALTER USER user2 GRANT CONNECT THROUGH proxyuser WITH ROLES proxyrole;
ALTER USER user3 GRANT CONNECT THROUGH proxyuser WITH ROLES proxyrole;

You can enable auditing of the queries that the users have run through the proxyrole as follows. Note: to enable auditing, you must set AUDIT_TRAIL=yes in the $ORACLE_BASE/admin/$ORACLE_SID/pfile/initSID.ora file and restart the database.

AUDIT SELECT BY proxyuser ON BEHALF OF user1;
AUDIT SELECT BY proxyuser ON BEHALF OF user2;
AUDIT SELECT BY proxyuser ON BEHALF OF user3;
Setting Up SQL Relay

SQL Relay should be set up to use the database authentication tier and to log into Oracle as the proxy user. Below is an sqlrelay.conf file that does this. Note the authtier attribute of the instance tag. Note also that there are no users defined as they are unnecessary for this kind of configuration.

<!DOCTYPE instances SYSTEM "sqlrelay.dtd">
<instances>

        <instance id="proxyuser" port="9000" socket="/tmp/proxyuser.socket" dbase="oracle8" connections="1" maxconnections="3" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="nobody" runasgroup="nobody" cursors="5" authtier="database">
                <users>
                </users>
                <connections>
                        <connection connectionid="proxyuser" string="user=proxyuser;password=proxyuser;oracle_sid=ora1;" metric="1"/>
                </connections>
        </instance>

</instances>
Running SQL Relay

Now that Oracle and SQL Relay are configured, you can run SQL Relay as follows:

sqlr-start -id proxyuser

You can use sqlrsh to access it as any of the database level users that you created earlier:

sqlrsh localhost 9000 "/tmp/proxyuser.socket" user1 user1
or
sqlrsh localhost 9000 "/tmp/proxyuser.socket" user2 user2
or
sqlrsh localhost 9000 "/tmp/proxyuser.socket" user3 user3