Privileges enable users to create, delete, or access database resources. Authority levels provide a method of grouping privileges and higher-level database manager maintenance and utility operations. Together, these act to control access to the database manager and its database objects. Users can access only those objects for which they have the appropriate authorization, i.e., the required privilege or authority.
A user or group can have one or more of the following levels of authorization and privileges:
Users with administrative authority (SYSADM or DBADM) or ownership privileges (CONTROL) can grant and revoke privileges to and from others, using the GRANT and REVOKE statements. It is also possible to grant a table, view, or schema privilege to another user if that privilege is held with the WITH GRANT OPTION. However, the WITH GRANT OPTION does not allow the person granting the privilege to revoke the privilege, once granted. You must have SYSADM authority, DBADM authority, or CONTROL privilege to revoke the privilege.
A user or group can be authorized for any combination of individual privileges or authorities. When a privilege is associated with a resource, that resource must already exist. For example, a user cannot be given the SELECT privilege on a table unless that table has previously been created.
Care must be taken when an authorization name is given authorities and privileges and no user exists with that authorization name. At some later time, a user can be created with that authorization name and automatically receive all of the authorities and privileges associated with that authorization name .
Tasks and Required Authorizations
Not all organizations divide job responsibilities in the same manner. Table 4.4 lists some other common job responsibilities by titles, the tasks that usually accompany them, and the authorities or privileges that are needed to carry out those tasks.
Table 4.4. Common Job Responsibilities
If an application program contains dynamic SQL statements, the program end user may need additional privileges to EXECUTE and CONNECT (such as SELECT, INSERT, DELETE, and UPDATE).
Using the System Catalog for Security Issues
Information about each database is automatically maintained in a set of views called the system catalog , which is created when the database is generated. This system catalog describes tables, columns , indexes, programs, privileges, and other objects. The system catalog views list the privileges held by users and the identity of the user granting each privilege, as described in Table 4.5.
Table 4.5. System Catalog Views
The following statement retrieves all authorization names with privileges:
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'DATABASE' FROM SYSCAT.DBAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'TABLE' FROM SYSCAT.TABAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'PACKAGE' FROM SYSCAT.PACKAGEAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'INDEX' FROM SYSCAT.INDEXAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'COLUMN' FROM SYSCAT.COLAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'SCHEMA' FROM SYSCAT.SCHEMAAUTH UNION SELECT DISTINCT GRANTEE, GRANTEETYPE, 'SERVER' FROM SYSCAT.PASSTHRUAUTH ORDER BY GRANTEE, GRANTEETYPE, 3;
Periodically, the list retrieved by this statement should be compared with lists of user and group names defined in the operating system security facility. You can then identify those authorization names (userids) that are no longer valid and revoke their privileges.
To retrieve all authorization names that are directly authorized to access the table EMPLOYEE with the qualifier DSNOW:
SELECT DISTINCT GRANTEETYPE, GRANTEE FROM SYSCAT.TABAUTH WHERE TABNAME = 'EMPLOYEE' AND TABSCHEMA = 'DSNOW' UNION SELECT DISTINCT GRANTEETYPE, GRANTEE FROM SYSCAT.COLAUTH WHERE TABNAME = 'EMPLOYEE'AND TABSCHEMA = 'DSNOW';
To retrieve all authorization names that have been directly granted DBADM authority:
SELECT DISTINCT GRANTEE FROM SYSCAT.DBAUTH WHERE DBADMAUTH = 'Y';
To find out who can update the table EMPLOYEE with the qualifier DSNOW, issue the following statement:
[View full width]
This retrieves any authorization names with DBADM authority, as well as those names to which CONTROL or UPDATE privileges have been directly granted. However, it will not return the authorization names of users who hold only SYSADM authority.
To retrieve a list of the database privileges that has been directly granted to an individual authorization name:
SELECT * FROM SYSCAT.DBAUTH WHERE GRANTEE = USER AND GRANTEETYPE = 'U';
To retrieve a list of the table privileges that were directly granted by a specific user: (The keyword USER in these statements is always equal to the value of a user's authorization name. USER is a read-only special register.)
SELECT * FROM SYSCAT.TABAUTH WHERE GRANTOR = USER;
The following statement retrieves a list of the individual column privileges that were directly granted by a specific user:
SELECT * FROM SYSCAT.COLAUTH WHERE GRANTOR = USER;
During database creation, SELECT privilege on the system catalog views is granted to PUBLIC. In most cases, this does not present any security problems. For very sensitive data, however, it may be inappropriate, because these tables describe every object in the database. If this is the case, consider revoking the SELECT privilege from PUBLIC, then grant the SELECT privilege as required to specific users. Granting and revoking SELECT on the system catalog views is done in the same way as for any view, but you must have either SYSADM or DBADM authority to do this.
To retrieve the owner and name of every table on which a user's authorization name has been directly granted SELECT privilege:
SELECT TABSCHEMA, TABNAME FROM SYSCAT.TABAUTH WHERE GRANTEETYPE = 'U' AND GRANTEE = USER AND SELECTAUTH = 'Y'