otlpaudit

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 1

README

OpenTelemetry Event Library

Go library for creating and sending audit log events to OpenTelemetry collector using HTTP requests.

Dependencies

  • go 1.23 or higher
  • Working OpenTelemetry collector instance with a HTTP receiver

How to use

Configuration

Configuration is being read from config.yaml file. The consumers should use LoadConfig function provided within common package to load and unmarshal configuration into a struct to be used by consumers. The section related to this library in consumer's config should look like this:

audit:
  endpoint: "<YOUR_ENDPOINT>"
  # potential auth config

The library allows two ways of authenticating against the target endpoint: mTLS and Basic Auth. If needed, they should be configured within the config.yaml. Please note that only one authenticating method can be implemented at a time. If both are provided, mTLS is prioritized. Example config snippets:

  basicAuth:
    username:
      source: file
      file:
        path: <JSON_FILE>
        format: json
        jsonPath: "$.<KEY_FOR_USERNAME_IN_JSONFILE>"
    password:
      source: file
      file:
        path: <JSON_FILE>
        format: json
        jsonPath: "$.<KEY_FOR_PASSWORD_IN_JSONFILE>"
   mtls:
    cert:
      source: file
      file:
        path: <JSON_FILE>
        format: json
        jsonPath: "$.<KEY_FOR_CERT_IN_JSONFILE>"
    certKey:
      source: file
      file:
        path: <JSON_FILE>
        format: json
        jsonPath: "$.<KEY_FOR_KEY_IN_JSONFILE>"
    serverCa:
      source: file
      file:
        path: <JSON_FILE>
        format: json
        jsonPath: "$.<KEY_FOR_SERVERCA_IN_JSONFILE>"

All of the secrets for Basic Auth and mTLS are defined as SourceRef - see common package for more info.

Event creation and sending

To use the library, consuming service must first instantiate a new audit logger using the config data, create event object and call the sending function to dispatch event.

Creating events

To create the event use one of provided New<EVENT_TYPE>Event(eventMetadata EventMetadata, args ...) (plog.Logs, error) functions. For each type it expects a EventMetadata object - it contains fields shared across each event type. To create one, use NewEventMetadata(userInitiatorID, tenantID, eventCorrelationID string) (userInitiatorID and tenantID are mandatory).

Sending events

Created event should be passed to SendEvent function that takes care of dispatching the event to collector defined in the config.

Full set of calls on the consumer side would look like for example like this:

auditLogger, _ := otlpaudit.NewLogger(&cfg.Audit)
eventMetadata, _ := otlpaudit.NewEventMetadata("userInitID", "tenantID", "eventCorrelationID")
event, _ := otlpaudit.NewCmkCreateEvent(eventMetadata, "cmkID")
auditLogger.SendEvent(ctx, event) 
Additional Properties

There is also a functionality of additional properties introduced that allow to add properties to OTLP logs separate from those belonging to specific event types. Please keep in mind that they'll be propagated to every event. The additional properties are loaded via config as a literal:

additionalProperties: |
    property1: x
    property2: y

Event catalog

