Note:

Write Logs to Oracle Cloud Infrastructure Private Stream using Oracle Cloud Infrastructure Functions

Introduction

Logs are a cornerstone of modern cloud operations, providing critical insights into system activity, performance, and security. For enterprises handling sensitive data, managing logs securely and efficiently is paramount. This tutorial will guide you in building a secure, scalable, and event-driven architecture for log management using Oracle Cloud Infrastructure (OCI).

At the heart of this solution is OCI Functions, which ensures logs are transmitted and processed securely without exposure to public endpoints. The architecture is driven by events from logs collected and compressed into OCI Object Storage through OCI Connector Hub. Each time a log file is created, it triggers an OCI Functions, which uncompresses it, breaks it into manageable chunks, and publishes the logs to a private stream for secure storage or further processing.

This event-driven approach ensures a seamless, automated pipeline where components react dynamically to changes, minimizing latency and maximizing efficiency. By leveraging OCI’s native services, you will achieve a secure and scalable framework to handle high-volume log processing in real-time.

Objective

Prerequisites

Task 1: Set Up the Required Policies and Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) Permissions

Each component of this solution must have access to the OCI resources it interacts with. To follow this tutorial, the following permissions are required.

Detailed policies can be found here:

Task 2: Create a Private Stream

OCI Streaming is a fully managed OCI service in which data is encrypted at rest and in transit, ensuring the integrity and security of messages. For enhanced security, you can use the OCI Vault service to store and manage your own encryption keys, meeting specific compliance or security requirements. Private endpoints can be configured within a Virtual Cloud Network (VCN) to further secure your streams, associating a private IP address to the stream pool. This ensures that OCI Streaming traffic stays within the VCN, avoiding the internet entirely. However, note that streams using private endpoints are not accessible from the internet, limiting the ability to view their latest messages through the console. To consume messages from a private stream, the consumer must have both route and access to the network where the private stream is hosted.

Create a stream and stream pool. Enter Stream Name and select Create New Stream Pool to create stream pool. In the Configure Stream Pool section, enter Stream Pool Name, select Private Endpoint and enter VCN and Subnet and network details accordingly. Though optional, we recommend providing a Network Security Group with an ingress rule for all traffic within that NSG. For more information, see Create Stream and Create Stream Pool.

Image of the NSG Rule

Image of the Stream and Stream Pool

You can use your own encryption keys, gaining greater control over the key’s lifecycle. You have an option to adjust the retention of messages within the stream. The default is 1 day, and the maximum is 7 days.

Image of the Stream Encryption

Image of the Completed Stream Pool

Note down the stream OCID and the messages endpoint. We need to pass this information on to the function.

Task 3: Create and Configure OCI Connector Hub

OCI Connector Hub acts as a secure message bus, facilitating the seamless and reliable data transfer between a source and a destination. In this architecture, the source is OCI Logging, and the destination is OCI Object Storage, where these logs are compressed and stored for further processing. By serving as an intermediary, the OCI Connector Hub ensures efficient data flow while maintaining the security and integrity of the transferred messages.

This tutorial assumes that flow logs are enabled on the subnets and an OCI Object Storage bucket is available. For more information to enable flow logs and create a bucket, see Enabling Flow Logs and Creating an Object Storage Bucket.

While creating a bucket, ensure to select Emit Object Events. This is the key for our event-driven architecture.

Image of the Bucket

Configure the OCI Connector hub, creating a data flow between the OCI Logging service and the OCI Object storage bucket. For more information, see Creating a Connector with a Logging Source.

Image of the SCH

By adjusting the batch rollover details, you can configure the frequency with which the logs are written to the OCI Object Storage bucket. The default is 100 MB or 7 minutes.

Task 4: Develop and Deploy the Function

This function will read the object from the OCI Object Storage and write the message to the stream. To achieve that, it performs the following operations in between:

  1. Read the object from the bucket.
  2. Uncompress the object.
  3. Check the object size and create 1 MB chunks, if needed. OCI Streaming service limits the maximum size of a unique message that producers can publish to a stream is 1 MB.
  4. Encode the message.
  5. Publish to the stream.

For more information, see Creating functions.

Image of the Function

The final step is to tell the function where the private stream is. This function uses configuration parameters, making it reusable if you want to deploy in another tenancy.

Image of the Function Config

Task 5: Create an Event and Subscribe to the Function

In this task, subscribe the function to the object upload event. Create a rule for Event Type as Object - Create with the bucket name as a conditional attribute. For more information, see Creating an Events Rule.

Image of the Event Config

Verification

There are multiple places where the data flow can be verified.

  1. Verify the log group metrics to check if the flow logs are ingested.

    Image of the Logging Metrics

  2. The next hop is the connector hub metrics. OCI Connector Hub gathers the logs and send them to the OCI Object Storage. Make sure there are no errors at source and target.

    Image of the SCH Metrics

  3. The next hop is the OCI Object Storage. Ensure the object count is increasing. If required, enable the read and write logs to debug further.

    Image of the OSS Metrics

  4. The next hop is the OCI Events Service. Review the metrics to ensure there are no delivery failures.

    Image of the Event Metrics

  5. The next step is to check the function Invocation metrics. Ensure there are no errors and the function is not throttling.

    Image of the Fn Metrics

  6. Check that the data is being ingested into the private stream.

    Image of the Private Stream Metrics

If the data is absent in any of the following charts, stop there and enable logs for that service. Logs will explain why a specific resource is failing to perform the task.

Next Steps

Congratulations on successfully implementing a secure and event-driven log management solution in OCI! By combining the power of OCI Logging, OCI Connector Hub, OCI Object Storage, and OCI private streams, you have created a robust architecture that ensures your logs are securely collected, processed, and published in near real-time.

This solution safeguards sensitive log data through private streams and demonstrates the efficiency of event-driven automation. As your system scales, this architecture will adapt seamlessly, enabling you to handle large volumes of logs with minimal manual intervention.

With this framework in place, you can ensure secure and efficient log processing while maintaining compliance with privacy requirements. This architecture provides flexibility for building custom processing pipelines tailored to your enterprise needs. Extending this setup with additional analytics or alerting mechanisms can gain deeper insights into system events and enhance your ability to detect and respond to anomalies proactively.

For more information about using OCI Functions and OCI private stream capabilities, contact your Oracle representative or see Cloud Security Solutions.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.