Start of change

CREATE PERMISSION

The CREATE PERMISSION statement creates a row permission for row access control at the current server.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared only if DYNAMICRULES run behavior is implicitly or explicitly specified.

Authorization

The privilege set that is defined below must include the following authority:

  • SECADM authority

SECADM authority can create a row permission in any schema. Additional privileges are not needed to reference other objects in the permission definition. For example, the SELECT privilege is not needed to retrieve from a table, and the EXECUTE privilege is not needed to invoke a user-defined function.

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the owner of the package. If the statement is dynamically prepared, the privilege set is the set of privileges that are held by the SQL authorization ID of the process. However, if it is running in a trusted context defined with the ROLE AS OBJECT OWNER AND QUALIFIER clause, the privilege set is the set of privileges that are held by the role in effect.

Syntax

>>-CREATE PERMISSION--permission-name--ON--table-name----------->

>--+--------------------------+--------------------------------->
   | .-AS-.                   |   
   '-+----+--correlation-name-'   

>--FOR ROWS WHERE--search-condition--ENFORCED FOR ALL ACCESS---->

   .-DISABLE-.   
>--+---------+-------------------------------------------------><
   '-ENABLE--'   

Description

permission-name
Names the row permission for row access control. The name, including the implicit or explicit qualifier, must not identify a row permission or a column mask that already exists at the current server
ON table-name
Identifies the table on which the row permission is created. The name must identify a table that exists at the current server. It must not identify any of the following objects:
  • An auxiliary table
  • A created or declared temporary table
  • A view
  • A catalog table
  • An alias
  • A synonym
  • A materialized query table or table that is directly or indirectly referenced in the definition of a materialized query table
  • A table that was implicitly created for an XML column
  • A table that contains a period
  • A history table
  • Start of changeAn accelerator-only tableEnd of change
  • A table that has a security label column.
correlation-name
Can be used within search-condition to designate the table. For the explanation of correlation-name, see Correlation names.
FOR ROWS WHERE
Indicates that a row permission is created. A row permission specifies a search condition under which rows of the table can be accessed.
search-condition
Specifies a condition that can be true, false, or unknown for a row of the table. search-condition follows the same rules that are used by the search condition in a WHERE clause of a subselect. In addition, the search condition must not reference any of the following objects:
  • A remote object
  • The table for which the row permission is being defined
  • A table that has a security label column
  • A created global temporary table or a declared global temporary table
  • An auxiliary table
  • A table that was implicitly created for an XML column
  • A user-defined external table function or a user-defined SQL table function
  • An XMLTABLE table function
  • A built-in table function, such as ADMIN_TASK_LIST and ADMIN_ TASK_STATUS
  • A host variable, SQL variable, SQL parameter, or trigger transition variable
  • A user-defined function that is defined as not secure
  • A function that is not deterministic or that has an external action or is defined with the MODIFIES SQL DATA option
  • A parameter marker
  • A column that is defined with a FIELDPROC
  • A LOB column or a distinct type column that is based on a LOB
  • An XML column
  • An XMLEXISTS predicate
  • An OLAP specification
  • A ROW CHANGE expression
  • A sequence reference
  • A select list notation * or name.* in the SELECT clause
  • A table reference that contains a period specification
  • A view that includes any of the preceding restrictions in its definition

The encoding scheme of the table is used to evaluate the search-condition. Tables and language elements that require multiple encoding scheme evaluation must not be referenced in the search-condition. See Determining the encoding scheme and CCSID of a string for those language elements.

If the search-condition references tables for which row or column access control is activated, access control from those tables is not cascaded.

ENFORCED FOR ALL ACCESS
Specifies that the row permission applies to all references of the table. If row access control is activated for the table, when the table is referenced in a data manipulation statement, DB2® implicitly applies the row permission to control the access of the table. If the reference of the table is for a fetch operation such as SELECT, the application of the row permission determines what set of rows can be retrieved by the user who requested the fetch operation. If the reference of the table is for a data change operation such as INSERT, the application of the row permission determines whether all rows to be changed are insertable or updatable by the user who requested the data change operation.
DISABLE or ENABLE
Specifies that the row permission is to be enabled or disabled for row access control.
DISABLE
Specifies that the row permission is to be disabled for row access control. The row permission will remain ineffective regardless the row access control is activated for the table or not.

DISABLE is the default.

ENABLE
Specifies that the row permission is to be enabled for row access control. If row access control is not currently activated for the table, the row permission will become effective when row access control is activated for the table. If row access control is currently activated for the table, the row permission becomes effective immediately and all packages and dynamic cached statements that reference the table are invalidated.

Notes

