aws

package
v0.0.1-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package aws is a regional AWS EC2 source plugin for instances, elastic network interfaces, and security groups, with optional VPC Flow Log ingestion from Amazon Data Firehose.

Source and collections

The plugin polls EC2 Describe APIs with full pagination at startup, every poll interval, and immediately when an optional SQS subscriber reports a matching CloudTrail change. Polling, not the event stream, is authoritative: events only trigger a current-state read, so duplicates and reordering are harmless. Each object is content-digested so retries keep stable event IDs, and the plugin publishes the aws/ec2/<region>/network-interfaces, instances, and security-groups collections.

Identity

Resources use the aws.amazon.com/v1 Resource scheme. The authority is each resource's 12-digit owner account, not the caller account, so shared-VPC resources owned by another account keep their owner's identity. Immutable keys are <partition>/ec2/<region>/<type>/<id>. The source ID aws/<partition>/<caller-account>/<region> identifies the observer only. Plugin.ResolveIdentityReference turns a Kubernetes Node's aws:// provider ID into an instance claim so Kubernetes can assert Node backed-by instance.

Graph output and failure behavior

The "inventory" contribution asserts instances, network interfaces, and security groups, network interface governed-by security group, and network interface exposes network destination for its current addresses, with an aws-security-group-rules facet carrying typed security semantics. An initial API failure prevents readiness. After a coherent publication, a failed poll republishes the last coherent input once with degraded health; recovery restores healthy status.

Telemetry

Plugin.FirehoseHandler authenticates Firehose HTTP endpoint deliveries for one stream and access key and decodes VPC Flow Log records with NormalizeVPCFlowLog. It acknowledges a delivery only after every event is accepted into the shared pipeline's bounded queue. A full queue blocks the delivery as backpressure, and a delivery abandoned while blocked returns 503 so Firehose retries. Raw events reach the sink before any graph rollup.

See https://agent-shield.dev/docs/plugins/aws/.

Index

Constants

View Source
const (
	// FirehosePath is the HTTP route the service mounts for Firehose HTTP endpoint
	// deliveries of VPC Flow Logs.
	FirehosePath = "/v1/aws/firehose/vpc-flow-logs"
)
View Source
const (
	// PluginID is the plugin and contribution owner ID.
	PluginID = "aws"
)

Variables

This section is empty.

Functions

func Descriptor

func Descriptor() discovery.Descriptor

Descriptor registers the aws.amazon.com/v1 Resource identity scheme. The per-region collections are added by Plugin.Descriptor.

func IdentitySchemeDefinition

func IdentitySchemeDefinition() graph.SchemeDefinition

IdentitySchemeDefinition normalizes aws.amazon.com/v1 Resource claims: a 12-digit owner account authority and a lowercased <partition>/ec2/<region>/<type>/<id> key for instances, network interfaces, and security groups.

func NormalizeVPCFlowLog

func NormalizeVPCFlowLog(scope ProjectionContext, line string) (telemetry.Event, error)

NormalizeVPCFlowLog maps one version 5 VPC Flow Log line in the 25-field custom order documented in https://agent-shield.dev/docs/plugins/aws/ to a telemetry event between network-destination claims for the source and destination addresses. The event ID digests the source ID and the complete record so Firehose redelivery is idempotent. NODATA and SKIPDATA records carry no flow and return an error that the Firehose handler skips.

func SourceID

func SourceID(partition, accountID, region string) (string, error)

SourceID returns aws/<partition>/<account>/<region>, the stable source ID for the authenticated caller. Changing accounts therefore changes the source and its contribution ownership.

Types

type CLIConfig

type CLIConfig struct {
	Region            string
	EventsQueueURL    string
	FirehoseStreamARN string
	FirehoseAccessKey string
}

CLIConfig contains AWS-owned runtime options.

func (*CLIConfig) RegisterFlags

func (config *CLIConfig) RegisterFlags(flags *pflag.FlagSet) error

RegisterFlags registers AWS flags in the aws-* namespace.

type ChangeBatch

type ChangeBatch struct {
	Subscriptions []string
	// contains filtered or unexported fields
}

ChangeBatch is one received set of notifications. Subscriptions lists the matched subscription names; the batch must be acknowledged only after the resulting reconciliation is published.

type Config

type Config struct {
	Partition         string
	Region            string
	SourceID          string
	EC2               EC2API
	Subscriber        EventSubscriber
	PollInterval      time.Duration
	FirehoseStreamARN string
	FirehoseAccessKey string
}

Config configures one regional source. SourceID should come from SourceID so it is bound to the authenticated caller account. Subscriber is optional; without it the plugin relies on PollInterval alone.

type EC2API

EC2API is the subset of the EC2 client used for inventory. Every method is fully paginated on each poll.

type EventSubscriber

type EventSubscriber interface {
	Receive(context.Context) (ChangeBatch, error)
	Acknowledge(context.Context, ChangeBatch) error
}

EventSubscriber delivers change notifications that trigger an immediate full reconciliation. Notifications are hints, not state: missing or duplicate notifications only change latency.

type EventSubscription

type EventSubscription struct {
	Name        string
	Source      string
	EventSource string
	EventNames  []string
}

EventSubscription names one inventory collection and the CloudTrail events that can change it.

func InventoryEventSubscriptions

func InventoryEventSubscriptions() []EventSubscription

InventoryEventSubscriptions declares the CloudTrail EC2 events that affect each inventory collection. The EventBridge rule documented in https://agent-shield.dev/docs/plugins/aws/ must cover the same event names.

type FirehoseConfig

type FirehoseConfig struct {
	StreamARN string
	AccessKey string
}

FirehoseConfig binds the receiver to one Firehose stream. AccessKey is the shared secret Firehose sends in X-Amz-Firehose-Access-Key; it is compared in constant time and never logged.

type Instance

type Instance struct {
	ID               string `json:"id"`
	OwnerID          string `json:"ownerId"`
	VPCID            string `json:"vpcId,omitempty"`
	SubnetID         string `json:"subnetId,omitempty"`
	AvailabilityZone string `json:"availabilityZone,omitempty"`
	InstanceType     string `json:"instanceType,omitempty"`
	State            string `json:"state,omitempty"`
	Revision         string `json:"-"`
	EventID          string `json:"-"`
}

Instance is the normalized EC2 instance observation.

type NetworkInterface

type NetworkInterface struct {
	ID                   string   `json:"id"`
	OwnerID              string   `json:"ownerId"`
	VPCID                string   `json:"vpcId,omitempty"`
	SubnetID             string   `json:"subnetId,omitempty"`
	AvailabilityZone     string   `json:"availabilityZone,omitempty"`
	InterfaceType        string   `json:"interfaceType,omitempty"`
	Status               string   `json:"status,omitempty"`
	RequesterManaged     bool     `json:"requesterManaged,omitempty"`
	AttachmentInstanceID string   `json:"attachmentInstanceId,omitempty"`
	SecurityGroupIDs     []string `json:"securityGroupIds,omitempty"`
	Addresses            []string `json:"addresses,omitempty"`
	Revision             string   `json:"-"`
	EventID              string   `json:"-"`
}

NetworkInterface is the normalized ENI observation published to the network-interfaces collection. Fields tagged json:"-" are delivery metadata excluded from the content digest.

type Plugin

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

Plugin is the AWS EC2 source plugin for one partition, account, and region.

func New

func New(config Config) (*Plugin, error)

New validates config and applies the default five-minute poll interval.

func (*Plugin) Descriptor

func (p *Plugin) Descriptor() discovery.Descriptor

Descriptor adds this region's published collections to Descriptor.

func (*Plugin) FirehoseHandler

func (p *Plugin) FirehoseHandler(config FirehoseConfig, ingestor telemetry.EventIngestor) (http.Handler, error)

FirehoseHandler returns an HTTP handler that accepts VPC Flow Log deliveries for the configured stream. The stream's account and region must match this plugin's source so flow endpoints resolve under the same authority as its inventory. A 200 response means the events are queued in the telemetry pipeline, not yet written to its sink.

func (*Plugin) ResolveIdentityReference

func (p *Plugin) ResolveIdentityReference(reference string) (graph.IdentityClaim, bool, error)

ResolveIdentityReference resolves a Kubernetes Node spec.providerID of the form aws:///<zone>/<instance-id> to an instance claim in this source's account and region. It reports false for non-AWS references so other resolvers may claim them.

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context, runtime discovery.Runtime) error

Run polls and reconciles until ctx ends. See the package documentation for readiness and degraded-health behavior.

