Skip to content

Vault: Revamp audit logging docs #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions content/vault/v1.20.x/content/docs/audit/best-practices.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
layout: docs
page_title: Audit Logging Best Practices
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
page_title: Audit Logging Best Practices
page_title: Audit logging best practices

Style correction: use sentence case

description: Recommendations for setting up audit logging in HashiCorp Vault.
---

# Best practices
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Best practices
# Best practices for audit logging


<Highlight title="Mileage may vary">
This page contains recommendations that are <strong>generally applicable</strong> to Vault customers. You should independently evaluate whether each recommendation on this page is advisable in the context of your organization's environment and use cases for Vault.
</Highlight>
Comment on lines +9 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Highlight title="Mileage may vary">
This page contains recommendations that are <strong>generally applicable</strong> to Vault customers. You should independently evaluate whether each recommendation on this page is advisable in the context of your organization's environment and use cases for Vault.
</Highlight>
The following recommendations apply generally to most Vault deployments. But you
should always independently evaluate whether a given recommendation makes sense
in the context of your deployment and use of Vault.

Style correction: write in active voice, limit use of asides


## Test configuration changes

You should test every configuration change to Vault's audit logging in a non-production environment. The non-production environment should closely mirror the production environment in all aspects relevant to the audit logging configuration and should include performance benchmarking under production-like loads.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You should test every configuration change to Vault's audit logging in a non-production environment. The non-production environment should closely mirror the production environment in all aspects relevant to the audit logging configuration and should include performance benchmarking under production-like loads.
Always test your audit logging changes in a non-production environment that
closely mirrors your production environment. Your test environment should
include performance benchmarking under production-like loads and match in all
aspects relevant to the audit logging configuration you want to test.

Style correction: write in active voice, use directive language


## Enable audit devices at cluster initialization

