<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Audit on Steve Sun</title><link>https://sund.site/en/tags/audit/</link><description>Recent content in Audit on Steve Sun</description><generator>Hugo</generator><language>en</language><copyright>© 2013-2026, Steve Sun</copyright><lastBuildDate>Mon, 15 Apr 2024 16:44:40 +0800</lastBuildDate><follow_challenge><feedId>41397727810093074</feedId><userId>56666701051455488</userId></follow_challenge><atom:link href="https://sund.site/en/tags/audit/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Design an Industry-Standard Audit System</title><link>https://sund.site/en/posts/2024/audit-system-design/</link><pubDate>Mon, 15 Apr 2024 16:44:40 +0800</pubDate><guid>https://sund.site/en/posts/2024/audit-system-design/</guid><description>&lt;p&gt;An audit trail is a service within a system that records critical security information such as user behavior logs and control component activity logs. Logs are typically arranged in chronological order, recording &amp;ldquo;who did what and when.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Below is the Kubernetes official documentation&amp;rsquo;s description of its audit service:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Kubernetes auditing provides a security-relevant, time-ordered set of records documenting the sequence of activities that affected the system by individual users, by applications using the Kubernetes API, and by the control plane itself.&lt;/p&gt;
&lt;p&gt;The audit feature enables cluster administrators to answer the following questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What happened?&lt;/li&gt;
&lt;li&gt;When did it happen?&lt;/li&gt;
&lt;li&gt;Who initiated it?&lt;/li&gt;
&lt;li&gt;On what (which) objects did the activity occur?&lt;/li&gt;
&lt;li&gt;Where was it observed?&lt;/li&gt;
&lt;li&gt;Where was it initiated from?&lt;/li&gt;
&lt;li&gt;What are the subsequent actions taken on the activity?&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;
&lt;h2 id="what-capabilities-should-an-audit-system-have"&gt;What Capabilities Should an Audit System Have?&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Log content is tamper-proof.&lt;/li&gt;
&lt;li&gt;Log chain structure is complete: individual log entries cannot be arbitrarily added or removed.&lt;/li&gt;
&lt;li&gt;Compatibility: clients sending logs should avoid invasive designs.&lt;/li&gt;
&lt;li&gt;The system&amp;rsquo;s encryption service should be initialized as early as possible to reduce unprotected log exposure.&lt;/li&gt;
&lt;li&gt;Service restart/shutdown should not cause audit log inconsistency. If a service is shut down under emergency conditions, the audit logs should remain verifiable.&lt;/li&gt;
&lt;li&gt;Key security: encryption keys (used to compute integrity checks) should be stored in a dedicated key store and reside in memory for the shortest possible time.&lt;/li&gt;
&lt;li&gt;Performance: ability to verify protected logs within seconds.&lt;/li&gt;
&lt;li&gt;Log rotation friendliness: audit logs should be compatible with typical log rotation strategies of distributed systems.&lt;/li&gt;
&lt;li&gt;Observability: logs should be easily parsed (machine-readable) and human-readable. Compatible with mainstream log processor formats, with dimensions designed to facilitate future filtering and screening.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="related-industry-standards"&gt;Related Industry Standards&lt;/h2&gt;
&lt;p&gt;Common industry standards related to auditing include IEC 62443 and NIST SP 800-92. Below are the audit-related sections in IEC.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Industry Standard&lt;/th&gt;
 &lt;th&gt;Section&lt;/th&gt;
 &lt;th&gt;Security Level&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR2.8&lt;/td&gt;
 &lt;td&gt;SL-C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR6.1&lt;/td&gt;
 &lt;td&gt;SL-C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR6.2&lt;/td&gt;
 &lt;td&gt;SL_C 2&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR1.13&lt;/td&gt;
 &lt;td&gt;SL_C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR2.9&lt;/td&gt;
 &lt;td&gt;SL_C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR2.10&lt;/td&gt;
 &lt;td&gt;SL_C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR3.7&lt;/td&gt;
 &lt;td&gt;SL_C 1&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;IEC 62443-4-2:2019&lt;/td&gt;
 &lt;td&gt;CR3.9&lt;/td&gt;
 &lt;td&gt;SL_C 2&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="what-protocols-or-standards-should-audit-log-format-follow"&gt;What Protocols or Standards Should Audit Log Format Follow?&lt;/h2&gt;
