收集 Oracle Cloud Infrastructure 审核日志

支持的平台:

本文档介绍了如何使用 Google Cloud Storage 将 Oracle Cloud Infrastructure 审核日志注入到 Google Security Operations。

Oracle Cloud Infrastructure Audit 服务会自动将对所有受支持的 Oracle Cloud Infrastructure 公共应用编程接口 (API) 端点的调用记录为日志事件。目前,所有服务都支持通过 Oracle Cloud Infrastructure Audit 进行日志记录。Oracle Cloud Infrastructure Audit 记录的日志事件包括 Oracle Cloud Infrastructure 控制台、命令行界面 (CLI)、软件开发套件 (SDK)、您自己的自定义客户端或其他 Oracle Cloud Infrastructure 服务发出的 API 调用。

准备工作

确保您满足以下前提条件:

  • Google SecOps 实例
  • 已启用 Cloud Storage API 的 GCP 项目
  • 创建和管理 GCS 存储分区的权限
  • 管理 GCS 存储分区的 IAM 政策的权限
  • 创建 Cloud Run 服务、Pub/Sub 主题和 Cloud Scheduler 作业的权限
  • 具有以下权限的 Oracle Cloud Infrastructure 账号:
    • Service Connector Hub
    • 函数
    • 对象存储分区
    • IAM 政策
  • 对 Oracle Cloud Infrastructure 控制台的特权访问权限

创建 Google Cloud Storage 存储桶

  1. 前往 Google Cloud 控制台
  2. 选择您的项目或创建新项目。
  3. 在导航菜单中,依次前往 Cloud Storage > 存储分区
  4. 点击创建存储分区
  5. 提供以下配置详细信息:

    设置
    为存储桶命名 输入一个全局唯一的名称(例如 oci-audit-logs-gcs
    位置类型 根据您的需求进行选择(区域级、双区域、多区域)
    位置 选择营业地点(例如 us-central1
    存储类别 标准(建议用于经常访问的日志)
    访问权限控制 均匀(推荐)
    保护工具 可选:启用对象版本控制或保留政策
  6. 点击创建

配置 Oracle Cloud Infrastructure 以将审核日志导出到 GCS

Oracle Cloud Infrastructure 不支持将数据原生导出到 Google Cloud Storage。您将使用 Oracle Cloud Infrastructure Service Connector Hub 和函数将审核日志转发到 GCS。

创建 Oracle Cloud Infrastructure 函数以将日志转发到 GCS

  1. 登录 Oracle Cloud 控制台
  2. 依次前往开发者服务 > 函数 > 应用
  3. 选择要在哪个功能应用所在的隔间中创建功能应用。
  4. 点击创建应用
  5. 提供以下配置详细信息:
    • 名称:输入 audit-logs-to-gcs-app
    • VCN:选择一个虚拟 Cloud 网络。
    • 子网:选择可访问互联网的子网。
  6. 点击创建
  7. 创建应用后,点击开始使用,然后按照说明使用 Fn CLI 设置本地开发环境。
  8. 在本地机器上创建一个新的函数目录:

    mkdir oci-audit-to-gcs
    cd oci-audit-to-gcs
    
  9. 初始化 Python 函数:

    fn init --runtime python oci-audit-to-gcs
    cd oci-audit-to-gcs
    
  10. func.py 的内容替换为以下代码:

    import io
    import json
    import logging
    import os
    from fdk import response
    from google.cloud import storage
    from google.oauth2 import service_account
    from datetime import datetime
    
    # Configure logging
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger()
    
    # Environment variables
    GCS_BUCKET = os.environ.get('GCS_BUCKET')
    GCS_PREFIX = os.environ.get('GCS_PREFIX', 'oci-audit-logs')
    GCS_CREDENTIALS_JSON = os.environ.get('GCS_CREDENTIALS_JSON')
    
    def handler(ctx, data: io.BytesIO = None):
        """
        Oracle Cloud Infrastructure Function to forward Audit logs to GCS.
    
        Args:
            ctx: Function context
            data: Input data containing Audit log events
        """
    
        if not all([GCS_BUCKET, GCS_CREDENTIALS_JSON]):
            logger.error('Missing required environment variables: GCS_BUCKET or GCS_CREDENTIALS_JSON')
            return response.Response(
                ctx, response_data=json.dumps({"error": "Missing configuration"}),
                headers={"Content-Type": "application/json"}
            )
    
        try:
            # Parse input data
            body = json.loads(data.getvalue())
            logger.info(f"Received event: {json.dumps(body)}")
    
            # Extract log entries
            log_entries = []
            if isinstance(body, list):
                log_entries = body
            elif isinstance(body, dict):
                # Service Connector Hub sends data in specific format
                if 'data' in body:
                    log_entries = [body['data']] if isinstance(body['data'], dict) else body['data']
                else:
                    log_entries = [body]
    
            if not log_entries:
                logger.info("No log entries to process")
                return response.Response(
                    ctx, response_data=json.dumps({"status": "no_logs"}),
                    headers={"Content-Type": "application/json"}
                )
    
            # Initialize GCS client with service account credentials
            credentials_dict = json.loads(GCS_CREDENTIALS_JSON)
            credentials = service_account.Credentials.from_service_account_info(credentials_dict)
            storage_client = storage.Client(credentials=credentials, project=credentials_dict.get('project_id'))
            bucket = storage_client.bucket(GCS_BUCKET)
    
            # Write logs to GCS as NDJSON
            timestamp = datetime.utcnow().strftime('%Y%m%d_%H%M%S_%f')
            object_key = f"{GCS_PREFIX}/logs_{timestamp}.ndjson"
            blob = bucket.blob(object_key)
    
            ndjson = '\n'.join([json.dumps(entry, ensure_ascii=False) for entry in log_entries]) + '\n'
            blob.upload_from_string(ndjson, content_type='application/x-ndjson')
    
            logger.info(f"Wrote {len(log_entries)} records to gs://{GCS_BUCKET}/{object_key}")
    
            return response.Response(
                ctx, response_data=json.dumps({"status": "success", "records": len(log_entries)}),
                headers={"Content-Type": "application/json"}
            )
    
        except Exception as e:
            logger.error(f'Error processing logs: {str(e)}')
            return response.Response(
                ctx, response_data=json.dumps({"error": str(e)}),
                headers={"Content-Type": "application/json"},
                status_code=500
            )
    
  11. 使用以下依赖项更新 requirements.txt

    fdk>=0.1.0
    google-cloud-storage>=2.0.0
    google-auth>=2.0.0
    
  12. 将函数部署到 Oracle Cloud Infrastructure:

    fn -v deploy --app audit-logs-to-gcs-app
    
  13. 部署完成后,记下函数 OCID。您将在下一步骤中用到它。

配置函数环境变量

  1. 在 Oracle Cloud 控制台中,依次前往开发者服务 > 函数 > 应用
  2. 点击相应应用 (audit-logs-to-gcs-app)。
  3. 点击函数名称 (oci-audit-to-gcs)。
  4. 点击配置
  5. 添加以下配置变量:

    GCS_BUCKET 您的 GCS 存储桶名称(例如 oci-audit-logs-gcs
    GCS_PREFIX 日志文件的前缀(例如,oci-audit-logs
    GCS_CREDENTIALS_JSON GCP 服务账号密钥的 JSON 字符串(见下文)
  6. 点击保存更改

为 Oracle Cloud Infrastructure 函数创建 GCP 服务账号

Oracle Cloud Infrastructure 函数需要一个 GCP 服务账号才能写入 GCS 存储桶。

  1. GCP 控制台中,依次前往 IAM 和管理 > 服务账号
  2. 点击创建服务账号
  3. 提供以下配置详细信息:
    • 服务账号名称:输入 oci-function-gcs-writer
    • 服务账号说明:输入 Service account for OCI Function to write Audit logs to GCS
  4. 点击创建并继续
  5. 向此服务账号授予对项目的访问权限部分中,添加以下角色:
    1. 点击选择角色
    2. 搜索并选择 Storage Object Admin
  6. 点击继续
  7. 点击完成
  8. 点击新创建的服务账号电子邮件地址。
  9. 前往密钥标签页。
  10. 点击添加密钥 > 创建新密钥
  11. 选择 JSON 作为密钥类型。
  12. 点击创建
  13. JSON 密钥文件将下载到您的计算机。
  14. 打开 JSON 密钥文件并复制其全部内容。
  15. 返回 Oracle Cloud 控制台函数配置。
  16. 将 JSON 内容粘贴到 GCS_CREDENTIALS_JSON 配置变量中。

授予对 GCS 存储桶的 IAM 权限

向服务账号授予对 GCS 存储桶的写入权限:

  1. 前往 Cloud Storage > 存储分区
  2. 点击您的存储桶名称 (oci-audit-logs-gcs)。
  3. 前往权限标签页。
  4. 点击授予访问权限
  5. 提供以下配置详细信息:
    • 添加主账号:输入服务账号电子邮件地址 (oci-function-gcs-writer@PROJECT_ID.iam.gserviceaccount.com)。
    • 分配角色:选择 Storage Object Admin
  6. 点击保存

创建 Oracle Cloud Infrastructure 服务连接器中心

  1. 登录 Oracle Cloud 控制台。
  2. 依次前往可观测性和管理 > Logging > Service Connector Hub
  3. 选择要在其中创建服务连接器的区间。
  4. 点击创建服务连接器
  5. 提供以下配置详细信息:

    • 服务连接器信息
    设置
    连接器名称 输入 audit-logs-to-gcs-connector
    说明 输入 Forward OCI Audit logs to Google Cloud Storage
    资源隔离区 选择隔离区
    • 配置来源
    设置
    来源 选择日志记录
    Compartment 选择包含审核日志的区间
    日志组 选择 _Audit(审核日志的默认日志组)
  6. 点击 + 另一条记录

  7. 选择您的区间对应的审核日志(例如 _Audit_Include_Subcompartment)。

    • 配置目标
    设置
    目标 选择函数
    功能区 选择包含函数的区间
    函数应用 选择audit-logs-to-gcs-app
    功能 选择oci-audit-to-gcs
  8. 滚动到配置任务(可选),然后保留默认设置。

  9. 点击创建

为服务连接器中心创建 IAM 政策

Service Connector Hub 需要权限才能调用函数。

  1. 在 Oracle Cloud 控制台中,前往身份与安全> 政策
  2. 选择您创建 Service Connector Hub 的区间。
  3. 点击创建政策
  4. 提供以下配置详细信息:
    • 名称:输入 service-connector-functions-policy
    • 说明:输入 Allow Service Connector Hub to invoke Functions
    • Compartment:选择隔离区。
  5. Policy Builder 部分中,切换 Show manual editor
  6. 输入以下政策声明:

    Allow any-user to use fn-function in compartment <compartment-name> where all {request.principal.type='serviceconnector'}
    Allow any-user to use fn-invocation in compartment <compartment-name> where all {request.principal.type='serviceconnector'}
    
    • <compartment-name> 替换为您的区间名称。
  7. 点击创建

测试集成

  1. 登录 Oracle Cloud 控制台。
  2. 执行一些会生成审核日志的操作(例如,创建或修改资源)。
  3. 等待 2-5 分钟,让系统处理日志。
  4. 在 GCP Console 中,前往 Cloud Storage > 存储分区
  5. 点击您的存储桶名称 (oci-audit-logs-gcs)。
  6. 前往前缀文件夹 (oci-audit-logs/)。
  7. 验证存储桶中是否显示新的 .ndjson 文件。

检索 Google SecOps 服务账号

Google SecOps 使用唯一的服务账号从您的 GCS 存储桶中读取数据。您必须授予此服务账号对您的存储桶的访问权限。

获取服务账号电子邮件地址

  1. 依次前往 SIEM 设置 > Feed
  2. 点击添加新 Feed
  3. 点击配置单个 Feed
  4. Feed 名称字段中,输入 Feed 的名称(例如 Oracle Cloud Audit Logs)。
  5. 选择 Google Cloud Storage V2 作为来源类型
  6. 选择 Oracle Cloud Infrastructure 审核日志作为日志类型
  7. 点击获取服务账号。系统会显示一个唯一的服务账号电子邮件地址,例如:

    chronicle-12345678@chronicle-gcp-prod.iam.gserviceaccount.com
    
  8. 复制此电子邮件地址,以便在下一步中使用。

向 Google SecOps 服务账号授予 IAM 权限

Google SecOps 服务账号需要您的 GCS 存储桶的 Storage Object Viewer 角色。

  1. 前往 Cloud Storage > 存储分区
  2. 点击您的存储桶名称 (oci-audit-logs-gcs)。
  3. 前往权限标签页。
  4. 点击授予访问权限
  5. 提供以下配置详细信息:
    • 添加主账号:粘贴 Google SecOps 服务账号电子邮件地址。
    • 分配角色:选择 Storage Object Viewer
  6. 点击保存

在 Google SecOps 中配置 Feed 以注入 Oracle Cloud Infrastructure 审核日志

  1. 依次前往 SIEM 设置 > Feed
  2. 点击添加新 Feed
  3. 点击配置单个 Feed
  4. Feed 名称字段中,输入 Feed 的名称(例如 Oracle Cloud Audit Logs)。
  5. 选择 Google Cloud Storage V2 作为来源类型
  6. 选择 Oracle Cloud Infrastructure 审核日志作为日志类型
  7. 点击下一步
  8. 为以下输入参数指定值:

    • 存储桶网址:输入带有前缀路径的 GCS 存储桶 URI:

      gs://oci-audit-logs-gcs/oci-audit-logs/
      
        • oci-audit-logs-gcs:您的 GCS 存储桶名称。
        • oci-audit-logs:存储日志的可选前缀/文件夹路径(留空表示根目录)。
      • 示例

        • 根存储桶:gs://company-logs/
        • 带前缀:gs://company-logs/oci-audit-logs/
        • 包含子文件夹:gs://company-logs/oracle/audit/
    • 来源删除选项:根据您的偏好选择删除选项:

      • 永不:转移后永不删除任何文件(建议用于测试)。
      • 删除已转移的文件:在成功转移后删除文件。
      • 删除已转移的文件和空目录:成功转移后删除文件和空目录。
    • 文件存在时间上限:包含在过去指定天数内修改的文件。默认值为 180 天。
    • 资产命名空间资产命名空间
    • 注入标签:要应用于此 Feed 中事件的标签。
  9. 点击下一步

  10. 最终确定界面中查看新的 Feed 配置,然后点击提交

UDM 映射表

日志字段 UDM 映射 逻辑
accept_encoding_field additional.fields 已合并
accept_field additional.fields 已合并
additional_app additional.fields 已合并
additional_content_type additional.fields 已合并
additional_sort_by additional.fields 已合并
additionaldetails_data additional.fields 已合并
allow_methods_field additional.fields 已合并
auth_type_label additional.fields 已合并
authorization_field additional.fields 已合并
backend_connect_time_field additional.fields 已合并
backend_processing_time_field additional.fields 已合并
caller_id_label additional.fields 已合并
caller_name_label additional.fields 已合并
cloud_event_versiom_field additional.fields 已合并
compartment_id_field additional.fields 已合并
compartment_name_field additional.fields 已合并
connection_field additional.fields 已合并
content_length_field additional.fields 已合并
content_type_field additional.fields 已合并
event_grouping_id_field additional.fields 已合并
event_name_label additional.fields 已合并
event_resource_label additional.fields 已合并
event_source_label additional.fields 已合并
event_type_label additional.fields 已合并
event_type_versiom_field additional.fields 已合并
has_compariment_id additional.fields 已映射:trueadditional_app
has_sort_by additional.fields 已映射:trueadditional_sort_by
listener_name_field additional.fields 已合并
log_group_id_field additional.fields 已合并
log_id_field additional.fields 已合并
message additional.fields 映射值(总共 41 个,例如 \/tenant_id_label\/auth_type_label\/ → `ca...)
opc_request_id_field additional.fields 已合并
origin_field additional.fields 已合并
param0_field additional.fields 已合并
param1_field additional.fields 已合并
referer_field additional.fields 已合并
request_processing_time_field additional.fields 已合并
resource_id_field additional.fields 已合并
routing_rules_engine_errors_field additional.fields 已合并
routing_rules_matched_rule_field additional.fields 已合并
routing_rules_rule_hits_field additional.fields 已合并
routing_rules_rule_misses_field additional.fields 已合并
source_field additional.fields 已合并
tenant_id_label additional.fields 已合并
column3 extensions.auth.type 已映射:login successfulAUTHTYPE_UNSPECIFIED
message extensions.auth.type 已映射:\/AUTHTYPE_UNSPECIFIED
column3 metadata.description 直接映射
data.message metadata.description 直接映射
column1 metadata.event_timestamp 解析为 yyyy-MM-dd HH:mm:ss
data_event_time metadata.event_timestamp 解析为 yyyy-MM-ddTHH:mm:ss.SSSSSSZ
time metadata.event_timestamp 解析为 ISO8601
metadata_event_type metadata.event_type 直接映射
type metadata.product_event_type 直接映射
data_event_id metadata.product_log_id 直接映射
id metadata.product_log_id 直接映射
message metadata.product_name 已映射:\/OCI_AUDIT
specversion metadata.product_version 直接映射
message metadata.vendor_name 已映射:\/Oracle
message network.application_protocol 已映射:\/HTTPS\/HTTP
protocol network.application_protocol 已映射:(?i)HTTPSHTTPS(?i)HTTPHTTP
version network.application_protocol_version 直接映射
data_request_action network.http.method 直接映射
method network.http.method 直接映射
data_identity_userAgent network.http.parsed_user_agent 已重命名/已映射
data_request_agent network.http.parsed_user_agent 已重命名/已映射
url network.http.referral_url 直接映射
data.backendStatusCode network.http.response_code 直接映射
data_response_status network.http.response_code 已重命名/已映射
data.userAgent network.http.user_agent 直接映射
data_identity_userAgent network.http.user_agent 直接映射
data_request_agent network.http.user_agent 直接映射
data.receivedBytes network.received_bytes 直接映射
message network.received_bytes 已映射:\/uinteger
data.sentBytes network.sent_bytes 直接映射
message network.sent_bytes 已映射:\/uinteger
data_identity_consoleSessionId network.session_id 已重命名/已映射
data.sslCipher network.tls.cipher 直接映射
data.sslProtocol network.tls.version 直接映射
data.host principal.asset.hostname 直接映射
hostname principal.asset.hostname 直接映射
column6 principal.asset.ip 已合并
data.forwardedForAddr principal.asset.ip 已合并
data_identity_ipAddress principal.asset.ip 已映射:^(?:[0-9]{1,3}[.]){3}[0-9]{1,3}$data_identity_ipAddress
data_request_origin principal.asset.ip 已合并
ip1 principal.asset.ip 已合并
ip2 principal.asset.ip 已合并
message principal.asset.ip 映射值(总共 7 个,例如 \/column6\/data_request_origin\/ip2
src_ip principal.asset.ip 已合并
data.host principal.hostname 直接映射
hostname principal.hostname 直接映射
column6 principal.ip 已合并
data.forwardedForAddr principal.ip 已合并
data_identity_ipAddress principal.ip 已映射:^(?:[0-9]{1,3}[.]){3}[0-9]{1,3}$data_identity_ipAddress
data_request_origin principal.ip 已合并
ip1 principal.ip 已合并
ip2 principal.ip 已合并
message principal.ip 映射值(总共 7 个,例如 \/column6\/data_request_origin\/ip2
src_ip principal.ip 已合并
data_request_headers_sec-ch-ua-platform_0 principal.platform 映射:(?i)LinuxLINUX(?i)windowsWINDOWS(?i)mac/iosMAC
message principal.platform 已映射:\/LINUX\/WINDOWS\/MAC
originalConnection.sourcePort principal.port 直接映射
src_port principal.port 直接映射
data_request_headers_oci-original-url_0 principal.url 直接映射
credentials_label principal.user.attribute.labels 已合并
message principal.user.attribute.labels 已映射:\/credentials_label
data.identity.principalName principal.user.user_display_name 直接映射
data.username principal.user.user_display_name 直接映射
data.identity.principalId principal.user.userid 直接映射
data.principalId principal.user.userid 直接映射
column3 security_result 已映射:login successfulsecurity_result
message security_result 已映射:\/security_result
allow_action security_result.action 已合并
column3 security_result.action 已映射:login successfulallow_action
message security_result.action 已映射:\/allow_action
credential_type_field security_result.detection_fields 已合并
message security_result.detection_fields 已映射:\/credential_type_field
data.response.message security_result.summary 直接映射
message target.asset.ip 已映射:\/originalConnection.destinationIp\/tar_ip
originalConnection.destinationIp target.asset.ip 已合并
tar_ip target.asset.ip 已合并
message target.ip 已映射:\/originalConnection.destinationIp\/tar_ip
originalConnection.destinationIp target.ip 已合并
tar_ip target.ip 已合并
originalConnection.destinationPort target.port 直接映射
tar_port target.port 直接映射
message target.resource.attribute.labels 已映射:\/namespace_label
namespace_label target.resource.attribute.labels 已合并
type target.resource.attribute.labels 已映射:listretentionrulesnamespace_label
data.resourceId target.resource.name 直接映射
data.resourceName target.resource.name 直接映射
bucketId target.resource.product_object_id 直接映射
data.resourceId target.resource.product_object_id 直接映射
data_request_id target.resource.product_object_id 直接映射
message target.resource.resource_type 已映射:\/STORAGE_BUCKET
type target.resource.resource_type 已映射:listretentionrulesSTORAGE_BUCKET
data_request_path target.url 直接映射
column2 target.user.email_addresses 已合并
message target.user.email_addresses 已映射:\/column2
不适用 extensions.auth.type 常量:AUTHTYPE_UNSPECIFIED
不适用 metadata.product_name 常量:OCI_AUDIT
不适用 metadata.vendor_name 常量:Oracle
不适用 network.application_protocol 常量:HTTPS
不适用 principal.platform 常量:LINUX
不适用 target.resource.resource_type 常量:STORAGE_BUCKET

更新日志

查看相应解析器的更改日志

需要更多帮助?获得社区成员和 Google SecOps 专业人士的解答。