Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Yandex SIEM
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Audit Trails
  • Getting started
    • All guides
    • Creating a trail
    • Managing a trail
    • Drafting a trail specification
    • Handling errors
    • Viewing operations with service resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Management event reference
  • Data event reference
  • Release notes

In this article:

  • Getting started
  • Creating a trail
  • Examples
  • Creating a trail with event filtering
  • Filtering by field value
  • What's next
  1. Step-by-step guides
  2. Creating a trail

Creating a trail to upload audit logs

Written by
Yandex Cloud
Improved by
Danila N.
Updated at November 2, 2026
View in Markdown
  • Getting started
  • Creating a trail
  • Examples
    • Creating a trail with event filtering
    • Filtering by field value
  • What's next

You can create a trail that will upload both management and data event audit logs into one of the destination objects:

  • Yandex Object Storage bucket.
  • Yandex Cloud Logging group.
  • Yandex Data Streams data stream.

When creating a trail via the CLI, Terraform, or API, you can set field value conditions in the data event filters. Thus you will reduce the event stream and the amount of stored logs.

Getting startedGetting started

Prepare a destination object and service account for your trail:

Object Storage bucket
Cloud Logging log group
Data Streams
  1. Create a bucket with restricted access the audit logs will be uploaded to.

  2. (Optional) Enable encryption for the bucket:

    Make sure the account you are going to use to create an encryption key for the bucket has the kms.editor role for the folder.

  3. Create a service account for the trail.

  4. Assign to the service account these roles for the trail to collect and upload logs:

    • storage.uploader for the bucket.

    • kms.keys.encrypter for the bucket encryption key.

      This role is only required if encryption was enabled for the bucket.

    • audit-trails.viewer for a resource defining the required log collection scope:

      • Organization: To collect logs in selected clouds of the organization.
      • Cloud: To collect logs in selected folders of the cloud.
      • Folder: To collect logs in this folder.

      Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.

  5. Make sure the account you are going to use to create a trail has the required roles:

    • audit-trails.editor for the folder to host the trail.
    • iam.serviceAccounts.user for the trail’s service account.
  1. Create a log group the audit logs will be uploaded to.

  2. Create a service account for the trail.

  3. Assign to the service account these roles for the trail to collect and upload logs:

    • logging.writer for the log group.
    • audit-trails.viewer for a resource defining the required log collection scope:

      • Organization: To collect logs in selected clouds of the organization.
      • Cloud: To collect logs in selected folders of the cloud.
      • Folder: To collect logs in this folder.

      Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.

  4. Make sure the account you are going to use to create a trail has the required roles:

    • audit-trails.editor for the folder to host the trail.
    • iam.serviceAccounts.user for the trail’s service account.
  1. Create a data stream the audit logs will be uploaded to.

    Tip

    We recommend enabling autopartitioning on the target data stream.

    When overloading individual shards or the entire stream, some events may get lost. Autopartitioning automatically adds shards as needed and distributes the workloads to avoid losses. If autopartitioning is disabled, remember to manually check and increase the number of shards.

  2. Create a service account for the trail.

  3. Assign to the service account these roles for the trail to collect and upload logs:

    • yds.writer for the data stream.
    • audit-trails.viewer for a resource defining the required log collection scope:

      • Organization: To collect logs in selected clouds of the organization.
      • Cloud: To collect logs in selected folders of the cloud.
      • Folder: To collect logs in this folder.

      Child resources inherit access permissions from their parent resources. For example, if a service account gets a role for a cloud, then the trail that uses this account will be able to collect logs for resources across all folders of this cloud. However, the trail will not be able to collect logs in other clouds owned by the organization: a role for the organization is required for that.

  4. Make sure the account you are going to use to create a trail has the required roles:

    • audit-trails.editor for the folder to host the trail.
    • iam.serviceAccounts.user for the trail’s service account.

Creating a trailCreating a trail

