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.
Index ¶
- Constants
- func Descriptor() discovery.Descriptor
- func IdentitySchemeDefinition() graph.SchemeDefinition
- func NormalizeVPCFlowLog(scope ProjectionContext, line string) (telemetry.Event, error)
- func SourceID(partition, accountID, region string) (string, error)
- type CLIConfig
- type ChangeBatch
- type Config
- type EC2API
- type EventSubscriber
- type EventSubscription
- type FirehoseConfig
- type Instance
- type NetworkInterface
- type Plugin
- func (p *Plugin) Descriptor() discovery.Descriptor
- func (p *Plugin) FirehoseHandler(config FirehoseConfig, ingestor telemetry.EventIngestor) (http.Handler, error)
- func (p *Plugin) ResolveIdentityReference(reference string) (graph.IdentityClaim, bool, error)
- func (p *Plugin) Run(ctx context.Context, runtime discovery.Runtime) error
- func (p *Plugin) SourceID() string
- func (p *Plugin) TelemetryReceivers(ingestor telemetry.EventIngestor) ([]discovery.TelemetryReceiver, error)
- type ProjectionContext
- type ProjectionResult
- type Rule
- type SQSAPI
- type SQSSubscriber
- type SQSSubscriberConfig
- type SecurityGroup
- type Snapshot
Constants ¶
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" )
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.
Types ¶
type CLIConfig ¶
type CLIConfig struct {
Region string
EventsQueueURL string
FirehoseStreamARN string
FirehoseAccessKey string
}
CLIConfig contains AWS-owned runtime options.
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 ¶
type EC2API interface {
DescribeNetworkInterfaces(context.Context, *ec2.DescribeNetworkInterfacesInput, ...func(*ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error)
DescribeInstances(context.Context, *ec2.DescribeInstancesInput, ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
DescribeSecurityGroups(context.Context, *ec2.DescribeSecurityGroupsInput, ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error)
}
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 ¶
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 ¶
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 (*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 ¶
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 ¶
Run polls and reconciles until ctx ends. See the package documentation for readiness and degraded-health behavior.
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 ¶
ProjectionContext scopes projection to one partition, region, and source.
type ProjectionResult ¶
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.