You should ensure that at least one audit device is enabled immediately after a new Vault cluster is initialized. The audit device's configuration must be [valid for all Vault cluster nodes](/vault/docs/audit#enabling-and-disabling-audit-devices).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You should ensure that at least one audit device is enabled immediately after a new Vault cluster is initialized. The audit device's configuration must be [valid for all Vault cluster nodes](/vault/docs/audit#enabling-and-disabling-audit-devices).
Ensure your configuration enables at least one audit device immediately after a
new Vault cluster initializes. The configuration of your initialization audit
device must be
[valid for all Vault cluster nodes](/vault/docs/audit#enabling-and-disabling-audit-devices).

Style correction: write in active voice, avoid possessives


When a new Vault cluster is initialized, audit logging is disabled by default. Enabling at least one audit device post-initialization ensures that all subsequent API requests, including those for initial cluster configuration and root token revocation, are audited.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When a new Vault cluster is initialized, audit logging is disabled by default. Enabling at least one audit device post-initialization ensures that all subsequent API requests, including those for initial cluster configuration and root token revocation, are audited.
By default, Vault leaves audit logging disabled when initializing a new cluster.
By enabling at least one audit device post-initialization, you ensures that Vault
audits all subsequent API requests, including initial cluster configuration
activites and root token revocation.

Style correction: write in active voice, use declarative language


## Enable at least two audit devices

You should enable at least two audit devices on each Vault cluster. We generally recommend enabling at least two audit devices of different types and configuring *at least one* of those devices to forward logs to a remote system for analysis and long-term storage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You should enable at least two audit devices on each Vault cluster. We generally recommend enabling at least two audit devices of different types and configuring *at least one* of those devices to forward logs to a remote system for analysis and long-term storage.
We recommend enabling at least two audit devices, of different types, on each
Vault cluster. At least one of those devices should also forward logs to a
remote system for analysis and long-term storage.

Style guide correction: Write in active voice with declarative language


<Warning>
<p>When only one audit device is enabled, and that audit device becomes partially or fully unavailable, Vault will not respond to client requests it cannot log. Enabling two or more audit devices reduces the risk of no audit devices being available.</p>

<p>When two or more audit devices are enabled, Vault will attempt to send each audit log entry to all audit devices. However, Vault guarantees only that an audit log entry is written to at least one audit device. When you configure two or more audit devices, you <strong>must</strong> analyze audit log entries across all configured devices to ensure that you have a complete record of all API requests and responses. You may deduplicate audit log entries based on the value of <code>.request.id</code>.</p>
</Warning>
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Warning>
<p>When only one audit device is enabled, and that audit device becomes partially or fully unavailable, Vault will not respond to client requests it cannot log. Enabling two or more audit devices reduces the risk of no audit devices being available.</p>
<p>When two or more audit devices are enabled, Vault will attempt to send each audit log entry to all audit devices. However, Vault guarantees only that an audit log entry is written to at least one audit device. When you configure two or more audit devices, you <strong>must</strong> analyze audit log entries across all configured devices to ensure that you have a complete record of all API requests and responses. You may deduplicate audit log entries based on the value of <code>.request.id</code>.</p>
</Warning>
Vault does not respond to client requests it cannot log. Having at least two
audit devices reduces the risk of Vault not responding to client requests when
the only audit device becomes partially or fully unavailable.
Vault sends each audit log entry to all enabled devices with the guarantee that
the audit log entry writes successfully to at least one audit device. But you
should always analyze your audit log entries across all configured devices to
ensure you have a complete record of all API requests and responses.
<Tip>
You can deduplicate audit log entries based on the `.request.id` value.
</Tip>

Style correction: write in active voice, avoid overusing alert tags


### File devices

If you configure a `file` audit device, ensure that you have a process in place for rotating the corresponding log file. You should also use a dedicated volume or partition for Vault's audit logs, to protect against the risk of other workloads on the system taking up the disk space intended for them.

Vault does not automatically rotate log files. If log files are not rotated, they may grow to consume all available disk space, eventually causing the audit device to become unavailable.

You should use a purpose-built system, such as *logrotate*, to rotate Vault's audit log file according to your organization's policies. You can configure your log rotation system to send Vault an `HUP` signal, which will cause Vault to start writing audit log entries to the new log file.

<Tip>
When running Vault on a Kubernetes cluster, a common approach is to configure a <code>file</code> audit device with <code>file_path</code> set to <code>stdout</code>. This will cause Vault's audit logs to be written to the container's standard output, from where they can be processed by a Kubernetes cluster-level log collector. You should also consider configuring the audit device with a <code>prefix</code> that enables the log collector to separate audit logs from server logs.
</Tip>

### Syslog devices

If you configure a `syslog` audit device, use a TCP listener to ensure successful recording of large audit log entries. Note that Vault can only write audit logs to the default syslog service running on the same host as the Vault server. Note also that Vault's `syslog` audit device is available only on Unix systems.

Vault logs API requests and responses in detail. As a result, some audit log entries can exceed the message size allowed for UDP transmission of syslog messages.

### Socket devices

If you configure a `socket` audit device, you should configure a local service to bind a Unix socket.

Socket devices using TCP and UDP listeners can result in lost audit log data when the TCP connection is interrupted or the receiving UDP endpoint becomes unavailable.
Comment on lines +33 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### File devices
If you configure a `file` audit device, ensure that you have a process in place for rotating the corresponding log file. You should also use a dedicated volume or partition for Vault's audit logs, to protect against the risk of other workloads on the system taking up the disk space intended for them.
Vault does not automatically rotate log files. If log files are not rotated, they may grow to consume all available disk space, eventually causing the audit device to become unavailable.
You should use a purpose-built system, such as *logrotate*, to rotate Vault's audit log file according to your organization's policies. You can configure your log rotation system to send Vault an `HUP` signal, which will cause Vault to start writing audit log entries to the new log file.
<Tip>
When running Vault on a Kubernetes cluster, a common approach is to configure a <code>file</code> audit device with <code>file_path</code> set to <code>stdout</code>. This will cause Vault's audit logs to be written to the container's standard output, from where they can be processed by a Kubernetes cluster-level log collector. You should also consider configuring the audit device with a <code>prefix</code> that enables the log collector to separate audit logs from server logs.
</Tip>
### Syslog devices
If you configure a `syslog` audit device, use a TCP listener to ensure successful recording of large audit log entries. Note that Vault can only write audit logs to the default syslog service running on the same host as the Vault server. Note also that Vault's `syslog` audit device is available only on Unix systems.
Vault logs API requests and responses in detail. As a result, some audit log entries can exceed the message size allowed for UDP transmission of syslog messages.
### Socket devices
If you configure a `socket` audit device, you should configure a local service to bind a Unix socket.
Socket devices using TCP and UDP listeners can result in lost audit log data when the TCP connection is interrupted or the receiving UDP endpoint becomes unavailable.

Folded into the next section


## Configure audit devices

You should review all configuration options that are [common](/vault/api-docs/system/audit#parameters) to all audit device types *and* those specific to a given audit device type (`file`, `syslog`, `socket`) and ensure that all audit devices are configured in a way that is appropriate for your organization and deployment.

In general, we recommend you set the following options:

- `elide_list_responses = true`. This reduces the volume of log data produced by API list requests (see [Eliding list response bodies](/vault/docs/audit#eliding-list-response-bodies)).
- `hmac_accessor = false`. A token accessor is generally not considered sensitive information: it does not grant any access to Vault, but rather serves as a unique identifier for a single Vault token. A token accessor enables you to [revoke](/vault/docs/commands/token/revoke) its corresponding Vault token, even when you do not know the token itself. By disabling token accessor hashing, if you identify unusual access patterns in your audit logs, you can quickly revoke the corresponding Vault token through its accessor.
Comment on lines +57 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Configure audit devices
You should review all configuration options that are [common](/vault/api-docs/system/audit#parameters) to all audit device types *and* those specific to a given audit device type (`file`, `syslog`, `socket`) and ensure that all audit devices are configured in a way that is appropriate for your organization and deployment.
In general, we recommend you set the following options:
- `elide_list_responses = true`. This reduces the volume of log data produced by API list requests (see [Eliding list response bodies](/vault/docs/audit#eliding-list-response-bodies)).
- `hmac_accessor = false`. A token accessor is generally not considered sensitive information: it does not grant any access to Vault, but rather serves as a unique identifier for a single Vault token. A token accessor enables you to [revoke](/vault/docs/commands/token/revoke) its corresponding Vault token, even when you do not know the token itself. By disabling token accessor hashing, if you identify unusual access patterns in your audit logs, you can quickly revoke the corresponding Vault token through its accessor.
## Fully configure your audit devices
In addition to the following deployment recommendations, we suggest reviewing
the type-specific configuration options for each audit device type in addition
to the [common](/vault/api-docs/system/audit#parameters) configuration options.
Reviewing type-specific options helps ensure you configure your audit devices
appropriately for your organization.
<Tabs>
<Tab heading="Recommended options">
We recommend setting the following options for all audit devices:
@include 'cli/audit/options/elide_list_responses.mdx'
<hr />
@include 'cli/audit/options/hmac_accessor.mdx'
</Tab>
<Tab heading="File">
When you configure a `file` audit device, we recommend using a dedicated volume
or partition for audit logs to protect against other workloads on the system
taking up the disk space intended for your log files.
Vault does not rotate log files automatically and unrotated logs can grow to
consume all available disk space which eventually makes the audit device
unavailable. We recommend establishing a log rotation process appropriate for
your organization, deployment, and applicable policies with purpose-built
systems like `logrotate`.
You can configure your log rotation system to send Vault an `HUP` signal, which
tells Vault to start writing audit log entries to the new log file.
<Tip title="Logging with Kubernetes">
When running Vault on a Kubernetes cluster, a common approach is to configure
a `file` audit device with `file_path` set to `stdout`. Using `stdout` for the
file path writes the audit logs to standard output for the container, which
lets you process the logs with a Kubernetes cluster-level log collector.
If you choose to use cluster-level log collection, we recommend configuring
the audit device with a `prefix` so your log collector can separate audit logs
from server logs.
</Tip>
</Tab>
<Tab heading="Syslog">
To configure a `syslog` audit device, you must deploy Vault on Unix and we
recommend using a TCP listener so you can successfuly record large audit log
entries. Vault can only write audit logs to the default Unix syslog service
running on the same host as the Vault server.
Vault logs API requests and responses in detail, so some audit log entries may
exceed the message size allowed for UDP transmission of syslog messages.
</Tab>
<Tab heading="Socket">
When you configure a `socket` audit device, we recommend configuring a local
service to bind a Unix socket. Socket devices using TCP and UDP listeners can
lead to lost audit log data if something interrupts the TCP connection or the
receiving UDP endpoint becomes unavailable.
</Tab>
</Tabs>


## Monitor audit device health

You should configure monitoring and alerting on the health of your audit devices.

Vault produces several [telemetry metrics](/vault/docs/internals/telemetry/metrics/audit) related to audit logging. You should especially monitor `vault.audit.log_request_failure`, `vault.audit.log_response_failure`, `vault.audit.{DEVICE}.log_request`, and `vault.audit.{DEVICE}.log_response` for spikes, which can indicate one or more audit devices failing.

Additionally, you should configure monitoring and alerting specific to each type of audit device, such as available disk space, disk IOPS, and log rotation status for `file` audit devices.
Comment on lines +68 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You should configure monitoring and alerting on the health of your audit devices.
Vault produces several [telemetry metrics](/vault/docs/internals/telemetry/metrics/audit) related to audit logging. You should especially monitor `vault.audit.log_request_failure`, `vault.audit.log_response_failure`, `vault.audit.{DEVICE}.log_request`, and `vault.audit.{DEVICE}.log_response` for spikes, which can indicate one or more audit devices failing.
Additionally, you should configure monitoring and alerting specific to each type of audit device, such as available disk space, disk IOPS, and log rotation status for `file` audit devices.
We strongly recommend monitoring and alerting on the health of your audit
devices, with specific alerts for each type of audit device. For example,
alerting on available disk space, disk IOPS, and log rotation status for `file`
audit devices.
Vault produces several audit logging
[telemetry metrics](/vault/docs/internals/telemetry/metrics/audit) and we
recommend monitoring the following metrics for spikes, which can indicate one or
more audit devices failing:
- [`vault.audit.log_request_failure`](/vault/docs/internals/telemetry/metrics/audit#vault-audit-log_request_failure)
- [`vault.audit.log_response_failure`](/vault/docs/internals/telemetry/metrics/audit#vault-audit-log_response_failure)
- [`vault.audit.{DEVICE}.log_request`](/vault/docs/internals/telemetry/metrics/audit#vault-audit-device-log_request)
- [`vault.audit.{DEVICE}.log_response`](/vault/docs/internals/telemetry/metrics/audit#vault-audit-device-log_response)


## Configure attribute hashing

For each authentication backend and secrets engine mount you configure in Vault, you should evaluate which request and response attributes need *not* be [hashed](/vault/docs/audit#hashing-of-sensitive-values) in the audit logs.

<Tip>
Hashing should be left on for attributes that are sensitive (e.g., passwords, private keys) or that may be excessively large for your audit log.
</Tip>
Comment on lines +76 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For each authentication backend and secrets engine mount you configure in Vault, you should evaluate which request and response attributes need *not* be [hashed](/vault/docs/audit#hashing-of-sensitive-values) in the audit logs.
<Tip>
Hashing should be left on for attributes that are sensitive (e.g., passwords, private keys) or that may be excessively large for your audit log.
</Tip>
We recommend [hashing](/vault/docs/audit#hashing-of-sensitive-values) for all
sensitive attributes (for example, passwords and private keys) and any attribute
may be excessively large for your audit log.
For all other attributes, we recommend reviewing each authentication backend and
secrets engine mount you configure in Vault to evaluate which request and
response attributes do not need hashing in the audit logs.


You can disable hashing for individual request and response attributes through the `audit_non_hmac_request_keys` and `audit_non_hmac_response_keys` attributes in the "tune" API endpoints of each [authentication backend](https://developer.hashicorp.com/vault/api-docs/system/auth#tune-auth-method) and [secret engine](https://developer.hashicorp.com/vault/api-docs/system/mounts#tune-mount-configuration) mount.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can disable hashing for individual request and response attributes through the `audit_non_hmac_request_keys` and `audit_non_hmac_response_keys` attributes in the "tune" API endpoints of each [authentication backend](https://developer.hashicorp.com/vault/api-docs/system/auth#tune-auth-method) and [secret engine](https://developer.hashicorp.com/vault/api-docs/system/mounts#tune-mount-configuration) mount.
You can disable hashing for individual request and response attributes with the
`audit_non_hmac_request_keys` and `audit_non_hmac_response_keys` attributes for
the following tuning endpoints:
- [`/sys/auth/{path}/tune`](/vault/api-docs/system/auth#tune-auth-method)
- [`/sys/mounts/{path}/tune`](/vault/api-docs/system/mounts#tune-mount-configuration)


## Monitor suspicious activity

You should configure monitoring and alerting of Vault's audit logs for unusual or suspicious activity.

Examples of events to monitor include root token creation, root token usage, modifications to audit loggig configuration, spikes in authentication failures, and spikes in permission denied failures.
Comment on lines +86 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You should configure monitoring and alerting of Vault's audit logs for unusual or suspicious activity.
Examples of events to monitor include root token creation, root token usage, modifications to audit loggig configuration, spikes in authentication failures, and spikes in permission denied failures.
We strongly recommend monitoring and alerting for unusual or suspicious activity
in your audit logs related to:
- root token creation
- root token usage
- modifications to audit logging configuration
- spikes in authentication failures
- spikes in permission denied failures

Loading
Loading