<?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 I</title>
        <link>http://www.cubrid.org/?mid=intro_cubrid_security</link>
        <description>Introduction to CUBRID Security - Part I</description>
        <language>en</language>
        <pubDate>Mon, 06 Dec 2010 11:46:39 -0800</pubDate>
        <lastBuildDate>Wed, 28 Sep 2011 05:06:46 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>Introduction to CUBRID Security - Part I</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/intro_cubrid_security</link>
            <guid isPermaLink="true">http://www.cubrid.org/intro_cubrid_security</guid>
                                    <description><![CDATA[<h1>Introduction to CUBRID Security - Part I</h1>

<div class="category"><a href="/tutorials">⇐Tutorials</a><a class="right" href="/intro_cubrid_security_2">Introduction to CUBRID Security - Part II⇒</a><br /><br />
<a class="pdf right" href="/files/docs/tutorials/cubrid/Introduction to CUBRID Security - Part I.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-model">CUBRID Security Model</a></li>
	<li><a href="#default-users">CUBRID Default Users</a></li>
	<li><a href="#managing-users">Managing users and groups</a></li>
	<ul>
		<li><a href="#create-update-users">Creating, Updating and Deleting Users &amp; Members</a></li>
		<li><a href="#grant-authorization">Granting/Revoking Authorizations</a></li>
		<li><a href="#cubrid-manager">Using CUBRID Manager Client to Manage Users</a></li>
	</ul>
	<li><a href="#see-also">See also</a>
	</li>
</ul>
</div>

<p>The scope of this tutorial is to give you an introduction to the CUBRID database security. In this 1<sup>st</sup> part, we will talk about the CUBRID
		security model, the security support available in SQL and show examples.
	</p>
	<p>
		Note: It is not in the scope of this tutorial to explain how to setup CUBRID in terms of security interaction with the OS or regarding the development
of secure CUBRID applications - they are subject to separate upcoming tutorials. Also, we are assuming a certain familiarity of the reader with&nbsp;<b>database security concepts</b>&nbsp;- if you need, you can find a good introduction here:		<a href="http://en.wikipedia.org/wiki/Database_security" target="_blank">http://en.wikipedia.org/wiki/Database_security</a>.
	</p>
	<p>
		The tutorial is based on CUBRID 8.3.0 release.
	</p>
	<h2 id="security-model">
		CUBRID Security Model
	</h2>
	<p>
Generally speaking, <b>database security</b> includes mechanisms that control access to and use of the database at the object level. Database		<b>security policy</b> determines which users have access to a specific schema object, and the specific types of actions allowed for each user on the
		object.
	</p>
	<p class="important">
		CUBRID Security model is based on the Access Control List (or ACL).<b></b>
	</p>
	<p>
		ACL means that different users will have varying levels of access to certain databases and tables and that they will be limited to performing only
		certain operations. For example, a user with full privileges to a database will be able to perform a range of operations such as SELECT, DELETE, UPDATE
		and INSERT, while a user with limited privileges would only be able to use the SELECT operation and so on.
	</p>
	<p>
		In CUBRID, the main security "actors" are:
	</p>
	<ul>
		<li>
			<b>Users</b>
		</li>
		<li>
			<b>Members</b>
		</li>
		<li>
			<b>Groups</b>
		</li>
	</ul>
	<p class="center"><img src="http://www.cubrid.org/files/attach/images/49/515/003/cubrid-security-actors.png" alt="CUBRID Security Actors" width="367" height="277" editor_component="image_link"/></p>
	<p>
		As you can see from the above image, a CUBRID database <b>user</b> can have <b>members</b>, which will have the same authorization(s). In other words,
		if authorization A is granted to a user, the same authorization is also granted to all members belonging to the user.
	</p>
	
	<p class="important">
		In CUBRID, a database user and its members are called a "<b>group</b>".
	</p>
	<p>
		Authorizations in a CUBRID database can be setup at the following levels:
	</p>
	<ul>
		<li>
			Tables/Views/Serials access
		</li>
		<li>
			Stored procedures access
		</li>
		<li>
			Triggers access
		</li>
		<li>
			Grant/Revoke authorizations
		</li>
	</ul>
	<p>
		<b>
			Login access to the database is automatically granted to all users-members defined in the database. The only way to deny login is to delete the
			user-member from the database.
		</b>
	</p>
	<p>
		In CUBRID, the smallest grant unit of authorization is a table. This means that CUBRID does not support authorizations at the columns level.
	</p>
	<p>
		The following table summarizes the type of privileges associated with CUBRID database objects:
	</p>
	<table class="blackcap rowbg">
	<thead>
	<tr>
		<th>Object type</th>
		<th>User privilege</th>
		<th>Description/Notes</th>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td rowspan="10">Table</td>
		<td>Alter</td>
		<td>Allows to modify table</td>
	</tr>
	<tr>
		<td>Delete</td>
		<td>Allows to delete data from the table</td>
	</tr>
	<tr>
		<td>Create</td>
		<td>Allows to create a new table</td>
	</tr>
	<tr>
		<td>Drop</td>
		<td>Permission to drop table</td>
	</tr>
	<tr>
		<td>Select</td>
		<td>Allows to query data from the table</td>
	</tr>
	<tr>
		<td>Insert</td>
		<td>Allows to create records in the table</td>
	</tr>
	<tr>
		<td>Index</td>
		<td>Allows to call table methods or instance methods</td>
	</tr>
	<tr>
		<td>Execute</td>
		<td>Allows to call table methods or instance methods</td>
	</tr>
	<tr>
		<td>Update</td>
		<td>Permission to update data in the table</td>
	</tr>
	<tr>
		<td></td>
		<td>The table name can be changed only by the table owner, <b>dba</b> and <b>dba</b> members. The other users must be granted permission to	change the name by the owner or <b>dba</b>.<br /><br />The <b>dba</b> user and the members of the <b>dba</b> group are automatically granted all authorizations for all tables.</td>
	</tr>
	<tr>
		<td>Views</td>
		<td>The way to grant an access privilege on a view is the same as on a table - see "Table" above.</td>
		<td>Before granting <b>SELECT</b>, <b>UPDATE</b>, <b>DELETE</b> and <b>INSERT</b> authorization for a virtual table, the owner of the virtual table must have <b>SELECT</b> and <b>GRANT</b> authorization for all the tables included in the queries in the virtual table's query specification.</td>
	</tr>
	<tr>
		<td>Serials</td>
		<td>Create<br />Update<br />Delete<br />Select</td>
		<td>All users including <b>public</b> can create a serial object. Once it is created, all users can get the number by using CURRENT_VALUE and NEXT_VALUE.<br /><br />Only owner of a created serial object and <b>dba</b> can update or delete a serial object. If an owner is <b>public</b>, all users can update or delete it.</td>
	</tr>
	<tr>
		<td>Stored procedures</td>
		<td>Create<br />Delete<br />Execute/CALL</td>
		<td>A Java stored function/procedure can be deleted only by the user who published it or by <b>dba</b> members. For example, if a <b>public</b> user published the 'sp_int' Java stored function, only the <b>public</b> or <b>dba</b> members can delete it.</td>
	</tr>
	<tr>
		<td>Triggers</td>
		<td>Depends on trigger type</td>
		<td>Trigger authorization is not granted explicitly. Authorization on the table trigger is automatically granted to the user if the authorization is granted on the event target table described in the trigger definition. In other words, triggers that have table targets (<b>INSERT</b>, <b>UPDATE</b>, etc.) are seen by all users.<br /><br />User triggers (<b>COMMIT</b> and <b>ROLLBACK</b>) are seen only by the user who defined the triggers. All authorizations are automatically granted to the trigger owner.	A user trigger can only be changed by its owner.</td>
	</tr>
	</tbody>
	</table>
	
	<h2 id="default-users">CUBRID Default Users</h2>
	
	<p class="important">By default, whenever you create a CUBRID database, there are two default users which are always created automatically: <b>dba</b> and <b>public</b>.</p>
	
	<p>
		<b>User "dba"</b>
	</p>
	<p>
		<b></b>
	</p>
	<p>
		User <b>dba </b>can access every object in the database, meaning that it has authorization at the highest level. And it is only <b>dba</b> which has
		sufficient authorization to add, alter and delete database users.
	</p>
	<p>
		The <b>dba </b>automatically becomes the member of all users and groups. That is, the <b>dba </b>is granted the access for all tables. Therefore, there
		is no need to grant authorization explicitly to the <b>dba </b>and <b>dba </b>members.
	</p>
	<p>
		<b>User "public"</b>
	</p>
	<p>
		The <b>public</b> user is also created automatically with any CUBRID database, but it is granted only limited access by default.
	</p>
	<p class="center"><img src="http://www.cubrid.org/files/attach/images/49/515/003/cubrid-edit-user.png" alt="CUBRID Edit User" width="725" height="401" editor_component="image_link"/></p>
	<p class="important">
		All users of the database are automatically members of the public.
	</p>
	<p>
Therefore, all database users have the authorizations which are granted to <b>public</b>. For example, if authorization <b>B</b> is added to		<b>public </b>group, all database members will automatically have the <b>B</b> authorization granted.
	</p>
	<p class="important">
		Granting authorization to the <b>public</b> means granting it to <b>all</b> database users.
	</p>
	<h2 id="managing-users">Managing users and groups</h2>
	<p>
		<b>Note: </b>
		Only <b>dba</b> and <b>dba</b> members can create, drop and alter users by using SQL statements.
	</p>
	<p>
		In the next section, we will present various examples of SQL statements for managing users and groups.
	</p>
	<p>
		For more details and to find the exact SQL syntax that is available in CUBRID, please read the CUBRID manuals and documentation:
	</p>
	<ul>
		<li>
			<a href="/manual/840/en/DB_AUTH">http://www.cubrid.org/manual/840/en/DB_AUTH</a>
		</li>
		<li>
			<a href="/manual/840/en/Changing%20the%20Authority%20of%20CM%20User">http://www.cubrid.org/manual/840/en/Changing%20the%20Authority%20of%20CM%20User</a>
		</li>
	</ul>
	<h3 id="create-update-users">Creating, Updating and Deleting Users &amp; Members</h3>
	<p>
		In this section we will go through the SQL statements that are used for managing users &amp; members, using examples.
	</p>
	<p>
		Create user "Fred" with password "1234":
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	CREATE USER Fred PASSWORD '1234';
	</div>
	</div>
	
	<p class="important">
		The length of a password must be between 4 and 32 characters. You are not allowed to use spaces.
	</p>
	<p>
		The following is an example in which a user is created and then members are added to the user:
	</p>
	<ul>
		<li>
			<b>company</b>
			becomes a group that has <b>engineering</b>, <b>marketing</b> and <b>design</b> as its members
		</li>
		<li>
			<b>marketing</b>
			becomes a group with members <b>smith</b> and <b>jones</b>
		</li>
		<li>
			<b>design</b>
			becomes a group with a member <b>smith</b>
		</li>
		<li>
			<b>engineering</b>
			becomes a group with a member <b>brown</b>
		</li>
	</ul>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	CREATE USER company;
	CREATE USER engineering GROUPS company;
	CREATE USER marketing GROUPS company;
	CREATE USER design GROUPS company;
	CREATE USER smith GROUPS design, marketing;
	CREATE USER jones GROUPS marketing;  
	CREATE USER brown GROUPS engineering;
	</div>
	</div>
	<p>
		The same results as above can be achieved using the "<b>MEMBERS</b>" keyword instead of "<b>GROUPS</b>":
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	CREATE USER smith;
	CREATE USER brown;
	CREATE USER jones;
	CREATE USER	engineering MEMBERS brown;
	CREATE USER marketing MEMBERS smith, jones;
	CREATE USER design MEMBERS smith;
	CREATE USER company MEMBERS engineering, marketing, design;
	</div>
	</div>
	
	<p>
		Change password for user "Fred" to "1a2b3c4d":
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	ALTER USER Fred PASSWORD '1a2b3c4d';
	</div>
	</div>
	
	<p>
		Delete user "Fred":
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	DROP USER Fred;
	</div>
	</div>
	<h3 id="grant-authorization">Granting/Revoking Authorizations</h3>
	<p>
		You must grant appropriate authorization to other users (groups) before allowing them to access the tables you created (and own). You can find the
		syntax for the SQL used for grant and revoke here:
	</p>
	<ul>
		<li>
			<a href="/manual/840/en/Granting%20Authorization">http://www.cubrid.org/manual/840/en/Granting%20Authorization</a>
		</li>
		<li>
			<a href="/manual/840/en/Revoking%20Authorization">http://www.cubrid.org/manual/840/en/Revoking%20Authorization</a>
		</li>
	</ul>
	<p class="important">You don't need to grant authorization individually because the members of the granted group have the same authorization. It is enough to grant it to the user.</p>
	<p>
		Remember: The access to a Table or View created by a public user is allowed to all other users.
	</p>
	<p>
		You can grant the following types of operations authorization to a user by using the GRANT SQL statement:
	</p>
	<ul>
		<li>
			<b>SELECT</b>
			: Allows to read the table definitions and retrieve records.
		</li>
		<li>
			<b>INSERT</b>
			: Allows to create records in the table.
		</li>
		<li>
			<b>UPDATE</b>
			: Allows to modify the records already existing in the table.
		</li>
		<li>
			<b>DELETE</b>
			: Allows to delete records in the table.
		</li>
		<li>
			<b>ALTER</b>
			: Allows to modify the table definition, rename or delete the table.
		</li>
		<li>
			<b>INDEX</b>
			: Allows to call table methods or instance methods.
		</li>
		<li>
			<b>EXECUTE</b>
			: Allows to call table methods or instance methods.
		</li>
		<li>
			<b>ALL PRIVILEGES</b>
			: Includes all permissions described above.
		</li>
	</ul>
	<p class="important">
		Using <b>WITH GRANT OPTION</b> in a GRANT statement allows the grantee of authorization to grant that same privilege to another user.
		The grantor of authorization must be the owner of all tables listed before the grant operation or have WITH GRANT OPTION specified.
	</p>
	
	<p>
		You can revoke privileges using the <b>REVOKE</b> statement. The privileges granted to a user can be revoked anytime. If more than one privilege is
		granted to a user, all or part of the privileges can be revoked. In addition, if privileges on multiple tables are granted to more than one user using
		one GRANT statement, the privileges can be selectively revoked for specific users and tables.
	</p>
	<p class="important">
		If the privilege (WITH GRANT OPTION) is revoked from the grantor, the privilege granted to the grantee by that grantor is also revoked
		(automatically).
	</p>
	<p>
		<b>Examples:</b>
	</p>
	<p>
		SELECT authorization for the <b>olympic</b> table is granted to "Fred" (all members of "Fred" user):
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	GRANT SELECT ON olympic TO Fred;
	</div>
	</div>

	<p>
		SELECT, INSERT, UPDATE and DELETE authorization for the <b>nation</b> and <b>athlete</b> tables are granted to "Jenifer" and "Daniel" (all members
		belonging to "Jenifer" and "Daniel"):
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	GRANT SELECT, INSERT, UPDATE, DELETE ON nation, athlete TO Jenifer, Daniel;
	</div>
	</div>
	<p>
		All authorization for the <b>game</b> and <b>event</b> tables is granted to all users:
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	GRANT ALL PRIVILEGES ON game, event TO public;
	</div>
	</div>
	<p>
		The GRANT statement grants search authorization for the <b>record</b> and <b>history</b> tables to "Ross", and WITH GRANT OPTION allows "Ross" to grant
		the same authorization to another user:
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	GRANT SELECT ON record, history TO Ross WITH GRANT OPTION;
	</div>
	</div>
	<p>
		REVOKE statement is used to allow "John" only the SELECT privilege while maintaining all the privileges for "Fred" granted before. If "John" granted
		the privileges to another user, the grantee is also allowed to use the SELECT privilege only:
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	REVOKE INSERT, UPDATE, DELETE ON nation, athlete FROM John;
	</div>
	</div>
	<p>
		The REVOKE statement is used to revoke all privileges granted to "Fred" before. If the statement is executed, "Fred" is not being allowed to perform
		any operation on the nation and athlete tables:
	</p>
	<div class="code">
	<div editor_component="code_highlighter" code_type="sql" first_line="1" collapse="false" nogutter="false" nocontrols="false">
	REVOKE ALL PRIVILEGES ON nation, athlete FROM Fred;
	</div>
	</div>
	<h3 id="cubrid-manager">Using CUBRID Manager Client to Manage Users</h3>
	<p>
		One easy way to manage users is through the GUI provided by CUBRID Manager Client, from where you can:
	</p>
	<ul>
		<li>
			<b>Browse</b> users
			<p class="center"><img src="http://www.cubrid.org/files/attach/images/49/515/003/cubrid-browse-users.png" alt="Browse Users" width="260" height="155" editor_component="image_link"/></p>
		</li>
		<li>
			<b>Create</b> and <b>Delete</b> users
			<p class="center"><img src="http://www.cubrid.org/files/attach/images/49/515/003/cubrid-create-users.png" alt="Create / Delete Users" width="504" height="266" editor_component="image_link"/></p>
		</li>
		<li>
			<b>Manage</b> user permissions
			<p class="center"><img src="http://www.cubrid.org/files/attach/images/49/515/003/cubrid-manage-permissions.png" alt="Manage Permissions" width="502" height="325" editor_component="image_link"/></p>
		</li>
	</ul>
	<p>
		You can find more information about using CUBRID Manager client for managing database users here:
	</p>
	<ul>
		<li>
			<a href="/manual/840/en/Setting%20User%20Authorization">http://www.cubrid.org/manual/840/en/Setting%20User%20Authorization</a>
		</li>
		<li>
			<a href="/manual/840/en/Adding,%20Editing,%20and%20Deleting%20Users">http://www.cubrid.org/manual/840/en/Adding,%20Editing,%20and%20Deleting%20Users</a>
		</li>
	</ul>
	<h2 id="see-also">See also</h2>
	<ul>
		<li><a href="/intro_cubrid_security_2" target="_self">Introduction to CUBRID Security - Part II</a></li>
		<li><a href="/tutorials" target="_self">CUBRID Tutorials</a></li>
	</ul>]]></description>
                        <pubDate>Tue, 07 Dec 2010 09:42:36 -0800</pubDate>
                                </item>
            </channel>
</rss>