&lt;p&gt;For locally running software, Syslog typically has better system compatibility. For projects using ELK to collect logs, CEF is more suitable. In other cases, custom JSON is recommended.&lt;/p&gt;
&lt;p&gt;Below is a comparison of the three formats (protocols).&lt;/p&gt;
&lt;h3 id="common-event-format-cef"&gt;&lt;a href="https://docs.elastic.co/en/integrations/cef"&gt;Common Event Format (CEF)&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A log format used by Elastic-Search, designed based on event-sourcing principles. The advantage is less redundant information, suitable for building monitoring systems in conjunction with the ELK stack. Its transport is based on the Syslog protocol while extending readable key-value pairs. The text-based design also allows CEF-format logs to be written to files. Overall, it is the most balanced of these formats in terms of readability, efficiency, and standardization.&lt;/p&gt;
&lt;h3 id="syslog"&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc5424"&gt;Syslog&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Syslog is the default audit log format for Linux operating systems, typically using its RFC 5424 version. Most SIEM&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt; systems support importing this format.
The Syslog protocol has great adaptability, and mTLS-based Syslog transport can maximize system security while remaining compatible with traditional software. However, for microservices, implementing and maintaining the standard protocol is costly. Therefore, services like AWS CloudTrail and OpenTelemetry have opted for the simpler HTTPS + JSON format.&lt;/p&gt;
&lt;h3 id="json-lines"&gt;&lt;a href="https://jsonlines.org/"&gt;JSON Lines&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Most SaaS products use JSON—it&amp;rsquo;s simple and efficient. JSON has the characteristic of more redundant information, but the structure is easy to parse. For example, below are the fields in the log model mentioned in the &lt;a href="https://opentelemetry.io/docs/specs/otel/logs/data-model/"&gt;OpenTelemetry official documentation&lt;/a&gt;:&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Field Name&lt;/th&gt;
 &lt;th&gt;Description&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Timestamp&lt;/td&gt;
 &lt;td&gt;Time when the event occurred.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;ObservedTimestamp&lt;/td&gt;
 &lt;td&gt;Time when the event was observed.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;TraceId&lt;/td&gt;
 &lt;td&gt;Request trace id.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SpanId&lt;/td&gt;
 &lt;td&gt;Request span id.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;TraceFlags&lt;/td&gt;
 &lt;td&gt;W3C trace flag.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SeverityText&lt;/td&gt;
 &lt;td&gt;The severity text (also known as log level).&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SeverityNumber&lt;/td&gt;
 &lt;td&gt;Numerical value of the severity.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Body&lt;/td&gt;
 &lt;td&gt;The body of the log record.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Resource&lt;/td&gt;
 &lt;td&gt;Describes the source of the log.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Attributes&lt;/td&gt;
 &lt;td&gt;Additional structured information.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="what-security-requirements-apply-to-audit-logs"&gt;What Security Requirements Apply to Audit Logs?&lt;/h2&gt;
