Skip to content

Configuring Retention for Ranger Audits in Solr

In Self Managed deployments, audit logs are stored in Apache Solr which is used by Privacera Portal to display audit logs. By default, audit logs are retained for 90 days in Solr. You can configure the retention period for Ranger audit logs in Solr.

The default retention period for Ranger audit logs in Solr is configured starting from version 9.0.7.1. If you wish to retain logs for a different period, you should configure it according to your requirements before upgrading to version 9.0.7.1 or higher.

Prerequisites

Prerequisite Description
Apache Solr In Self Managed deployments, Apache Solr is installed by default

Setup

Follow these steps to configure the retention period for Ranger audits in Solr:

  1. SSH into the instance where Privacera Manager is installed.
  2. Navigate to the privacera-manager directory using the following command:
    Bash
    cd ~/privacera/privacera-manager/
    
  3. Run the following command to copy the sample vars. The -n flag ensures that the file is not overwritten if it already exists.
    Bash
    cp -n sample-vars/vars.solr.yml custom-vars/
    
  4. Run the following command to open the .yml file for editing.
    Bash
    vi custom-vars/vars.solr.yml
    
  5. Add or update the following property:
Variable Definition
MAX_AUDIT_RETENTION_DAYS Retention period for ranger access audit logs in days. Default is 90 Days.

YAML
MAX_AUDIT_RETENTION_DAYS: "90" #Audits will be automatically deleted after 90 days.
6. Once the properties are configured, update your Privacera Manager platform instance by following the
Bash
1
2
3
cd ~/privacera/privacera-manager
./privacera-manager.sh setup
./pm_with_helm.sh upgrade 

Validation

To confirm that the setup is successful, after running the above steps and make some access operation which will generate audit logs. The new audit logs will have the TTL set as per the configuration. If you have access to the Solr UI, you can verify the TTL configuration for the ranger_audits collection for the newly created audit logs.

Here is a sample solrconfig file with ranger-audits TTL set to +7DAYS: solrconfig_with_updated_ttl

Here is a sample ranger-audit with TTL set to +7DAYS:

ranger_audit_with_updated_ttl

Purging Historical Ranger Audits

Ranger access audits created before upgrade to Privacera version 9.0.7.1 might not have TTL set and needs to be manually deleted from Apache Solr. This can be done by making HTTP post requests to the Solr collection to delete the audits greater than the retention period.

Here is a sample script to delete ranger-audits from Solr manually. Please use this script as a reference and modify it as per your requirement.

This assumes that Apache Solr has been configured without basic authentication. If you have configured basic authentication, you need to pass the credentials in the curl command.

Create a script file called delete_ranger_audits.sh with the following content. Update SOLR_URL with your Solr URL

Here is a sample script to delete ranger-audits from Solr manually.
delete_ranger_audits.sh
#!/bin/bash

# Check if correct number of arguments are provided
if [ "$#" -ne 2 ]; then
  echo "Usage: $0 <start_date> <end_date>"
  echo "Dates should be in ISO 8601 format, e.g., 2024-01-01T00:00:00Z"
  exit 1
fi

# Assign input arguments to variables
START_DATE=$1
END_DATE=$2

# Solr server and collection details
# UPDATE THE SOLR_URL variable with your Solr URL. Make sure this URL is accessible from the machine where the script is executed.
SOLR_URL="https://localhost:8983/solr"  # Update with your Solr URL
COLLECTION_NAME="ranger_audits"      # Replace with your collection name
DATE_FIELD="evtTime"                 # Replace with your date field name

# Formulate the query for deletion
QUERY="${DATE_FIELD}:[${START_DATE} TO ${END_DATE}]"

# Endpoint for updating (deleting) documents
DELETE_URL="${SOLR_URL}/${COLLECTION_NAME}/update"

# Delete command payload
DELETE_PAYLOAD=$(cat <<EOF
{
  "delete": {
    "query": "${QUERY}"
  }
}
EOF
)

# Make the delete request
echo "Deleting documents between ${START_DATE} and ${END_DATE} in collection '${COLLECTION_NAME}'..."
curl -X POST -H "Content-Type: application/json" --data "${DELETE_PAYLOAD}" "${DELETE_URL}"

# Commit the changes to apply deletion
echo "Committing changes..."
curl "${DELETE_URL}?commit=true"

echo "Deletion process completed."      
  1. Make the Script Executable
    Bash
        chmod +x delete_ranger_audits.sh
    
  2. Run the Script
    Bash
    #./delete_ranger_audits.sh ${delete_doc_from_date} ${delete_doc_to_date}
    ./delete_ranger_audits.sh 2024-01-01T00:00:00Z 2024-01-31T23:59:59Z
    

Comments