plugin

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package plugin provides the core plugin architecture for Aurelian modules. This replaces the dependency on the Janus framework with a simple, standalone plugin system inspired by Nerva's architecture.

Package plugin provides the core plugin architecture for Aurelian modules.

Index

Constants

View Source
const (
	AnyResourceType = "any"
)

Variables

View Source
var Registry = &registry{
	modules:   make(map[string]RegistryEntry),
	hierarchy: make(map[Platform]map[Category][]string),
}

Registry is the global module registry

Functions

func Bind

func Bind(cfg Config, dst any) error

Bind populates dst from cfg.Args, validates, and sets struct fields.

func Count

func Count() int

Count returns the total number of registered modules

func GetHierarchy

func GetHierarchy() map[Platform]map[Category][]string

GetHierarchy returns the complete module hierarchy for CLI generation The returned map is a copy, safe for concurrent use

func IsSystemProject

func IsSystemProject(projectID string) bool

func Register

func Register(m Module)

Register adds a module to the registry This function is thread-safe and can be called from init() functions

func RegisterAzureEnricher

func RegisterAzureEnricher(resourceType string, fn AzureEnricherFunc)

RegisterAzureEnricher registers an enricher function for a resource type. The resourceType should be lowercase (e.g., "microsoft.web/sites"). Called from init() in individual enricher files.

func RegisterAzureEvaluator

func RegisterAzureEvaluator(templateID string, fn AzureEvaluatorFunc)

RegisterAzureEvaluator registers an evaluator function for a template ID.

func RegisterEnricher

func RegisterEnricher(resourceType string, fn EnricherFunc)

func RegisterGCPEnricher

func RegisterGCPEnricher(resourceType string, fn GCPEnricherFunc)

func ResetAzureEnricherRegistry

func ResetAzureEnricherRegistry()

ResetAzureEnricherRegistry clears all registered Azure enrichers. Test utility only.

func ResetAzureEvaluatorRegistry

func ResetAzureEvaluatorRegistry()

ResetAzureEvaluatorRegistry clears all registered evaluators. Test utility only.

func ResetEnricherRegistry

func ResetEnricherRegistry()

func ResetGCPEnricherRegistry

func ResetGCPEnricherRegistry()

func ResetRegistry

func ResetRegistry()

ResetRegistry clears the global registry. Intended for tests.

Types

type AWSCommonRecon

type AWSCommonRecon struct {
	AWSReconBase
	Concurrency  int      `param:"concurrency"    desc:"Maximum concurrent API requests" default:"5"`
	Regions      []string `param:"regions"        desc:"AWS regions to scan" default:"all" shortcode:"r"`
	ResourceType []string `param:"resource-type"  desc:"AWS Cloud Control resource type" default:"all" shortcode:"t"`
	ResourceARN  []string `param:"resource-arn"   desc:"AWS target resource ARN" shortcode:"a"`
}

func (*AWSCommonRecon) PostBind

func (c *AWSCommonRecon) PostBind(_ Config, _ Module) error

type AWSReconBase

type AWSReconBase struct {
	OutputDir  string `param:"output-dir"   desc:"Base output directory" default:"aurelian-output"`
	Profile    string `param:"profile"      desc:"AWS profile to use" shortcode:"p"`
	ProfileDir string `param:"profile-dir"  desc:"Set to override the default AWS profile directory"`
	OpsecLevel string `param:"opsec_level"  desc:"Operational security level for AWS operations" default:"none"`
}

type AzureCommonRecon

type AzureCommonRecon struct {
	AzureReconBase
	Concurrency     int                    `param:"concurrency" desc:"Maximum concurrent API requests" default:"5"`
	SubscriptionIDs []string               `` /* 135-byte string literal not displayed */
	AzureCredential azcore.TokenCredential `param:"-"`
}

AzureCommonRecon contains common parameters for Azure reconnaissance modules.

func (*AzureCommonRecon) PostBind

func (c *AzureCommonRecon) PostBind(_ Config, _ Module) error

type AzureEnricherConfig

type AzureEnricherConfig struct {
	Context    context.Context
	Credential azcore.TokenCredential
}

AzureEnricherConfig provides context and credentials to Azure enricher functions.

type AzureEnricherFunc

type AzureEnricherFunc func(cfg AzureEnricherConfig, result *templates.ARGQueryResult) error

AzureEnricherFunc adds properties to an ARG query result via Azure SDK API calls. Enrichers mutate result.Properties and always return nil on success. Errors are logged by the pipeline wrapper; the result is still forwarded.

func GetAzureEnrichers

func GetAzureEnrichers(resourceType string) []AzureEnricherFunc