func (*Plugin) SourceID

func (p *Plugin) SourceID() string

SourceID returns the configured source ID.

func (*Plugin) TelemetryReceivers

func (p *Plugin) TelemetryReceivers(ingestor telemetry.EventIngestor) ([]discovery.TelemetryReceiver, error)

TelemetryReceivers registers the optional Firehose transport owned by this AWS source. The host supplies only the shared event ingestor.

type ProjectionContext

type ProjectionContext struct {
	Partition string
	Region    string
	SourceID  string
}

ProjectionContext scopes projection to one partition, region, and source.

type ProjectionResult

type ProjectionResult struct {
	Input graph.Input
}

ProjectionResult is the complete inventory contribution input.

func Project

func Project(scope ProjectionContext, snapshot Snapshot) (ProjectionResult, error)

Project deterministically projects one coherent snapshot into the inventory contribution. Security group attachments are emitted only for groups present in the same snapshot with a known owner; others become bounded attributes.

type Rule

type Rule struct {
	Protocol         string   `json:"protocol"`
	FromPort         *int32   `json:"fromPort,omitempty"`
	ToPort           *int32   `json:"toPort,omitempty"`
	IPv4Ranges       []string `json:"ipv4Ranges,omitempty"`
	IPv6Ranges       []string `json:"ipv6Ranges,omitempty"`
	PrefixListIDs    []string `json:"prefixListIds,omitempty"`
	SecurityGroupIDs []string `json:"securityGroupIds,omitempty"`
}

Rule is one normalized security group permission. Lists are sorted so equivalent provider responses digest identically.

type SQSAPI

type SQSAPI interface {
	ReceiveMessage(context.Context, *sqs.ReceiveMessageInput, ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error)
	DeleteMessageBatch(context.Context, *sqs.DeleteMessageBatchInput, ...func(*sqs.Options)) (*sqs.DeleteMessageBatchOutput, error)
}

SQSAPI is the subset of the SQS client used by SQSSubscriber.

type SQSSubscriber

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

SQSSubscriber long-polls an SQS queue that receives EventBridge CloudTrail events.

func NewSQSSubscriber

func NewSQSSubscriber(client SQSAPI, config SQSSubscriberConfig) (*SQSSubscriber, error)

NewSQSSubscriber validates config and indexes the subscribed events.

func (*SQSSubscriber) Acknowledge

func (s *SQSSubscriber) Acknowledge(ctx context.Context, batch ChangeBatch) error

Acknowledge deletes every message in batch, matched or not.

func (*SQSSubscriber) Discarded

func (s *SQSSubscriber) Discarded() uint64

Discarded returns how many malformed messages were discarded.

func (*SQSSubscriber) Receive

func (s *SQSSubscriber) Receive(ctx context.Context) (ChangeBatch, error)

Receive long-polls up to ten messages. Valid but unmatched events, and messages that fail to decode or lack CloudTrail fields, are returned for acknowledgement without a subscription. A malformed message is discarded rather than returned as an error: it can never become valid, and failing would stop the plugin on every redelivery. Notifications are only hints, so the periodic poll covers whatever change it described. A message without a receipt handle cannot be deleted and is skipped.

type SQSSubscriberConfig

type SQSSubscriberConfig struct {
	QueueURL      string
	AccountID     string
	Region        string
	Subscriptions []EventSubscription
}

SQSSubscriberConfig binds a queue to the account and region whose events are accepted; events for any other account or region are acknowledged without reconciliation.

type SecurityGroup

type SecurityGroup struct {
	ID       string `json:"id"`
	OwnerID  string `json:"ownerId"`
	VPCID    string `json:"vpcId,omitempty"`
	Name     string `json:"name,omitempty"`
	Ingress  []Rule `json:"ingress"`
	Egress   []Rule `json:"egress"`
	Revision string `json:"-"`
	EventID  string `json:"-"`
}

SecurityGroup is the normalized security group observation with its ingress and egress rules.

type Snapshot

type Snapshot struct {
	NetworkInterfaces []NetworkInterface
	Instances         []Instance
	SecurityGroups    []SecurityGroup
}

Snapshot is one coherent, fully paginated read of all three EC2 APIs. The projector only ever sees a complete snapshot.

Jump to

Keyboard shortcuts

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