Event type Function signature
keyCreate NewKeyCreateEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyDelete NewKeyDeleteEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyRestore NewKeyRestoreEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyPurge NewKeyPurgeEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyRotate NewKeyRotateEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyEnable NewKeyEnableEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
keyDisable NewKeyDisableEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType)
workflowStart NewWorkflowStartEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool)
workflowUpdate NewWorkflowUpdateEvent(metadata EventMetadata, objectID string, oldValue, newValue any, dpp bool)
workflowExecute NewWorkflowExecuteEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool)
workflowTerminate NewWorkflowTerminateEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool)
groupCreate NewGroupCreateEvent(metadata EventMetadata, objectID string, value any, dpp bool)
groupRead NewGroupReadEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool)
groupDelete NewGroupDeleteEvent(metadata EventMetadata, objectID string, value any, dpp bool)
groupUpdate NewGroupUpdateEvent(metadata EventMetadata, objectID, propertyName string, oldValue, newValue any, dpp bool)
userLoginSuccess NewUserLoginSuccessEvent(metadata EventMetadata, objectID string, l LoginMethod, t MfaType, u UserType, value any)
userLoginFailure NewUserLoginFailureEvent(metadata EventMetadata, objectID string, l LoginMethod, f FailReason, value any)
tenantOnboarding NewTenantOnboardingEvent(metadata EventMetadata, tenantID string)
tenantOffboarding NewTenantOffboardingEvent(metadata EventMetadata, tenantID string)
tenantUpdate NewTenantUpdateEvent(metadata EventMetadata, objectID, propertyName string, t TenantUpdateActionType, oldValue, newValue any)
configurationCreate NewConfigurationCreateEvent(metadata EventMetadata, objectID string, value any)
configurationRead NewConfigurationUpdateEvent(metadata EventMetadata, objectID string, oldValue, newValue any) `
configurationDelete NewConfigurationDeleteEvent(metadata EventMetadata, objectID string, value any)
configurationUpdate NewConfigurationReadEvent(metadata EventMetadata, objectID, channelType, channelID string, value any)
credentialCreate NewCredentialCreateEvent(metadata EventMetadata, credentialID string, c CredentialType)
credentialExpiration NewCredentialExpirationEvent(metadata EventMetadata, credentialID string, c CredentialType)
credentialDelete NewCredentialDeleteEvent(metadata EventMetadata, credentialID string, c CredentialType)
credentialRevokation NewCredentialRevokationEvent(metadata EventMetadata, credentialID string, c CredentialType)
cmkOnboarding NewCmkOnboardingEvent(metadata EventMetadata, cmkID, systemID string)
cmkOffboarding NewCmkOffboardingEvent(metadata EventMetadata, cmkID, systemID string)
cmkSwitch NewCmkSwitchEvent(metadata EventMetadata, cmkID, cmkIDOld, cmkIDNew string)
cmkTenantModification NewCmkTenantModificationEvent(metadata EventMetadata, cmkID, systemID string, c CmkAction)
cmkTenantDelete NewCmkTenantDeleteEvent(metadata EventMetadata, cmkID string)
cmkCreate NewCmkCreateEvent(metadata EventMetadata, cmkID string)
cmkDelete NewCmkDeleteEvent(metadata EventMetadata, cmkID string)
cmkDetach NewCmkDetachEvent(metadata EventMetadata, cmkID string, systemID string)
cmkRestore NewCmkRestoreEvent(metadata EventMetadata, cmkID string)
cmkEnable NewCmkEnableEvent(metadata EventMetadata, cmkID string)
cmkDisable NewCmkDisableEvent(metadata EventMetadata, cmkID string)
cmkRotate NewCmkRotateEvent(metadata EventMetadata, cmkID string)
cmkAvailable NewCmkAvailableEvent(metadata EventMetadata, cmkID string)
cmkUnavailable NewCmkUnavailableEvent(metadata EventMetadata, cmkID string)
unauthenticatedRequest NewUnauthenticatedRequestEvent(metadata EventMetadata)
unauthorizedRequest NewUnauthorizedRequestEvent(metadata EventMetadata, resource string, action string)

All the enums in the functions above are provided within this library. For every enum values can be empty (it will be set to UNSPECIFIED), but if they are provided they must match the enums defined in this library, otherwise there will be an error. All *value properties are optional with the exception of ones present in event types: tenantUpdate, configurationCreate, configurationRead, configurationDelete and configurationUpdate. All other properties are considered required.

Documentation

Index

Constants

View Source
const (
	ConfigCreateEvent           = "configurationCreate"
	ConfigReadEvent             = "configurationRead"
	ConfigUpdateEvent           = "configurationUpdate"
	ConfigDeleteEvent           = "configurationDelete"
	GroupCreateEvent            = "groupCreate"
	GroupReadEvent              = "groupRead"
	GroupUpdateEvent            = "groupUpdate"
	GroupDeleteEvent            = "groupDelete"
	KeyCreateEvent              = "keyCreate"
	KeyDeleteEvent              = "keyDelete"
	KeyRestoreEvent             = "keyRestore"
	KeyPurgeEvent               = "keyPurge"
	KeyRotateEvent              = "keyRotate"
	KeyEnableEvent              = "keyEnable"
	KeyDisableEvent             = "keyDisable"
	WorkflowStartEvent          = "workflowStart"
	WorkflowUpdateEvent         = "workflowUpdate"
	WorkflowExecuteEvent        = "workflowExecute"
	WorkflowTerminateEvent      = "workflowTerminate"
	UserLoginSuccessEvent       = "userLoginSuccess"
	UserLoginFailureEvent       = "userLoginFailure"
	TenantOnboardingEvent       = "tenantOnboarding"
	TenantOffboardingEvent      = "tenantOffboarding"
	TenantUpdateEvent           = "tenantUpdate"
	CredentialExpirationEvent   = "credentialExpiration"
	CredentialCreateEvent       = "credentialCreate"
	CredentialRevokationEvent   = "credentialRevokation"
	CredentialDeleteEvent       = "credentialDelete"
	CmkOnboardingEvent          = "cmkOnboarding"
	CmkOffboardingEvent         = "cmkOffboarding"
	CmkSwitchEvent              = "cmkSwitch"
	CmkTenantModificationEvent  = "cmkTenantModification"
	CmkTenantDeleteEvent        = "cmkTenantDelete"
	CmkCreateEvent              = "cmkCreate"
	CmkDeleteEvent              = "cmkDelete"
	CmkDetachEvent              = "cmkDetach"
	CmkRestoreEvent             = "cmkRestore"
	CmkEnableEvent              = "cmkEnable"
	CmkDisableEvent             = "cmkDisable"
	CmkRotateEvent              = "cmkRotate"
	CmkAvailableEvent           = "cmkAvailable"
	CmkUnavailableEvent         = "cmkUnavailable"
	UnauthorizedRequestEvent    = "unauthorizedRequest"
	UnauthenticatedRequestEvent = "unauthenticatedRequest"
)
View Source
const (
	EventTypeKey          = "eventType"
	ObjectIDKey           = "objectID"
	ObjectTypeKey         = "objectType"
	ActionTypeKey         = "actionType"
	ChannelTypeKey        = "channelType"
	ChannelIDKey          = "channelID"
	LoginMethodKey        = "loginMethod"
	MfaTypeKey            = "mfaType"
	UserTypeKey           = "userType"
	FailureReasonKey      = "failureReason"
	CredentialTypeKey     = "credentialType"
	ValueKey              = "value"
	PropertyNameKey       = "propertyName"
	OldValueKey           = "oldValue"
	NewValueKey           = "newValue"
	DppKey                = "dpp"
	UserInitiatorIDKey    = "userInitiatorID"
	TenantIDKey           = "tenantID"
	EventCorrelationIDKey = "eventCorrelationID"
	SystemIDKey           = "systemID"
	CmkIDKey              = "cmkID"
	CmkIDOldKey           = "cmkIDOld"
	CmkIDNewKey           = "cmkIDNew"
	ResourceKey           = "resource"
	ActionKey             = "action"
)
View Source
const UNSPECIFIED = "UNSPECIFIED"

Variables

This section is empty.

Functions

func NewCmkAvailableEvent added in v1.5.0

func NewCmkAvailableEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkCreateEvent added in v0.2.2

func NewCmkCreateEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkDeleteEvent added in v0.3.0

func NewCmkDeleteEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkDetachEvent added in v1.7.0

func NewCmkDetachEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkDisableEvent added in v0.2.2

func NewCmkDisableEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkEnableEvent added in v0.2.2

func NewCmkEnableEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkOffboardingEvent added in v0.2.2

func NewCmkOffboardingEvent(metadata EventMetadata, cmkID, systemID string) (plog.Logs, error)

func NewCmkOnboardingEvent added in v0.2.2

func NewCmkOnboardingEvent(metadata EventMetadata, cmkID, systemID string) (plog.Logs, error)

func NewCmkRestoreEvent added in v0.2.2

func NewCmkRestoreEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkRotateEvent added in v0.2.2

func NewCmkRotateEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkSwitchEvent added in v0.2.2

func NewCmkSwitchEvent(metadata EventMetadata, systemID, cmkIDOld, cmkIDNew string) (plog.Logs, error)

func NewCmkTenantDeleteEvent added in v1.7.0

func NewCmkTenantDeleteEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewCmkTenantModificationEvent added in v0.2.2

func NewCmkTenantModificationEvent(metadata EventMetadata, cmkID, systemID string, c CmkAction) (plog.Logs, error)

func NewCmkUnavailableEvent added in v1.5.0

func NewCmkUnavailableEvent(metadata EventMetadata, cmkID string) (plog.Logs, error)

func NewConfigurationCreateEvent

func NewConfigurationCreateEvent(metadata EventMetadata, objectID string, value any) (plog.Logs, error)

func NewConfigurationDeleteEvent

func NewConfigurationDeleteEvent(metadata EventMetadata, objectID string, value any) (plog.Logs, error)

func NewConfigurationReadEvent

func NewConfigurationReadEvent(metadata EventMetadata, objectID, channelType, channelID string, value any) (plog.Logs, error)

func NewConfigurationUpdateEvent

func NewConfigurationUpdateEvent(metadata EventMetadata, objectID string, oldValue, newValue any) (plog.Logs, error)

func NewCredentialCreateEvent

func NewCredentialCreateEvent(metadata EventMetadata, credentialID string, c CredentialType) (plog.Logs, error)

func NewCredentialDeleteEvent

func NewCredentialDeleteEvent(metadata EventMetadata, credentialID string, c CredentialType) (plog.Logs, error)

func NewCredentialExpirationEvent

func NewCredentialExpirationEvent(metadata EventMetadata, credentialID string, c CredentialType) (plog.Logs, error)

func NewCredentialRevokationEvent

func NewCredentialRevokationEvent(metadata EventMetadata, credentialID string, c CredentialType) (plog.Logs, error)

func NewGroupCreateEvent

func NewGroupCreateEvent(metadata EventMetadata, objectID string, value any, dpp bool) (plog.Logs, error)

func NewGroupDeleteEvent

func NewGroupDeleteEvent(metadata EventMetadata, objectID string, value any, dpp bool) (plog.Logs, error)

func NewGroupReadEvent

func NewGroupReadEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool) (plog.Logs, error)

func NewGroupUpdateEvent

func NewGroupUpdateEvent(metadata EventMetadata, objectID, propertyName string, oldValue, newValue any, dpp bool) (plog.Logs, error)

func NewKeyCreateEvent

func NewKeyCreateEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyDeleteEvent

func NewKeyDeleteEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyDisableEvent added in v0.2.2

func NewKeyDisableEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyEnableEvent added in v0.2.2

func NewKeyEnableEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyPurgeEvent added in v0.2.2

func NewKeyPurgeEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyRestoreEvent added in v0.2.2

func NewKeyRestoreEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewKeyRotateEvent added in v0.2.2

func NewKeyRotateEvent(metadata EventMetadata, objectID, systemID, cmkID string, t KeyType) (plog.Logs, error)

func NewTenantOffboardingEvent

func NewTenantOffboardingEvent(metadata EventMetadata, tenantID string) (plog.Logs, error)

func NewTenantOnboardingEvent

func NewTenantOnboardingEvent(metadata EventMetadata, tenantID string) (plog.Logs, error)

func NewTenantUpdateEvent

func NewTenantUpdateEvent(metadata EventMetadata, objectID, propertyName string, oldValue, newValue any) (plog.Logs, error)

func NewUnauthenticatedRequestEvent added in v0.5.0

func NewUnauthenticatedRequestEvent(metadata EventMetadata) (plog.Logs, error)

func NewUnauthorizedRequestEvent added in v0.5.0

func NewUnauthorizedRequestEvent(metadata EventMetadata, resource, action string) (plog.Logs, error)

func NewUserLoginFailureEvent

func NewUserLoginFailureEvent(metadata EventMetadata, objectID string, l LoginMethod, f FailReason, value any) (plog.Logs, error)

func NewUserLoginSuccessEvent

func NewUserLoginSuccessEvent(metadata EventMetadata, objectID string, l LoginMethod, t MfaType, u UserType, value any) (plog.Logs, error)

func NewWorkflowExecuteEvent

func NewWorkflowExecuteEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool) (plog.Logs, error)

func NewWorkflowStartEvent

func NewWorkflowStartEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool) (plog.Logs, error)

func NewWorkflowTerminateEvent

func NewWorkflowTerminateEvent(metadata EventMetadata, objectID, channelID, channelType string, value any, dpp bool) (plog.Logs, error)

func NewWorkflowUpdateEvent

func NewWorkflowUpdateEvent(metadata EventMetadata, objectID string, oldValue, newValue any, dpp bool) (plog.Logs, error)

Types

type AuditLogger added in v0.2.2

type AuditLogger struct {
	// contains filtered or unexported fields
}

func NewLogger added in v0.2.2

func NewLogger(config *commoncfg.Audit) (*AuditLogger, error)

func (*AuditLogger) SendEvent added in v0.2.2

func (auditLogger *AuditLogger) SendEvent(ctx context.Context, logs plog.Logs) error

type CmkAction added in v0.2.2

type CmkAction string
const (
	CMKACTION_ONBOARD      CmkAction = "ONBOARD"
	CMKACTION_BLOCK        CmkAction = "BLOCK"
	CMKACTION_SHUTDOWN     CmkAction = "SHUTDOWN"
	CMKACTION_CSEKFALLBACK CmkAction = "CSEKFALLBACK"
	CMKACTION_RESTORE      CmkAction = "RESTORE"
)

func (CmkAction) IsValid added in v0.2.2

func (c CmkAction) IsValid() bool

type CredentialType

type CredentialType string
const (
	CREDTYPE_X509CERT CredentialType = "X509_CERTIFICATE"
	CREDTYPE_KEY      CredentialType = "KEY"
	CREDTYPE_SECRET   CredentialType = "SECRET"
)

func (CredentialType) IsValid

func (c CredentialType) IsValid() bool

type EventMetadata

type EventMetadata map[string]string

func NewEventMetadata

func NewEventMetadata(userInitiatorID, tenantID, eventCorrelationID string) (EventMetadata, error)

type FailReason

type FailReason string
const (
	FAILREASON_PASSWORD        FailReason = "PASSWORD"
	FAILREASON_MFAFAIL         FailReason = "MFA_FAILED"
	FAILREASON_USERNOTFOUND    FailReason = "USER_NOT_FOUND"
	FAILREASON_USERLOCKED      FailReason = "USER_LOCKED"
	FAILREASON_USERBLOCKED     FailReason = "USER_BLOCKED"
	FAILREASON_USERUNVERIFIED  FailReason = "USER_UNVERIFIED"
	FAILREASON_USEREXPIRED     FailReason = "USER_EXPIRED"
	FAILREASON_USERINVALID     FailReason = "USER_INVALID"
	FAILREASON_INSECURECONNECT FailReason = "INSECURE_CONNECTION"
	FAILREASON_METHODDISABLED  FailReason = "LOGIN_METHOD_DISABLED"
	FAILREASON_TOKENEXPIRED    FailReason = "TOKEN_EXPIRED"
	FAILREASON_TOKENREVOKED    FailReason = "TOKEN_REVOKED"
	FAILREASON_TOKENINVALID    FailReason = "TOKEN_INVALID"
	FAILREASON_SESSIONEXPIRED  FailReason = "SESSION_EXPIRED"
	FAILREASON_SESSIONREVOKED  FailReason = "SESSION_REVOKED"
	FAILREASON_CERTEXPIRED     FailReason = "CERTIFICATE_EXPIRED"
	FAILREASON_CERTREVOKED     FailReason = "CERTIFICATE_REVOKED"
	FAILREASON_CERTINVALID     FailReason = "CERTIFICATE_INVALID"
)

func (FailReason) IsValid

func (r FailReason) IsValid() bool

type KeyCreateActionType

type KeyCreateActionType string

type KeyReadActionType

type KeyReadActionType string

type KeyType added in v0.2.2

type KeyType string
const (
	KEYTYPE_SYSTEM  KeyType = "SYSTEM"
	KEYTYPE_SERVICE KeyType = "SERVICE"
	KEYTYPE_DATA    KeyType = "DATA"
	KEYTYPE_KEK     KeyType = "KEK"
)

func (KeyType) IsValid added in v0.2.2

func (l KeyType) IsValid() bool

type KeyUpdateActionType

type KeyUpdateActionType string

type LoginMethod

type LoginMethod string
const (
	LOGINMETHOD_OPENIDCONNECT LoginMethod = "OPEN_ID_CONNECT"
	LOGINMETHOD_X509CERT      LoginMethod = "X509_CERTIFICATE"
)

func (LoginMethod) IsValid

func (l LoginMethod) IsValid() bool

type MfaType

type MfaType string
const (
	MFATYPE_WEBAUTHN MfaType = "WEB_AUTHN"
	MFATYPE_NONE     MfaType = "NONE"
)

func (MfaType) IsValid

func (l MfaType) IsValid() bool

type TenantUpdateActionType

type TenantUpdateActionType string
const (
	TENANTUPDATE_TESTMODE        TenantUpdateActionType = "TEST_MODE"
	TENANTUPDATE_WORKFLOWENABLE  TenantUpdateActionType = "WORKFLOW_ENABLE"
	TENANTUPDATE_WORKFLOWDISABLE TenantUpdateActionType = "WORKFLOW_DISABLE"
)

func (TenantUpdateActionType) IsValid

func (t TenantUpdateActionType) IsValid() bool

type UserLoginFailureActionType

type UserLoginFailureActionType string

type UserType

type UserType string
const (
	USERTYPE_BUSINESS  UserType = "BUSINESS_USER"
	USERTYPE_TECHNICAL UserType = "TECHNICAL_USER"
)

func (UserType) IsValid

func (u UserType) IsValid() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL