Documentation
¶
Index ¶
Constants ¶
const ( AppsecFieldTag = "ddwaf" AppsecFieldTagValueIgnore = "ignore" )
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load loads libddwaf's dynamic library. The dynamic library is opened only once by the first call to this function and internally stored globally. No function is currently provided in this API to unload it.
This function is automatically called by NewBuilder, and most users need not explicitly call it. It is however useful in order to explicitly check for the status of the WAF library's initialization.
The function returns true when libddwaf was successfully loaded, along with an error value. An error might still be returned even though the WAF load was successful: in such cases the error is indicative that some non-critical features are not available; but the WAF may still be used.
func Usable ¶
Usable returns true if the WAF is usable, false and an error otherwise.
If the WAF is usable, an error value may still be returned and should be treated as a warning (it is non-blocking).
The following conditions are checked:
- The WAF library has been loaded successfully (you need to call Load first for this case to be taken into account)
- The WAF library has not been manually disabled with the `datadog.no_waf` go build tag
- The WAF library is not in an unsupported OS/Arch
- The WAF library is not in an unsupported Go version
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder manages an evolving WAF configuration over time. Its lifecycle is typically tied to that of a remote configuration client, as its purpose is to keep an up-to-date view of the current coniguration with low overhead. This type is not safe for concurrent use, and users should protect it with a mutex or similar when sharing it across multiple goroutines. All methods of this type are safe to call with a nil receiver.
func NewBuilder ¶
NewBuilder creates a new Builder instance. Its lifecycle is typically tied to that of a remote configuration client, as its purpose is to keep an up-to-date view of the current coniguration with low overhead. Returns nil if an error occurs when initializing the builder. The caller is responsible for calling Builder.Close when the builder is no longer needed.
func (*Builder) AddOrUpdateConfig ¶
func (b *Builder) AddOrUpdateConfig(path string, fragment any) (Diagnostics, error)
AddOrUpdateConfig adds or updates a configuration fragment to this Builder. Returns the Diagnostics produced by adding or updating this configuration.
func (*Builder) Build ¶
Build creates a new Handle instance that uses the current configuration. Returns nil if an error occurs when building the handle. The caller is responsible for calling Handle.Close when the handle is no longer needed. This function may return nil.
func (*Builder) Close ¶
func (b *Builder) Close()
Close releases all resources associated with this builder.
func (*Builder) ConfigPaths ¶
ConfigPaths returns the list of currently loaded configuration paths.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a WAF execution context. It allows running the WAF incrementally when calling it multiple times to run its rules every time new addresses become available. Each request must have its own Context. New Context instances can be created by calling Handle.NewContext.
func (*Context) Close ¶
func (context *Context) Close()
Close disposes of the underlying `ddwaf_context` and releases the associated internal data. It also decreases the reference count of the Handle which created this Context, possibly releasing it completely (if this was the last Context created from it, and it is no longer in use by its creator).
func (*Context) Run ¶
func (context *Context) Run(addressData RunAddressData) (res Result, err error)
Run encodes the given RunAddressData values and runs them against the WAF rules. Callers must check the returned Result object even when an error is returned, as the WAF might have been able to match some rules and generate events or actions before the error was reached; especially when the error is waferrors.ErrTimeout.
type Diagnostics ¶
type Diagnostics struct {
// Rules contains information about the loaded rules.
Rules *Feature
// CustomRules contains information about the loaded custom rules.
CustomRules *Feature
// Actions contains information about the loaded actions.
Actions *Feature
// Exclusions contains information about the loaded exclusions.
Exclusions *Feature
// RulesOverrides contains information about the loaded rules overrides.
RulesOverrides *Feature
// RulesData contains information about the loaded rules data.
RulesData *Feature
// ExclusionData contains information about the loaded exclusion data.
ExclusionData *Feature
// Processors contains information about the loaded processors.
Processors *Feature
// Scanners contains information about the loaded scanners.
Scanners *Feature
// Version is the version of the parsed ruleset if available.
Version string
}
Diagnostics stores the information as provided by the WAF about WAF rules parsing and loading. It is returned by Builder.AddOrUpdateConfig.
func (*Diagnostics) EachFeature ¶
func (d *Diagnostics) EachFeature(cb func(string, *Feature))
EachFeature calls the provided callback for each (non-nil) feature in this diagnostics object.
func (*Diagnostics) TopLevelError ¶
func (d *Diagnostics) TopLevelError() error
TopLevelError returns the list of top-level errors reported by the WAF on any of the Diagnostics entries, rolled up into a single error value. Returns nil if no top-level errors were reported. Individual, item-level errors might still exist.
type Feature ¶
type Feature struct {
// Errors is a map of parsing errors to a list of unique identifiers from the elements which
// failed loading due to this specific error.
Errors map[string][]string
// Warnings is a map of parsing warnings to a list of unique identifiers from the elements which
// resulted in this specific warning.
Warnings map[string][]string
// Error is the single error which prevented parsing this feature.
Error string
// Loaded is a list of the unique identifiers from successfully loaded elements.
Loaded []string
// Failed is a list of the unique identifiers from the elements which couldn't be loaded.
Failed []string
// Skipped is a list of the unique identifiers from the elements which were skipped.
Skipped []string
}
Feature stores the information as provided by the WAF about loaded and failed rules for a specific feature of the WAF ruleset.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle represents an instance of the WAF for a given ruleset. It is obtained from Builder.Build; and must be disposed of by calling Handle.Close once no longer in use.
func (*Handle) Actions ¶
Actions returns the list of actions the WAF has been configured to monitor based on the input ruleset.
func (*Handle) Addresses ¶
Addresses returns the list of addresses the WAF has been configured to monitor based on the input ruleset.
type Result ¶
type Result struct {
// Events is the list of events the WAF detected, together with any relevant
// details. These are typically forwarded as opaque objects to the Datadog
// backend.
Events []any
// Derivatives is the set of key-value pairs generated by the WAF, and which
// need to be reported on the trace to provide additional data to the Datadog
// backend.
Derivatives map[string]any
// Actions is the set of actions the WAF decided on when evaluating rules
// against the provided address data. It maps action types to their dynamic
// parameter values.
Actions map[string]any
// TimeSpent is the time the WAF self-reported as spent processing the call to
// [Context.Run].
TimeSpent time.Duration
}
Result stores the multiple values returned by a call to Context.Run.
func (*Result) HasActions ¶
HasActions return true if the Result holds at least 1 action.
func (*Result) HasDerivatives ¶
HasDerivatives return true if the Result holds at least 1 derivative.
type RunAddressData ¶
type RunAddressData struct {
// Persistent address data is scoped to the lifetime of a given Context, and subsquent calls to
// [Context.Run] with the same address name will be silently ignored.
Persistent map[string]any
// Ephemeral address data is scoped to a given [Context.Run] call and is not persisted across
// calls. This is used for protocols such as gRPC client/server streaming or GraphQL, where a
// single request can incur multiple subrequests.
Ephemeral map[string]any
// Scope is the way to classify the different runs in the same context in order to have different
// metrics.
Scope Scope
}
RunAddressData provides address data to the Context.Run method. If a given key is present in both [RunAddressData.Persistent] and [RunAddressData.Ephemeral], the value from [RunAddressData.Persistent] will take precedence. When encoding Go structs to the WAF-compatible format, fields with the `ddwaf:"ignore"` tag are ignored and will not be visible to the WAF.
type Scope ¶
type Scope string
Scope is the way to classify the different runs in the same context in order to have different metrics
type Stats ¶
type Stats struct {
// Timers returns a map of metrics and their durations.
Timers map[string]time.Duration
// TimeoutCount for the Default Scope i.e. "waf"
TimeoutCount uint64
// TimeoutRASPCount for the RASP Scope i.e. "rasp"
TimeoutRASPCount uint64
// Truncations provides details about truncations that occurred while
// encoding address data for WAF execution.
Truncations map[TruncationReason][]int
// TruncationsRASP provides details about truncations that occurred while
// encoding address data for RASP execution.
TruncationsRASP map[TruncationReason][]int
}
Stats stores the metrics collected by the WAF.
type TruncationReason ¶
type TruncationReason uint8
TruncationReason is a flag representing reasons why some input was not encoded in full.
const ( // StringTooLong indicates a string exceeded the maximum string length configured. The truncation // values indicate the actual length of truncated strings. StringTooLong TruncationReason = 1 << iota // ContainerTooLarge indicates a container (list, map, struct) exceeded the maximum number of // elements configured. The truncation values indicate the actual number of elements in the // truncated container. ContainerTooLarge // ObjectTooDeep indicates an overall object exceeded the maximum encoding depths configured. The // truncation values indicate an estimated actual depth of the truncated object. The value is // guaranteed to be less than or equal to the actual depth (it may not be more). ObjectTooDeep )
func (TruncationReason) String ¶
func (reason TruncationReason) String() string