2025年8月29日金曜日

Oracle Database 19c EEをTLS有効にしてEntra IDでユーザー認証できるように設定する

オンプレミス環境を想定したOracle Database 19c Enterprise Editionのインスタンスを対象にして、TLSによる暗号化を有効にし、Entra IDによるユーザー認証ができることを確認します。

VirutalBoxの仮想マシンを作成して、その仮想マシン上でOracle Database 19c EEのインスタンスを実行します。作業にはAppleのMacbook Proを使用します。

Oracle Database 19c EEのインスタンスは、以下の記事で紹介した手順で作成しています。

Apple M1 MacにOracle Database 19cをインストールする

SIDORCLPDBがひとつORCLPDB1として作成されています。OSユーザーoracleでデータベース・サーバーが実行されています。仮想マシンにはポート・フォワーディングの設定がされていて、ホストからはポート番号10022を宛先にしてSSH接続ができます。

最初にTLSによる暗号化を有効にします。


TLSの有効化



以前の記事「Oracle Database 23ai FreeでTLSでの通信を有効化する」とほぼ同じ手順です。SID名などが異なるため、指定するパスが変わっています。

以前の記事を読み替えて作業すると間違えることもありそうなので、実施手順を再掲します。

最初にホスト・コンピュータから仮想マシンに、ユーザーoracleでSSH接続します。

orcl19c % ssh -p 10022 oracle@localhost

oracle@localhost's password: ********

Activate the web console with: systemctl enable --now cockpit.socket


Last login: Fri Aug 29 15:42:54 2025 from 10.0.2.2

[oracle@localhost ~]$ 


データベースが起動していなければ、起動します。

export NLS_LANG=American_America.AL32UTF8
. oraenv
lsnrctl start
sqlplus / as sysdba
startup
alter pluggable database orclpdb1 open read write;
show pdbs
exit

[oracle@localhost ~]$ export NLS_LANG=American_America.AL32UTF8

[oracle@localhost ~]$ . oraenv

ORACLE_SID = [ORCL] ? 

The Oracle base remains unchanged with value /opt/oracle

[oracle@localhost ~]$ lsnrctl start


LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-AUG-2025 15:59:02


Copyright (c) 1991, 2023, Oracle.  All rights reserved.


Starting /opt/oracle/product/19c/dbhome/bin/tnslsnr: please wait...


TNSLSNR for Linux: Version 19.0.0.0.0 - Production

System parameter file is /opt/oracle/product/19c/dbhome/network/admin/listener.ora

Log messages written to /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production

Start Date                29-AUG-2025 15:59:02

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /opt/oracle/product/19c/dbhome/network/admin/listener.ora

Listener Log File         /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

The listener supports no services

The command completed successfully

[oracle@localhost ~]$ sqlplus / as sysdba


SQL*Plus: Release 19.0.0.0.0 - Production on Fri Aug 29 15:59:07 2025

Version 19.19.0.0.0


Copyright (c) 1982, 2023, Oracle.  All rights reserved.


Connected to an idle instance.


SQL> startup

ORACLE instance started.


Total System Global Area 4664064424 bytes

Fixed Size     9173416 bytes

Variable Size   905969664 bytes

Database Buffers 3741319168 bytes

Redo Buffers     7602176 bytes

Database mounted.

Database opened.

SQL> alter pluggable database orclpdb1 open read write;


Pluggable database altered.


SQL> show pdbs


    CON_ID CON_NAME   OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

2 PDB$SEED   READ ONLY  NO

3 ORCLPDB1   READ WRITE NO

SQL> exit

Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0

[oracle@localhost ~]$ 


ルートCAの鍵を、ファイルrootCA.keyとして生成します。パスフレーズの入力を求められるので、適切な文字列を入力し記録しておきます。

openssl genrsa -aes256 -out rootCA.key 4096

[oracle@localhost ~]$ openssl genrsa -aes256 -out rootCA.key 4096