Management console
CLI
Terraform
API
  1. In the management console, select the folder to host the trail.

  2. Navigate to Audit Trails.

  3. Click Create trail.

  4. Under Destination, select one of the destination objects and specify its settings:

    • Object Storage: Uploading audit logs to an Object Storage bucket. Recommended for long-term data storage. Configure log storage settings:

      • Bucket: Bucket you created earlier.

      • Object prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.

        Note

        Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.

      • Encryption key: Bucket encryption key. You only need to select it if encryption was enabled for the bucket.

    • Cloud Logging: Log group you created earlier. Audit logs will be uploaded into this log group. Recommended for quick log collection and analysis.

    • Data Streams: Data stream you created earlier. Audit logs will be uploaded into this stream. Recommended for streaming logs to other services or systems.

  5. Under Control plane log collection:

    1. Enable log collection.

    2. Select a resource: Organization, Cloud, or Folder.

    3. Depending on the resource you selected, select specific clouds or folders to collect events from:

      • For the Organization collection scope, select one or more clouds to collect events from in the Cloud drop-down list.

        Keep the default value (All) to collect events from all clouds in the organization.

      • For the Cloud collection scope, select one or more folders to collect events from in the Folder drop-down list.

        Keep the default value (All) to collect events from all folders in the cloud.

  6. Under Data plane log collection:

    Warning

    In the management console, collection of some data events is on by default. Their delivery is billed as per the pricing policy. If you do not need data events, disable their collection.

    1. Enable log collection.

    2. Select the services to collect audit logs for.

    3. Configure the event collection scope and filter for each service:

      1. Click to the right of the service name.

      2. Select a resource: Organization, Cloud, or Folder.

      3. Depending on the resource you selected, select specific clouds or folders to collect events from:

        • For the Organization collection scope, select one or more clouds to collect events from in the Cloud drop-down list.

          Keep the default value (All) to collect events from all clouds in the organization.

        • For the Cloud collection scope, select one or more folders to collect events from in the Folder drop-down list.

          Keep the default value (All) to collect events from all folders in the cloud.

      4. Select the event filter:

        • Get all: To collect all events within the service.
        • Selected: To collect only selected events. Then proceed to select the events.
        • Exclude: To collect all events except for the selected ones. Then proceed to select the events.

    To restrict event collection by field values, set the filtering conditions via the CLI, API, or Terraform.

  7. Under Service account, select the previously created service account the trail will operate under.

  8. In the Name field, enter a name for the trail. It must be unique within the folder.

  9. Optionally, enter a description for the trail.

  10. Click Create.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.

If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

View the description of the CLI command for creating a trail:

yc audit-trails trail create --help

Use a YAML specification for collecting data events. If you only need management events, provide parameters directly in the command.