GetAzureEnrichers returns all enrichers registered for a resource type.

type AzureEntraRecon

type AzureEntraRecon struct {
	AzureReconBase
	AzureCredential azcore.TokenCredential `param:"-"`
}

AzureEntraRecon contains parameters for Entra ID (Azure AD) modules that operate at the tenant level and do not require subscription IDs.

func (*AzureEntraRecon) PostBind

func (c *AzureEntraRecon) PostBind(_ Config, _ Module) error

type AzureEvaluatorFunc

type AzureEvaluatorFunc func(result templates.ARGQueryResult) bool

AzureEvaluatorFunc checks enriched properties on an ARG query result. Returns true to confirm the finding, false to drop it.

func GetAzureEvaluator

func GetAzureEvaluator(templateID string) (AzureEvaluatorFunc, bool)

GetAzureEvaluator returns the evaluator for a template ID, if any.

type AzureReconBase

type AzureReconBase struct {
	OutputDir string `param:"output-dir" desc:"Base output directory" default:"aurelian-output"`
}

AzureReconBase contains base parameters shared by all Azure recon modules.

type Category

type Category string

Category represents the module category

const (
	CategoryRecon   Category = "recon"
	CategoryAnalyze Category = "analyze"
	CategorySecrets Category = "secrets"
)

type Config

type Config struct {
	Args    map[string]any  // Runtime arguments (backward compat)
	Params  Parameters      // Typed parameter set
	Context context.Context // Execution context
	Output  io.Writer       // Output destination
	Verbose bool            // Verbose logging
	Log     *Logger         // User-facing terminal logger
}

Config holds runtime configuration for a module

func (Config) Fail

func (c Config) Fail(format string, args ...any)

Fail logs a failure message if a Logger is configured.

func (Config) Info

func (c Config) Info(format string, args ...any)

Info logs an informational message if a Logger is configured.

func (Config) Success

func (c Config) Success(format string, args ...any)

Success logs a success message if a Logger is configured.

func (Config) Warn

func (c Config) Warn(format string, args ...any)

Warn logs a warning message if a Logger is configured.

type ConsoleFormatter

type ConsoleFormatter struct {
	Writer io.Writer
}

ConsoleFormatter outputs results to console in a human-readable format

func (*ConsoleFormatter) Format

func (f *ConsoleFormatter) Format(results []model.AurelianModel) error

Format implements the Formatter interface for console output

type EnricherConfig

type EnricherConfig struct {
	Context   context.Context
	AWSConfig aws.Config
}

type EnricherFunc

type EnricherFunc func(cfg EnricherConfig, r *output.AWSResource) error

func GetEnrichers

func GetEnrichers(resourceType string) []EnricherFunc

type Finding

type Finding struct {
	model.BaseAurelianModel
	// RuleID is the machine-readable identifier for the detection rule
	// Examples: "lambda-no-auth-function-url", "s3-public-bucket"
	RuleID string

	// Severity indicates impact level
	// Valid values: "low", "medium", "high", "critical"
	Severity string

	// Name is the human-readable name of the finding
	// Example: "Lambda Function URL Without Authentication"
	Name string

	// Description provides detailed explanation of the vulnerability
	Description string

	// Resource is the cloud resource with the vulnerability
	Resource output.AWSResource

	// References contains external documentation links (optional)
	References []string

	// Recommendation provides remediation guidance (optional)
	Recommendation string
}

Finding represents a security vulnerability or misconfiguration discovered by an analyzer. Analyzers (both YAML rules and Go modules) return []Finding from their Run() method.

type Formatter

type Formatter interface {
	Format(results []model.AurelianModel) error
}

Formatter handles output formatting for module results

type GCPCommonRecon

type GCPCommonRecon struct {
	ProjectID          []string              `param:"project-id"           desc:"GCP project IDs" shortcode:"p"`
	OrgID              []string              `param:"org-id"               desc:"GCP organization IDs" shortcode:"o"`
	FolderID           []string              `param:"folder-id"            desc:"GCP folder IDs"`
	ResourceType       []string              `param:"resource-type"        desc:"Resource types to enumerate" default:"all" shortcode:"t"`
	Concurrency        int                   `param:"concurrency"          desc:"Max concurrent API requests" default:"5"`
	CredentialsFile    string                `param:"creds-file"           desc:"Path to GCP credentials JSON" shortcode:"c"`
	IncludeSysProjects bool                  `param:"include-sys-projects" desc:"Include system projects" default:"false"`
	ClientOptions      []option.ClientOption `param:"-"`
	ResolvedProjects   []string              `param:"-"`
}

func (*GCPCommonRecon) PostBind