Generating RSA private key, 4096 bit long modulus (2 primes)

.............................................................................................................................................................................................................................................................................++++

..................++++

e is 65537 (0x010001)

Enter pass phrase for rootCA.key: ****

Verifying - Enter pass phrase for rootCA.key: ****

[oracle@localhost ~]$ 


自己署名によるルートCA証明書を作成します。証明書のサブジェクトはCN=My Root CAとしています。rootCA.keyを開くために、rootCA.keyを作成するときに設定したパスフレーズを入力します。

openssl req -x509 -new -key rootCA.key -sha256 -days 3650 -out rootCA.crt -subj "/CN=My Root CA"

[oracle@localhost ~]$ openssl req -x509 -new -key rootCA.key -sha256 -days 3650 -out rootCA.crt -subj "/CN=My Root CA"

Enter pass phrase for rootCA.key: ****

[oracle@localhost ~]$ 


以下の内容を記載したファイルをorcl19c.confとして作成します。CNおよびSANに指定するホスト名はorcl19cとしています。
[ req ]
default_bits       = 2048
prompt             = no
default_md         = sha256
distinguished_name = dn
req_extensions     = v3_req

[ dn ]
CN = orcl19c

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage         = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName   = @alt_names

[ alt_names ]
DNS.1 = orcl19c

サーバーの秘密鍵を、ファイルserver.keyとして作成します。

openssl genrsa -out server.key 2048

[oracle@localhost ~]$ openssl genrsa -out server.key 2048

Generating RSA private key, 2048 bit long modulus (2 primes)

.................................................+++++

.....................................................................................+++++

e is 65537 (0x010001)

[oracle@localhost ~]$ 


設定ファイルorcl19c.confを元に、CSR(Certificate Singing Request - 証明書署名要求)をファイルserver.csrとして作成します。

openssl req -new -key server.key -out server.csr -config orcl19c.conf

[oracle@localhost ~]$ openssl req -new -key server.key -out server.csr -config orcl19c.conf

[oracle@localhost ~]$ 


server.csrをルートCAで署名し、サーバー証明書sever.crtを作成します。

openssl x509 -req -in server.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt -days 397 -sha256 -extfile orcl19c.conf -extensions v3_req

[oracle@localhost ~]$ openssl x509 -req -in server.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt -days 397 -sha256 -extfile orcl19c.conf -extensions v3_req

Signature ok

subject=CN = orcl19c

Getting CA Private Key

Enter pass phrase for rootCA.key: ****

[oracle@localhost ~]$ 


作成されたサーバー証明書server.crtに、SANが記載されているか確認します。

openssl x509 -in server.crt -noout -text | grep -A2 "Subject Alternative Name"

[oracle@localhost ~]$ openssl x509 -in server.crt -noout -text | grep -A2 "Subject Alternative Name"

            X509v3 Subject Alternative Name: 

                DNS:orcl19c

    Signature Algorithm: sha256WithRSAEncryption

[oracle@localhost ~]$ 


ルートCAの証明書、サーバー証明書およびサーバー秘密鍵を、PKCS12形式のファイルserver.p12にまとめます。エクスポートしたファイルにパスワードを設定します。

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt -certfile rootCA.crt -name "orcl19c"

[oracle@localhost ~]$ openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt -certfile rootCA.crt -name "orcl19c"

Enter Export Password: ****

Verifying - Enter Export Password: ****


Oracle Walletを作成します。ウォレットの位置は/opt/oracle/admin/ORCL/walletとします。

orapki wallet create -wallet /opt/oracle/admin/ORCL/wallet -pwd <パスワード> -auto_login

[oracle@localhost ~]$ orapki wallet create -wallet /opt/oracle/admin/ORCL/wallet -pwd ********** -auto_login

Oracle PKI Tool Release 19.0.0.0.0 - Production

19.4.0.0.0: バージョン{1}

Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.


操作は正常に完了しました。

[oracle@localhost ~]$ 