In the YAML specification
  1. Create a YAML file with the trail configuration. In this template, logs are uploaded to the bucket:

    name: <trail_name>
    folder_id: <folder_ID>
    destination:
      object_storage:
        bucket_id: <bucket_name>
        object_prefix: <prefix_for_objects>
    service_account_id: <service_account_ID>
    filtering_policy:
      management_events_filter:
        resource_scopes:
          - id: <cloud_or_folder_organization_ID>
            type: <type>
      data_events_filters:
        - service: <service_name>
          resource_scopes:
            - id: <cloud_or_folder_organization_ID>
              type: <type>
          included_events:
            event_types:
              - <full_event_name>
    

    You can also use the specification for an existing trail as a basis.

    Configuration parameters:

    • name: Trail name. It must be unique within the folder.

    • folder_id: ID of the folder the trail will reside in.

    • destination: Settings for the audit log destination object.

      Specify only one destination: object_storage, cloud_logging, or data_stream.

      • object_storage: Uploading logs to a Yandex Object Storage bucket:

        • bucket_id: Name of the bucket you created earlier.

          To view a list of bucket names in the default folder, run this command:

          yc storage bucket list
          
        • object_prefix: Prefix to assign to the objects with audit logs within the bucket. It is an optional parameter used in the full name of the audit log file.

          Note

          Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.

      • cloud_logging: Uploading logs to a Yandex Cloud Logging group.

        Replace the destination section in the template:

        destination:
          cloud_logging:
            log_group_id: <log_group_ID>
        

        In the log_group_id parameter, specify the ID of the log group you created earlier. You can request the ID with the list of log groups in the folder.

      • data_stream: Uploading logs to a data stream in Yandex Data Streams:

        Replace the destination section in the template:

        destination:
          data_stream:
            stream_name: <data_stream_name>
            database_id: <database_ID>
            codec: RAW
        
        • stream_name: Name of the data stream you created earlier. You can request the name with the list of data streams in the folder.
        • database_id: ID of the YDB database used by Data Streams. You can request the ID with the list of YDB databases in the folder.
        • codec: Event compression method when writing to Data Streams. The possible values are RAW (no compression, default), GZIP, and ZSTD. Enable compression if you expect an event flow greater than 1 MB/s.
    • service_account_id: ID of the service account you created earlier.

    • filtering_policy: Settings of the filtering policy that determines which events to collect and include in the audit logs. The policy consists of filters pertaining to different levels of events.

      Warning

      You must configure at least one filter for the policy; otherwise, you will not be able to create a trail.

      Available filters:

      • management_events_filter: Management event filter.

        Specify the log collection scope in the resource_scopes parameter:

        • id: Organization, cloud, or folder ID.

        • type: Scope type according to the specified ID:

          • organization-manager.organization: Organization.
          • resource-manager.cloud: Cloud.
          • resource-manager.folder: Folder.

        You can combine several scopes belonging to the same organization in one resource_scopes parameter. For example, you can collect logs from one entire cloud and only from particular folders in another cloud:

        resource_scopes:
          # Collecting logs from all of cloud 1
          - id: <ID_of_cloud_1>
            type: resource-manager.cloud
          # Collecting logs from folder 1 of cloud 2
          - id: <folder_1_ID>
            type: resource-manager.folder
          # Collecting logs from folder 2 of cloud 2
          - id: <folder_2_ID>
            type: resource-manager.folder
        

        Service account permissions must allow collecting logs from the specified scopes.

      • data_events_filters: Data event filters. You can configure several filters of this type, one filter per service.

        A filter for one service has the following structure:

        • service: Service name. You can get it from the data event reference.

        • resource_scopes: Places to collect data events from. You can configure this parameter the same way as the management event filter.

        • *_events: Full names of events to collect or exclude:

          • included_events.event_types: Collect only specified events.
          • excluded_events.event_types: Collect all events other than the specified ones.

          To exclude events, replace the included_events section in the template:

          excluded_events:
            event_types:
              - <full_event_name>
          

          Use the full name from the event_type field of the audit log. For example, yandex.cloud.audit.iam.CreateIamToken corresponds to the CreateIamToken event from the reference.

        Warning

        For filters by event name, the included_events and excluded_events sections are mutually exclusive. If they are not specified, all events are recorded. You can additionally set field value conditions in the same filter.

  2. Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the include_rules and exclude_rules rules in the filtering_policy.data_events_filters list item. For filter configuration examples, see Creating a trail.

  3. Run this command:

    yc audit-trails trail create --file <file_path>
    
In command parameters

To collect management events from a folder and upload them to a bucket, run this command:

yc audit-trails trail create \
  --name <trail_name> \
  --service-account-id <service_account_ID> \
  --destination-bucket <bucket_name> \
  --filter-all-folder-id <folder_ID>

For a different destination object, replace --destination-bucket with one of these options:

  • Log group:

    --destination-log-group-id <log_group_ID>
    
  • Data stream:

    --destination-yds-stream <data_stream_name> \
    --destination-yds-database-id <database_ID>
    

