Skip to content

Server: audit in the service envelope, specific audits for user management and KeyCredential push - #5226

Merged
marcschier merged 5 commits into
masterfrom
romanett/ss6-audit-triggers-9a6e78
Dec 1, 2026
Merged

marcschier merged 5 commits into
masterfrom
romanett/ss6-audit-triggers-9a6e78

Conversation

@romanett

@romanett romanett commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Finishes finding SS-6 of the 2026-11-15 server architecture review. #5130 added the envelope, #5187 the IAuditEventSink.

Service → audit event table

Spec: OPC 10000-4 §6.5.5–§6.5.10, OPC 10000-5 §6.4 (SourceName of AuditUpdateMethodEventType is Attribute/Call), OPC 10000-12 §8.6.9/§8.6.10.

Service Spec On failure (service fault) On success Old behaviour New behaviour
Read §6.5.8 (not required) AuditEventType, Attribute/Read none per-service callback envelope table (same event)
HistoryRead §6.5.8 (not required) AuditEventType, Attribute/HistoryRead none per-service callback envelope table (same event)
Write §6.5.8 both AuditEventType, Attribute/Write; per operation AuditWriteUpdateEventType per operation AuditWriteUpdateEventType (dispatcher) callback + dispatcher envelope table + dispatcher (unchanged)
HistoryUpdate §6.5.8 both AuditEventType, Attribute/HistoryUpdate; per operation AuditHistory*EventType per operation (historian) callback + historian envelope table + historian (unchanged)
Call §6.5.9 both, AuditUpdateMethodEventType or subtype AuditEventType, Method/Call; rejected call items: AuditUpdateMethodEventType the method's own event (certificate/TrustList push, roles, programs, GDS, conditions, now UserManagement and KeyCredential) callback envelope table
AddNodes / DeleteNodes / AddReferences / DeleteReferences §6.5.7 both AuditAddNodes / DeleteNodes / AddReferences / DeleteReferences EventType, Status false same type, Status from results specific fault callback unchanged (specific fault audit replaces the generic one)
CreateSession / ActivateSession §6.5.6 both AuditCreateSession / AuditActivateSession (+ certificate events) same own envelope unchanged
CloseSession §6.5.6 both AuditSessionEventType, Status false, Session/CloseSession AuditSessionEventType, Session/CloseSession success only failure added
Cancel §6.5.6 both AuditCancelEventType, Status = fault AuditCancelEventType success only failure added (specific fault audit, carries RequestHandle)
TransferSubscriptions §6.5.10 both, AuditSessionEventType AuditSessionEventType, Status false, Session/TransferSubscriptions, SourceNode = session (service fault) per subscription AuditSessionEventType (SubscriptionManager) per subscription only; a service fault (e.g. Bad_NothingToDo, too many operations) was not audited service fault added
Browse, BrowseNext, TranslateBrowsePaths, Register/UnregisterNodes, QueryFirst/Next §6.5.10 none none none none none
Create/Modify/Delete Subscription(s), SetPublishingMode, Publish, Republish, Create/Modify/Delete MonitoredItems, SetMonitoringMode, SetTriggering §6.5.10 none none none none none
OpenSecureChannel / CloseSecureChannel §6.5.5 transport (AuditOpenSecureChannel / AuditChannel / AuditCertificate*) transport transport unchanged

Not audited at all (unchanged): a request that fails in ValidateRequestAsync (no session, bad token, too busy) never reaches the envelope's try, so there is no operation context and no ClientUserId; auditing them would flood the trail with unauthenticated noise.

Method audits