ルートCA証明書rootCA.crtを、信頼済み証明書としてウォレットに追加します。

orapki wallet add -wallet /opt/oracle/admin/ORCL/wallet -trusted_cert -cert rootCA.crt -pwd ********

[oracle@localhost ~]$ orapki wallet add -wallet /opt/oracle/admin/ORCL/wallet -trusted_cert -cert rootCA.crt -pwd ********

Oracle PKI Tool Release 19.0.0.0.0 - Production

19.4.0.0.0: バージョン{1}

Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.


操作は正常に完了しました。

[oracle@localhost ~]$ 


サーバーの鍵と証明書を含むファイルserver.p12をウォレットに追加します。-pwdで指定するパスワードはOracle Walletのパスワードです。-pkcs12pwdで指定するパスワードは、PKCS12形式のファイルserver.p12の作成時に設定したパスワードです。

orapki wallet import_pkcs12 -wallet /opt/oracle/admin/ORCL/wallet -pwd <Oracle Walletのパスワード> -pkcs12file server.p12 -pkcs12pwd <server.p12のパスワード>

[oracle@localhost ~]$ orapki wallet import_pkcs12 -wallet /opt/oracle/admin/ORCL/wallet -pwd ******** -pkcs12file server.p12 -pkcs12pwd ********

Oracle PKI Tool Release 19.0.0.0.0 - Production

19.4.0.0.0: バージョン{1}

Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.


orapki command import_pkcs12 executed successfully.

[oracle@localhost ~]$ 


以上でOracle Walletは作成できました。作成したウォレットの内容を確認します。

orapki wallet display -wallet /opt/oracle/admin/ORCL/wallet -pwd <パスワード> -summary

User CertificatesとしてCN=orcl19cTrusted CertificatesとしてCN=My Root CAが見つかります。

[oracle@localhost ~]$ orapki wallet display -wallet /opt/oracle/admin/ORCL/wallet -pwd ******** -summary

Oracle PKI Tool Release 19.0.0.0.0 - Production

19.4.0.0.0: バージョン{1}

Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.


Requested Certificates: 

User Certificates:

Subject:        CN=orcl19c

Trusted Certificates: 

Subject:        CN=My Root CA

[oracle@localhost ~]$ 


ネットワーク設定を更新します。

cd $ORACLE_HOME/network/admin

[oracle@localhost ~]$ cd $ORACLE_HOME/network/admin

[oracle@localhost admin]$ 


listener.oraの内容を以下に変更します。
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCPS)(HOST = localhost)(PORT = 1522))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

SSL_CLIENT_AUTHENTICATION = FALSE
WALLET_LOCATION = 
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
        (DIRECTORY = /opt/oracle/admin/ORCL/wallet)
    )
  )
sqlnet.oraWALLET_LOCATIONを追記します。
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
        (DIRECTORY = /opt/oracle/admin/ORCL/wallet)
    )
  )
TNSリスナーを再起動します。

lsnrctl stop
lsnrctl start

[oracle@localhost admin]$ lsnrctl stop


LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-AUG-2025 16:25:11


Copyright (c) 1991, 2023, Oracle.  All rights reserved.


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

The command completed successfully

[oracle@localhost admin]$ lsnrctl start


LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-AUG-2025 16:25:14


Copyright (c) 1991, 2023, Oracle.  All rights reserved.


Starting /opt/oracle/product/19c/dbhome/bin/tnslsnr: please wait...


TNSLSNR for Linux: Version 19.0.0.0.0 - Production

System parameter file is /opt/oracle/product/19c/dbhome/network/admin/listener.ora

Log messages written to /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost)(PORT=1522)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production

Start Date                29-AUG-2025 16:25:14

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /opt/oracle/product/19c/dbhome/network/admin/listener.ora

Listener Log File         /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost)(PORT=1522)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

The listener supports no services

The command completed successfully

[oracle@localhost admin]$ 


TNSリスナーの再起動後にサービスを認識させます。

sqlplus / as sysdba
alter system register;
exit