func (c *GCPCommonRecon) PostBind(_ Config, _ Module) error

type GCPEnricherConfig

type GCPEnricherConfig struct {
	Context       context.Context
	ClientOptions []option.ClientOption
}

type GCPEnricherFunc

type GCPEnricherFunc func(cfg GCPEnricherConfig, r *output.GCPResource) error

func GetGCPEnrichers

func GetGCPEnrichers(resourceType string) []GCPEnricherFunc

type GraphFormatter

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

GraphFormatter formats module results as Neo4j graph

func NewGraphFormatter

func NewGraphFormatter(uri, username, password string) (*GraphFormatter, error)

NewGraphFormatter creates a new graph formatter with Neo4j connection

func (*GraphFormatter) Close

func (f *GraphFormatter) Close() error

Close releases database resources

func (*GraphFormatter) Format

func (f *GraphFormatter) Format(results []model.AurelianModel) error

Format processes module results and writes to Neo4j

type GraphOutputBase

type GraphOutputBase struct {
	Neo4jURI      string `param:"neo4j-uri" desc:"Neo4j connection URI (e.g., bolt://localhost:7687)" default:""`
	Neo4jUsername string `param:"neo4j-username" desc:"Neo4j username" default:"neo4j"`
	Neo4jPassword string `param:"neo4j-password" desc:"Neo4j password" default:"neo4j" sensitive:"true"`
}

GraphOutputBase provides reusable Neo4j connection parameters. Embed in any module config that needs graph output. Usage: type MyConfig struct { plugin.GraphOutputBase }

type JSONFormatter

type JSONFormatter struct {
	Writer io.Writer
	Pretty bool
}

JSONFormatter outputs results as JSON

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(results []model.AurelianModel) error

Format implements the Formatter interface for JSON output

type Logger

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

Logger provides pwnlib-style terminal output for modules. User-facing messages (Success, Fail, Info, Warn) always print unless quiet. Status provides transient in-place updates for phase messages. RenderProgress manages a multi-line progress area at the bottom of output. Framework/debug messages should use slog directly.

func DiscardLogger

func DiscardLogger() *Logger

DiscardLogger returns a Logger that silently discards all output. Used as a default when no Logger is configured (e.g., library usage, tests).

func NewLogger

func NewLogger(w io.Writer, noColor, quiet bool) *Logger

NewLogger creates a Logger writing to w. If noColor is true, ANSI colors are disabled. If quiet is true, all user messages are suppressed.

func (*Logger) Banner

func (l *Logger) Banner(text string)

Banner prints ASCII art or banner text.

func (*Logger) Fail

func (l *Logger) Fail(format string, args ...any)

Fail prints a [-] message (red).

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info prints a [*] message (blue).

func (*Logger) ProgressFunc

func (l *Logger) ProgressFunc(label string) func(completed, total int64)

ProgressFunc returns a callback bound to the given label, suitable for passing directly to pipeline.PipeOpts.Progress.

func (*Logger) RenderProgress

func (l *Logger) RenderProgress(label string, completed, total int64)

RenderProgress renders a progress bar for the given label. Each unique label gets its own dedicated line in a multi-line progress area.

When completed and total are both negative, the bar for that label is removed (used as a completion signal by the pipeline).

When total is negative (but not -1,-1 sentinel), it signals that the upstream input is still flowing — the absolute value is the current item count and the bar is capped at 99% to prevent false 100% readings. Once total becomes positive, the denominator is final and real progress is shown.

On non-TTY or quiet mode, progress updates are suppressed.

func (*Logger) Status

func (l *Logger) Status(format string, args ...any)

Status displays a transient in-place message (cyan [~]). On non-TTY or quiet mode, status messages are suppressed. When progress bars are active, Status is a no-op (progress bars provide the visual feedback).

func (*Logger) Success

func (l *Logger) Success(format string, args ...any)

Success prints a [+] message (green).

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn prints a [!] message (yellow).

type Module

type Module interface {
	// Metadata
	ID() string
	Name() string
	Description() string
	Platform() Platform
	Category() Category
	OpsecLevel() string
	Authors() []string
	References() []string
	SupportedResourceTypes() []string

	// Parameters returns a pointer to the module's config struct for parameter
	// binding, or nil if the module has no parameters. The returned value is
	// used both for deriving CLI flags (via ParametersFrom) and as the bind
	// target for Bind before Run is called.
	Parameters() any

	// Execution — send results into the pipeline via out.Send().
	// The caller owns the pipeline lifecycle (including Close).
	Run(cfg Config, out *pipeline.P[model.AurelianModel]) error
}

Module is the core interface that all Aurelian modules implement

func ByPlatform added in v1.0.3

