DB2 10.5 for Linux, UNIX, and Windows

CREATE TRUSTED CONTEXT statement

The CREATE TRUSTED CONTEXT statement defines a trusted context 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 in effect for the package (SQLSTATE 42509).

Authorization

The privileges held by the authorization ID of the statement must include SECADM authority.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CREATE TRUSTED CONTEXT--context-name------------------------->

>--BASED UPON CONNECTION USING---------------------------------->

>--SYSTEM AUTHID--authorization-name--●--ATTRIBUTES------------->

      .-,-----------------------------------------------------------------------.         
      V  (1)                                                                    |         
>--(----------+-ADDRESS--address-value--+-----------------------------------+-+-+--)--●-->
              |                         '-WITH ENCRYPTION--encryption-value-' |           
              |  (2)                                                          |           
              '-------ENCRYPTION--encryption-value----------------------------'           

   .-NO DEFAULT ROLE---------.     .-DISABLE-.      
>--+-------------------------+--●--+---------+--●--------------->
   '-DEFAULT ROLE--role-name-'     '-ENABLE--'      

>--+-------------------------------------------------------------------------------------------+-->
   |               .-,-----------------------------------------------------------------------. |   
   |               V                                              .-WITHOUT AUTHENTICATION-. | |   
   '-WITH USE FOR----+-authorization-name--+-----------------+-+--+------------------------+-+-'   
                     |                     '-ROLE--role-name-' |  '-WITH AUTHENTICATION----'       
                     '-PUBLIC----------------------------------'                                   

>--●-----------------------------------------------------------><

Notes:
  1. Each combination of an attribute name and its corresponding value, as a pair, must be unique (SQLSTATE 4274D).
  2. ENCRYPTION cannot be specified more than once (SQLSTATE 42614); however, WITH ENCRYPTION can be specified for each ADDRESS that is specified.

Description

context-name
Names the trusted context. This is a one-part name. It is an SQL identifier (either ordinary or delimited). The name must not identify a trusted context that already exists at the current server (SQLSTATE 42710). The name must not begin with the characters 'SYS' (SQLSTATE 42939).
BASED UPON CONNECTION USING SYSTEM AUTHID authorization-name
Specifies that the context is a connection established by system authorization ID authorization-name, which must not be associated with an existing trusted context (SQLSTATE 428GL). It cannot be the authorization ID of the statement (SQLSTATE 42502).
ATTRIBUTES (...)
Specifies a list of one or more connection trust attributes upon which the trusted context is defined.
ADDRESS address-value
Specifies the actual communication address used by the client to communicate with the database server. The only protocol supported is TCP/IP. The ADDRESS attribute can be specified multiple times, but each address-value pair must be unique for the set of attributes (SQLSTATE 4274D).

When establishing a trusted connection, if multiple values are defined for the ADDRESS attribute of a trusted context, a candidate connection is considered to match this attribute if the address used by the connection matches any of the defined values for the ADDRESS attribute of the trusted context.

address-value
Specifies a string constant that contains the value to be associated with the ADDRESS trust attribute. The address-value must be an IPv4 address, an IPv6 address, or a secure domain name.
  • An IPv4 address must not contain leading spaces and is represented as a dotted decimal address. An example of an IPv4 address is 9.112.46.111. The value 'localhost' or its equivalent representation '127.0.0.1' will not result in a match; the real IPv4 address of the host must be specified instead.
  • An IPv6 address must not contain leading spaces and is represented as a colon hexadecimal address. An example of an IPv6 address is 2001:0DB8:0000:0000:0008:0800:200C:417A. IPv4-mapped IPv6 addresses (for example, ::ffff:192.0.2.128) will not result in a match. Similarly, 'localhost' or its IPv6 short representation '::1' will not result in a match.
  • A domain name is converted to an IP address by the domain name server where a resulting IPv4 or IPv6 address is determined. An example of a domain name is corona.torolab.ibm.com. When a domain name is converted to an IP address, the result of this conversion could be a set of one or more IP addresses. In this case, an incoming connection is said to match the ADDRESS attribute of a trusted context object if the IP address from which the connection originates matches any of the IP addresses to which the domain name was converted. When creating a trusted context object, it is advantageous to provide domain name values for the ADDRESS attribute instead of static IP addresses, particularly in Dynamic Host Configuration Protocol (DHCP) environments. With DHCP, a device can have a different IP address each time it connects to the network. So, if a static IP address is provided for the ADDRESS attribute of a trusted context object, some device might acquire a trusted connection unintentionally. Providing domain names for the ADDRESS attribute of a trusted context object avoids this problem in DHCP environments.