[oracle@localhost admin]$ sqlplus / as sysdba


SQL*Plus: Release 19.0.0.0.0 - Production on Fri Aug 29 16:27:09 2025

Version 19.19.0.0.0


Copyright (c) 1982, 2023, Oracle.  All rights reserved.



Connected to:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0


SQL> alter system register;


System altered.


SQL> exit

Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0

[oracle@localhost admin]$ 


以上でサーバー側のTLS有効化は完了です。

接続確認はホスト・コンピュータより実施します。そのために必要な設定を行ないます。

Oracle Linuxではfirewalldがデフォルトで起動します。firewalldがポート1521と1522の接続を許可するように設定します。

sudo -s
firewall-cmd --add-port=1521/tcp
firewall-cmd --add-port=1522/tcp
firewall-cmd --runtime-to-permanent
firewall-cmd --list-all
exit

[oracle@localhost admin]$ sudo -s

[sudo] oracle のパスワード: ********

[root@localhost admin]# firewall-cmd --add-port=1521/tcp 

success

[root@localhost admin]# firewall-cmd --add-port=1522/tcp

success

[root@localhost admin]# firewall-cmd --runtime-to-permanent

success

[root@localhost admin]# firewall-cmd --list-all

public (active)

  target: default

  icmp-block-inversion: no

  interfaces: enp0s8

  sources: 

  services: cockpit dhcpv6-client ssh

  ports: 1521/tcp 1522/tcp

  protocols: 

  forward: no

  masquerade: no

  forward-ports: 

  source-ports: 

  icmp-blocks: 

  rich rules: 

[root@localhost admin]# exit

exit

[oracle@localhost admin]$ 


仮想マシンのネットワークを開きます。


モードをExpertに切り替え、ポートフォワーディングを開きます。


プラス(+)アイコンをクリックして設定行を増やし、以下の2行を設定します。

通常のSQL*Net通信を転送する設定を、名前SQLホストポートゲストポートともに1521として設定します。

TLSで暗号化したSQL*Net通信を転送する設定を、名前SQLTLSホストポートゲストポートともに1522として設定します。

OKをクリックします。


ネットワーク設定に戻るので、OKをクリックします。


以上で仮想マシンと、仮想マシンで実行されているオラクル・データベースの設定は完了です。

ホスト・コンピュータでの作業に移ります。

ネットワーク設定を保存するディレクトリとしてtns_adminを作成し移動します。

mkdir tns_admin
cd tns_admin
 

orcl19c % mkdir tns_admin

orcl19c % cd tns_admin 

tns_admin % 


仮想マシンからOracle Walletをホストにコピーします。sftpを使用します。

sftp -P 10022 oracle@localhost
cd /opt/oracle/admin/ORCL/wallet
get *
exit

tns_admin % sftp -P 10022 oracle@localhost

oracle@localhost's password: *********

Connected to localhost.

sftp> cd /opt/oracle/admin/ORCL/wallet

sftp> get *

Fetching /opt/oracle/admin/ORCL/wallet/cwallet.sso to cwallet.sso

cwallet.sso                                   100% 4053   640.8KB/s   00:00    

Fetching /opt/oracle/admin/ORCL/wallet/cwallet.sso.lck to cwallet.sso.lck

Fetching /opt/oracle/admin/ORCL/wallet/ewallet.p12 to ewallet.p12

ewallet.p12                                   100% 4008   759.6KB/s   00:00    

Fetching /opt/oracle/admin/ORCL/wallet/ewallet.p12.lck to ewallet.p12.lck

sftp> exit

tns_admin % 


sqlnet.oraを以下の内容で作成します。DIRECTORYには、先ほど作成したディレクトリtns_adminをフルパスで指定します。
SSL_CLIENT_AUTHENTICATION = FALSE
WALLET_LOCATION = 
  (SOURCE =
    (METHOD = FILE)
    (METHOD_DATA =
        (DIRECTORY = /Users/**********/Documents/orcl19c/tns_admin)
    )
  )