Command parameters:

  • --name: Name of the new trail.
  • --description: Trail description. This is an optional setting.

  • --labels: List of labels. This is an optional setting. You can specify one or more labels separated by commas in <key1>=<value1>,<key2>=<value2> format.

  • --service-account-id: Service account ID.

  • --destination-bucket: Name of the Yandex Object Storage bucket you want to upload audit logs to.

    You cannot use this parameter together with --destination-log-group-id or --destination-yds-stream.

  • --destination-bucket-object-prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.

    Note

    Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.

  • --destination-log-group-id: ID of the Yandex Cloud Logging log group the audit logs will be uploaded to.

    You cannot use this parameter together with --destination-bucket or --destination-yds-stream.

  • --destination-yds-stream: Name of the Yandex Data Streams data stream the audit logs will be uploaded to.

    You cannot use this parameter together with --destination-bucket or --destination-log-group-id.

  • --destination-yds-database-id: ID of the YDB database used by Data Streams.

  • --destination-yds-codec: Event compression method when writing to Data Streams. The possible values are RAW (no compression, default), GZIP, ZSTD. Enable compression if you expect an event flow greater than 1 MB/s.

  • --filter-all-folder-id: Folder ID. The system will be logging management events for all resources in this folder.

  • --filter-all-cloud-id: Cloud ID. The system will be logging management events for all resources in this cloud.

  • --filter-all-organisation-id: Organization ID. The system will be logging management events for all resources in this organization.

  • --filter-some-folder-ids: List of folder IDs. The system will be logging management events for all resources in those folders, in the cloud specified in --filter-from-cloud-id.

    This parameter can only be used together with --filter-from-cloud-id.

  • --filter-from-cloud-id: ID of the cloud housing the folders specified in the --filter-some-folder-ids parameter.

    This parameter can only be used together with --filter-some-folder-ids.

  • --filter-some-cloud-ids: List of cloud IDs. The system will be logging management events for all resources in those clouds, in the organization specified in --filter-from-organisation-id.

    This parameter can only be used together with --filter-from-organisation-id.

  • --filter-from-organisation-id: ID of the organization housing the clouds specified under --filter-some-cloud-ids.

    This parameter can only be used together with --filter-some-cloud-ids.

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the guides on the Terraform website or its mirror.

If you do not have Terraform yet, install it and configure the Yandex Cloud provider.

To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.

  1. Specify the trail properties in the configuration file. In this template, logs are uploaded to the bucket:

    resource "yandex_audit_trails_trail" "basic_trail" {
      name        = "<trail_name>"
      folder_id   = "<folder_ID>"
      description = "<trail_description>"
      labels = {
        key = "value"
      }
      service_account_id = "<service_account_ID>"
    
      storage_destination {
        bucket_name   = "<bucket_name>"
        object_prefix = "<prefix>"
      }
    
      filtering_policy {
        management_events_filter {
          resource_scope {
            resource_id   = "<cloud_or_folder_organization_ID>"
            resource_type = "<type>"
          }
        }
    
        data_events_filter {
          service         = "<service_name>"
          included_events = ["<full_event_name>"]
    
          resource_scope {
            resource_id   = "<cloud_or_folder_organization_ID>"
            resource_type = "<type>"
          }
        }
      }
    }
    

    Where:

    • name: Name of the new trail. The naming requirements are as follows:

      • Length: between 3 and 63 characters.
      • It can only contain lowercase Latin letters, numbers, and hyphens.
      • It must start with a letter and cannot end with a hyphen.
    • folder_id: ID of the folder to create the trail in.

    • description: Trail description. This is an optional parameter.

    • labels: List of labels in key=value format. This is an optional parameter.

    • service_account_id: ID of the service account the trail uses to collect and upload audit logs.

      Based on the audit log collection scope, the service account must have the audit-trails.viewer role for the organization, cloud, or folder whose audit logs the trail will be collecting.

    Specify only one destination: storage_destination, logging_destination, or data_stream_destination.

    • logging_destination: Uploading logs to a Yandex Cloud Logging group.

      Replace the storage_destination section in the template:

      logging_destination {
        log_group_id = "<log_group_ID>"
      }
      
      • log_group_id: ID of the log group for the trail to save audit logs to.
    • storage_destination: Uploading logs to a Yandex Object Storage bucket:

      • log_group_id: Name of the bucket for the trail to save audit logs to.

      • object_prefix: Prefix that will be assigned to the objects with audit logs in the bucket. It is an optional parameter used in the full name of the audit log file.

        Note

        Use a prefix to store audit logs and third-party data in the same bucket. Do not use the same prefix for logs and other bucket objects because that may cause logs and third-party objects to overwrite each other.

    • data_stream_destination: Uploading logs to a data stream in Yandex Data Streams:

      Replace the storage_destination section in the template:

      data_stream_destination {
        database_id = "<database_ID>"
        stream_name = "<data_stream_name>"
        codec       = "RAW"
      }
      
      • stream_name: Name of the data stream for the trail to save audit logs to.
      • database_id: ID of the Yandex Managed Service for YDB database used by Data Streams.
      • codec: Event compression method when writing to Data Streams. The possible values are RAW (no compression, default), GZIP, and ZSTD. Enable compression if you expect an event flow greater than 1 MB/s.
    • filtering_policy: Settings of the filtering policy that determines which events to collect and include in the audit logs. The policy consists of filters pertaining to different levels of events. It contains the management_events_filter and data_events_filter sections.

      • management_events_filter: Management event filter.

        • resource_scope: Log collection scope. You can specify multiple resource_scope sections for scopes belonging to the same organization. For example, you can collect logs from one entire cloud and only from particular folders in another cloud. Service account permissions must allow collecting logs from the specified scopes.

          • resource_id: ID of the collection scope (organization, cloud, or folder).

          • resource_type: Scope type according to the specified ID:

            • organization-manager.organization: Organization.
            • resource-manager.cloud: Cloud.
            • resource-manager.folder: Folder.
      • data_events_filter: Data event filter. You can configure several filters of this type, one filter per service. A filter for one service has the following structure:

        • service: Name of the service in which the trail will process events. You can get it from the data event reference.

        • resource_scope: Places to collect data events from. You can configure this section the same way as the management event filter.

        • included_events: Full names of events to collect. You can replace it with excluded_events (full names of events to exclude). These parameters are mutually exclusive. If both are not set, selection is not limited to event names.

          Use the full name from the event_type field of the audit log. For example, yandex.cloud.audit.iam.CreateIamToken corresponds to the CreateIamToken event from the reference.

        • include_rule and exclude_rule: Optional rules with conditions based on field values. These apply together with event selection by names.

    For more on the properties of the yandex_audit_trails_trail resource, see this provider guide.

  2. Optionally, supplement the filter with conditions based on field values for the relevant service. To do this, under filtering_policy.data_events_filter, set the include_rule and exclude_rule. Use the Yandex Cloud provider version 0.225.0 or higher. For filter configuration examples, see Creating a trail.

  3. Create the resources:

    1. In the terminal, navigate to the configuration file directory.

    2. Make sure the configuration is correct using this command:

      terraform validate
      

      If the configuration is valid, you will get this message:

      Success! The configuration is valid.
      
    3. Run this command:

      terraform plan
      

      You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.

    4. Apply the configuration changes:

      terraform apply
      
    5. Type yes and press Enter to confirm the changes.

    Terraform will create all the required resources. You can check the new resources and their settings either in the management console or using this CLI command:

    yc audit-trails trail get <trail_name>
    
  1. Authenticate with the API.

  2. Prepare the following trail parameters: folder, destination object, service account, and filtering policy with the relevant services and scopes.

    To use the settings of an existing trail as a basis, get them using the get REST API method or TrailService/Get gRPC API call.

  3. Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the includeRules and excludeRules rules in the filteringPolicy.dataEventsFilters list item in the REST API request. In the gRPC API, use include_rules and exclude_rules in filtering_policy.data_events_filters. For a filter configuration example, see Creating a trail.

  4. To create a trail, use the create REST API method for the Trail resource or the TrailService/Create gRPC API call.

