DB2 10.5 for Linux, UNIX, and Windows

Updating of LBAC protected data

Your LBAC credentials must allow you write access to data before you can update it. In the case of updating a protected row, your LBAC credentials must also allow read access to the row.

Updating protected columns

When you try to update data in a protected column, your LBAC credentials are compared to the security label protecting the column. The comparison made is for write access. If write access is blocked then an error is returned and the statement fails, otherwise the update continues.

The details of how your LBAC credentials are compared to a security label are given in the topic about how LBAC security labels are compared.

Example:

Assume there is a table T1 in which column DEPTNO is protected by a security label L2 and column PAYSCALE is protected by a security label L3. T1, including its data, looks like this:

Table 1. Table T1
EMPNO LASTNAME

DEPTNO
Protected by
L2

PAYSCALE
Protected by
L3

1 Rjaibi 11 4
2 Miller 11 7
3 Bird 11 9
User Lhakpa has no LBAC credentials. He issues this SQL statement:
UPDATE T1 SET EMPNO = 4 
   WHERE LASTNAME = "Bird"

This statement executes without error because it does not update any protected columns. T1 now looks like this:

Table 2. Table T1 After Update
EMPNO LASTNAME

DEPTNO
Protected by
L2

PAYSCALE
Protected by
L3

1 Rjaibi 11 4
2 Miller 11 7
4 Bird 11 9
Lhakpa next issues this SQL statement:
UPDATE T1 SET DEPTNO = 55 
   WHERE LASTNAME = "Miller"

This statement fails and an error is returned because DEPTNO is protected and Lhakpa has no LBAC credentials.

Assume Lhakpa is granted LBAC credentials and that allow the access summarized in the following table. The details of what those credentials are and what elements are in the security labels are not important for this example.

Security label protecting the data Can read? Can Write?
L2 No Yes
L3 No No
Lhakpa issues this SQL statement again:
UPDATE T1 SET DEPTNO = 55 
   WHERE LASTNAME = "Miller"

This time the statement executes without error because Lhakpa's LBAC credentials allow him to write to data protected by the security label that is protecting the column DEPTNO. It does not matter that he is not able to read from that same column. The data in T1 now looks like this:

Table 3. Table T1 After Second Update
EMPNO LASTNAME

DEPTNO
Protected by
L2

PAYSCALE
Protected by
L3

1 Rjaibi 11 4
2 Miller 55 7
4 Bird 11 9
Next Lhakpa issues this SQL statement:
UPDATE T1 SET DEPTNO = 55, PAYSCALE = 4 
   WHERE LASTNAME = "Bird"

The column PAYSCALE is protected by the security label L3 and Lhakpa's LBAC credentials do not allow him to write to it. Because Lhakpa is unable to write to the column, the update fails and no data is changed.

Updating protected rows

If your LBAC credentials do not allow you to read a row, then it is as if that row does not exist for you so there is no way for you to update that row. For rows that you are able to read, you must also be able to write to the row in order to update it.

When you try to update a row, your LBAC credentials for writing are compared to the security label protecting the row. If write access is blocked, the update fails and an error is returned. If write access is not blocked, then the update continues.

The update that is performed is done the same way as an update to a non-protected row except for the treatment of the column that has a data type of DB2SECURITYLABEL. If you do not explicitly set the value of that column, it is automatically set to the security label that you hold for write access. If you do not have a security label for write access, an error is returned and the statement fails.

If the update explicitly sets the column that has a data type of DB2SECURITYLABEL, then your LBAC credentials are checked again. If the update you are trying to perform would create a row that your current LBAC credentials would not allow you to write to, then what happens depends on the security policy that is protecting the table. If the security policy has the RESTRICT NOT AUTHORIZED WRITE SECURITY LABEL option, then the update fails and an error is returned. If the security policy does not have the RESTRICT NOT AUTHORIZED WRITE SECURITY LABEL option or if it instead has the OVERRIDE NOT AUTHORIZED WRITE SECURITY LABEL option, then the security label you provide is ignored and if you hold a security label for write access, it is used instead. If you do not hold a security label for write access, an error is returned.

Example:

