Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Read Messages Published to an OCI Stream from Oracle Access Governance Event Data Publisher
Introduction
Event Data Publishing is a process to export one-time data and continually publish ongoing data events to external systems, such as an Oracle Cloud Infrastructure (OCI) cloud account. With Oracle Access Governance, you have the flexibility to export one-off and continually publish data events, such as identity, identity collections, policy, resource, access to resources, and so on, to your cloud tenancy. You may use this data for deriving insights, storing data for compliance, or for analyzing access management and governance data.
An event refers to any change in data state that occurs when there’s creation, modification, or deletion of Oracle Access Governance components, such as identity, policies, resources, and so on. Using Event Data Publisher, administrators get complete control over access and identity data and may use it to automate event logging and streamline compliance reporting.
Data Event Publishing flow uses OCI buckets for one-off export, and publish subsequent updates either to OCI streams or OCI buckets depending on the file size.
In this tutorial, we will walk you through how user updates in OCI are captured and published to OCI streams by Oracle Access Governance and how to consume and decode these stream messages using a script through the OCI Cloud Shell.
Note: The Event Data Publisher supports exporting identities, identity collections, policies, and resources, however, this tutorial focuses on capturing events for identities.
Overview of the Shell Script
The purpose of this shell script is to retrieve and decode messages published in an OCI stream. These messages are encoded in a way that makes them unreadable in their raw format. By running the script, you can see the messages in a clear, human-readable format, ensuring that critical information is accessible even after it disappears from the OCI Console.
Specifically, the script creates a cursor to mark a starting point for reading messages from the specified OCI stream. The cursor is based on a specified offset and a partition whose values are fetched by producing a test stream message. Using the cursor, the script fetches messages from the OCI stream. Eventually, the script processes and decodes each retrieved message.
Audience
Oracle Access Governance and Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) administrators.
Objectives
-
Retrieve key parameters for your OCI stream.
-
Modify a few attributes for one or more OCI user from the console.
-
Perform the data load in Oracle Access Governance for OCI.
-
Configure the OCI Cloud Shell environment to run the script.
-
Read the stream messages by running the script.
Prerequisites
-
An Oracle Access Governance instance with administrative rights. For more information, see Set Up Service Instance and About Application Roles.
-
An OCI tenancy integrated with Oracle Access Governance. For more information, see Integrate with Oracle Cloud Infrastructure (OCI) Identity and Access Management (IAM).
-
Event Data Publisher configured from Oracle Access Governance to OCI. For more information, see Configure Event Data Publisher in Oracle Access Governance.
Task 1: Retrieve Key Parameters for your OCI Stream
In this task, we will log in to the OCI Console to retrieve key parameters for the stream.
-
Log in to the OCI Console, navigate to Analytics & AI, Messaging and click Streaming.
-
Make sure to select the compartment where your stream is located and click the stream to view details.
-
Note down the values for stream OCID and Messages Endpoint.
-
Click Produce Test Message, enter the sample message as Data and click Produce. It should return a Success message.
-
Click Cancel to close the Test Stream window.
-
Click Load Messages to check the test message.
-
From the Recent Messages section, note down the Partition and Offset values.
Task 2: Update User Attributes in OCI
In this task, we will make changes to user attributes in OCI.
-
Go to the OCI Console, navigate to Identity & Security and click Domains.
-
Select your domain and click Users. Click the user that you would like to update and click Edit User.
-
Update the values of Country, Title, Department, Cost Center, User Type, Employee Number and so on.
-
Click Save changes.
Note: Optionally, you can update a few more users if preferred.
Task 3: Perform Data Load in Oracle Access Governance
In this task, we will perform data load in Oracle Access Governance to synchronize the OCI changes.
-
Log in to Oracle Access Governance, navigate to Service Administration and Orchestrated Systems.
-
Locate the orchestrated system for OCI, click the three-dots (⋮) icon and select Manage Integration.
-
Click Load data now and wait for the data load to complete.
Task 4: Configure OCI Cloud Shell to Run Script to Capture Messages from the Stream
In this task, we will configure OCI Cloud Shell and use the provided script to decode messages published by Oracle Access Governance.
-
Go to the OCI Console, click Cloud Shell from the upper-right corner and wait for the cloud shell window to initialize.
-
Initialize the following parameters.
export STREAM_OCID=<STREAM_OCID_VALUE> export ENDPOINT=<MESSAGES_ENDPOINT> export CURSOR_TYPE="AFTER_OFFSET" export PARTITION=<PARTITION> export OFFSET=<OFFSET>
-
Replace the
STREAM_OCID
,ENDPOINT
,PARTITION
andOFFSET
parameters for the stream with the values captured in Task 1. -
The
CURSOR_TYPE
is set toAFTER_OFFSET
to include all messages generated after the specified offset value for reading. Do not modify this value.Note: A sample value for the offset can be obtained from the test message, but you should choose a value after which you will like to capture the messages. This is what the
CURSOR_TYPE
asAFTER_OFFSET
does.
-
-
Create a shell script file and make it executable.
touch ag-streaming.sh chmod u+x ag-streaming.sh
-
Open the script with vi editor.
vi ag-streaming.sh
-
Press i to enter the Insert Mode. Paste the following content, then press Esc and :wq! to save the changes.
#!/bin/bash # Validate required environment variables required_vars=("STREAM_OCID" "ENDPOINT" "CURSOR_TYPE" "PARTITION" "OFFSET") for var in "${required_vars[@]}"; do if [ -z "${!var}" ]; then echo "Error: Environment variable $var is not set." exit 1 fi done # Create a cursor for the OCI Stream # echo "Creating a cursor for the OCI Stream..." oci streaming stream cursor create-cursor \ --partition "$PARTITION" \ --stream-id "$STREAM_OCID" \ --type "$CURSOR_TYPE" \ --offset "$OFFSET" \ --endpoint "$ENDPOINT" > cursor.json # Extract cursor value cursor=$(jq -r '.data.value' cursor.json) if [ -z "$cursor" ]; then echo "Error: Failed to retrieve cursor value." exit 1 fi # Read messages from the OCI Stream echo "Reading messages from the OCI Stream..." messages=$(oci streaming stream message get \ --stream-id "$STREAM_OCID" \ --cursor "$cursor" \ --endpoint "$ENDPOINT") # Check if messages were retrieved if [ -z "$messages" ] || ! echo "$messages" | jq -e '.data[] | select(.key != null)' > /dev/null 2>&1; then echo "No valid messages found." exit 1 fi # Extract and decode the data from messages echo "Processing messages..." # Extract and count the number of messages message_count=$(echo "$messages" | jq -r '.data[] | select(.key != null) | .value' | wc -l) echo "$messages" | jq -r '.data[] | select(.key != null) | .value' | while read -r value; do if [ -n "$value" ]; then counter=$((counter + 1)) echo echo "Decoding message $counter of $message_count..." # Base64 decode the message decoded_message=$(echo "$value" | base64 --decode 2>/dev/null || echo "Error decoding message") final_decoded_message=$(echo "$decoded_message" | base64 --decode 2>/dev/null || echo "Error decoding message further") # Print the decoded message echo "Decoded Message : $final_decoded_message" fi done
-
Run the script and redirect the output messages to a file (messages_dump.txt is used as an example). Alternatively, you can run the script to display messages on the console.
./ag-streaming.sh > messages_dump.txt
-
Download the
messages_dump.txt
file from the OCI Cloud Shell to check the decoded messages for the user updates previously made.
In this tutorial, we learned how to read messages from an OCI stream that are published from event data publisher in Oracle Access Governance. We saw how we can leverage OCI Command Line Interface (CLI) using OCI Cloud Shell to read the messages based on a specified offset. These messages contain changes pertaining to OCI users, groups, resources and policy associations and are therefore important from the auditing, compliance and reporting perspective.
Next Steps
After completing these tutorial, you can analyze the contents of the data event messages published from Oracle Access Governance to OCI streams. You can optionally set up further processes to analyze the event messages for auditing and compliance requirements. You can also move data from streams to autonomous data warehouse to perform advanced analytics and visualization. Data can also be moved to OCI Object Storage for long term storage, or to run Hadoop/Spark jobs.
Related Links
Acknowledgments
- Author - Anuj Tripathi (Principal Cloud Architect, NA Solution Engineering)
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.
Read Messages Published to an OCI Stream from Oracle Access Governance Event Data Publisher
G20517-01
November 2024