<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>Introduction to CUBRID Security - Part II</title>
        <link>http://www.cubrid.org/?mid=intro_cubrid_security_2</link>
        <description>Introduction to CUBRID Security - Part II</description>
        <language>en</language>
        <pubDate>Tue, 07 Dec 2010 12:00:00 -0800</pubDate>
        <lastBuildDate>Mon, 23 Jan 2012 07:03:42 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>Introduction to ...</title>
            <dc:creator>CUBRID</dc:creator>
            <link>http://www.cubrid.org/intro_cubrid_security_2</link>
            <guid isPermaLink="true">http://www.cubrid.org/intro_cubrid_security_2</guid>
                                    <description><![CDATA[<h1>Introduction to CUBRID Security - Part II</h1>

<div class="category"><a href="/intro_cubrid_security">⇐Introduction to CUBRID Security - Part I</a><a class="pdf right" href="/files/docs/tutorials/cubrid/Introduction to CUBRID Security - Part II.pdf">Download this document in PDF</a>
</div>

<div class="contents-table">
<h3>Table of Contents</h3>
<ul>
	<li><a class="toTop">Back to Top</a></li>
	<li><a href="#security-related-metadata">Security Related Metadata</a></li>
	<ul>
		<li><a href="#db_auth">db_auth</a></li>
		<li><a href="#db_user">db_user</a></li>
	</ul>
	<li><a href="#metadata-authorization">Metadata Authorization</a></li>
	<li><a href="#security-related-functions">Security Related Functions</a></li>
	<ul>
		<li><a href="#sql-functions">SQL Functions</a></li>
		<li><a href="#db_user-db_authorizations">db_user &amp; db_authorizations methods</a></li>
	</ul>
	<li><a href="#sql-auditing">SQL Auditing</a></li>
	<li><a href="#cubrid-specifics">CUBRID Specifics</a></li>
	<li><a href="#security-guidelines">Security Guidelines</a></li>
	<li><a href="#see-also">See also</a>
	</li>
</ul>
</div>

<p>
	Welcome to the 2<sup>nd</sup> part of the CUBRID Security tutorial. In the <a href="/intro_cubrid_security">Intro to CUBRID Security Part I</a> we focused on:
</p>
<ul>
<li>The CUBRID database security model
</li>
<li>Managing authorizations using SQL statements
</li>
</ul>
<p>
	In the 2<sup>nd</sup> part of the tutorial we will talk about CUBRID database metadata related to security, security related functions and guidelines
	for managing security.
</p>
<h2 id="security-related-metadata">Security Related Metadata</h2>
<p>
	In CUBRID, we have specialized system objects (catalogs) that hold information related to database security definitions:
</p>
<ul>
	<li>
		<b>System tables</b>
	</li>
	<ul>
		<li>
			_db_auth
		</li>
		<li>
			_db_authorization
		</li>
		<li>
			_db_authorizations
		</li>
		<li>
			db_user
		</li>
	</ul>
</ul>

<ul>
	<li>
		<b>System views</b>
	</li>
	<ul>
		<li>
			o db_auth
		</li>
	</ul>
</ul>

<p>
	If you need to find detailed information about the structure of each of these objects, use CUBRID Manager and look at the definitions and browse the data. You will also notice that in many other database metadata objects, there is a column usually named "owner", of type "db_user", which holds the owner of the data referenced. We will take a look now at two of these objects, which are probably the most used: <b>db_auth</b> and <b>db_user</b>.
</p>

<h3 id="db_auth">db_auth</h3>

<p>
	This view shows user authorization information for the database objects. Below is the table structure:
</p>
<table class="blackcap rowbg">
<thead>
<tr>
	<th width="200px">
			<b>Attribute Name</b>
	</th>
	<th>
			<b>Description</b>
	</th>
</tr>
</thead>
<tbody>
<tr>
	<td>
		
			grantor_name
		
	</td>
	<td>
		
			Authorization grantor
		
	</td>
</tr>
<tr>
	<td>
		
			grantee_name
		
	</td>
	<td>
		
			Authorization grantee
		
	</td>
</tr>
<tr>
	<td>
		
			class_name
		
	</td>
	<td>
		
			Class (table) object to which authorization is granted.
		
	</td>
</tr>
<tr>
	<td>
		
			auth_type
		
	</td>
	<td>
		
			Type name of the authorization granted.
		
	</td>
</tr>
<tr>
	<td>
		
			is_grantable
		
	</td>
	<td>
		
			YES if authorization for the class can be granted to other users and NO otherwise.
		
	</td>
</tr>
</tbody>
</table>

<p class="center"><img src="/files/attach/images/49/578/003/cubrid-db_auth-table.png" alt="CUBRID db_auth Table" width="584" height="214" editor_component="image_link"/></p>

<h3 id="db_user">db_user</h3>
<p>
	This view shows the users defined in the database, along with the groups and the authorizations. Below is the table structure:
</p>
<table class="blackcap rowbg">
<thead>
<tr>
	<th width="200px">Attribute Name</th>
	<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
	<td>

	name

	</td>
	<td>

	User name

	</td>
</tr>
<tr>
	<td>

	id

	</td>
	<td>

	User identifier

	</td>
</tr>
<tr>
	<td>

	password

	</td>
	<td>

	User password. Not displayed to the user.

	</td>
</tr>
<tr>
	<td>

	direct_groups

	</td>
	<td>

	Groups to which the user belongs directly

	</td>
</tr>
<tr>
	<td>

	groups

	</td>
	<td>

	Groups to which the user belongs directly or indirectly

	</td>
</tr>
<tr>
	<td>

	authorization

	</td>
	<td>

	Information of the authorization owned by the user

	</td>
</tr>
<tr>
	<td>

	triggers

	</td>
	<td>

	Triggers that occur due to user actions

	</td>
</tr>
</tbody>
</table>

<p class="center"><img src="/files/attach/images/49/578/003/cubrid-db_user-table.png" alt="CUBRID db_user Table" width="548" height="87" editor_component="image_link"/></p>

<h2 id="metadata-authorization">Metadata Authorization</h2>
<p>
	Metadata objects (=<b>Catalog classes</b>) are created to be owned by <b>dba</b>. However, <b>dba</b> can only execute SELECT operations. If <b>dba</b>
	executes operations such as UPDATE/DELETE, an authorization failure error occurs.
</p>

<p class="important">
	General users cannot execute queries on system catalog classes.
</p>
<p>
	Although catalog virtual classes are created to be owned by <b>dba</b>, all users can perform the SELECT statement on metadata views (catalog virtual
	classes).
</p>
<p>
	Of course, UPDATE/DELETE operations on catalog virtual classes are not allowed. Updating catalog classes/virtual classes is automatically performed by
	the system when users execute a DDL statement that creates/modifies/deletes a class/attribute/index/user/authorization.
</p>
<h2 id="security-related-functions">Security Related Functions</h2>

<h3 id="sql-functions">SQL Functions</h3>

<h4>CURRENT_USER, USER, USER(), SYSTEM_USER()</h4>

<p>
	CURRENT_USER and USER are used interchangeably. They return the user name that is currently logged in to the database as a string. USER() and SYSTEM_USER() are used interchangeably. They return the user name with a host name. Below you can see the examples:
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
--selecting the current user on the session
SELECT USER;
 
=== &lt;Result of SELECT Command in Line 1&gt; ===
 
   CURRENT_USER
======================
   'PUBLIC'
 
SELECT USER(), CURRENT_USER;
 
=== &lt;Result of SELECT Command in Line 1&gt; ===
 
   user()                CURRENT_USER
============================================
   'PUBLIC@cdbs006.cub'  'PUBLIC'
</div>
</div>

<h3 id="db_user-db_authorizations">db_user &amp; db_authorizations methods</h3>
<p>
	The database administrator (<b>dba</b>) can check and modify user authorization by calling authorization-related methods defined in <b>db_user</b>
	(where information about database user is stored), and <b>db_authorizations</b> (the system authorization metadata table). The administrator can
	specify <b>db_user</b> or <b>db_authorization</b> depending on the method to be called (and save the return value of a method to a variable).
</p>
<p class="important">Note: Some of these methods can be called only by dba or members of dba group.</p>

<h4>login(…)</h4>
<p>
	As a class method of <b>db_user</b> class, this method is used to change the users who are currently connected to the database. The name and password
	of a new user to connect are given as parameters, and they must be string type. If there is no password, a blank string ('') can be used as the
	parameter. <b>dba</b> and <b>dba</b> members can call the login(…) method without a password.
</p>

<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Connect as dba user who has no password
CALL login ('dba', '') ON CLASS db_user;
-- Connect as a user_1 whose password is cubrid
CALL login ('user_1', 'cubrid') ON CLASS db_user;
</div>
</div>

<h4>add_user(...)</h4>
<p>
	As a class method of <b>db_user</b> class, this method is used to add a new user. The name and password of a new user to add are given as parameters,
	and they must be string type. At this time, the new user name should not duplicate any user name already registered in a database. The add_user(…) can
	be called only by <b>dba</b> or members of <b>dba</b> group.
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Add user_2 who has no password
CALL add_user ('user_2', '') ON CLASS db_user;
-- Add user_3 who has no password, and save the return value of a method into an admin variable
CALL add_user ('user_2', '') ON CLASS db_user to admin;
</div>
</div>

<h4>drop_user(…)</h4>
<p>
	As a class method of <b>db_user</b> class, this method is used to drop an existing user. Only the user name to be dropped is given as a parameter, and
	it must be a string type. However, the owner of a class cannot be dropped thus dba needs to specify a new owner of the class before dropping the user.
	The drop_user(…) method can be also called only by <b>dba</b> or members of <b>dba</b>.
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Delete user_2
CALL drop_user ('user_2') ON CLASS db_user;
</div>
</div>

<h4>find_user(…)</h4>
<p>
	As a class method of <b>db_user</b> class, this method is used to find a user who is given as a parameter. The name of a user to be found is given as a
	parameter, and the return value of the method is stored into a variable that follows 'to'. The stored value can be used in a next query execution.
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Find user_2 and save it into a variable called 'admin'
CALL find_user ('user_2') ON CLASS db_user to admin;
</div>
</div>

<h4>set_password(…)</h4>
<p>
	This method is an instance method that can call each user instance, and it is used to change a user's password. The new password of a specified user is
	given as a parameter. General users other than <b>dba</b> and <b>dba</b> group members can only change their own passwords.
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Add user_4 and save it into a variable called user_common
CALL add_user ('user_4','') ON CLASS db_user to user_common;
-- Change the password of user_4 to 'abcdef'
CALL set_password('abcdef') on user_common;
</div>
</div>
<h4>change_owner(…)</h4>
<p>
	As a class method of <b>db_authorizations</b> class, this method is used to change the owner of a class. The name of a class for which you want to
	change the owner, and the name of a new owner are given as parameters. At this time, the class and owner that are specified as a parameter must exist
	in a database. Otherwise, an error occurs. change_owner(…) can be called only by <b>dba</b> or members of <b>dba</b> group.
</p>
<div class="code">
<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
-- Change the owner of table_1 to user_4
CALL change_owner ('table_1', 'user_4') ON CLASS db_authorizations;
</div>
</div>
<h2 id="sql-auditing">SQL Auditing</h2>
<p>
	Note: You will talk in this section only about <b>SQL logs</b>. Other CUBRID logs, like error or access log are not in the scope of this tutorial.
</p>
<p>
By default, the execution of the SQLs is logged by the CUBRID broker, in the following folder (relative to the installation path):		<b>logbrokersql_log</b>

</p><p class="center"><img src="/files/attach/images/49/578/003/cubrid-sql-log.png" alt="CUBRID SQL Log" width="517" height="411" editor_component="image_link"/></p>

<p class="important">
	Warning: All the executed queries are stored in the log file only if the SQL_LOG parameter of the Broker is <b>ON</b>.
</p>

<p>
	If you open one of the log files in this location, you will find in there all the details regarding the SQLs executed in the database:
</p>

<p class="center"><img src="/files/attach/images/49/578/003/cubrid-sql-log-file.png" alt="CUBRID SQL Log File" width="601" height="318" editor_component="image_link"/></p>

<p class="important">
	CUBRID Manager provides a useful utility - <b>Execute log</b>, which can be used to re-execute the SQL log stored in the log script.
	You can tune queries and correct errors by modifying and re-executing log queries.
</p>

<p>
	Other things to know about:
</p>
<ul>
<li>You can view the execution log of the trigger from a terminal by using the SET TRIGGER TRACE statement.
</li>
<li>There are three types of logs that relate to starting the Broker: access, error and SQL logs. Each log can be found in the log directory under the
	installation directory. You can change the directory where these logs are to be saved through LOG_DIR and ERROR_LOG_DIR parameters of the broker
	environment configuration file (<b>cubrid_broker.conf</b>).
</li>
<li>The size of the SQL log file to be generated cannot exceed the value set for the SQL_LOG_MAX_SIZE parameter.
</li>
<li>CUBRID provides the <b>broker_log_top</b>, <b>broker_log_converter</b>, and <b>broker_log_runner</b> utilities to manage SQL logs.
</li>
<li>More information regarding logging in CUBRID can be found here:		<a href="/manual/840/en/CUBRID%20Manager%20Server%20Logs">http://www.cubrid.org/manual/840/en/CUBRID%20Manager%20Server%20Logs</a>.
</li>
</ul>
<h2 id="cubrid-specifics">CUBRID Specifics</h2>
<ul>
<li>You can't specify from where (IP address) a user can login to the server; if you need to implement such a functionality, consider using a firewall
	(see <a href="/general_security_configuration">http://www.cubrid.org/general_security_configuration</a>)
</li>
<li>There is currently no support for restricting the time of the day/the periods when the user can connect to the CUBRID database. Please use a firewall
	to enforce such restrictions.
</li>
<li>The cubrid createdb utility creates databases and initializes them with the built-in CUBRID system tables. But it can also be used to define initial
users to be authorized in the - see		<a href="/manual/840/en/Database%20Administration-Creating%20Database">http://www.cubrid.org/manual/840/en/Database%20Administration-Creating%20Database</a>.
</li>
<li>When a slave database is created, the ownership of every class is changed to that of the replication user.
</li>
<li>The <b>public</b> user can't be removed from a database.
</li>
<li>You must always run the distribution database with the <b>dba</b> account to ensure security. The <b>repl_make_distdb</b> utility requires the name
	of the distribution database and the password for its dba account.
</li>
</ul>
<h2 id="security-guidelines">Security Guidelines</h2>
<ul>
	<li>
Make sure the password for the <b>dba</b> user is "strong" enough; you can find some guidelines on how to create strong passwords here:			<a href="http://en.wikipedia.org/wiki/Password_strength" target="_blank">http://en.wikipedia.org/wiki/Password_strength</a>.
	</li>
<li>When you connect to the database using the CUBRID Manager, the initial user ID and password are <b>admin/admin</b>. Use them only for the first
	connection, but you must change the password immediately after for obvious security reasons.
</li>
	<li>
		Do not use the <b>dba</b> user to test your application or to setup the database structure.
	</li>
<li>Do not store users and password related data in applications' files.
</li>
<li>Make sure you enforce a policy of changing the passwords periodically; CUBRID does not have a way to automatically "expire" passwords validity - it
	is up to the CUBRID administrator to setup and enforce such a best practice.
</li>
<li>Do not give anyone access to the <b>db_user</b> table.</li>
<li>Give permissions only as needed and use different logins for different applications.
</li>
</ul>
<h2 id="see-also">See also</h2>
<ul>
<li><a href="/intro_cubrid_security" target="_self">Introduction to CUBRID Security - Part I</a></li><li><a href="/general_security_configuration" target="_self">
	CUBRID Security Wiki</a></li><li><a href="/tutorials" target="_self">CUBRID Tutorials</a></li>
<li><a href="http://databases.about.com/od/security/Database_Security_Issues.htm" target="_blank">
	Database Security Issues</a></li>
<li><a href="http://databases.about.com/od/security/a/accesscontrols.htm" target="_blank">
	Access Controls in SQL</a></li>
<li><a href="http://www.databasesecurity.com/" target="_blank">DatabaseSecurity.com Resources</a></li>
<li><a href="http://www.amazon.com/s/ref=dp_srsubj_entry?ie=UTF8&amp;index=books&amp;field-keywords=Database%20security" target="_blank">
	Database Security Books</a></li>
<li><a href="http://www.sqlsecurity.com/" target="_blank">SQLSecurity.com</a></li>
<li><a href="http://www.securitymagazine.com/articles/database-security-best-practices-1" target="_blank">
	Database Security Best Practices</a></li>
<li><a href="http://php.net/manual/en/security.database.php" target="_blank">
	PHP: Database Security - Manual</a></li>
</ul>
<p>This concludes the 2<sup>nd</sup> part of the CUBRID Security tutorial. Please let us know your feedback and remember to periodically check the CUBRID web site for other tutorials and resources.</p><p></p>]]></description>
                        <pubDate>Wed, 08 Dec 2010 02:53:04 -0800</pubDate>
                                </item>
            </channel>
</rss>