Assume that table T1 is protected by a security policy named P1 and has a column named LABEL that has a data type of DB2SECURITYLABEL.

T1, including its data, looks like this:
Table 4. Table T1
EMPNO LASTNAME DEPTNO LABEL
1 Rjaibi 11 L1
2 Miller 11 L2
3 Bird 11 L3

Assume that user Jenni has LBAC credentials that allow her to read and write data protected by the security labels L0 and L1 but not data protected by any other security labels. The security label she holds for both read and write is L0. The details of her full credentials and of what elements are in the labels are not important for this example.

Jenni issues this SQL statement:
SELECT * FROM T1
Jenni sees only one row in the table:
Table 5. Jenni's SELECT Query Result
EMPNO LASTNAME DEPTNO LABEL
1 Rjaibi 11 L1

The rows protected by labels L2 and L3 are not included in the result set because Jenni's LBAC credentials do not allow her to read those rows. For Jenni it is as if those rows do not exist.

Jenni issues these SQL statements:
UPDATE T1 SET DEPTNO = 44 WHERE DEPTNO = 11;
SELECT * FROM T1;
The result set returned by the query looks like this:
Table 6. Jenni's UPDATE & SELECT Query Result
EMPNO LASTNAME DEPTNO LABEL
1 Rjaibi 44 L0
The actual data in the table looks like this:
Table 7. Table T1
EMPNO LASTNAME DEPTNO LABEL
1 Rjaibi 44 L0
2 Miller 11 L2
3 Bird 11 L3

The statement executed without error but affected only the first row. The second and third rows are not readable by Jenni so they are not selected for update by the statement even though they meet the condition in the WHERE clause.

Notice that the value of the LABEL column in the updated row has changed even though that column was not explicitly set in the UPDATE statement. The column was set to the security label that Jenni held for writing.

Now Jenni is granted LBAC credentials that allow her to read data protected by any security label. Her LBAC credentials for writing do not change. She is still only able to write to data protected by L0 and L1.

Jenni again issues this SQL statement:
UPDATE T1 SET DEPTNO = 44 WHERE DEPTNO = 11

This time the update fails because of the second and third rows. Jenni is able to read those rows, so they are selected for update by the statement. She is not, however, able to write to them because they are protected by security labels L2 and L3. The update does not occur and an error is returned.

Jenni now issues this SQL statement:

UPDATE T1 
 SET DEPTNO = 55, LABEL = SECLABEL_BY_NAME( 'P1', 'L2' ) 
 WHERE LASTNAME = "Rjaibi"

The SECLABEL_BY_NAME function in the statement returns the security label named L2. Jenni is trying to explicitly set the security label protecting the first row. Jenni's LBAC credentials allow her to read the first row, so it is selected for update. Her LBAC credentials allow her to write to rows protected by the security label L0 so she is allowed to update the row. Her LBAC credentials would not, however, allow her to write to a row protected by the security label L2, so she is not allowed to set the column LABEL to that value. The statement fails and an error is returned. No columns in the row are updated.

Jenni now issues this SQL statement:

UPDATE T1 SET LABEL = SECLABEL_BY_NAME( 'P1', 'L1' ) WHERE LASTNAME = "Rjaibi"

The statement succeeds because she would be able to write to a row protected by the security label L1.

T1 now looks like this:
Table 8. Table T1
EMPNO LASTNAME DEPTNO LABEL
1 Rjaibi 44 L1
2 Miller 11 L2
3 Bird 11 L3

Updating protected rows that contain protected columns

If you try to update protected columns in a table with protected rows then your LBAC credentials must allow writing to of all of the protected columns affected by the update, otherwise the update fails and an error is returned. This is as described in section about updating protected columns, earlier. If you are allowed to update all of the protected columns affected by the update you will still only be able to update rows that your LBAC credentials allow you to both read from and write to. This is as described in the section about updating protected rows, earlier. The handling of a column with a data type of DB2SECURITYLABEL is the same whether the update affects protected columns or not.

If the column that has a data type of DB2SECURITYLABEL is itself a protected column then your LBAC credentials must allow you to write to that column or you cannot update any of the rows in the table.