Connect Go Applications with a Wallet (mTLS)

You can connect Go applications to your Autonomous Database instance with a wallet.

Topics

Download an Oracle Wallet File

You must download an Oracle Wallet (mTLS) file to obtain client security credentials that enable you to connect to an Autonomous Database instance.

  1. Download a wallet file from the Autonomous Database instance to obtain a zip file that contains the client security credentials and network configuration settings required to access an Autonomous Database instance.

    Depending on whether you are an Admin user or a non-Admin user, obtain the client security credentials (wallet.zip file) as follows:

    • ADMIN user: On the Oracle Cloud Infrastructure Console, click Database connection. See Download Client Credentials (Wallets).

    • Other user (non-administrator): Obtain the Oracle Wallet from the administrator for your Autonomous Database instance.

      Note

      Protect the wallet.zip file and its contents to prevent unauthorized database access.
  2. Unzip the client credentials file (wallet.zip).

Run Go Applications with a Wallet (mTLS)

You can connect Go applications to your Autonomous Database instance with a wallet. You must download a zipped wallet file from the Autonomous Database instance that contains the client security credentials.

The godror driver requires Oracle Client Libraries. See Install Oracle Client Library to use Godror. The Oracle Client libraries are installed where you run the Go Application.

The wallet file is in a zip archive format. The database service names can be found in the tnsnames.ora file in the wallet zip file. In the example given below, you will use the mydb_high network service name found in the tnsnames.ora file.

The following three files from the wallet zip file are required:
  • tnsnames.ora: Contains the net service names used for application connection strings and maps the strings to your database services.

  • sqlnet.ora: Specifies the SQLNet client side configuration.

  • cwallet.sso: Contains the auto-open SSO wallet.

Follow these steps to connect your Go application to an Autonomous Database instance using a wallet (mTLS):

  1. Place the files tnsnames.ora, sqlnet.ora, and cwallet.sso on the optional (opt) directory of your Linux system. The /opt directory is used to install optional or add-on software packages that are not part of the core operating system. You can place the files anywhere on your Microsoft Windows operating system. For example, subdirectory on C drive (C:) of your Microsoft Windows operating system.

    You can move the files to any accessible directory.

    For example, on Linux move the files to the directory /opt/OracleCloud/MYDB and edit sqlnet.ora to change the wallet location directory to the directory containing the cwallet.sso file.

    For example, on Linux edit sqlnet.ora as follows:

    WALLET_LOCATION = (SOURCE = (METHOD=file) (METHOD_DATA = (DIRECTORY="/opt/OracleCloud/MYDB")))
    SSL_SERVER_DN_MATCH=yes

    When the configuration files are not in the default location, your Go application needs to indicate where they are with the config_dir parameter.

    Note

    Neither of these settings are needed, and you do not need to edit sqlnet.ora if you put all the configuration files in the network/admin directory.
  2. In your Go application set the following connection parameters to connect to the Autonomous Database instance:
    • user: Specifies the Cloud Database user.
    • password: Specifies the Cloud Database user's password.
    • config_dir: Specifies the configuration directory where you are placing the tnsnames.ora and sqlnet.ora files. This is required when the configuration files are placed in a directory outside of the instant client configuration directory network/admin.
    • dsn: Specifies the desired network alias from the tnsnames.ora file.

    For example, to connect as the ADMIN user and connect with the mydb_high network service name (where the service name is found in /opt/OracleCloud/MYDB/tnsnames.ora):

    
    dsn := `user="admin"       
          password="password"       
          connectString="mydb_high"             
          configDir="/opt/OracleCloud/MYDB"` 
    db, _ := sql.Open("godror", dsn)
         

    You can use the above code in your Go application to create a connection string and connect to the Autonomous Database.