Documentation
¶
Index ¶
- func Health() (bool, error)
- func Load() (ok bool, err error)
- func SupportsTarget() (bool, error)
- func Version() string
- type Context
- type DiagnosticAddresses
- type DiagnosticEntry
- type Diagnostics
- type Handle
- type ManuallyDisabledError
- type PanicError
- type Result
- type RunAddressData
- type RunError
- type UnsupportedGoVersionError
- type UnsupportedOSArchError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Health ¶ added in v2.2.0
Health returns true if the waf is usable, false otherwise. At the same time it can return an error if the waf is not usable, but the error is not blocking if true is returned, otherwise it is. 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
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, and no function is currently provided in this API to close the opened handle. Calling this function is not mandatory and is automatically performed by calls to NewHandle, the entrypoint of libddwaf, but Load is useful in order to explicitly check libddwaf's general health where calling NewHandle doesn't necessarily apply nor is doable. The function returns ok when libddwaf was successfully loaded, along with a non-nil error if any. Note that both ok and err can be set, meaning that libddwaf is usable but some non-critical errors happened, such as failures to remove temporary files. It is safe to continue using libddwaf in such case.
func SupportsTarget ¶
SupportsTarget returns true and a nil error when the target host environment is supported by this package and can be further used. Otherwise, it returns false along with an error detailing why.
Types ¶
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.
func NewContext ¶
NewContext returns a new WAF context of to the given WAF handle. A nil value is returned when the WAF handle was released or when the WAF context couldn't be created. handle. A nil value is returned when the WAF handle can no longer be used or the WAF context couldn't be created.
func (*Context) Close ¶
func (context *Context) Close()
Close calls handle.closeContext which calls ddwaf_context_destroy and maybe also close the handle if it in termination state.
func (*Context) Run ¶
func (context *Context) Run(addressData RunAddressData, timeout time.Duration) (res Result, err error)
Run encodes the given addressData values and runs them against the WAF rules within the given timeout value. If a given address is present both as persistent and ephemeral, the persistent value takes precedence. It returns the matches as a JSON string (usually opaquely used) along with the corresponding actions in any. In case of an error, matches and actions can still be returned, for instance in the case of a timeout error. Errors can be tested against the RunError type.
func (*Context) TotalRuntime ¶
TotalRuntime returns the cumulated WAF runtime across various run calls within the same WAF context. Returned time is in nanoseconds.
func (*Context) TotalTimeouts ¶
TotalTimeouts returns the cumulated amount of WAF timeouts across various run calls within the same WAF context.
type DiagnosticAddresses ¶
DiagnosticAddresses stores the information - provided by the WAF - about the known addresses and whether they are required or optional. Addresses used by WAF rules are always required. Addresses used by WAF exclusion filters may be required or (rarely) optional. Addresses used by WAF processors may be required or optional.
type DiagnosticEntry ¶
type DiagnosticEntry struct {
Addresses *DiagnosticAddresses
Loaded []string // Successfully loaded entity identifiers (or index:#)
Failed []string // Failed entity identifiers (or index:#)
Error string // If the entire entry was in error (e.g: invalid format)
Errors map[string][]string // Item-level errors (map of error message to entity identifiers or index:#)
}
DiagnosticEntry stores the information - provided by the WAF - about loaded and failed rules for a specific entry in the WAF ruleset
type Diagnostics ¶
type Diagnostics struct {
Version string
Rules *DiagnosticEntry
CustomRules *DiagnosticEntry
Exclusions *DiagnosticEntry
RulesOverrides *DiagnosticEntry
RulesData *DiagnosticEntry
Processors *DiagnosticEntry
Scanners *DiagnosticEntry
}
Diagnostics stores the information - provided by the WAF - about WAF rules initialization.
func (*Diagnostics) TopLevelError ¶ added in v2.2.0
func (d *Diagnostics) TopLevelError() error
TopLevelErrors 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 Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle represents an instance of the WAF for a given ruleset.
func NewHandle ¶
NewHandle creates and returns a new instance of the WAF with the given security rules and configuration of the sensitive data obfuscator. The returned handle is nil in case of an error. Rules-related metrics, including errors, are accessible with the `RulesetInfo()` method.
func (*Handle) Close ¶
func (handle *Handle) Close()
Close puts the handle in termination state, when all the contexts are closed the handle will be destroyed
func (*Handle) Diagnostics ¶
func (handle *Handle) Diagnostics() Diagnostics
Diagnostics returns the rules initialization metrics for the current WAF handle
type ManuallyDisabledError ¶ added in v2.2.0
type ManuallyDisabledError struct{}
ManuallyDisabledError is a wrapper error type helping to handle the error case of trying to execute this package when the WAF has been manually disabled with the `datadog.no_waf` go build tag.
func (ManuallyDisabledError) Error ¶ added in v2.2.0
func (e ManuallyDisabledError) Error() string
type PanicError ¶
type PanicError struct {
// The recovered panic error while executing the function `in`.
Err error
// contains filtered or unexported fields
}
PanicError is an error type wrapping a recovered panic value that happened during a function call. Such error must be considered unrecoverable and be used to try to gracefully abort. Keeping using this package after such an error is unreliable and the caller must rather stop using the library. Examples include safety checks errors.
func (*PanicError) Error ¶
func (e *PanicError) Error() string
Error returns the error string representation.
func (*PanicError) Unwrap ¶
func (e *PanicError) Unwrap() error
Unwrap the error and return it. Required by errors.Is and errors.As functions.
type Result ¶
Result stores the multiple values returned by a call to ddwaf_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
}
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.
type RunError ¶
type RunError int
RunError the WAF can return when running it.
type UnsupportedGoVersionError ¶ added in v2.2.0
type UnsupportedGoVersionError struct {
Version string
}
UnsupportedGoVersionError is a wrapper error type helping to handle the error case of trying to execute this package when the Go version is not supported.
func (UnsupportedGoVersionError) Error ¶ added in v2.2.0
func (e UnsupportedGoVersionError) Error() string
type UnsupportedOSArchError ¶ added in v2.2.0
UnsupportedOSArchError is a wrapper error type helping to handle the error case of trying to execute this package when the OS or architecture is not supported.
func (UnsupportedOSArchError) Error ¶ added in v2.2.0
func (e UnsupportedOSArchError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package include is required to help go tools support vendoring.
|
Package include is required to help go tools support vendoring. |
|
internal
|
|
|
lib
Package lib provides a built-in WAF library version for the relevant runtime platform.
|
Package lib provides a built-in WAF library version for the relevant runtime platform. |
|
noopfree
Package noopfree provides a noop-ed free function.
|
Package noopfree provides a noop-ed free function. |