Autonomous Database(ATP/ADW/AJSON) は、従来は Autonomous Database自体が持つウォレットのファイル群を
クライアント側に配置する必要がありましたが、ウォレット無しのTLS接続を許可するオプションが追加されました。
Update Network Options to Allow TLS or Require Only Mutual TLS (mTLS) Authentication on Autonomous Database
https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/support-tls-mtls-authentication.html#GUID-3F3F1FA4-DD7D-4211-A1D3-A74ED35C0AF5About TLS Authentication
https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/connect-introduction.html#GUID-5ACCC8FF-7637-48F6-8FE4-049A720AC275
If the client is connecting with JDBC Thin using TLS authentication, the client can connect without providing a wallet.
:
今回はこの追加された機能を使用して、ウォレット無しで Autonomous Database に接続してみるやで。
彡(゚)(゚)
1. Autonomous Database(ATP) の作成
まず Autonomous Database を作成します。ウォレット無しのTLS接続 は ADB の
ACL(Access Control List) による接続制限を行うか、プライベートエンドポイントで作成する必要があります。
Update Network Options to Allow TLS or Require Only Mutual TLS (mTLS) Authentication on Autonomous Database
https://docs.oracle.com/en/cloud/paas/autonomous-database/adbsa/support-tls-mtls-authentication.html#GUID-3F3F1FA4-DD7D-4211-A1D3-A74ED35C0AF5
If the instance is configured to operate over the public internet,
then one or more Access Control Lists (ACLs) must be defined before you allow TLS authentication.
:
If the instance is configured with a private endpoint, then you can allow TLS authentication.
:
今回は下記のトポロジーで Private Endpoint に ATP を作成します。
2. Mutual TLS(mTLS)認証必須の無効化
DB作成後、Autonomous Database のコンソールからmTLS認証必須を無効化します。
3. TLS接続の接続文字列確認
DB Connection ⇒ TLS(プルダウン) で TLS接続 の接続文字列を確認します。
従来の mTLS はポート番号が 1522 なのですが、TLS接続は 1521 となるもよう。
事前定義サービスは幾つかあるのですが、今回は TP接続 を選択します。彡(゚)(゚)
4. Instant Client(jdbc) の yum install(※オプション)
Compute に Instant Client を yum install して JDBC Thin Driver をゲットしておきます。
既に JDBC Thin Driver が有る場合は省略して構いません。下記では無駄に sqlplus をインストールしていたり…。
sudo su -
cd /etc/yum.repos.d
wget http://yum.oracle.com/public-yum-ol7.repo
yum install -y yum-utils
yum-config-manager --enable ol7_oracle_instantclient
yum list | grep -i oracle-instant
yum install oracle-instantclient-basic.x86_64
yum install oracle-instantclient-sqlplus.x86_64
yum install oracle-instantclient-jdbc.x86_64
yum install oracle-instantclient-tools.x86_64
export ORACLE_HOME=/usr/lib/oracle/21/client64
export PATH=${ORACLE_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
sqlplus /nolog
SQL*Plus: Release 21.0.0.0.0 - Production on Sat Oct 30 06:38:42 2021
Version 21.3.0.0.0
5. JDKダウンロードと展開(※オプション)
Compute に JDK をダウンロードして展開します。既にJDKインストール済みの場合は省略して構いません。
今回は JDK17 をダウンロードして展開します。生の wget で tar.gz の JDK をダウンロードできる…!
彡(゚)(゚)
mkdir work
cd work
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
tar xvzf latest/jdk-17_linux-x64_bin.tar.gz
cd jdk-17.0.1
cd bin
./java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
6. サンプルのソースコード
ソースコードは以前の記事のものを流用します。
Autonomous DB(ADW/ATP) に Java の JDBC Thin Driver で接続してみる。(OCI, Oracle Cloud Infrastructure)
https://qiita.com/ora_gonsuke777/items/91ec0e15848a78ede385
接続文字列部分には 3. で確認した接続文字列をセットします。
接続文字列内のダブルクォートは \ でエスケープしておきましょう。
import java.sql.*;
public class GetContainerName {
public static void main(String[] args) {
final String path = "jdbc:oracle:thin:@(description=(retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=xxxxxxxx.adb.ap-tokyo-1.oraclecloud.com))(connect_data=(service_name=xxxxxxxxxxxx_ayuatp1_tp.adb.oraclecloud.com))(security=(ssl_server_cert_dn=\"CN=adb.ap-tokyo-1.oraclecloud.com, OU=Oracle ADB TOKYO, O=Oracle Corporation, L=Redwood City, ST=California, C=US\")))";
final String id = "ADMIN"; //ID
final String pw = "xxxxxxxx"; //password
try (
Connection conn = DriverManager.getConnection(path, id, pw);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT NAME FROM V$CONTAINERS");
) {
while (rs.next()) {
String cn = rs.getString("name");
System.out.println("Container Name => " + cn);
}
} catch(SQLException ex) {
ex.printStackTrace(); //Error
}
}
}
7. コンパイルと実行
ソースをコンパイルして実行します。漢の 生javac に 生java実行……。
export JAVA_HOME=/home/opc/work/jdk-17.0.1
export PATH=${JAVA_HOME}/bin:${PATH}
javac GetContainerName.java
java -classpath /usr/lib/oracle/21/client64/lib/ojdbc8.jar:. GetContainerName
Container Name => xxxxxxxxxxxxxx_AYUATP1
ウォレット無しでも ADB(ATP) への接続が成功して、コンテナ名が取得できました。
8. まとめ
幾つか事前準備は有りますが、ウォレット無しでも Autonomous Database に接続できるようになりました。
ウォレットの管理やローテション等の手間が無くなり、より使いやすくなっています。
Autonomous Database は Exadata のリソースを安価に使用できるので、皆さん活用して下さいね。
彡(^)(^)