【翻译自mos文章】怎么允许特定版本的client 登陆到database中

本文介绍如何通过配置Oracle数据库的sqlnet.ora文件中的SQLNET.ALLOWED_LOGON_VERSION参数来控制允许登录数据库的客户端版本。这有助于限制对数据库的访问并确保安全性。

怎么允许特定版本的client 登陆到database中

来源于:
How to Allow Login to Database Based on the Client Version (文档 ID 402193.1)

适用于:
Oracle Net Services - Version 10.1.0.2 to 12.1.0.2 [Release 10.1 to 12.1]
Information in this document applies to any platform.

目标:
本文的目的是怎么定义一个能连接到database中的最小版本的oracle client。通过指定允许的最小版本,可以限制数据库的访问。
如果一个client不满足或者超过了版本指定,client连接会被拒绝,报错为ora-28040

解决方案:

在sqlnet.ora文件中使用SQLNET.ALLOWED_LOGON_VERSION参数来只指定哪个身份验证协议被client 或者database 允许。
该参数定义了能连接到database中的最小版本的oracle client。该参数从Oracle database 10g中被引入,并取代了init.ora中的参数DB_ALLOWED_LOGON_VERSION

语法:
SQLNET.ALLOWED_LOGON_VERSION = n
默认值为8

允许的值如下:
11 ---对database 11g和database 10g。注意11g和10g 共享了同样的身份验证协议。因此11g的设置允许从10g client登陆
10 --- database 11g和database 10g身份验证协议
9  ---Oracle 9i和更新的身份验证协议
8  ---Oracle 8i和更新的身份验证协议

例子1:
在server端的sqlnet.ora文件中有如下:
SQLNET.ALLOWED_LOGON_VERSION = 9
Version 9 和更新的版本被运行登陆到database中,也就是说:以上参数允许9i、10g、11版本去连接db。8i的client连接db时会报:'ORA-28040: No matching authentication protocol'

 

例子2:
在server端的sqlnet.ora文件中有如下:
SQLNET.ALLOWED_LOGON_VERSION = 10
上面的参数允许10g 和11g client 连接数据库,oracle 9i和8i 访问数据库时遇到ORA-28040

请注意:当你设置该参数为11时,应该特别考虑,如下来自文档:

Oracle Database Net Services Reference 
11g Release 1 (11.1) 

The following excerpt is taken from this reference: 

"Note the following implications of setting the value to 11: 
To take advantage of the password protections introduced in Oracle Database 11g, 
users must change their passwords so that old password verifiers are purged from the system. 
Releases of OCI clients before Oracle Database 10g and all versions of JDBC thin clients 
cannot authenticate to the Oracle database using password-based authentication."

请注意:该参数在oracle database 12c中已经有所改变

The SQLNET.ALLOWED_LOGON_VERSION parameter is deprecated in Oracle Database 12c. 
This parameter has been replaced with two new Oracle Net Services parameters: 

SQLNET.ALLOWED_LOGON_VERSION_SERVER 
SQLNET.ALLOWED_LOGON_VERSION_CLIENT 

See Oracle Database Net Services Reference for information

 