How row permission are applied and how they affect certain statements:
See the ALTER TABLE statement with the ACTIVATE ROW ACCESS CONTROL clause for information on how to activate row access control and how row permissions are applied. See the description of subselect for information on how the application of row permissions affects the fetch operation. See the data change statements for information on how the application of row permissions affects the data change operation.
Row permissions that are created before row access control is activated for a table:
The CREATE PERMISSION statement is an independent statement that can be used to create a row permission before row access control is activated for a table. The only requirement is that the table and the columns exist before the permission is created. Multiple row permissions can be created for a table.

The definition of the row permission is stored in the DB2 catalog. Dependency on the table for which the permission is being created and dependencies on other objects referenced in the definition are recorded. No package or dynamic cached statement is invalidated. A row permission can be created as enabled or disabled for row access control. An enabled row permission does not take effect until the ALTER TABLE statement with the ACTIVATE ROW ACCESS CONTROL clause is used to activate row access control for the table. A disabled row permission remains ineffective even when row access control is activated for the table. The ALTER PERMISSION statement can be used to alter between ENABLE and DISABLE.

After row access control is activated for a table, when the table is referenced in a data manipulation statement, all enabled row permissions that are defined for the table are implicitly applied by DB2 to control access to the table.

Creating row permissions before activating row access control for a table is the recommended sequence to avoid multiple invalidations of packages and dynamic cached statements that reference the table.

Row permissions that are created after row access control is activated for a table:
An enabled row permission becomes effective as soon as it is committed. All the packages and dynamic cached statements that reference the table are invalidated. Thereafter, when the table is referenced in a data manipulation statement, all enabled row permissions are implicitly applied to the statement. Any disabled row permission remains ineffective even when row access control is activated for the table.
No cascaded effect when row or column access control enforced tables are referenced in row permission definitions:
A row permission definition may reference tables and columns that are currently enforced by row or column access control. Access control from those tables are ignored when the table for which the row permission is being created is referenced in a data manipulation statement.
Multiple column masks and row permissions sharing the same environment variables:
Multiple column masks and row permissions can be created for a table. They must use the same set of environment variables. The set of environment variables is determined when the first column mask or row permission is created for the table.

The catalog table SYSENVIRONMENT contains the list of environment variables. The following table shows which environment variable must be the same among the multiple column masks and row permissions.

