」と全く同じ保護を適用しますが、対象のデータベースはAutonomous AI Databaseの26aiではなく、手元の仮想マシンで実行しているOracle Database 19c EEです。そのため、セクション「
以下よりオンプレミスのOracle Database 19c EEを対象として、Real Application Securityを構成する手順を確認します。確認する手順は、RASの管理ユーザーRASADMINを作成するまでになります。
Oracle Database 19c EEはVirtualBoxの仮想マシンで動作しています。ネットワークのポートフォワーディングを構成することにより、ホスト・マシンからポート1521および1522を宛先としてSQL*Net接続できるようにしています。SIDはORCL、PDBとしてORCLPDB1が作成されています。
最初に、Real Application Securityの確認に使用するHRスキーマをインストールします。サンプル・データセットをダウンロードしたのち、解凍します。
@hr_install
tlsdb % cd db-sample-schemas-23.3/human_resources
human_resources % sql sys@localhost/orclpdb1 as sysdba
SQLcl: 火 2月 17 15:50:20 2026のリリース25.4 Production
Copyright (c) 1982, 2026, Oracle. All rights reserved.
パスワード (**********?) ******
接続先:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0
SQL> @hr_install
Thank you for installing the Oracle Human Resources Sample Schema.
This installation script will automatically exit your database session
at the end of the installation or if any error is encountered.
The entire installation will be logged into the 'hr_install.log' log file.
Enter a password for the user HR: ******
USERS
Enter a tablespace for HR [USERS]:
Do you want to overwrite the schema, if it already exists? [YES|no]:
Old HR schema has been dropped.
****** Creating REGIONS table ....
Table REGIONSは作成されました。
[中略]
コミットが完了しました。
Installation verification
____________________________
Verification:
Table provided actual
______________ ___________ _________
regions 5 5
countries 25 25
departments 27 27
locations 23 23
employees 107 107
jobs 19 19
job_history 10 10
Thank you!
___________________________________________________________
The installation of the sample schema is now finished.
Please check the installation verification output above.
You will now be disconnected from the database.
Thank you for using Oracle Database!
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0から切断されました
human_resources %
データベース・ユーザー
RASADMINを作成し、最低限必要な権限を与えます。作業はユーザーSYSで実施します。
create user rasadmin identified by [パスワード];
grant create session to rasadmin;
tlsdb % sql sys@localhost/orclpdb1 as sysdba
SQLcl: 火 2月 17 15:53:23 2026のリリース25.4 Production
Copyright (c) 1982, 2026, Oracle. All rights reserved.
パスワード (**********?) ******
接続先:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0
SQL> create user rasadmin identified by *********;
User RASADMINは作成されました。
SQL> grant create session to rasadmin;
Grantが正常に実行されました。
SQL>
ユーザーRASADMINに、Real Application Securityを構成するために必要な権限を与えます。パッケージXS_ADMIN_CLOUD_UTILの代わりにXS_ADMIN_UTILを呼び出します。
begin
sys.xs_admin_util.grant_system_privilege('PROVISION','RASADMIN');
sys.xs_admin_util.grant_system_privilege('ADMIN_ANY_SEC_POLICY','RASADMIN');
end;
/
SQL> begin
2 sys.xs_admin_util.grant_system_privilege('PROVISION','RASADMIN');
3 sys.xs_admin_util.grant_system_privilege('ADMIN_ANY_SEC_POLICY','RASADMIN');
4 end;
5* /
PL/SQLプロシージャが正常に完了しました。
SQL>
ロール
HR_ROLEを作成し、ユーザー
RASADMINに割り当てます。ロール
HR_ROLEは後ほど、ユーザー
RASADMINが作成したアプリケーション・ロール
EMPLOYEEに割り当てます。
create role hr_role;
grant select on hr.departments to hr_role;
grant select on hr.employees to hr_role;
grant select on hr.jobs to hr_role;
grant select on hr.job_history to hr_role;
grant select on hr.locations to hr_role;
grant select on hr.regions to hr_role;
grant select on hr.countries to hr_role;
grant select on hr.emp_details_view to hr_role;
grant hr_role to rasadmin with admin option;
SQL> create role hr_role;
Role HR_ROLEは作成されました。
SQL> grant select on hr.departments to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.employees to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.jobs to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.job_history to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.locations to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.regions to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.countries to hr_role;
Grantが正常に実行されました。
SQL> grant select on hr.emp_details_view to hr_role;
Grantが正常に実行されました。
SQL> grant hr_role to rasadmin with admin option;
Grantが正常に実行されました。
SQL>
MCPサーバーの接続ユーザーMCPUSERに、RASセッションを操作する権限を与えます。呼び出すパッケージはXS_ADMIN_UTILになります。
begin
sys.xs_admin_util.grant_system_privilege('ADMINISTER_SESSION','MCPUSER');
end;
/
SQL> begin
2 sys.xs_admin_util.grant_system_privilege('ADMINISTER_SESSION','MCPUSER');
3 end;
4* /
PL/SQLプロシージャが正常に完了しました。
SQL>
Autonomous DatabaseでRASを構成したときは、ユーザーMCPUSERにスキーマHR以下のオブジェクトを検索する権限を与えていました。
grant select any table on schema hr to mcpuser;
今回はこの権限は与えません。ロール
HR_ROLEはRASの動的ロール
EMPLOYEEとしてRASユーザーに割り当てられるため、必ずしもユーザー
MCPUSERが同じ権限を持つ必要はありません。
ユーザーMCPUSERがスキーマHRのオブジェクトを検索する権限を持たない場合、RASポリシーが適用される前は、スキーマHRのオブジェクト自体が見えません。そのため、表HR.EMPLOYEESを検索すると「ORA-00942: 表またはビューが存在しません。」が発生します。検索する権限がある場合は「行が選択されていません」が返されます。
以上でRASの管理ユーザーRASADMINが作成できました。
動作確認
SQLclのMCPサーバーからOracle Database 19c EEのデータベースに接続し、Real Application Securityによる保護を確認します。
MCPサーバーからのデータベース接続をEntra IDで認証するには、TOKEN_AUTHにAZURE_DEVICE_CODEは使用できません。OAUTHかAZURE_INTERACTIVEのどちらかを設定することになりますが、AZURE_INTERACTIVEでユーザー認証するにはURLの書き換えが必要なため、今回はTOKEN_AUTH=OAUTHで接続することにします。
tnsnames.oraにTNS名として、以下のORCLPDB1_TLS_OAUTHを追記します。TOKEN_LOCATIONは、コマンドaz account get-access-tokenを実行して取り出すアクセス・トークンの保存先となるファイルを指定します。
ORCLPDB1_TLS_OAUTH =
(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=OAUTH)
(TOKEN_LOCATION=/Users/________/Documents/tlsdb/token.txt)
)
)
azure-cli(azコマンド)を実行して、データベースへの認証に使用するアクセス・トークンを取得します。
Entra IDにサインインします。
az login --tenant "テナントID" --scope "アプリケーションIDのURI/session:scope:connect"
ブラウザのサインイン画面が開きます。以下はすでにサインイン済みだったので、アカウントの選択のみを求められています。サインインするユーザーを選択します。
サインインが完了します。
コマンドaz loginを実行したターミナルでは、サブスクリプションの選択を求められます。サブスクリプションは1つしかないので、デフォルトのサブスクリプションを選択しました。
以上で、Entra IDにサインインできました。
tlsdb % az login --tenant "********-****-****-****-************" --scope "https://_________outlook.onmicrosoft.com/********-****-****-****-************/session:scope:connect"
A web browser has been opened at https://login.microsoftonline.com/********-****-****-****-************/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
Retrieving subscriptions for the selection...
[Tenant and subscription selection]
No Subscription name Subscription ID Tenant
----- -------------------- ------------------------------------ ------------------------------------
[1] * Azure subscription 1 ********-****-****-****-************ ********-****-****-****-************
The default is marked with an *; the default tenant is '********-****-****-****-************' and subscription is 'Azure subscription 1' (********-****-****-****-************).
Select a subscription and tenant (Type a number or Enter for no changes):
Tenant: ********-****-****-****-************
Subscription: Azure subscription 1 (********-****-****-****-************)
[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236
If you encounter any problem, please open an issue at https://aka.ms/azclibug
[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.
tlsdb %
アクセス・トークンを取得します。token.txtの出力先は、ORCLPDB1_TLS_OAUTHのTOKEN_LOCATIONとして指定した位置です。
az account get-access-token --scope "アプリケーションIDのURI/session:scope:connect" --query accessToken -o tsv > token.txttlsdb % az account get-access-token --scope "https://________outlook.onmicrosoft.com/********-****-****-****-************/session:scope:connect" --query accessToken -o tsv > token.txt
tlsdb %
最初にSQLclからORCLPDB1_TLS_OAUTHに接続し、MCPサーバーから利用できるように接続を保存します。
sql -home $TNS_ADMIN /nolog
conn -save orclpdb1_tls_oauth -savepwd /@orclpdb1_tls_oauth
select sys_context('userenv','authentication_method') from dual;
exit
AUTHENTICATION_METHODがTOKEN_GLOBALであることを確認します。
tlsdb % sql -home $TNS_ADMIN /nolog
SQLcl: 火 2月 17 16:05:44 2026のリリース25.4 Production
Copyright (c) 1982, 2026, Oracle. All rights reserved.
SQL> conn -save orclpdb1_tls_oauth -savepwd /@orclpdb1_tls_oauth
名前: orclpdb1_tls_oauth
接続文字列: orclpdb1_tls_oauth
ユーザー:
パスワード: 未保存
接続しました.
SQL> select sys_context('userenv','authentication_method') from dual;
SYS_CONTEXT('USERENV','AUTHENTICATION_METHOD')
_________________________________________________
TOKEN_GLOBAL
SQL> exit
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0から切断されました
tlsdb %
SQLclのMCPサーバーの動作確認に、MCP Inspectorを使用します。
MCP Inspectorを起動します。
npx -y @modelcontextprotocol/inspector
ブラウザにMCP Inspectorの画面が開きます。
tlsdb % npx -y @modelcontextprotocol/inspector
Starting MCP inspector...
⚙️ Proxy server listening on localhost:6277
🔑 Session token: 64ab1208c1766378438b53f8f5f00ca7bdb55bb6cbb57dd917c68bdfc164902d
Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
🚀 MCP Inspector is up and running at:
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=64ab1208c1766378438b53f8f5f00ca7bdb55bb6cbb57dd917c68bdfc164902d
🌐 Opening browser...
MCP Inspectorの画面で以下の設定を行ないます。
Transport TypeにSTDIOを選択し、CommandにSQLcl(コマンドとしてはsql)をフルパスで指定します。Arugmentsとして-homeに接続を保存しているディレクトリ、それに加えて-mcpオプションを設定します。
次にAdd Environment Variableをクリックし、追加されたEnvironment VariableとしてTNS_ADMINとそのディレクトリを設定します。
以上の設定を実施し、ボタンConnectをクリックしてSQLclのMCPサーバーを起動します。
MCPサーバーの起動を確認し、Toolsタブを開きます。List Toolsをクリックし、呼び出すことができるツールを取得します。
Toolsよりlist-connectionsを選択し、Run Toolをクリックします。Tool Resultに先ほど作成した接続orclpdb1_tls_oauthが含まれていることを確認します。
Toolsよりconnectを選択します。connection_nameにorclpdb1_tls_oauthを記述し、Run Toolsをクリックします。
Tool ResultにSuccessが返され、データベースに接続できたことを確認します。
Toolsよりrun-sqlを選択します。sqlに以下をを記述し、Run Toolsをクリックします。
select * from hr.employees
まだRASのポリシーが有効化されていず、また、データベース・ユーザーMCPUSERにスキーマHRの持つ表の参照権限を与えていないため、ORA-00942が発生します。
RASポリシーを有効化します。
Toolsよりrun-sqlclを選択します。sqlclに以下をを記述し、Run Toolsをクリックします。
exec emp_dept_ctx_pkg.init;
Tool ResultとしてSuccessが返され、プロシージャが実行されたことを確認します。
Toolsよりrun-sqlを選択します。sqlに以下をを記述し、Run Toolsをクリックします。
select employee_id, first_name, last_name, email, salary, commission_pct, manager_id, department_id from hr.employees;
RASポリシーが適用されて、DEPARTMENT_IDが60の行のみ(Entra IDで認証されたユーザーと同じ部署に所属している従業員)が返されていることを確認します。
以上でオンプレミスのOracle Database 19c EEについても、Entra IDによるユーザー認証およびReal Application Securityによる保護が適用ができることを確認しました。
Toolsよりdisconnectを選択し、Run Toolsをクリックします。データベースから切断されます。
Disconnectをクリックします。MCPサーバーとして起動しているSQLclが終了します。
今回の記事は以上になります。