tnsnames.oraを作成し、TNS名としてORCLPDB1_TLSを設定します。
ORCLPDB1_TLS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCPS)(HOST = 0.0.0.0)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCLPDB1)
    )
    (SECURITY =
      (SSL_SERVER_DN_MATCH=TRUE)
      (SSL_SERVER_CERT_DN="CN=orcl19c")
    )
  )
SQLclで接続することを考慮し、ojdbc.propertiesを作成して以下を記述します。
oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=${TNS_ADMIN})))

ディレクトリtns_adminを環境変数TNS_ADMINに設定します。実際にTNS_ADMINに設定するディレクトリは環境ごとに異なります。

cd ..
export TNS_ADMIN=$HOME/Documents/orcl19c/tns_admin

tns_admin % cd ..

orcl19c % export TNS_ADMIN=$PWD/tns_admin 

orcl19c % 


SQLclで接続を確認します。

sql system@orclpdb1_tls
select sys_context('userenv','network_protocol') from dual;
exit

orcl19c % sql system@orclpdb1_tls



SQLcl: 金 8月 29 17:03:20 2025のリリース25.2 Production


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


パスワード (**********?) ******

Last Successful login time: 金 8月  29 2025 17:03:20 +09:00


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0


SQL> select sys_context('userenv','network_protocol') from dual;


SYS_CONTEXT('USERENV','NETWORK_PROTOCOL')    

____________________________________________ 

tcps                                         


SQL> exit

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0から切断されました

orcl19c % 


通信プロトコルとしてtcpsが使用されていることが確認できました。

以上でオンプレミスのOracle Database 19c Enterprise EditionのSQL*Net通信をTLSで暗号化することができました。


Entra IDによるユーザー認証



Entra IDのアプリケーションの作成手順は、記事「SQLclのMCPサーバーのデータベース接続をMicrosoft Entra IDのOAuth2で認証する」で紹介した手順とほぼ同じです。

1点だけ違いがあります。

アプリケーションIDのURIapi://...を設定していると、データベースのalert.logに以下のメッセージが出力され、ユーザー認証に失敗します。

ORCLPDB1(3):Token Auth: AZURE_AD application_id_uri check failed! application_id_uri in not beginning with https://


アプリケーションIDのURIhttps://で始まることが必須のようです。

Entra IDのコンソールより規定のディレクトリ | 概要を開き、プライマリ ドメインの値を確認します。


APIの公開で設定するアプリケーションID URIの値は、以下の形式で設定します。

https://[プライマリドメイン]/[アプリケーション(クライアント)ID]

スコープはアプリケーションID URIの末尾に/sessioin:scope:connectを付加します。

https://[プライマリドメイン]/[アプリケーション(クライアント)ID]/session:scope:connect


 アプリケーションIDのURIapi://アプリケーションIDの形式を指定しないため、マニフェストを編集してEntra ID v2アクセストークンに変更する作業は不要です


データベースの構成



アプリケーションID URIhttps://で始まるアプリケーションとしてORCL19Cを作成しました。

アプリケーションの概要のページより、アプリケーション(クライアント)ID,ディレクトリ(テナント)IDアプリケーションIDのURIの3つの値をコピーして保存します。


SYSユーザーでORCLPDB1に接続し、identity_provider_typeを確認します。

select name, value from v$parameter where name = 'identity_provider_type';

identity_provider_typeは、未設定であればNONEになります。