The trail will be created and start uploading audit logs to the selected destination object.

When uploading to Cloud Logging, you may get duplicate events in a log group. To find duplicates, refer to the unique record ID, json_payload.event_id.

ExamplesExamples

Creating a trail with event filteringCreating a trail with event filtering

In our example, we create the sample-trail-all-planes trail in folder0***, and it writes logs to sample-logs-bucket under the service0*** service account.

The filters dictate which events are logged:

  • Management events: From all the org1*** organization’s clouds.
  • Data events:
    • Managed Service for PostgreSQL: All events from cloud1*** and folder1*** except for CreateDatabase and UpdateDatabase.
    • Identity and Access Management: Only CreateIamToken events from folder2***. Events with both the iam.session credentials type and user@example.com for the subject name are excluded.
CLI
Terraform
API
  1. Create a YAML file named sample-trail-all-planes.yaml with the trail configuration:

    name: sample-trail-all-planes
    folder_id: folder0***
    destination:
      object_storage:
        bucket_id: sample-logs-bucket
    service_account_id: service0***
    filtering_policy:
      management_events_filter:
        resource_scopes:
          - id: org1***
            type: organization-manager.organization
      data_events_filters:
        - service: mdb.postgresql
          resource_scopes:
            - id: cloud1***
              type: resource-manager.cloud
            - id: folder1***
              type: resource-manager.folder
          excluded_events:
            event_types:
              - yandex.cloud.audit.mdb.postgresql.CreateDatabase
              - yandex.cloud.audit.mdb.postgresql.UpdateDatabase
        - service: iam
          resource_scopes:
            - id: folder2***
              type: resource-manager.folder
          included_events:
            event_types:
              - yandex.cloud.audit.iam.CreateIamToken
          exclude_rules:
            - conditions:
                - field: $.details.credential.type
                  operator: IN
                  values:
                    - iam.session
                - field: $.details.subject_name
                  operator: IN
                  values:
                    - user@example.com
    
  2. Run this command:

    yc audit-trails trail create --file sample-trail-all-planes.yaml
    
  1. Specify the trail properties in the Terraform configuration file:

    resource "yandex_audit_trails_trail" "basic_trail" {
      name               = "sample-trail-all-planes"
      folder_id          = "folder0***"
      service_account_id = "service0***"
    
      storage_destination {
        bucket_name = "sample-logs-bucket"
      }
    
      filtering_policy {
        management_events_filter {
          resource_scope {
            resource_id   = "org1***"
            resource_type = "organization-manager.organization"
          }
        }
    
        data_events_filter {
          service = "mdb.postgresql"
          excluded_events = [
            "yandex.cloud.audit.mdb.postgresql.CreateDatabase",
            "yandex.cloud.audit.mdb.postgresql.UpdateDatabase",
          ]
    
          resource_scope {
            resource_id   = "cloud1***"
            resource_type = "resource-manager.cloud"
          }
    
          resource_scope {
            resource_id   = "folder1***"
            resource_type = "resource-manager.folder"
          }
        }
    
        data_events_filter {
          service         = "iam"
          included_events = ["yandex.cloud.audit.iam.CreateIamToken"]
    
          resource_scope {
            resource_id   = "folder2***"
            resource_type = "resource-manager.folder"
          }
    
          exclude_rule {
            condition {
              field    = "$.details.credential.type"
              operator = "IN"
              values   = ["iam.session"]
            }
    
            condition {
              field    = "$.details.subject_name"
              operator = "IN"
              values   = ["user@example.com"]
            }
          }
        }
      }
    }
    
  2. Apply the configuration:

    terraform apply
    