Table 1. Environment Variables in SYSIBM.SYSENVIRONMENT
Environment variables shown as SYSENVIRONMENT columns Description Static create statement Dynamic create statement Must be the same among multiple column masks and row permissions?
ENVID Internal identifier of the environment Assigned by DB2 Assigned by DB2 Yes
CURRENT_SCHEMA The qualifier used to qualify unqualified objects such as tables, views. etc. Package owner Value of CURRENT_SCHEMA special register Yes
PATHSCHEMAS The schema path used to qualify unqualified object such as user-defined functions and CAST functions for distinct types. PATH bind option Value of CURRENT_PATH special register Yes
APPLICATION_
ENCODING_
CCSID
The CCSID of the application environment ENCODING bind option CURRENT APPLICATION ENCODING SCHEME special register Yes
ORIGINAL_
ENCODING_
CCSID
The original CCSID of the statement text string CCSID(n) pre-compiler option or EBCDIC CCSID on DSNTIPF installation panel CCSID based on DEF ENCODING SCHEME on DSNTIPF installation panel Yes
DECIMAL_POINT The decimal point indicator COMMA or PERIOD precompiler option or DECIMAL POINT IS on DSNTIPF installation panelv DECIMAL POINT IS on DSNTIPF installation panel Yes
MIN_DIVIDE_SCALE The minimum divide scale MINIMUM DIVIDE SCALE on DSNTIP4 installation panel MINIMUM DIVIDE SCALE on DSNTIP4 installation panelv Yesv
STRING_DELIMITER The string delimiter that is used in COBOL string constants APOST precompiler option or STRING DELIMITER on DSNTIPF installation panel STRING DELIMITER on DSNTIPF installation panel No
SQL_
STRING_
DELIMITER
The SQL string delimiter that is used in constants APOSTSQL pre-compiler option or SQL STRING DELIMITER on DSNTIPF installation panel SQL STRING DELIMITER on DSNTIPF installation panel Yes
MIXED_DATA Uses mixed DBCS data MIXED DATA on DSNTIPF installation panel MIXED DATA on DSNTIPF installation panel Yes
DECIMAL_
ARITHMETIC
The rules that are to be used for CURRENT PRECISION and when both operands in a decimal operation have a precision of 15 or less. DEC(15) or DEC(31) precompiler option or DECIMAL ARITHMETIC on DSNTIP4 installation panel DECIMAL ARITHMETIC on DSNTIP4 installation panel Yes
DATE_FORMAT The date format DATE pre-compiler option or DATE FORMAT on DSNTIP4 installation panel DATE FORMAT on DSNTIP4 installation panel Yes
TIME_FORMAT The time format TIME pre-compiler option or TIME FORMAT on DSNTIP4 installation panel TIME FORMAT on DSNTIP4 installation panel Yes
FLOAT_FORMAT The floating point format FLOAT (S390 | IEEE) pre-compiler option or default of FLOAT S390 Default of FLOAT S390 No
HOST_LANGUAGE The host language HOST pre-compiler option or LANGUAGE DEFAULT on DSNTIPF installation panel LANGUAGE DEFAULT on DSNTIPF installation panel No
CHARSET The character set CCSID(n) pre-compiler option or EBCDIC CCSID on DSNTIPF installation panel EBCDIC CCSID on DSNTIPF installation panel No
FOLD FOLD is only applicable when HOST_LANGUAGE is C or CPP. Otherwise FOLD is blank. HOST(C(FOL D) precompiler option or default of NO FOLD default of NO FOLD No
ROUNDING The rounding mode that is used when arithmetic and casting operations are performed on DECFLOAT data. ROUNDING bind option CURRENT DECFLOAT ROUNDING MODE special register Yes
Note: In a data sharing environment, if a separate DSNHDECP module is provided for each member of the group, the DSNHDECP settings for each environment variable should be the same in all members of the data sharing group, otherwise an error might be issued when multiple column masks or row permissions are created.
Ordinary SQL identifiers specified in a static CREATE PERMISSION statement in a COBOL application:
If the CREATE PERMISSION statement is a static statement in a COBOL application, the ordinary SQL identifiers used in the row permission definition must not follow the rules for naming COBOL words (DSNH20474, reason code 14). They must follow the rules for naming SQL identifiers as described in the topic “SQL identifiers” in DB2 SQL Reference. For example, the COBOL word 1ST-TIME is not allowed as an ordinary SQL identifier in a row permission definition; change it to FIRST_TIME or put it in the delimiters.
Encoding scheme and CCSIDs of the data manipulation statement after row permissions are applied:
The encoding scheme and CCSIDs of the data manipulation statement are not affected by the row permissions that are implicitly applied by DB2 for the row access control. The row permission definition is evaluated using its target table's encoding scheme and CCSIDs.
Consideration for DB2 limits:
If the data manipulation statement already approaches some DB2 limits in the statement, it should be noted that the more enabled row permissions and enabled column masks are created, the more likely they would impact some limits. For example, they may cause the statement to exceed the maximum total length (32600 bytes) of columns of a query operation requiring sort and evaluating aggregate functions (MULTIPLE DISTINCT and GROUP BY). This is because the enabled column mask and enabled row permission definitions are implicitly merged into the statement when the table is referenced in a data manipulation statement. See "Limits in DB2 for z/OS®" in SQL Reference for the limits of a statement.

Examples

Example 1:
Secure user-defined function ACCOUNTING_UDF in row permission SALARY_ROW_ACCESS processes the sensitive data in column SALARY. After row access control is activated for table EMPLOYEE, Accountant Paul retrieves the salary of employee with EMPNO 123456 who is making $100,000 a year. Paul may or may not see the row depending on the output value from user-defined function ACCOUNTING_UDF.
CREATE PERMISSION SALARY_ROW_ACCESS ON EMPLOYEE
   FOR ROWS WHERE VERIFY_GROUP_FOR_USER(SESSION_USER,'MGR','ACCOUNTING') = 1
            AND
            ACCOUNTING_UDF(SALARY) < 120000
   ENFORCED FOR ALL ACCESS
   ENABLE;

COMMIT;

ALTER TABLE EMPLOYEE 
	ACTIVATE ROW ACCESS CONTROL;

COMMIT;

SELECT SALARY FROM EMPLOYEE 
   WHERE EMPNO = 123456;
Example 2:
The tellers in a bank can only access customers from their branch. All tellers have secondary authorization ID TELLER. The customer service representatives are allowed to access all customers of the bank. All customer service representatives have secondary authorization ID CSR. A row permission is created for each group of personnel in the bank accordingly to the access rule defined by SECADM authority. After row access control is activated for table CUSTOMER, in the SELECT statement the search conditions of both row permissions are merged into the statement and they are combined with the logic OR operator to control the set of rows accessible by each group.
CREATE PERMISSION TELLER_ROW_ACCESS ON CUSTOMER
   FOR ROWS WHERE VERIFY_GROUP_FOR_USER(SESSION_USER,'TELLER') = 1
            AND
            BRANCH = (SELECT HOME_BRANCH FROM INTERNAL_INFO
                         WHERE EMP_ID = SESSION_USER)
    ENFORCED FOR ALL ACCESS
    ENABLE;

COMMIT;

CREATE PERMISSION CSR_ROW_ACCESS ON CUSTOMER
   FOR ROWS WHERE VERIFY_GROUP_FOR_USER(SESSION_USER,'CSR') = 1
   ENFORCED FOR ALL ACCESS
   ENABLE;

COMMIT;

ALTER TABLE CUSTOMER 
   ACTIVATE ROW ACCESS CONTROL;

COMMIT;

SELECT * FROM CUSTOMER;
End of change