orcl19c % sql sys/******@localhost/orclpdb1 as sysdba



SQLcl: 金 8月 29 17:33:34 2025のリリース25.2 Production


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0


SQL> select name, value from v$parameter where name = 'identity_provider_type';


NAME                      VALUE    

_________________________ ________ 

identity_provider_type    NONE     


SQL> 


identity_provider_typeとしてAZURE_ADを設定します。

alter system set identity_provider_type=AZURE_AD scope=both;

SQL> alter system set identity_provider_type=AZURE_AD scope=both;


Systemが変更されました。


SQL> 


再度SELECT文を実行し、設定されたidentity_provider_typeを確認します。

select name, value from v$parameter where name = 'identity_provider_type';

SQL> select name, value from v$parameter where name = 'identity_provider_type';


NAME                      VALUE       

_________________________ ___________ 

identity_provider_type    AZURE_AD    


SQL> 


以下のコマンドのアプリケーションIDのURIディレクトリ(テナントID)アプリケーション(クライアント)IDを、作成したアプリケーション(今回の例ではORCL19C)の値で置き換えて実行します。
alter system set identity_provider_config = 
'{
   "application_id_uri": "アプリケーション ID の URI" ,
   "tenant_id": "ディレクトリ (テナント) ID",
   "app_id": "アプリケーション (クライアント) ID"
}' scope=both;

SQL> alter system set identity_provider_config =

  2  '{

  3     "application_id_uri": "https://__________.onmicrosoft.com/20f65749-****-****-****-1cfd84ff3e01",

  4     "tenant_id": "3940511e-****-****-****-01b080952758",

  5     "app_id": "20f65749-****-****-****-1cfd84ff3e01"

  6* }' scope=both;


Systemが変更されました。


SQL> 


Entra IDでユーザー認証するデータベース・ユーザーをMCPUSERとして作成します。

Oracle Database 23aiではEntra IDのアプリロールにユーザーを割り当てて認証させていましたが、Oracle Database 19cではalert.logに以下のエラーが書き込まれ、ユーザー認証に失敗します。

ORCLPDB1(3):Token Auth: AZURE_AD Get groups failed! Only shared mapping is supported, but roles array does not exist or its size is 0


どうも、アプリロールに割り当てて認証されるのはグループのみで、ユーザーには対応していないようです。今回の作業では無償利用できる範囲でEntra IDを使用しているため、アプリロールにグループを割り当てることはできません。

Entra IDでのユーザー認証が確認できればよいので、データベース・ユーザーMCPUSERは、AZURE_USERを指定してアクセス・トークンの属性upn(ユーザーの識別子)でマップするように変更しました。

create user mcpuser identified globally as 'AZURE_USER=Entra IDのユーザーのupn';
alter user mcpuser quota 25m on users;
grant create table, create view, create sequence, create synonym to mcpuser;
grant create session to mcpuser;

SQL> create user mcpuser identified globally as 'AZURE_USER=yuji______.com_EXT_@________.onmicrosoft.com';


User MCPUSERは作成されました。


SQL> alter user mcpuser quota 25m on users;


User MCPUSERが変更されました。


SQL> grant create table, create view, create sequence, create synonym to mcpuser;


Grantが正常に実行されました。


SQL> grant create session to mcpuser;


Grantが正常に実行されました。


SQL> 


データベース・ユーザーMCPUSERがネットワーク接続できるように、ACLを追加します。
begin
    dbms_network_acl_admin.append_host_ace(
        host => '*',
        ace => xs$ace_type(
            privilege_list => xs$name_list('connect'),
            principal_name => 'MCPUSER',
            principal_type => xs_acl.ptype_db
        )
    );
end;
/

SQL> begin

  2      dbms_network_acl_admin.append_host_ace(

  3          host => '*',

  4          ace => xs$ace_type(

  5              privilege_list => xs$name_list('connect'),

  6              principal_name => 'MCPUSER',

  7              principal_type => xs_acl.ptype_db

  8          )

  9      );

 10  end;

 11* /


PL/SQLプロシージャが正常に完了しました。


SQL> exit

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0から切断されました

orcl19c % 


以上でデータベース・サーバーの設定は完了です。


TOKEN_AUTH=AZURE_DEVICE_CODEでの接続



ホスト・コンピュータからSQLclで接続する際に、TOKEN_AUTH=AZURE_DEVICE_CODEで接続できるようにします。設定手順は記事「SQLclのMCPサーバーのデータベース接続にTOKEN_AUTH=AZURE_INTERACTIVEの設定を使用する」で紹介しています。

Entra IDにクライアントとなるアプリケーションとしてORCL19C-CLIを作成します。その後に、SQLclにsdkとしてjdbc-azureをインストールします。

Entra IDのアプリケーションORCL19C-CLI概要を開き、アプリケーション(クライアント)IDの値をコピーします。この値をCLIENT_IDとして設定します。次にディレクトリ(テナント)IDの値をコピーします。この値をTENANT_IDとして設定します。


アプリケーションIDのURIはアプリケーションORCL19Cの値を参照します。この値はAZURE_DB_APP_ID_URIとして設定します。

tns_admin/tnsnames.oraTOKEN_AUTHTENANT_IDCLIENT_IDAZURE_DB_APP_ID_URIの指定を加えた、以下のようなエントリORCLPDB1_TLS_CODEを追加します。
ORCLPDB1_TLS_CODE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCPS)(HOST = 0.0.0.0)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCLPDB1)
    )
    (SECURITY =
      (SSL_SERVER_DN_MATCH=TRUE)
      (SSL_SERVER_CERT_DN="CN=orcl19c")
      (TOKEN_AUTH=AZURE_DEVICE_CODE)
      (TENANT_ID=3940511e-****-****-****-01b080952758)
      (CLIENT_ID=763f0b0e-****-****-****-8d506d4ba989)
      (AZURE_DB_APP_ID_URI=https://_____________.onmicrosoft.com/20f65749-****-****-****-1cfd84ff3e01)
    )
  )
追加したTNS名ORCLPDB1_TLS_CODEを使って、データベースORCLPDB1に接続します。

sql /@orclpdb1_tls_code

orcl19c % sql /@orclpdb1_tls_code   



SQLcl: 金 8月 29 18:16:41 2025のリリース25.2 Production


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code NEVQFUJBH to authenticate.



ブラウザでhttps://microsoft.com/deviceloginを開き、表示されているコードを入力します。

次へ進みます。


Entra IDに登録されたユーザーでサインインします。以下のスクリーンショットは、すでにサインインしているため、サインイン済みのユーザーを選択しています。


アプリケーションORCL19C-CLIにサインインします。

続行をクリックします。


アプリケーションORCL19C-CLIにサインインできました。


SCLclでは、データベースへの接続が完了しています。

orcl19c % sql /@orclpdb1_tls_code   



SQLcl: 金 8月 29 18:16:41 2025のリリース25.2 Production


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code NEVQFUJBH to authenticate.

接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0


SQL> 


以下のSELECT文を実行し、接続ユーザーを確認します。
select
    sys_context('userenv','session_user') as session_user,
    sys_context('userenv','current_user') as current_user,
    sys_context('userenv','authentication_method') as method,
    sys_context('userenv','authenticated_identity') as azure_user
from dual;

SQL> select

  2      sys_context('userenv','session_user') as session_user,

  3      sys_context('userenv','current_user') as current_user,

  4      sys_context('userenv','authentication_method') as method,

  5      sys_context('userenv','authenticated_identity') as azure_user

  6* from dual;


SESSION_USER    CURRENT_USER    METHOD          AZURE_USER                                                    

_______________ _______________ _______________ _____________________________________________________________ 

MCPUSER         MCPUSER         TOKEN_GLOBAL    _____________.com_EXT_@_______________.onmicrosoft.com    


SQL> exit

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.19.0.0.0から切断されました

orcl19c % 


システム・コンテキストUSERENVAUTHENTICATED_IDENTITYに、Entra IDでのupnの値が設定されていることが確認できます。

以上で、TOKEN_AUTH=AZURE_DEVICE_CODEでの認証を確認できました。


まとめ



オンプレミスにインストールしたOracle Database 19c Enterprise Editionでも、Entra IDによるユーザー認証ができることが確認できました。

今回の記事は以上になります。