Use the create REST API method for the Trail resource.

To use the examples, install cURL.

The example below is for MacOS and Linux. To run it on Windows, check the details on working with Bash in Microsoft Windows.

  1. Get an IAM token for API authentication and write it into an environment variable:

    export IAM_TOKEN=<IAM_token>
    
  2. Create a file named body.json with the following request body:

    {
      "folderId": "folder0***",
      "name": "sample-trail-all-planes",
      "destination": {
        "objectStorage": {
          "bucketId": "sample-logs-bucket"
        }
      },
      "serviceAccountId": "service0***",
      "filteringPolicy": {
        "managementEventsFilter": {
          "resourceScopes": [
            {
              "id": "org1***",
              "type": "organization-manager.organization"
            }
          ]
        },
        "dataEventsFilters": [
          {
            "service": "mdb.postgresql",
            "resourceScopes": [
              {
                "id": "cloud1***",
                "type": "resource-manager.cloud"
              },
              {
                "id": "folder1***",
                "type": "resource-manager.folder"
              }
            ],
            "excludedEvents": {
              "eventTypes": [
                "yandex.cloud.audit.mdb.postgresql.CreateDatabase",
                "yandex.cloud.audit.mdb.postgresql.UpdateDatabase"
              ]
            }
          },
          {
            "service": "iam",
            "resourceScopes": [
              {
                "id": "folder2***",
                "type": "resource-manager.folder"
              }
            ],
            "includedEvents": {
              "eventTypes": [
                "yandex.cloud.audit.iam.CreateIamToken"
              ]
            },
            "excludeRules": [
              {
                "conditions": [
                  {
                    "field": "$.details.credential.type",
                    "operator": "IN",
                    "values": ["iam.session"]
                  },
                  {
                    "field": "$.details.subject_name",
                    "operator": "IN",
                    "values": ["user@example.com"]
                  }
                ]
              }
            ]
          }
        ]
      }
    }
    
  3. Run this request:

    curl \
      --request POST \
      --header "Authorization: Bearer ${IAM_TOKEN}" \
      --header "Content-Type: application/json" \
      --data "@body.json" \
      https://audittrails.api.cloud.yandex.net/audit-trails/v1/trails
    

