Creating a trail to upload audit logs
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
Getting started
Depending on the selected destination object for logs, prepare the required infrastructure to create a trail:
-
Create a bucket with restricted access the audit logs will be uploaded to.
-
(Optional) Enable encryption for the bucket:
Make sure your account has the
kms.editor
role for the folder the bucket encryption key will be created in. -
Create a service account for the trail.
-
Assign roles to the service account for the trail to be able to collect and upload logs:
-
storage.uploader
for a bucket. -
kms.keys.encrypter
for a bucket encryption key.This role is only required if encryption was enabled for the bucket.
-
audit-trails.viewer
for one of the resources that defines 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.
-
-
Make sure your account has the roles required for creating a trail:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
-
Create a log group the audit logs will be uploaded to.
-
Create a service account for the trail.
-
Assign roles to the service account for the trail to be able to collect and upload logs:
logging.writer
for a log group.
-
audit-trails.viewer
for one of the resources that defines 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.
-
Make sure your account has the roles required for creating a trail:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
-
Create a data stream the audit logs will be uploaded to.
-
Create a service account for the trail.
-
Assign roles to the service account for the trail to be able to collect and upload logs:
yds.writer
for a data stream.
-
audit-trails.viewer
for one of the resources that defines 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.
-
Make sure your account has the roles required for creating a trail:
- audit-trails.editor for the folder to host the trail.
- iam.serviceAccounts.user for the trail’s service account.
Creating a trail
-
In the management console
, select the folder to host the trail. -
Select Audit Trails.
-
Click Create trail.
-
Enter a name for the trail. It must be unique within the folder.
-
(Optional) Enter a description for the trail.
-
Under Destination, select one of the destination objects and specify its settings:
-
Object Storage: Uploading audit logs to the Object Storage bucket:
-
Bucket: Name of the 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: Specify the name of the log group you created earlier. Audit logs will be uploaded into this log group.
-
Data Streams: Specify the name of the data stream you created earlier. Audit logs will be uploaded into this stream.
-
-
Under Service account, select the previously created service account the trail will use to operate.
-
Enable and configure collection of events from one or two levels. Such events will get into the audit logs.
To configure Collecting management events:
-
Select the log collection scope:
Organization
,Cloud
, orFolder
. The events that end up in the logs will belong to the specified scope.The permissions of the service account you created earlier must allow collecting logs from the specified scope.
-
Depending on the selected log collection scope, select specific clouds or folders to collect events from:
-
For the
Organization
collection scope, from the Cloud drop-down list, select one or more clouds to collect events from.Keep the default value (
All
) to collect events from all clouds in the organization. -
For the
Cloud
collection scope, from the Folder drop-down list, select one or more folders to collect events from.Keep the default value (
All
) to collect events from all folders in the cloud.
-
To configure Collecting data events:
-
Select one or more services to collect events from.
-
For each such service, select the log collection scope:
Organization
,Cloud
, orFolder
. The events that end up in the logs will belong to the specified scope.The permissions of the service account you created earlier must allow collecting logs from the specified scope.
-
Depending on the selected log collection scope, select specific clouds or folders to collect events from:
-
For the
Organization
collection scope, from the Cloud drop-down list, select one or more clouds to collect events from.Keep the default value (
All
) to collect events from all clouds in the organization. -
For the
Cloud
collection scope, from the Folder drop-down list, select one or more folders to collect events from.Keep the default value (
All
) to collect events from all folders in the cloud.
-
-
For each such service, select one of the following event filters:
Receive all
: To collect all events within the service.Selected
: To collect only selected events. Proceed to select the events.Exclude
: To collect all events except for the selected ones. Proceed to select the events.
-
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
You can create a trail in two ways:
-
Create a YAML file containing your trail parameters and provide this file to the command to create the trail.
This method simplifies working with trail parameters and reduces the probability of error.
-
Provide the trail parameters in the command arguments to create the trail.
See the description of the CLI trail create command for details about the arguments you can use:
yc audit-trails trail create --help
Tip
Use this method if your trail configuration is simple and contains few parameters.
To create a trail using a YAML file:
-
Create a YAML file with the trail configuration:
name: <trail_name> folder_id: <folder_ID> destination: # Only one destination must be specified: # object_storage, cloud_logging, data_stream # Settings for all destinations are provided for illustration purposes object_storage: bucket_id: <bucket_name> object_prefix: <prefix_for_objects> cloud_logging: log_group_id: <log_group_ID> data_stream: stream_name: <YDS_name> database_id: <YDS_database_ID> 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> # You can specify included_events, excluded_events, # or neither of the two to collect all the events of the service. # Both parameters are provided for illustration purposes. included_events: event_types: - <these_events_will_be_collected> excluded_events: event_types: - <these_events_will_not_be_collected>
Where:
-
name
: Trail name. It must be unique within the folder. -
folder_id
: ID of the folder the trail will reside in. -
destination
: Settings of the selected destination the audit logs will be uploaded to.Warning
Destination settings are mutually exclusive. Using some settings makes it impossible to use others.
-
object_storage
: Uploading logs to the Object Storage bucket:-
bucket_id
: Name of the bucket you created earlier.You can request the name of the bucket with the list of buckets in the folder (the default folder is used):
yc storage bucket list
-
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.
-
-
cloud_logging
: Upload logs to a Cloud Logging group.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
: Upload logs to a Data Streams data stream:-
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.
-
-
-
service_account_id
: ID of the service account you created earlier. -
filtering_policy
: The 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
: Organizationresource-manager.cloud
: Cloudresource-manager.folder
: Folder
You can combine several scopes belonging to the same organization in one
resource_scopes
parameter. For example, to collect logs from one entire cloud and only from particular folders in another cloud:resource_scopes: # Collecting logs from entire 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 for each 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
: Data event filters.included_events.event_types
: Collect only specified events.excluded_events.event_types
: Collect all events other than the specified ones.
You can get a list of events from the data event reference.
Warning
These filters are mutually exclusive:
- Either configure
included_events
- or
excluded_events
If you configure neither, all events will be collected.
-
-
-
-
Run this command:
yc audit-trails trail create --file <path_to_file>
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the configuration file, describe the parameters of the trail to collect audit logs:
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>" logging_destination { log_group_id = "<log_group_ID>" } filter { path_filter { some_filter { resource_id = "<organization_ID>" resource_type = "<parent_resource_type>" any_filters { resource_id = "<ID_of_cloud_1>" resource_type = "<child_resource_type>" } any_filters { resource_id = "<ID_of_cloud_2>" resource_type = "<child_resource_type>" } } } event_filters { service = "<ID_of_service_1>" categories { plane = "DATA_PLANE" type = "<action_type>" } path_filter { any_filter { resource_id = "<organization_ID>" resource_type = "<resource_type>" } } } event_filters { service = "<ID_of_service_2>" categories { plane = "DATA_PLANE" type = "<action_type>" } path_filter { any_filter { resource_id = "<organization_ID>" resource_type = "<resource_type>" } } } } }
Where:
-
name
: Name of the trail being created. The name format requirements are as follows:- It must be 2 to 63 characters long.
- It may 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 a trail in. -
description
: Description of the trail to distinguish it from other trails, e.g.,My very first trail
. This is an optional parameter. -
labels
: List of labels inkey=value
format. This is an optional parameter. -
service_account_id
: ID of the service account that the trail will use to upload audit log files to the bucket.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 collect.
log_group_id
: ID of the log group for the trail to save audit logs to.
filter
: Structure describing how the trail processes events. It contains thepath_filter
andevent_filters
objects.-
path_filter
: Structure describing how the trail processes management (control plane) events. It may contain a singlesome_filter
object or a singleany_filter
object. If thepath_filter
object is missing in the configuration, the trail will not process control plane events.-
some_filter
: Structure describing the resources whose audit logs will be collected. Based on the audit log collection scope, it allows configuring event processing in specific organization clouds or cloud folders associated with the trail.-
resource_id
: ID of the parent resource the new trail belongs to and for whose resources audit logs will be collected. Based on the audit log collection scope, specify the organization ID or the ID of the cloud associated with the trail in this parameter. -
resource_type
: Type of the Yandex Cloud parent resource to create a trail in. Based on the audit log collection scope, specifyorganization-manager.organization
orresource-manager.cloud
in this parameter. -
any_filters
: Structure describing one child resource audit logs will be collected in. To specify multiple child resources, set theany_filters
parameter as many times as needed. Based on the audit log collection scope, in this parameter, specify information on the clouds or folders whose events the trail will process:resource_id
: Child resource ID. Based on the audit log collection scope, specify the ID of the cloud or folder whose audit logs the trail will collect.resource_type
: Child resource type. Based on the audit log collection scope, specifyresource-manager.cloud
orresource-manager.folder
in this parameter.
To set the current folder as the audit log collection scope, use the
any_filter
parameter instead ofsome_filter
.You cannot use
some_filter
together withany_filter
. -
-
any_filter
: Structure describing the resources whose audit logs will be collected. Based on the audit log collection scope, it allows configuring event processing in all clouds of the organization associated with the trail, in all folders of the cloud associated with the trail, or in the current folder where you want to create the trail. You cannot useany_filter
together withsome_filter
.resource_id
: ID of the resource the new trail belongs to and for whose resources audit logs will be collected. Based on the audit log collection scope, specify the organization, cloud, or folder ID in this parameter.resource_type
: Yandex Cloud resource type. Based on the audit log collection scope, specifyorganization-manager.organization
,resource-manager.cloud
, orresource-manager.folder
.
-
-
event_filters
: Structure describing how the trail processes data (data plane) evens. If theevent_filters
object is missing in the configuration, the trail will not process data plane events. A singleevent_filters
section is used to configure data plane audit log processing for a single Yandex Cloud service. To configure the trail processing of data plane events for multiple services, specify theevent_filters
parameter in the configuration as many times as you need.-
service
: ID of the service whose events the trail will process.
The possible values include:dns
kms
lockbox
mdb.mongodb
mdb.mysql
mdb.postgresql
storage
-
categories
: Structure describing the type of events to collect.plane
: Event plane. For data plane events, specifyDATA_PLANE
.type
: Type of resource event action. The possible values areREAD
andWRITE
.
-
path_filter
: Structure describing how the trail processes data (data plane) events. It may contain a singlesome_filter
object or a singleany_filter
object.-
some_filter
: Structure describing the resources whose audit logs will be collected. Based on the audit log collection scope, it allows configuring event processing in specific organization clouds or cloud folders associated with the trail.-
resource_id
: ID of the parent resource the new trail belongs to and for whose resources audit logs will be collected. Based on the audit log collection scope, specify the organization ID or the ID of the cloud associated with the trail in this parameter. -
resource_type
: Type of the Yandex Cloud parent resource to create a trail in. Based on the audit log collection scope, specifyorganization-manager.organization
orresource-manager.cloud
in this parameter. -
any_filters
: Structure describing one child resource audit logs will be collected in. To specify multiple child resources, set theany_filters
parameter as many times as needed. Based on the audit log collection scope, in this parameter, specify information on the clouds or folders whose events the trail will process:resource_id
: Child resource ID. Based on the audit log collection scope, specify the ID of the cloud or folder whose audit logs the trail will collect.resource_type
: Child resource type. Based on the audit log collection scope, specifyresource-manager.cloud
orresource-manager.folder
in this parameter.
To set the current folder as the audit log collection scope, use the
any_filter
parameter instead ofsome_filter
.You cannot use
some_filter
together withany_filter
. -
-
any_filter
: Structure describing the resources whose audit logs will be collected. Based on the audit log collection scope, it allows configuring event processing in all clouds of the organization associated with the trail, in all folders of the cloud associated with the trail, or in the current folder where you want to create the trail. You cannot useany_filter
together withsome_filter
.resource_id
: ID of the resource the new trail belongs to and for whose resources audit logs will be collected. Based on the audit log collection scope, specify the organization, cloud, or folder ID in this parameter.resource_type
: Yandex Cloud resource type. Based on the audit log collection scope, specifyorganization-manager.organization
,resource-manager.cloud
, orresource-manager.folder
.
-
-
-
For more information about the
yandex_audit_trails_trail
resource parameters in Terraform, see the provider documentation . -
-
Create the resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
Terraform will create all the required resources. You can check the new resources and their settings using the management console
or this CLI command:yc audit-trails trail get <trail_name>
-
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
.
Examples
Creating a trail with management and data event filters
Create a trail with the following parameters:
-
sample-trail-all-planes
: Trail name. -
folder0***
: ID of the folder the trail will reside in. -
Destination object: Object Storage bucket named
sample-logs-bucket
. -
service0***
: ID of the service account for the trail. -
Management event filter settings:
The log collection scope is the organization with the ID
org1***
. Logs will be collected from all clouds that belong to this organization. -
Data event filter settings:
-
For Managed Service for PostgreSQL, logs will be collected from the cloud with the ID
cloud1***
and the folder with the IDfolder1***
.All the events of the service will be collected except for the following:
yandex.cloud.audit.mdb.postgresql.CreateDatabase
yandex.cloud.audit.mdb.postgresql.UpdateDatabase
-
For Object Storage, logs will be collected from the clouds with the IDs
cloud2***
andcloud3***
.Only the following events will be collected:
yandex.cloud.audit.storage.ObjectCreate
yandex.cloud.audit.storage.ObjectUpdate
yandex.cloud.audit.storage.ObjectDelete
-
For Compute Cloud, logs will be collected from the folders with the IDs
folder2***
andfolder3***
.All service events of the service will be collected.
-
-
Create a YAML named
sample-trail-all-planes.yaml
with the trail configuration.sample-trail-all-planes.yaml
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: storage resource_scopes: - id: cloud2*** type: resource-manager.cloud - id: cloud3*** type: resource-manager.cloud included_events: event_types: - yandex.cloud.audit.storage.ObjectCreate - yandex.cloud.audit.storage.ObjectUpdate - yandex.cloud.audit.storage.ObjectDelete - service: compute resource_scopes: - id: folder2*** type: resource-manager.folder - id: folder3*** type: resource-manager.folder
-
Run this command:
yc audit-trails trail create --file sample-trail-all-planes.yaml
A trail will be created with the specified parameters.
What's next
- Learn more about the audit log format.
- Find out about the procedure for uploading audit logs to SIEM.
- Learn more about searching audit logs in buckets.