&lt;p&gt;For audit logs, security requirements are higher than for general log systems.&lt;/p&gt;
&lt;p&gt;Security can typically be considered from three dimensions: Confidentiality, Integrity, and Availability.&lt;/p&gt;
&lt;h3 id="confidentiality"&gt;Confidentiality&lt;/h3&gt;
&lt;p&gt;Attackers can exploit system security vulnerabilities to obtain special privileges and then view certain audit logs.&lt;/p&gt;
&lt;p&gt;The following measures can be taken:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Encrypt logs: use encryption technology to protect logs, ensuring that only authorized users can access and modify them.&lt;/li&gt;
&lt;li&gt;Access control: restrict access to log-sending and log-receiving interfaces.&lt;/li&gt;
&lt;li&gt;Sensitive information filtering: do not record user sensitive information in logs, such as passwords, certificates, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="integrity"&gt;Integrity&lt;/h3&gt;
&lt;p&gt;Attackers can exploit system security vulnerabilities to modify or delete certain audit logs.&lt;/p&gt;
&lt;p&gt;In addition to the encryption and access control mentioned above, the following measures can also be taken:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Integrity checks&lt;sup id="fnref:2"&gt;&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref"&gt;2&lt;/a&gt;&lt;/sup&gt;: add hash values to log entries so that any tampering or truncation can be quickly detected during log verification.&lt;/li&gt;
&lt;li&gt;Regular backups: regularly back up logs to prevent attackers from deleting or modifying all log entries.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Log file limitations&lt;/strong&gt;: in addition to limiting the size of log files, it&amp;rsquo;s typically necessary to limit the number of backups, maximum backup days, etc. Below are the parameters in Kubernetes for log file storage:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--audit-log-path&lt;/code&gt; specifies the log file path used to write audit events. If this flag is not specified, the log backend is disabled.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--audit-log-maxage&lt;/code&gt; defines the maximum number of days to retain old audit log files.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--audit-log-maxbackup&lt;/code&gt; defines the maximum number of audit log files to retain.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--audit-log-maxsize&lt;/code&gt; defines the maximum size (in megabytes) of audit log files before rotation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="availability"&gt;Availability&lt;/h3&gt;
&lt;p&gt;Attackers can attack the audit trail service, causing the audit trail service to run out of memory, disk space, etc.&lt;/p&gt;
&lt;p&gt;The audit service should cache audit-related context, such as the mapping between service names and IDs, event IDs and descriptions, etc. When different services send messages to the audit service, the message structure should be designed with minimal length as a principle. The audit service&amp;rsquo;s policy should allow users to configure log levels, filter rules, etc., to reduce system burden.&lt;/p&gt;
&lt;h2 id="log-export"&gt;Log Export&lt;/h2&gt;
&lt;p&gt;In addition to exporting file-format logs, the audit service usually needs to support export to third-party systems. We typically refer to third-party services that analyze and store logs as SIEM (Security Information and Event Management). In Kubernetes, the module that exports logs to third-party web services is called a webhook.&lt;/p&gt;
&lt;p&gt;Exporting to third-party systems can typically use the standard Syslog format or JSON Lines, which has the widest support. Additionally, you need to consider log truncation, and the configuration of third-party systems&amp;rsquo; batch and stream processing. You can refer to &lt;a href="https://kubernetes.io/zh-cn/docs/tasks/debug/debug-cluster/audit/#webhook-backend"&gt;this Kubernetes document&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="architecture-designs-of-open-source-projects"&gt;Architecture Designs of Open-Source Projects&lt;/h2&gt;
&lt;p&gt;Due to different design focuses, each of the following open-source projects needs careful consideration of its advantages and disadvantages, whether its features meet your needs, and whether the system environment is distributed or monolithic.&lt;/p&gt;
&lt;h3 id="auditd"&gt;Auditd&lt;/h3&gt;
&lt;p&gt;&lt;figure
 class="image-caption"
&gt;
 
 &lt;img src="https://sund.site/images/audit-system-design/Linux-Auditd-Architecture.png" alt="auditd-architecture" loading="lazy" /&gt;
 
 &lt;figcaption&gt;auditd-architecture&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The default audit service for most Linux systems, when paired with tools like rsyslog, can solve local device log collection, viewing, and filtering. rsyslog&amp;rsquo;s string template-based log format configuration can meet the integration needs of users using different SIEM systems.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advantages: process-based communication, standard log format, easy export. Excellent performance.&lt;/li&gt;
&lt;li&gt;Disadvantages: the process model is not suitable for network services.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="aws-cloud-trail-and-kubernetes"&gt;AWS Cloud Trail and Kubernetes&lt;/h3&gt;
&lt;p&gt;&lt;figure
 class="image-caption"
&gt;
 
 &lt;img src="https://sund.site/images/audit-system-design/aws-audit.png" alt="aws log" loading="lazy" /&gt;
 
 &lt;figcaption&gt;aws log&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;AWS CloudTrail adopts a model where application services actively push audit events. Users can set policies for designing tracking services, and the collected logs flow as needed into subsequent batch and stream processing toolchains.&lt;/p&gt;
&lt;p&gt;Kubernetes&amp;rsquo;s log collection is similar to AWS&amp;rsquo;s implementation, also based on a centralized service, but this architecture is not designed solely for audit logs. It follows many Kubernetes declarative design philosophies and is well worth studying.&lt;/p&gt;
&lt;p&gt;&lt;figure
 class="image-caption"