WITH ENCRYPTION encryption-value
Specifies the minimum level of encryption of the data stream or network encryption for this specific address-value. This encryption-value overrides the global ENCRYPTION attribute setting for this specific address-value.
encryption-value
Specifies a string constant that contains the value to be associated with the ENCRYPTION trust attribute for this specific address-value. The encryption-value must be one of the following values (SQLSTATE 42615):
  • NONE, no specific level of encryption is required
  • LOW, a minimum of light encryption is required; the authentication type on the database manager must be DATA_ENCRYPT if an incoming connection is to match the encryption setting for this specific address
  • HIGH, Secure Sockets Layer (SSL) encryption must be used for data communication between the database client and the database server if an incoming connection is to match the encryption setting for this specific address
ENCRYPTION encryption-value
Specifies the minimum level of encryption of the data stream or network encryption. The default is NONE.
encryption-value
Specifies a string constant that contains the value to be associated with the ENCRYPTION trust attribute for this specific address-value. The encryption-value must be one of the following values (SQLSTATE 42615):
  • NONE, no specific level of encryption is required for an incoming connection to match the ENCRYPTION attribute of this trusted context object
  • LOW, a minimum of light encryption is required; the authentication type on the database manager must be DATA_ENCRYPT if an incoming connection is to match the ENCRYPTION attribute of this trusted context object
  • HIGH, Secure Sockets Layer (SSL) encryption must be used for data communication between the database client and the database server if an incoming connection is to match the ENCRYPTION attribute of this trusted context object
The following table summarizes when a trusted context can be used, depending on the encryption used by the existing connection. If the trusted context cannot be used for the connection, a warning is returned (SQLSTATE 01679) and the SQLWARN8 field of the SQLCA is set to 'Y', indicating that the connection is a regular (non-trusted) connection.
Table 1. Encryption and trusted contexts
Encryption used by existing connection ENCRYPTION value for trusted context Can the trusted context be used for the connection?
No encryption 'NONE' Yes
No encryption 'LOW' No
No encryption 'HIGH' No
Low encryption (DATA_ENCRYPT) 'NONE' Yes
Low encryption (DATA_ENCRYPT) 'LOW' Yes
Low encryption (DATA_ENCRYPT) 'HIGH' No
High encryption (SSL) 'NONE' Yes
High encryption (SSL) 'LOW' Yes
High encryption (SSL) 'HIGH' Yes
NO DEFAULT ROLE or DEFAULT ROLE role-name
Specifies whether or not a default role is associated with a trusted connection that is based on this trusted context. The default is NO DEFAULT ROLE.
NO DEFAULT ROLE
Specifies that the trusted context does not have a default role.
DEFAULT ROLE role-name
Specifies that role-name is the default role for the trusted context. The role-name must identify a role that exists at the current server (SQLSTATE 42704). This role is used with the user in a trusted connection, based on this trusted context, when the user does not have a user-specific role defined as part of the definition of the trusted context.
DISABLE or ENABLE
Specifies whether the trusted context is created in the enabled or disabled state. The default is DISABLE.
DISABLE
Specifies that the trusted context is created in the disabled state. A trusted context that is disabled is not considered when a trusted connection is established.
ENABLE
Specifies that the trusted context is created in the enabled state.
WITH USE FOR
Specifies who can use a trusted connection that is based on this trusted context.
authorization-name
Specifies that the trusted connection can be used by the specified authorization-name. The authorization-name must not be specified more than once in the WITH USE FOR clause (SQLSTATE 428GM). It must also not be the authorization ID of the statement (SQLSTATE 42502). If the definition of a trusted context allows access by both PUBLIC and a list of users, the specifications for a user override the specifications for PUBLIC. For example, assume that a trusted context is defined that allows access by both PUBLIC WITH AUTHENTICATION and JOE WITHOUT AUTHENTICATION. If the trusted context is used by JOE, authentication is not required. However, if the trusted context is used by GEORGE, authentication is required.
ROLE role-name
Specifies that role-name is the role to be used for the user when a trusted connection is using the trusted context. The role-name must identify a role that exists at the current server (SQLSTATE 42704). The role explicitly specified for the user overrides any default role associated with the trusted context.
PUBLIC
Specifies that a trusted connection that is based on this trusted context can be used by any user. PUBLIC must not be specified more than once (SQLSTATE 428GM). All users using such a trusted connection make use of the privileges associated with the default role for the associated trusted context. If a default role is not defined for the trusted context, there is no role associated with the users that use a trusted connection based on this trusted context.
WITHOUT AUTHENTICATION or WITH AUTHENTICATION
Specifies whether or not switching the user on a trusted connection requires authentication of the user. The default is WITHOUT AUTHENTICATION.
WITHOUT AUTHENTICATION
Specifies that switching the current user on a trusted connection to this user does not require authentication.
WITH AUTHENTICATION
Specifies that switching the current user on a trusted connection to this user requires authentication.

Rules

Notes

Examples