Managing a trail
You can update the destination object, event levels, audit log collection scopes, and other trail settings or delete the trail.
Updating a trail
You can add conditions based on field values to data event filters using the CLI, Terraform, or API. When updating your filter policy, provide it fully with the other relevant filters preserved.
To update a trail:
- In the management console
, select the folder containing the trail. - Navigate
to Audit Trails. - In the row with the trail, click
and select Edit. - Edit the trail settings. For a list of editable trail settings, see Trail settings.
- Click Save.
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.
See the description of the CLI command for updating a trail:
yc audit-trails trail update --help
You can update a trail by specifying its parameters in one of these two ways:
In the YAML specification
Create a YAML specification containing the updated trail parameters and specify this file in the trail update command.
This method simplifies working with trail parameters and reduces error probability. In addition, you can only customize the registration of data events using the YAML specification.
-
Draft the YAML specification based on the current trail settings and update the parameters as needed.
-
Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the
include_rulesandexclude_rulesrules in thefiltering_policy.data_events_filterslist item. For filter configuration examples, see Creating a trail. -
To update a trail, run this command:
yc audit-trails trail update --file <file_path>
In command parameters
Use this method if your trail configuration is simple and contains few parameters.
Note
You can only customize the registration of data events using the YAML specification.
In the command, specify only the parameters you want to update. For example, to update the trail name, run this command:
yc audit-trails trail update \
--name <trail_name> \
--new-name <new_trail_name>
Command parameters:
--name: Name of the trail you need to update. Instead of a name, you can provide the trail ID in the--idparameter.--new-name: New trail name. The name must be unique within the folder. This is an optional parameter.
-
--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-idor--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-bucketor--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-bucketor--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 areRAW(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-idsparameter.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
Terraform is distributed under the Business Source License
For more information about the provider resources, see the guides on the Terraform
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.
-
To update a trail created with Terraform, open the Terraform configuration file and update the trail description fragment:
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 inkey=valueformat. 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.viewerrole for the organization, cloud, or folder whose audit logs the trail will be collecting.
Specify only one destination:
storage_destination,logging_destination, ordata_stream_destination.-
logging_destination: Uploading logs to a Yandex Cloud Logging group.Replace the
storage_destinationsection 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_destinationsection 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 areRAW(no compression, default),GZIP, andZSTD. 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 themanagement_events_filteranddata_events_filtersections.-
management_events_filter: Management event filter.-
resource_scope: Log collection scope. You can specify multipleresource_scopesections 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 withexcluded_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_typefield of the audit log. For example,yandex.cloud.audit.iam.CreateIamTokencorresponds to theCreateIamTokenevent from the reference. -
include_ruleandexclude_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_trailresource, see this provider guide. -
-
Optionally, supplement the filter with conditions based on field values for the relevant service. To do this, under
filtering_policy.data_events_filter, set theinclude_ruleandexclude_rule. Use the Yandex Cloud provider version 0.225.0 or higher. For filter configuration examples, see Creating a trail. -
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou 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.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
Check the trail settings using the management console
or this CLI command:yc audit-trails trail get <trail_name> -
-
Get authenticated in the API and use the get REST API method or the TrailService/Get gRPC API call to get the trail settings.
-
Update the trail parameters as needed.
-
Optionally, supplement the filter with conditions based on field values for the relevant service. Do it by setting the
includeRulesandexcludeRulesrules in thefilteringPolicy.dataEventsFilterslist item in the REST API request. In the gRPC API, useinclude_rulesandexclude_rulesinfiltering_policy.data_events_filters. For a filter configuration example, see Creating a trail. -
Use the update REST API method for the Trail resource or the TrailService/Update gRPC API call to update the trail. Provide the trail ID, updated parameters, and update mask.
If updating the filtering policy, enable
filteringPolicyinupdateMaskfor the REST API orfiltering_policyinupdate_mask.pathsfor the gRPC API.
Examples of filters from the guide on creating a trail can also be used to update a trail.
Deleting a trail
To delete a trail:
- In the management console
, select the folder containing the trail. - Navigate
to Audit Trails. - In the row with the trail, click
and select Delete. - In the window that opens, confirm the deletion.
To delete a trail, run this command:
yc audit-trails trail delete <trail_name_or_ID>
To find out the names and IDs of available trails, use this tutorial.
To delete a trail created using Terraform:
-
Open the Terraform configuration file and delete the trail description section.
Example of a trail description in a Terraform configuration:
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>" } } } } -
In the command line, navigate to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors detected in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes. -
To make sure the trail has been deleted, use this tutorial.
To delete a trail, use the delete REST API method for the Trail resource or the TrailService/Delete gRPC API call.