Method Event Input arguments Old New
UserManagement AddUser / ModifyUser / RemoveUser / ChangePassword (Part 18 §5.2) AuditUpdateMethodEventType (Part 18 has no specific type; §6.5.9 needs this type or a subtype) passwords → null Variant nothing on success; only a call rejected by the dispatcher (method permissions) raised the dispatcher's AuditUpdateMethodEventType one event per call: success, failure, RoleAuthorizationGate denial, a provider that throws, and a call MethodState rejects in argument validation (no arguments copied); ActionTimeStamp = call start
KeyCredential UpdateCredential (Part 12 §8.6.9) KeyCredentialUpdatedAuditEventType, ResourceUri CredentialSecret → AuditEvents.RedactedPrivateKey nothing one event per call (incl. a throwing store and a validation reject)
KeyCredential DeleteCredential (§8.6.10) KeyCredentialDeletedAuditEventType, ResourceUri none nothing one event per call
KeyCredential CreateCredential AuditUpdateMethodEventType (no specific type in Part 12) all (no secret) nothing one event per call
KeyCredential GetEncryptingKey none (read-only; §6.5.9 "may") nothing nothing
RoleType Add/Remove Identity/Application/Endpoint RoleMappingRuleChangedAuditEventType 2 sites per method 1 site per method, same events

Correction to the review: there is no generic success-path method audit in the server. The "generic method-call audit" is only the dispatcher's AuditUpdateMethodEventType for call items rejected before the method runs. A generic post-call audit for every method would double-emit wherever a method raises its own subtype, so it is left out (follow-up if wanted: an opt-out flag on MethodState).

Trigger consolidation

  • 5 per-service fault lambdas in StandardServer → one ReportServiceFaultAudit(RequestType, …) switch.
  • RoleStateBinding 12 → 6 sites.
  • Left in place (domain-specific): certificate/TrustList push (ConfigurationNodeManager.PushMethods, TrustList — SS-5 area), session establishment/close/timeout, secure channel, AuditWriteUpdate/History per operation in the dispatcher/historian, Cancel success in RequestManager, TransferSubscriptions per subscription in SubscriptionManager (SB-4 area).
  • Everything goes through IAuditEventSink: ServerInternalData.ReportEvent/ReportEventAsync now route any AuditEventState to the sink. Before, audit events that node managers raise on nodes (conditions, programs, ConfigurationUpdated, FiniteStateMachine transitions) reached the address space but skipped a host sink. The one remaining bypass: AuditEvents.ReportTrustList*AuditEvent overloads called with a null server fall back to TrustListState.ReportEvent; in-tree TrustList always passes its server (SetAuditEventServer). Also note: the TrustList helpers do not check Auditing themselves; ServerInternalData.ReportAuditEvent does.

Behaviour changes

  1. CloseSession that fails with a service fault raises AuditSessionEventType (Status false).
  2. Cancel that fails with a service fault raises AuditCancelEventType with the fault status.
  3. TransferSubscriptions that fails with a service fault raises one AuditSessionEventType (SourceNode = session).
  4. UserManagement methods raise AuditUpdateMethodEventType on every call (passwords redacted).
  5. KeyCredential Update/Delete raise their Part 12 types, Create raises AuditUpdateMethodEventType.
  6. A host IAuditEventSink now also receives audit events raised through IServerInternal.ReportEvent/ReportEventAsync (conditions, programs, configuration), once per publication: an occurrence that reaches the server through several root notifiers is delivered to the sink once, as the Server object publishes it once (an independent publication of the same instance is delivered again). ReportEventAsync awaits the sink when it is an IAsyncAuditEventSink (new public interface, implemented by AddressSpaceAuditEventSink and CompositeAuditEventSink; new ServerInternalData.PublishAuditEventAsync), so a full event channel does not block the caller and the cancellation token is observed, with or without a host sink.
  7. NodeManagement failure audits are now skipped up front when auditing is off (the helpers already returned early; no observable change).
  8. The session-service fault audits (CloseSession, TransferSubscriptions) take ClientUserId from the request's captured identity (OperationContext.ClientUserId), not the session's current one, so a reactivation under another user during the request does not re-attribute the failure.
  9. Method audits record the ActionTimeStamp when the call started (ReportAuditMethodCallEvent gained an optional actionTimeStamp), not when it returned.

No change to event queues, queue sizes or overflow events (CTT Auditing group).