Filtering by field valueFiltering by field value

You can use these examples to create or update a trail. Add the relevant snippet to the filter of the service in question: in the CLI, to the filtering_policy.data_events_filters list item; in Terraform, to the filtering_policy.data_events_filter section.

Excluding events by credentials type and user

The filter for iam excludes events with the iam.session credentials type and the user@example.com subject name, e.g., CreateIamToken.

CLI
Terraform
exclude_rules:
  - conditions:
      - field: $.details.credential.type
        operator: IN
        values:
          - iam.session
      - field: $.details.subject_name
        operator: IN
        values:
          - user@example.com
exclude_rule {
  condition {
    field    = "$.details.credential.type"
    operator = "IN"
    values   = ["iam.session"]
  }

  condition {
    field    = "$.details.subject_name"
    operator = "IN"
    values   = ["user@example.com"]
  }
}
Excluding events by IP address

The filter for mdb.mongodb excludes GenericAuditEvent events with details.remote_address from the 192.0.2.0/24 subnet.

CLI
Terraform
exclude_rules:
  - conditions:
      - field: $.event_type
        operator: IN
        values:
          - yandex.cloud.audit.mdb.mongodb.GenericAuditEvent
      - field: $.details.remote_address
        operator: IP_IN
        values:
          - 192.0.2.0/24
exclude_rule {
  condition {
    field    = "$.event_type"
    operator = "IN"
    values   = ["yandex.cloud.audit.mdb.mongodb.GenericAuditEvent"]
  }

  condition {
    field    = "$.details.remote_address"
    operator = "IP_IN"
    values   = ["192.0.2.0/24"]
  }
}
Excluding network events by source and destination addresses

The filter for network excludes ExternalFlow events with source and destination addresses from the 198.51.100.0/24 subnet.

CLI
Terraform
exclude_rules:
  - conditions:
      - field: $.event_type
        operator: IN
        values:
          - yandex.cloud.audit.network.flowlogs.ExternalFlow
      - field: $.details.dst_addr
        operator: IP_IN
        values:
          - 198.51.100.0/24
      - field: $.details.src_addr
        operator: IP_IN
        values:
          - 198.51.100.0/24
exclude_rule {
  condition {
    field    = "$.event_type"
    operator = "IN"
    values   = ["yandex.cloud.audit.network.flowlogs.ExternalFlow"]
  }

  condition {
    field    = "$.details.dst_addr"
    operator = "IP_IN"
    values   = ["198.51.100.0/24"]
  }

  condition {
    field    = "$.details.src_addr"
    operator = "IP_IN"
    values   = ["198.51.100.0/24"]
  }
}
Collecting Kubernetes secret read events

The filter for k8s only keeps ApiServerWatch, ApiServerGet, and ApiServerList events for secrets resources.

CLI
Terraform
include_rules:
  - conditions:
      - field: $.event_type
        operator: IN
        values:
          - yandex.cloud.audit.k8s.apiserver.ApiServerWatch
          - yandex.cloud.audit.k8s.apiserver.ApiServerGet
          - yandex.cloud.audit.k8s.apiserver.ApiServerList
      - field: $.details.native_api_server_event.objectRef.resource
        operator: IN
        values:
          - secrets
include_rule {
  condition {
    field    = "$.event_type"
    operator = "IN"
    values = [
      "yandex.cloud.audit.k8s.apiserver.ApiServerWatch",
      "yandex.cloud.audit.k8s.apiserver.ApiServerGet",
      "yandex.cloud.audit.k8s.apiserver.ApiServerList",
    ]
  }

  condition {
    field    = "$.details.native_api_server_event.objectRef.resource"
    operator = "IN"
    values   = ["secrets"]
  }
}

The objectRef key register matches the Kubernetes source event.

What's nextWhat's next

  • Learn more about the audit log format.
  • Find out about the procedure for uploading audit logs to SIEM.
  • Learn how to search for events in audit logs.

Was the article helpful?

Previous
All guides
Next
Managing a trail
© 2026 Direct Cursus Technology L.L.C.