GaussDB(DWS) allows you to access databases using IAM authentication. When you use the JDBC application program to connect to a cluster, set the IAM username, credential, and other information as you configure the JDBC URL. After doing this, when you try to access a database, the system will automatically generate a temporary credential and a connection will be set up.
IAM supports two types of user credential: password and Access Key ID/Secret Access Key (AK/SK). JDBC connection requires the latter.
The IAM account you use to access a database must be granted with the DWS Database Access permission. Only users with both the DWS Administrator and DWS Database Access permissions can connect to GaussDB(DWS) databases using the temporary database user credentials generated based on IAM users.
The DWS Database Access permission can only be granted to user groups. Ensure that your IAM account is in a user group with this permission.
On IAM, only users in the admin group have the permissions to manage users. This requires that your IAM account be in the admin user group. Otherwise, contact the IAM account administrator to grant your IAM account this permission.
The process of accessing a database is as follows:
Only users in the admin user group of IAM can perform this step. In IAM, only users in the admin user group can manage users, including creating user groups and users and setting user group rights.
For details, see "User and User Group Management > Viewing or Modifying User Group Information" in the Identity and Access Management User Guide.
You can also create an IAM user group, and set a policy for, grant the DWS Administrator and DWS Database Access permissions to, and add your IAM user to it. For details, see "User and User Group Management > Creating a User Group" in the Identity and Access Management User Guide.
You can log in to the management console to create an AK/SK pair or use an existing one.
Each user can create a maximum of two AK/SK pairs, which are valid permanently. To ensure account security, change your AK/SK pairs periodically and keep them safe.
Configuring JDBC Connection Parameters
Parameter |
Description |
---|---|
url |
gsjdbc4.jar/gsjdbc200.jar database connection descriptor. The JDBC API does not provide the connection retry capability. You need to implement the retry processing in the service code. The URL example is as follows: jdbc:dws:iam://dws-IAM-demo:eu-de/gaussdb?AccessKeyID=XXXXXXXXXXXXXXXXXXXX&SecretAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&DbUser=user_test&AutoCreate=true
JDBC URL parameters:
|
info |
Database connection properties. Common properties include the following:
|
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | //The following uses gsjdbc4.jar as an example. // The following code encapsulates the database connection obtaining operations into an API. You can connect to the database by specifying the region where the cluster is located, cluster name, access key ID, secret access key, and the corresponding IAM username. public static Connection GetConnection(String clustername, String regionname, String AK, String SK, String username) { // Driver class. String driver = "org.postgresql.Driver"; // Database connection descriptor. String sourceURL = "jdbc:dws:iam://" + clustername + ":" + regionname + "/postgresgaussdb?" + "AccessKeyID=" + AK + "&SecretAccessKey=" + SK + "&DbUser=" + username + "&autoCreate=true"; Connection conn = null; try { // Load the driver. Class.forName(driver); } catch (ClassNotFoundException e) { return null; } try { // Create a connection. conn = DriverManager.getConnection(sourceURL); System.out.println("Connection succeed!"); } catch (SQLException e) { return null; } return conn; } |