Request URI: /dbs, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0);, full error: {'ok': 0.0, 'errmsg': 'Error=13, Details=\'Response status code does not indicate success: Forbidden (403); Substatus: 0; ActivityId: 8139f2d1-8bbe-46e3-9a84-71d66f0bcc3b; Reason: ({"code":"Forbidden","message":"\\"Operation \'POST\' on resource \'dbs\' is not allowed through Azure Cosmos DB endpoint. Please switch on such operations for your account, or perform this operation through Azure Resource Manager, Azure Portal, Azure CLI or Azure Powershell\\"\\r\\nActivityId: 8139f2d1-8bbe-46e3-9a84-71d66f0bcc3b, Microsoft.Azure.Documents.Common/2.14.0"}\r\nRequestUri: https://tsc-01-cosmos-mango-cnn3-prod-chinanorth3.documents.azure.cn/dbs;\r\nRequestMethod: POST;\r\nHeader: Authorization Length: 82;\r\nHeader: x-ms-date Length: 29;\r\nHeader: x-ms-cosmos-sdk-supportedcapabilities Length: 1;\r\nHeader: x-ms-activity-id Length: 36;\r\nHeader: Cache-Control Length: 8;\r\nHeader: User-Agent Length: 147;\r\nHeader: x-ms-cosmos-apitype Length: 7;\r\nHeader: x-ms-version Length: 10;\r\nHeader: Accept Length: 16;\r\nHeader: x-ms-gateway-signature Length: 92;\r\nHeader: x-ms-cosmos-compute-hop-count Length: 1;\r\nHeader: x-ms-gateway-use-mtls Length: 1;\r\nHeader: traceparent Length: 55;\r\n, Request URI: /dbs, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0);', 'code': 13, 'codeName': 'Unauthorized'}
06-24
### Azure Cosmos DB 403 Forbidden 错误分析与解决方案 在使用 Azure Cosmos DB 时,如果遇到 `403 Forbidden` 错误,通常表示客户端尝试执行的操作被服务器拒绝。这种错误可能由多种原因引起,包括权限不足、密钥过期或不正确、资源限制等。以下是可能导致此问题的常见原因及解决方案: #### 1. 权限不足 Azure Cosmos DB 的操作需要特定的权限才能执行。如果客户端使用的身份或密钥没有足够的权限来执行 POST 操作,则会返回 403 错误。确保为执行操作的身份分配了正确的角色或权限[^1]。 - **检查点**:确认用于连接 Azure Cosmos DB 的主密钥或资源令牌是否具有足够的权限。 - **解决方法**:为执行操作的用户分配适当的 RBAC 角色(如 `Cosmos DB Account Contributor` 或 `Cosmos DB Data Contributor`)。 #### 2. 密钥过期或不正确 如果使用的主密钥或资源令牌已过期或配置错误,也会导致 403 错误。建议定期轮换密钥以确保安全性,并验证当前使用的密钥是否有效。 - **检查点**:验证连接字符串和密钥是否正确无误。 - **解决方法**:重新生成并更新主密钥或资源令牌[^1]。 ```python from azure.cosmos import CosmosClient, PartitionKey # 替换为实际的连接字符串和密钥 url = "https://<your-cosmosdb-account>.documents.azure.com:443/" key = "<your-primary-key>" client = CosmosClient(url, credential=key) database_name = "SampleDatabase" container_name = "SampleContainer" try: database = client.get_database_client(database_name) container = database.get_container_client(container_name) # 示例操作 item = {"id": "1", "name": "Test Item"} container.upsert_item(body=item) except Exception as e: print(f"Error occurred: {e}") ``` #### 3. 配额或资源限制 Azure Cosmos DB 对每个账户、数据库或容器都有配额限制。如果超出这些限制(例如 RU/s),POST 操作可能会被拒绝。 - **检查点**:查看 Azure 门户中的配额和使用情况,确认是否有任何限制被触发。 - **解决方法**:增加吞吐量(RU/s)或调整分区键设计以优化资源使用。 #### 4. 请求头或签名问题 Azure Cosmos DB 要求所有请求都包含正确的授权签名。如果签名无效或请求头配置错误,服务器将拒绝请求。 - **检查点**:确保请求头中包含正确的 `x-ms-date` 和 `Authorization` 字段。 - **解决方法**:使用 Azure SDK 或手动生成符合规范的签名。 #### 5. IP 白名单限制 如果启用了防火墙规则或 IP 白名单,只有来自特定 IP 地址的请求才会被允许。如果客户端的 IP 地址未列入白名单,则会收到 403 错误。 - **检查点**:确认客户端的 IP 地址是否在 Azure Cosmos DB 的防火墙规则中。 - **解决方法**:将客户端的 IP 地址添加到白名单中[^1]。 --- ### 示例代码:检查和处理 403 错误 以下是一个简单的 Python 示例,展示如何捕获并处理 403 错误: ```python from azure.cosmos import CosmosClient, exceptions url = "https://<your-cosmosdb-account>.documents.azure.com:443/" key = "<your-primary-key>" client = CosmosClient(url, credential=key) database_name = "SampleDatabase" container_name = "SampleContainer" try: database = client.get_database_client(database_name) container = database.get_container_client(container_name) # 尝试插入数据 item = {"id": "1", "name": "Test Item"} container.upsert_item(body=item) except exceptions.CosmosHttpResponseError as e: if e.status_code == 403: print("Forbidden error occurred. Check permissions, key, or firewall settings.") else: print(f"An error occurred: {e}") ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值