Tests

  • Opc.Ua.Server.Tests/Diagnostics/ServiceAuditEnvelopeTests (in-process StandardServer with a capturing sink): Read/HistoryRead/Write/HistoryUpdate/Call faults → exactly one AuditEventType with SourceName, Status, ActionTimeStamp, ServerId, ClientAuditEntryId, ClientUserId; TransferSubscriptions fault; CloseSession fault (table); Browse/CreateMonitoredItems/Publish/AddNodes/Cancel → no generic event; AddNodes fault → only AuditAddNodesEventType; Cancel success → one AuditCancelEventType; successful Read → nothing; audit events reported as plain events reach the sink, plain events do not; auditing off → nothing at all; an audit event through two root notifiers reaches the sink once (sync and async), an independent publication again; ReportEventAsync with a waiting composite sink does not complete synchronously and is cancelled by the token; a session fault after a simulated reactivation names the original user.
  • UserManagementBindingTests.Audit: four methods → four AuditUpdateMethodEventType with the fields, no password in arguments; denied call → Status false with the caller's ClientUserId; auditing off → nothing; a throwing provider → Status false then rethrow; an argument-validation reject through MethodState.CallAsync → Status false without arguments and the handler never runs; ActionTimeStamp ≤ handler entry.
  • KeyCredential/KeyCredentialPushAuditTests: Create/Update/Delete → AuditUpdateMethod / KeyCredentialUpdated / KeyCredentialDeleted with ResourceUri and redacted secret; denied update → Status false; auditing off → nothing. A throwing store → Status false, ResourceUri, redacted secret; argument-validation rejects of Create/Update/Delete → their own types, Status false, ResourceUri on Update/Delete, no arguments.
  • Local runs (net10.0): Opc.Ua.Server.Tests 12575 passed (after review fixes) / 8 failed (the PhysicalFileSystemProvider symlink tests, environmental) / 7 skipped; Opc.Ua.Gds.Tests 3049 passed / 0 failed / 56 skipped (a first run overlapped RT-6's GDS run and showed the known 241 shared-PKI failures; the isolated rerun is clean); Opc.Ua.Core.Security.Tests ~Audit 95 passed / 0 failed. net48 builds Opc.Ua.Server, Opc.Ua.Server.Tests and Opc.Ua.Gds.Server with 0 warnings.

🤖 Generated with Claude Code

romanett and others added 2 commits November 30, 2026 20:44
The generic service-failure audit is now a property of the StandardServer
service envelope instead of a callback each service opts into. On a service
fault, while Auditing is on, the envelope reports the service's specific
fault audit (NodeManagement, Cancel: their events carry the request) or
else the generic one for its service set (OPC 10000-4 6.5):

- Read/HistoryRead/Write/HistoryUpdate: AuditEventType, Attribute/<Service>
- Call: AuditEventType, Method/Call
- CloseSession: AuditSessionEventType, Status false (new)
- TransferSubscriptions: AuditSessionEventType, SourceNode = session (new)
- Cancel: AuditCancelEventType with the fault status (new)
- View/Query/MonitoredItem/Subscription: none (6.5.10)

The success path is unchanged and does no audit work.

ServerInternalData.ReportEvent/ReportEventAsync now hand every
AuditEventState to the IAuditEventSink (dropped while Auditing is off), so
a host sink also sees the audit events node managers raise (conditions,
programs, ConfigurationUpdated). The default sink keeps the address-space
publication and the async path unchanged.

Adds AuditEvents.ReportAuditMethodCallEvent, a shared helper for
AuditUpdateMethodEventType and its subtypes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ush (SS-6)

- UserManagement AddUser/ModifyUser/RemoveUser/ChangePassword raise one
  AuditUpdateMethodEventType each, on success and failure (incl. denied
  calls); OPC 10000-18 defines no specific type. Passwords are replaced by
  a null Variant.
- KeyCredential push (OPC 10000-12 8.6): UpdateCredential raises
  KeyCredentialUpdatedAuditEventType, DeleteCredential
  KeyCredentialDeletedAuditEventType, both with ResourceUri;
  CreateCredential an AuditUpdateMethodEventType. The credential secret is
  redacted. GetEncryptingKey only reads and is not audited. The audit
  wrappers live in a new partial file; KeyCredentialPushSubject.cs only
  changes its three wiring lines and gains `partial`.
- RoleStateBinding: one audit site per method instead of two (denied and
  completed calls share the exit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:02
@romanett romanett changed the title Server: audit in the service envelope, specific audits for user management and KeyCredential push (SS-6) Server: audit in the service envelope, specific audits for user management and KeyCredential push Dec 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Composite audit delivery can block on full channels and lose cancellation, while other unresolved issues cause missing, duplicate, or incorrectly attributed audit records.

6 open issues
What changed in this PR

Extends the server audit infrastructure introduced in #5130 and #5187, centralizing service-fault reporting and adding user-management and KeyCredential method audits.

Changes:

  • Consolidates service-fault auditing and adds failure events for CloseSession, Cancel, and TransferSubscriptions.
  • Adds method audits with secret redaction and consolidates role-management audit sites.
  • Routes node-originated audit events through the configured sink and adds regression coverage.
File Description
tests/​Opc.Ua.Server.Tests/​UserManagementBindingTests.cs Makes the fixture partial for audit tests.
tests/​Opc.Ua.Server.Tests/​UserManagementBindingTests.Audit.cs Tests user-management audits, password redaction, and auditing-off behavior.
tests/​Opc.Ua.Server.Tests/​KeyCredential/​KeyCredentialPushAuditTests.cs Tests credential audit types, fields, redaction, and denied calls.
tests/​Opc.Ua.Server.Tests/​Diagnostics/​ServiceAuditEnvelopeTests.cs Tests service-fault audits, sink routing, and auditing-off behavior.
src/​Opc.Ua.Server/​Server/​StandardServer.cs Centralizes fault-audit selection and adds session-service failure reporting.
src/​Opc.Ua.Server/​Server/​ServerInternalData.cs Routes audit events through the configured sink.
src/​Opc.Ua.Server/​RoleBasedUserManagement/​UserManagement/​UserManagementBinding.cs Wraps user-management handlers with redacted audit reporting.
src/​Opc.Ua.Server/​RoleBasedUserManagement/​RoleStateBinding.cs Consolidates each role method’s audit reporting into one site.
src/​Opc.Ua.Server/​KeyCredential/​KeyCredentialPushSubject.cs Connects credential methods to audited wrappers.
src/​Opc.Ua.Server/​KeyCredential/​KeyCredentialPushSubject.Audit.cs Implements credential audit wrappers and secret redaction.
src/​Opc.Ua.Server/​Diagnostics/​AuditEvents.cs Adds session-fault and reusable method-audit helpers.

Review effort: Balanced

…s, rejected calls)

- IAsyncAuditEventSink: the default and composite sinks publish asynchronously,
  so ReportEventAsync of an audit event never blocks on a full event channel and
  observes the caller's cancellation, with or without a host sink.
- An audit event that reaches the server through several root notifiers in one
  publication is delivered to the sink once (NodeState propagation visit).
- Session-service fault audits name the user captured with the request.
- Method audits record the ActionTimeStamp when the call started.
- UserManagement and KeyCredential calls whose handler throws, or that MethodState
  rejects in argument validation, are audited as failures (no unvalidated arguments).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code coverage

✅ Coverage gate passed.

Check Result Threshold
✅ Project line rate 89.51% (515633/576062 lines) >= 70.00%
✅ Project branch rate 80.15% >= 60.00%
✅ Patch coverage 91.42% (309/338 changed lines) >= 75.00% (> 100 changed lines)
ℹ️ Baseline delta (advisory) +15.91 pp 73.60% recorded
Uncovered changed lines
  • src/Opc.Ua.Server/Server/ServerInternalData.cs: 1350, 1385
  • src/Opc.Ua.Server/RoleBasedUserManagement/UserManagement/UserManagementBinding.cs: 214, 216, 217, 253, 255, 256, 287, 289, 290
  • src/Opc.Ua.Server/Diagnostics/AuditEvents.cs: 1792, 1821, 1834, 1836, 1837, 1887, 1921, 1923, 1924
  • src/Opc.Ua.Server/KeyCredential/KeyCredentialPushSubject.Audit.cs: 63, 65, 66, 124, 126, 127
  • src/Opc.Ua.Server/Diagnostics/IAuditEventSink.cs: 193, 200, 202

Coverage is above the recorded baseline - consider ratcheting coverage-thresholds.json.

Thresholds live in coverage-thresholds.json. Whole report before exclusions: line 89.06%, branch 79.67%.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Audit events can still misattribute an anonymous request to a later authenticated user because the captured null client identity does not overwrite the live session identity.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Anonymous caller audit attribution can use the reactivated session user

src/​Opc.Ua.Server/​Diagnostics/​AuditEvents.cs:1821

The anonymous-caller case still retains the session's current identity. OperationContext.ClientUserId legitimately captures null for an anonymous request, but InitializeAuditSessionEvent has already populated this field from the live session. If that session is reactivated as a named user before CloseSession or TransferSubscriptions fails, this condition skips the overwrite and attributes the anonymous request to the new user. Always assign the captured value, including null, and extend the reactivation regression test to cover an initially anonymous caller.

6 resolved since last review

Review effort: Balanced

… (SS-6 review)

The captured ClientUserId of the request always replaces the session's live one, so
an anonymous request is not attributed to a user the session was reactivated under.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed to weigh repository-convention concerns involving logging, sync-over-async in a test, and locking in the test sink.

No open issues 🎉

Review effort: Balanced

…t sink (SS-6 review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.35294% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.86%. Comparing base (aa5f140) to head (3ec7274).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/Opc.Ua.Server/Diagnostics/AuditEvents.cs 75.86% 9 Missing and 5 partials ⚠️
...Management/UserManagement/UserManagementBinding.cs 86.41% 9 Missing and 2 partials ⚠️
...er/KeyCredential/KeyCredentialPushSubject.Audit.cs 91.48% 6 Missing and 2 partials ⚠️
src/Opc.Ua.Server/Diagnostics/IAuditEventSink.cs 64.28% 3 Missing and 2 partials ⚠️
src/Opc.Ua.Server/Server/ServerInternalData.cs 87.87% 2 Missing and 2 partials ⚠️
src/Opc.Ua.Server/Server/StandardServer.cs 97.14% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5226      +/-   ##
==========================================
- Coverage   83.87%   83.86%   -0.02%     
==========================================
  Files        3879     3880       +1     
  Lines      575722   576062     +340     
  Branches    99270    99313      +43     
==========================================
+ Hits       482903   483125     +222     
- Misses      60122    60207      +85     
- Partials    32697    32730      +33     
Flag Coverage Δ
actions 83.86% <87.35%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...a.Server/KeyCredential/KeyCredentialPushSubject.cs 75.39% <100.00%> (+0.23%) ⬆️
...Server/RoleBasedUserManagement/RoleStateBinding.cs 87.19% <100.00%> (+2.35%) ⬆️
...c/Opc.Ua.Types/State/NodeState.EventPropagation.cs 100.00% <100.00%> (ø)
src/Opc.Ua.Server/Server/StandardServer.cs 90.64% <97.14%> (+0.09%) ⬆️
src/Opc.Ua.Server/Server/ServerInternalData.cs 90.36% <87.87%> (+0.37%) ⬆️
src/Opc.Ua.Server/Diagnostics/IAuditEventSink.cs 86.04% <64.28%> (-10.51%) ⬇️
...er/KeyCredential/KeyCredentialPushSubject.Audit.cs 91.48% <91.48%> (ø)
...Management/UserManagement/UserManagementBinding.cs 91.24% <86.41%> (-2.17%) ⬇️
src/Opc.Ua.Server/Diagnostics/AuditEvents.cs 88.74% <75.86%> (-0.57%) ⬇️

... and 80 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier
marcschier merged commit c1ffa3b into master Dec 1, 2026
245 of 247 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants