Documentation
¶
Overview ¶
Package mockalerts generates mock cloud-provider security alerts. v1 supports GCP Security Command Center; Azure and AWS are planned.
Package secmock generates realistic mock security alerts for GCP, Azure, and AWS cloud providers.
v1 supports GCP Security Command Center v2 (full NotificationMessage envelopes matching what a Pub/Sub subscriber receives). Azure and AWS are planned as sibling Provider implementations under providers/.
Useful for SIEM ingestion testing, load generation, and developer tooling.
Quickstart:
import (
"context"
"github.com/coderite/secmock"
"github.com/coderite/secmock/providers/gcp"
_ "github.com/coderite/secmock/providers/gcp/categories" // register built-in templates
)
func generate(ctx context.Context) error {
return secmock.WriteN(ctx, gcp.New(), "./alerts", 1000,
secmock.Options{Seed: 42})
}
Determinism: same Seed and n produce byte-identical files regardless of Workers, because per-alert PCG seeds are derived sequentially from a master RNG before workers start.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownClass = errors.New("mockalerts: unknown finding class") ErrUnknownCategory = errors.New("mockalerts: unknown finding category") ErrEmptyCatalog = errors.New("mockalerts: provider catalog is empty") )
Sentinel errors returned by Provider methods and WriteN.
Functions ¶
func WriteN ¶
WriteN generates n envelopes from p and writes each to dir as an individual JSON file named "<FilePrefix><zero-padded-index>.json".
Determinism: same Seed and n produce byte-identical files regardless of Workers, because per-alert PCG seeds are pre-allocated sequentially from a master RNG before workers start.
On error mid-run, already-written files are retained on disk. The directory is not cleared beforehand; pre-existing files at the same indices are overwritten.
Example ¶
package main
import (
"context"
"fmt"
"os"
secmock "github.com/coderite/secmock"
"github.com/coderite/secmock/providers/gcp"
_ "github.com/coderite/secmock/providers/gcp/categories"
)
func main() {
dir, _ := os.MkdirTemp("", "alerts-example-")
defer os.RemoveAll(dir)
err := secmock.WriteN(context.Background(), gcp.New(), dir, 5,
secmock.Options{
Seed: 42,
Workers: 2,
Mode: secmock.ModeByClass,
Class: gcp.ClassThreat,
})
if err != nil {
fmt.Println("error:", err)
return
}
entries, _ := os.ReadDir(dir)
fmt.Println("files written:", len(entries))
}
Output: files written: 5
Types ¶
type Options ¶
type Options struct {
// Seed for the master PCG RNG; 0 means time-based.
Seed uint64
// Workers is the number of goroutines doing template + marshal + write.
// 0 uses runtime.GOMAXPROCS(0).
Workers int
// Indent toggles pretty-printed JSON output.
Indent bool
// FilePrefix overrides the default "alert-" prefix.
FilePrefix string
// Mode selects generation strategy.
Mode Mode
// Class is required when Mode != ModeRandom.
Class string
// Category is required when Mode == ModeByCategory.
Category string
// OnProgress, if non-nil, is invoked after each successful file write
// with the running total. Called from worker goroutines; the callback
// MUST be safe to invoke concurrently.
OnProgress func(written int)
}
Options configures a WriteN run.
type Provider ¶
type Provider interface {
// Name returns the provider identifier ("gcp", "azure", "aws").
Name() string
// Random returns a random envelope drawn uniformly across classes.
Random(r *rand.Rand) (proto.Message, error)
// ByClass returns an envelope for a random category within the given class.
ByClass(class string, r *rand.Rand) (proto.Message, error)
// ByCategory returns an envelope for the specific class+category.
ByCategory(class, category string, r *rand.Rand) (proto.Message, error)
// Catalog returns the supported classes and their categories.
Catalog() Catalog
}
Provider generates mock security alerts for a single cloud provider.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
jsonwrite
Package jsonwrite provides pooled buffers and atomic file writes for the bulk-alert pipeline.
|
Package jsonwrite provides pooled buffers and atomic file writes for the bulk-alert pipeline. |
|
providers
|
|
|
gcp/categories
Package categories registers the built-in GCP SCC category templates.
|
Package categories registers the built-in GCP SCC category templates. |
|
gcp/faker
Package faker produces deterministic GCP-shaped fake data for SCC findings.
|
Package faker produces deterministic GCP-shaped fake data for SCC findings. |