&gt;
 
 &lt;img src="https://sund.site/images/audit-system-design/k8s-audit.png" alt="kubernetes log" loading="lazy" /&gt;
 
 &lt;figcaption&gt;kubernetes log&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;For example, Kubernetes has stages specifically designed for auditing:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Each request can be recorded with its associated stages. The defined stages are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;RequestReceived - The stage corresponds to the event generated when the audit handler receives a request, and before delegating to the remaining handlers.&lt;/li&gt;
&lt;li&gt;ResponseStarted - The event is generated after the response message headers are sent, but before the response message body is sent. Only long-running requests (such as watch) generate this stage.&lt;/li&gt;
&lt;li&gt;ResponseComplete - When the response message body is complete and no more data needs to be transmitted.&lt;/li&gt;
&lt;li&gt;Panic - Generated when a panic occurs.&lt;/li&gt;
&lt;/ul&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="https://kubernetes.io/zh-cn/docs/tasks/debug/debug-cluster/audit/"&gt;Kubernetes audit events&lt;/a&gt; use a different message structure from the Event API&lt;sup id="fnref:3"&gt;&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref"&gt;3&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;In summary, the cloud platform&amp;rsquo;s audit service design can be summarized as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advantages: microservice design, more flexible JSON format logs, centralized log collection service easily integrates with more application services and exports to open-source data processing tools.&lt;/li&gt;
&lt;li&gt;Disadvantages: distributed architecture requires higher storage, server-side encryption, communication security, and integrity.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="opentelemetry"&gt;OpenTelemetry&lt;/h3&gt;
&lt;p&gt;&lt;figure
 class="image-caption"
&gt;
 
 &lt;img src="https://sund.site/images/audit-system-design/opentel.png" alt="OpenTel" loading="lazy" /&gt;
 
 &lt;figcaption&gt;OpenTel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;OpenTelemetry is currently the most mainstream logging framework in cloud-native environments. It supports both invasive (SDK) and non-invasive (Agent) log collection modes. The Collector design allows some log processing work to be done on the log sender side.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advantages: microservice design, supports infrastructure like Kubernetes, multi-language and multi-platform SDK and extensibility. Comprehensive security and integrity considerations. Suitable for small and medium-sized enterprises.&lt;/li&gt;
&lt;li&gt;Disadvantages: in most cases, log collection still requires invasive modification of code inside the app. Log collection tools don&amp;rsquo;t support languages like Go well (as of this writing).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;An audit trail refers to the time-ordered records of all operations or events affecting the system, used to track system activity and verify whether violations have occurred.&lt;/p&gt;
&lt;p&gt;Audit logs should have the following characteristics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tamper-proof (encrypted storage, integrity verification)&lt;/li&gt;
&lt;li&gt;High performance (fast verification)&lt;/li&gt;
&lt;li&gt;Observability (machine/human readable)&lt;/li&gt;
&lt;li&gt;Security (confidentiality, availability, integrity)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Common audit log formats include Syslog, CEF, and JSON, with the main differences being redundant information, readability, and compatibility with log collection systems.&lt;/p&gt;
&lt;p&gt;Audit logs have high security requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Confidentiality: only authorized users can access, achieved through access control&lt;/li&gt;
&lt;li&gt;Availability: prevent deletion or destruction by attackers, achieved through resource limits, multi-replica storage, etc.&lt;/li&gt;
&lt;li&gt;Integrity: prevent tampering or truncation, achieved through encryption, integrity verification, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some typical audit log system architectures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Native Linux log programs such as Auditd, rsyslog&lt;/li&gt;
&lt;li&gt;Cloud products like AWS&lt;/li&gt;
&lt;li&gt;OpenTelemetry&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;SIEM stands for Security Information and Event Management. &lt;a href="https://www.microsoft.com/en-us/security/business/security-101/what-is-siem"&gt;https://www.microsoft.com/en-us/security/business/security-101/what-is-siem&lt;/a&gt;&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;For log encryption, the server typically adds an additional checksum chain to logs for verification. You can refer to Amazon&amp;rsquo;s implementation of &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingServerSideEncryption.html"&gt;server-side encryption (SSE-S3)&lt;/a&gt;.&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:3"&gt;
&lt;p&gt;&lt;a href="https://kubernetes.io/zh-cn/docs/reference/config-api/apiserver-audit.v1/#audit-k8s-io-v1-Event"&gt;Kubernetes audit event structure definition&lt;/a&gt;&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description></item></channel></rss>