func ByPlatform(p Platform) []Module

ByPlatform returns a snapshot of all registered modules for a given platform. Safe for concurrent use; returns a freshly-allocated slice on each call so callers cannot mutate registry state.

func Get

func Get(platform Platform, category Category, id string) (Module, bool)

Get retrieves a module by platform, category, and ID

type ModuleWrapper

type ModuleWrapper struct {
	Module
}

func (*ModuleWrapper) Run

func (m *ModuleWrapper) Run(cfg Config, out *pipeline.P[model.AurelianModel]) error

type OrgPoliciesParam

type OrgPoliciesParam struct {
	OrgPoliciesFile string                   `param:"org-policies-file" desc:"Path to Org Policies JSON file"`
	OrgPolicies     *orgpolicies.OrgPolicies `param:"-"`
}

func (*OrgPoliciesParam) PostBind

func (c *OrgPoliciesParam) PostBind(_ Config, _ Module) error

type Parameter

type Parameter struct {
	Name        string
	Description string
	Type        string // "string", "int", "bool", "[]string"
	Required    bool
	Default     any
	Shortcode   string
	Hidden      bool           // Hide from help output
	Pattern     *regexp.Regexp // Regex validation for string values
	Enum        []string       // Allowed values (case-insensitive)
	Sensitive   bool           // Mask in logs and help text
	Value       any            // Runtime value
	IsSet       bool           // Whether explicitly provided
}

Parameter describes a module parameter

func ParametersFrom

func ParametersFrom(v any) ([]Parameter, error)

ParametersFrom derives []Parameter from a struct's field tags. Supported tags: param, desc, default, enum, shortcode, required, hidden, sensitive.

Every exported, non-embedded field in the struct must have a `param` tag (use `param:"-"` to explicitly skip a field). This prevents silent misconfiguration where a module author adds a field but forgets to tag it.

func (*Parameter) EffectiveValue

func (p *Parameter) EffectiveValue() any

EffectiveValue returns the explicitly set value, or the default, or nil.

type Parameters

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

Parameters is a typed, validated parameter collection.

func NewParameters

func NewParameters(params ...Parameter) Parameters

NewParameters creates a Parameters set from the given parameters.

func (*Parameters) Bool

func (ps *Parameters) Bool(name string) bool

Bool returns the effective bool value for the named parameter.

func (*Parameters) Int

func (ps *Parameters) Int(name string) int

Int returns the effective int value for the named parameter.

func (*Parameters) IsSet

func (ps *Parameters) IsSet(name string) bool

IsSet reports whether the named parameter was explicitly provided.

func (*Parameters) Set

func (ps *Parameters) Set(name string, value any)

Set assigns a value to the named parameter and marks it as explicitly set.

func (*Parameters) String

func (ps *Parameters) String(name string) string

String returns the effective string value for the named parameter.

func (*Parameters) StringSlice

func (ps *Parameters) StringSlice(name string) []string

StringSlice returns the effective []string value for the named parameter.

func (*Parameters) Validate

func (ps *Parameters) Validate() error

Validate checks all constraints: required fields, patterns, enums, and group rules.

type Platform

type Platform string

Platform represents the cloud platform or service category

const (
	PlatformAWS   Platform = "aws"
	PlatformAzure Platform = "azure"
	PlatformGCP   Platform = "gcp"
	PlatformSaaS  Platform = "saas"
)

type PostBinder

type PostBinder interface {
	PostBind(cfg Config, m Module) error
}

ModuleWrapper wraps a Module so that Run automatically binds cfg.Args into the module's Parameters struct before delegating to the inner Run method. All modules retrieved from the registry are wrapped, ensuring callers never need to call Bind manually.

type RegistryEntry

type RegistryEntry struct {
	Module   Module
	Platform Platform
	Category Category
}

RegistryEntry holds a module and its platform/category metadata

type SlogHandler

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

SlogHandler routes slog messages through the Logger for clean terminal output. Warn messages render as [!], Error messages render as [-]. Info and Debug are controlled by the minimum level.

func NewSlogHandler

func NewSlogHandler(logger *Logger, minLevel slog.Level) *SlogHandler

NewSlogHandler creates a slog.Handler that routes through the Logger. Messages below minLevel are suppressed. Warn/Error always route through the Logger regardless of level (they use [!] and [-] prefixes).

func (*SlogHandler) Enabled

func (h *SlogHandler) Enabled(_ context.Context, level slog.Level) bool

func (*SlogHandler) Handle

func (h *SlogHandler) Handle(_ context.Context, r slog.Record) error

func (*SlogHandler) WithAttrs

func (h *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SlogHandler) WithGroup

func (h *SlogHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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