Overview
The FjallSecurityGroup construct extends the AWS CDK ec2.SecurityGroup. It adds exactly one thing: a default description of <id> Security Group when you omit one. Every other property, method and default comes straight from the CDK construct.
Most applications never construct one directly. Fjall creates the security groups its resources need, and the connections array on a compute resource opens the rules between them.
There is no
fjall add security-group. Security groups arrive with the
resources that need them. Construct one by hand only when you write custom CDK
in your application’s infrastructure.ts.What Fjall Creates
Opening Access Between Resources
Declare the resource on a service’sconnections array. Fjall calls allowToDefaultPort on the target’s connections, so the database opens its port to that service only.
additionalTcpPorts opens those extra ports on the same group.
Import
Every example below assumes these imports.Basic Usage
description and the group is described as ApiSecurityGroup Security Group.
Configuration Options
Every other
ec2.SecurityGroupProps field passes through unchanged.
Default Behaviour
- Inbound: nothing is allowed. Add each ingress rule explicitly.
- Outbound: all IPv4 traffic is allowed. Set
allowAllOutbound: falseto lock it down. - Rules are inlined into the
AWS::EC2::SecurityGroupresource unlessdisableInlineRulesistrue.
Adding Rules
UseaddIngressRule and addEgressRule for static rules, and the connections interface when both sides are CDK constructs.
Restricting Outbound Traffic
Port Ranges and Protocols
ec2.Port factory methods (tcp, udp, tcpRange, allTcp, allTraffic). The new ec2.Port({ ... }) constructor also requires a stringRepresentation field.
Prefix Lists
Managed prefix-list IDs are opaque and region-specific, so look yours up rather than hardcoding a name.Least Privilege
Referencing another security group rather than a CIDR keeps rules correct when instances scale or IPs change.
Troubleshooting
Cross-Stack References
Adding an ingress rule to a security group that lives in another stack makes that stack reference back into yours, which CloudFormation rejects as a cycle. Import the peer into the local stack first, which is what Fjall does for separate migration tasks.Inspecting Deployed Rules
Next Steps
VPC
Define the network the security group attaches to.
ECS Cluster
Declare services and their connections array.
RDS Instance
Restrict database access to the tiers that need it.
Lambda Function
Place functions inside a secured VPC.