Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions contrib/server/enforce_authz_networkfirewall_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"context"
"crypto/sha256"
"encoding/hex"
"io"
"net/http"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
)

// signedJSONTarget sends a SigV4-signed AWS JSON 1.0 request for the given
// X-Amz-Target and returns the status and body.
func signedJSONTarget(t *testing.T, endpoint string, c aws.Credentials, service, target, body string) (int, string) {
t.Helper()

req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, endpoint+"/", strings.NewReader(body))
if err != nil {
t.Fatalf("new request: %v", err)
}

req.Header.Set("Content-Type", "application/x-amz-json-1.0")
req.Header.Set("X-Amz-Target", target)

sum := sha256.Sum256([]byte(body))
if err := v4.NewSigner().SignHTTP(context.Background(), c, req, hex.EncodeToString(sum[:]), service, "us-east-1", time.Now()); err != nil {
t.Fatalf("sign: %v", err)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatalf("do: %v", err)
}
defer resp.Body.Close()

raw, _ := io.ReadAll(resp.Body)

return resp.StatusCode, string(raw)
}

// TestEnforceAuthNetworkFirewall proves the operations added for the Network
// Firewall parity work are authorised per IAM action under --enforce-auth: a
// user allowed only network-firewall:DescribeFirewall passes the gate on that
// operation (the handler then answers its own 400 for the unknown firewall) and
// is refused on the new ones, while an administrator is allowed everywhere.
func TestEnforceAuthNetworkFirewall(t *testing.T) {
endpoint, stop := enforceAuthServer(t)
defer stop()

boot := clientsFor(t, endpoint, seedBootUser(t, endpoint))
reader := boot.newUser(t, "fw-reader", allowDoc("network-firewall:DescribeFirewall"))
const prefix = "NetworkFirewall_20201112."

for _, op := range []string{
"UpdateFirewallDescription", "UpdateSubnetChangeProtection", "CreateTLSInspectionConfiguration",
"CreateVpcEndpointAssociation", "PutResourcePolicy", "StartFlowCapture", "StartAnalysisReport",
} {
status, body := signedJSONTarget(t, endpoint, reader, "network-firewall", prefix+op, `{}`)
if status != http.StatusForbidden || !strings.Contains(body, "AccessDenied") {
t.Fatalf("%s as a describe-only user: %d %s, want 403 AccessDenied", op, status, body)
}

status, body = signedJSONTarget(t, endpoint, boot.cred, "network-firewall", prefix+op, `{}`)
if status == http.StatusForbidden {
t.Fatalf("%s as the administrator: %d %s, want the handler's own answer", op, status, body)
}
}

status, body := signedJSONTarget(t, endpoint, reader, "network-firewall", prefix+"DescribeFirewall", `{"FirewallName":"ghost"}`)
if status == http.StatusForbidden || !strings.Contains(body, "ResourceNotFoundException") {
t.Fatalf("DescribeFirewall as the allowed user: %d %s, want the handler's ResourceNotFoundException", status, body)
}
}
100 changes: 99 additions & 1 deletion docs/coverage/aws/networkfirewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,104 @@ AWS's `networkfirewall` service · portable interface `driver.NetworkFirewall`
| `UpdateLoggingConfiguration` | |
| `UpdateRuleGroup` | |

## Optional capabilities

Discovered by type assertion; only some providers implement these.

### AnalysisReports

AnalysisReports covers the analysis report family.

| Operation | Description |
| --- | --- |
| `GetAnalysisReport` | GetAnalysisReport returns one report (its results are always empty). |
| `ListAnalysisReports` | |
| `StartAnalysisReport` | |

### AvailabilityZones

AvailabilityZones covers the Availability-Zone associations of a transit

| Operation | Description |
| --- | --- |
| `AssociateAvailabilityZones` | |
| `DisassociateAvailabilityZones` | |

### FirewallSettings

FirewallSettings covers the firewall-level setters.

| Operation | Description |
| --- | --- |
| `UpdateAvailabilityZoneChangeProtection` | |
| `UpdateFirewallAnalysisSettings` | |
| `UpdateFirewallDescription` | |
| `UpdateFirewallPolicyChangeProtection` | |
| `UpdateSubnetChangeProtection` | |

### FlowOperations

FlowOperations covers the flow capture / flush family.

| Operation | Description |
| --- | --- |
| `DescribeFlowOperation` | |
| `ListFlowOperationResults` | ListFlowOperationResults returns the operation and its (always empty, there is no |
| `ListFlowOperations` | |
| `StartFlowCapture` | |
| `StartFlowFlush` | |

### Metadata

Metadata covers the read-only metadata/summary operations.

| Operation | Description |
| --- | --- |
| `DescribeFirewallMetadata` | |
| `DescribeRuleGroupMetadata` | |
| `DescribeRuleGroupSummary` | |

### ResourcePolicies

ResourcePolicies covers the resource-sharing IAM policies attached to a rule

| Operation | Description |
| --- | --- |
| `DeleteResourcePolicy` | |
| `DescribeResourcePolicy` | |
| `PutResourcePolicy` | |

### TLSInspection

TLSInspection covers the TLS inspection configuration family.

| Operation | Description |
| --- | --- |
| `CreateTLSInspectionConfiguration` | |
| `DeleteTLSInspectionConfiguration` | |
| `DescribeTLSInspectionConfiguration` | |
| `ListTLSInspectionConfigurations` | |
| `UpdateTLSInspectionConfiguration` | |

### VPCEndpointAssociations

VPCEndpointAssociations covers the VPC endpoint association family.

| Operation | Description |
| --- | --- |
| `CreateVpcEndpointAssociation` | |
| `DeleteVpcEndpointAssociation` | |
| `DescribeVpcEndpointAssociation` | |
| `ListVpcEndpointAssociations` | |

## Not in scope

_Not documented yet. See the [emulator boundary](../../../README.md) for cloudemu-wide non-goals._
- Not implemented (the operations answer `InvalidRequestException: unknown operation`): the proxy family (`CreateProxy`, `CreateProxyConfiguration`, `CreateProxyRuleGroup`, `CreateProxyRules`, the matching describe, update, delete and list operations, `AttachRuleGroupsToProxyConfiguration`, `DetachRuleGroupsFromProxyConfiguration`, `UpdateProxyRulePriorities`, `UpdateProxyRuleGroupPriorities`), the container association family (`CreateContainerAssociation` and its describe, update, delete and list operations), the transit gateway attachment operations (`AcceptNetworkFirewallTransitGatewayAttachment`, `RejectNetworkFirewallTransitGatewayAttachment`, `DeleteNetworkFirewallTransitGatewayAttachment`) and `UpdateFirewallEncryptionConfiguration`. `EncryptionConfiguration` on create and update requests is accepted and ignored.
- There is no packet data plane. Flow capture and flush operations are accepted and complete (immediately, or after the settle window under `--async-settle`) but their results list no flows. Analysis reports complete with no results. Nothing is published to the `AWS/NetworkFirewall` CloudWatch namespace, and the logging configuration is validated and stored but no alert, flow or TLS log is delivered to S3, CloudWatch Logs or Kinesis Data Firehose.
- Checks that need another service are not made: the VPC, subnet and Availability Zone ids a firewall or VPC endpoint association names are syntax-checked only, and the certificates, certificate authorities, KMS keys, log destinations and IAM principals named in TLS inspection configurations, logging configurations and resource policies are not looked up. Resource policies are validated (JSON, allowed actions per resource kind) and stored but never evaluated; sharing through Resource Access Manager is not modeled.
- A firewall subnet's Availability Zone is the zone the subnet really sits in when the subnet exists in the emulated VPC (a firewall takes at most one subnet per zone, as in AWS, and refuses a second one). A subnet id the VPC store does not know (a library user who never created it) gets a zone derived from its id instead, so that zone is stable but not real. Each zone has its own endpoint id, fixed while the subnet stays attached, and a VPC endpoint association reports the same zone.
- A transit gateway-attached firewall can be created, described and have Availability Zones associated and disassociated, but no transit gateway attachment is created, so its status never reports a transit gateway attachment sync state.
- Firewalls, policies, rule groups and TLS inspection configurations are `READY` or `ACTIVE` as soon as they are created; there is no `PROVISIONING` period, and `DeleteFirewall` removes the record at once while answering `DELETING`, so `--async-settle` never shows those intermediate states for these resources (only flow operations settle). `DryRun` and `AnalyzeRuleGroup` on create and update requests are accepted and ignored, so a dry run really makes the change and no rule group analysis results are produced.
- Rule content is stored and returned byte for byte. Only the parts needed for capacity and summaries are read: stateful rules (one unit per rule in `RulesString`, `StatefulRules` and `RulesSourceList` targets) and stateless rules (the product of the element counts of the match settings, as the CreateRuleGroup reference describes). Suricata syntax, rule variables and reference sets are not validated, and a rule group whose rules need more than its `Capacity` is rejected with `InvalidRequestException` (the exception real AWS uses for this is unconfirmed).
- Behaviours the AWS reference does not state were chosen conservatively and are unconfirmed against the live service: a duplicate name answers `InvalidRequestException` (the one exception every Create operation models); deleting a firewall that still has VPC endpoint associations is refused with `InvalidOperationException`; describing or deleting a resource policy that does not exist answers `ResourceNotFoundException`; `DescribeRuleGroupSummary` on a stateless rule group answers `InvalidRequestException` and reports only the options named in the rule group's `SummaryConfiguration`; tagging a resource does not change its update token; a request that gives both a name and an ARN uses the name.
- List operations take `MaxResults` (1 to 100, default 100) and `NextToken`, an opaque offset over results sorted by name, so it is only stable while the list does not change between pages. `ListRuleGroups` filters on `Type`, `Scope` and `ManagedType`; the emulator holds no AWS-managed rule groups, so `Scope=MANAGED` or any `ManagedType` returns an empty list.
142 changes: 142 additions & 0 deletions docs/coverage/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -12687,6 +12687,148 @@
"name": "UpdateRuleGroup"
}
],
"optionalCapabilities": [
{
"name": "AnalysisReports",
"doc": "AnalysisReports covers the analysis report family.",
"operations": [
{
"name": "GetAnalysisReport",
"doc": "GetAnalysisReport returns one report (its results are always empty)."
},
{
"name": "ListAnalysisReports"
},
{
"name": "StartAnalysisReport"
}
]
},
{
"name": "AvailabilityZones",
"doc": "AvailabilityZones covers the Availability-Zone associations of a transit",
"operations": [
{
"name": "AssociateAvailabilityZones"
},
{
"name": "DisassociateAvailabilityZones"
}
]
},
{
"name": "FirewallSettings",
"doc": "FirewallSettings covers the firewall-level setters.",
"operations": [
{
"name": "UpdateAvailabilityZoneChangeProtection"
},
{
"name": "UpdateFirewallAnalysisSettings"
},
{
"name": "UpdateFirewallDescription"
},
{
"name": "UpdateFirewallPolicyChangeProtection"
},
{
"name": "UpdateSubnetChangeProtection"
}
]
},
{
"name": "FlowOperations",
"doc": "FlowOperations covers the flow capture / flush family.",
"operations": [
{
"name": "DescribeFlowOperation"
},
{
"name": "ListFlowOperationResults",
"doc": "ListFlowOperationResults returns the operation and its (always empty, there is no"
},
{
"name": "ListFlowOperations"
},
{
"name": "StartFlowCapture"
},
{
"name": "StartFlowFlush"
}
]
},
{
"name": "Metadata",
"doc": "Metadata covers the read-only metadata/summary operations.",
"operations": [
{
"name": "DescribeFirewallMetadata"
},
{
"name": "DescribeRuleGroupMetadata"
},
{
"name": "DescribeRuleGroupSummary"
}
]
},
{
"name": "ResourcePolicies",
"doc": "ResourcePolicies covers the resource-sharing IAM policies attached to a rule",
"operations": [
{
"name": "DeleteResourcePolicy"
},
{
"name": "DescribeResourcePolicy"
},
{
"name": "PutResourcePolicy"
}
]
},
{
"name": "TLSInspection",
"doc": "TLSInspection covers the TLS inspection configuration family.",
"operations": [
{
"name": "CreateTLSInspectionConfiguration"
},
{
"name": "DeleteTLSInspectionConfiguration"
},
{
"name": "DescribeTLSInspectionConfiguration"
},
{
"name": "ListTLSInspectionConfigurations"
},
{
"name": "UpdateTLSInspectionConfiguration"
}
]
},
{
"name": "VPCEndpointAssociations",
"doc": "VPCEndpointAssociations covers the VPC endpoint association family.",
"operations": [
{
"name": "CreateVpcEndpointAssociation"
},
{
"name": "DeleteVpcEndpointAssociation"
},
{
"name": "DescribeVpcEndpointAssociation"
},
{
"name": "ListVpcEndpointAssociations"
}
]
}
],
"providers": {
"aws": "NetworkFirewall"
}
Expand Down
9 changes: 9 additions & 0 deletions docs/coverage/nongoals/networkfirewall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Not implemented (the operations answer `InvalidRequestException: unknown operation`): the proxy family (`CreateProxy`, `CreateProxyConfiguration`, `CreateProxyRuleGroup`, `CreateProxyRules`, the matching describe, update, delete and list operations, `AttachRuleGroupsToProxyConfiguration`, `DetachRuleGroupsFromProxyConfiguration`, `UpdateProxyRulePriorities`, `UpdateProxyRuleGroupPriorities`), the container association family (`CreateContainerAssociation` and its describe, update, delete and list operations), the transit gateway attachment operations (`AcceptNetworkFirewallTransitGatewayAttachment`, `RejectNetworkFirewallTransitGatewayAttachment`, `DeleteNetworkFirewallTransitGatewayAttachment`) and `UpdateFirewallEncryptionConfiguration`. `EncryptionConfiguration` on create and update requests is accepted and ignored.
- There is no packet data plane. Flow capture and flush operations are accepted and complete (immediately, or after the settle window under `--async-settle`) but their results list no flows. Analysis reports complete with no results. Nothing is published to the `AWS/NetworkFirewall` CloudWatch namespace, and the logging configuration is validated and stored but no alert, flow or TLS log is delivered to S3, CloudWatch Logs or Kinesis Data Firehose.
- Checks that need another service are not made: the VPC, subnet and Availability Zone ids a firewall or VPC endpoint association names are syntax-checked only, and the certificates, certificate authorities, KMS keys, log destinations and IAM principals named in TLS inspection configurations, logging configurations and resource policies are not looked up. Resource policies are validated (JSON, allowed actions per resource kind) and stored but never evaluated; sharing through Resource Access Manager is not modeled.
- A firewall subnet's Availability Zone is the zone the subnet really sits in when the subnet exists in the emulated VPC (a firewall takes at most one subnet per zone, as in AWS, and refuses a second one). A subnet id the VPC store does not know (a library user who never created it) gets a zone derived from its id instead, so that zone is stable but not real. Each zone has its own endpoint id, fixed while the subnet stays attached, and a VPC endpoint association reports the same zone.
- A transit gateway-attached firewall can be created, described and have Availability Zones associated and disassociated, but no transit gateway attachment is created, so its status never reports a transit gateway attachment sync state.
- Firewalls, policies, rule groups and TLS inspection configurations are `READY` or `ACTIVE` as soon as they are created; there is no `PROVISIONING` period, and `DeleteFirewall` removes the record at once while answering `DELETING`, so `--async-settle` never shows those intermediate states for these resources (only flow operations settle). `DryRun` and `AnalyzeRuleGroup` on create and update requests are accepted and ignored, so a dry run really makes the change and no rule group analysis results are produced.
- Rule content is stored and returned byte for byte. Only the parts needed for capacity and summaries are read: stateful rules (one unit per rule in `RulesString`, `StatefulRules` and `RulesSourceList` targets) and stateless rules (the product of the element counts of the match settings, as the CreateRuleGroup reference describes). Suricata syntax, rule variables and reference sets are not validated, and a rule group whose rules need more than its `Capacity` is rejected with `InvalidRequestException` (the exception real AWS uses for this is unconfirmed).
- Behaviours the AWS reference does not state were chosen conservatively and are unconfirmed against the live service: a duplicate name answers `InvalidRequestException` (the one exception every Create operation models); deleting a firewall that still has VPC endpoint associations is refused with `InvalidOperationException`; describing or deleting a resource policy that does not exist answers `ResourceNotFoundException`; `DescribeRuleGroupSummary` on a stateless rule group answers `InvalidRequestException` and reports only the options named in the rule group's `SummaryConfiguration`; tagging a resource does not change its update token; a request that gives both a name and an ARN uses the name.
- List operations take `MaxResults` (1 to 100, default 100) and `NextToken`, an opaque offset over results sorted by name, so it is only stable while the list does not change between pages. `ListRuleGroups` filters on `Type`, `Scope` and `ManagedType`; the emulator holds no AWS-managed rule groups, so `Scope=MANAGED` or any `ManagedType` returns an empty list.
4 changes: 2 additions & 2 deletions docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -3962,7 +3962,7 @@ delete) is still enforced.
| Serverless | 26 |
| Networking | 51 |
| Networking: AWS-specific (Transit Gateway / VPN / DHCP / prefix lists / egress-only IGW / endpoint services / Client VPN / Traffic Mirroring / Network Insights / VPC Block Public Access / IPAM full incl. discovery/BYOASN/BYOIP/resolver/policy + AWS/IPAM metrics) | 162 |
| Network Firewall: AWS | 20 |
| Network Firewall: AWS | 23 (+30 optional) |
| Monitoring | 12 |
| IAM | 35 |
| DNS | 15 |
Expand Down Expand Up @@ -4008,7 +4008,7 @@ delete) is still enforced.
| Data Integration: AWS Glue | 299 |
| Threat Detection: Amazon GuardDuty | 87 |
| Streaming: Amazon MSK | 59 |
| **Grand Total** | **2842** (+227 optional) |
| **Grand Total** | **2845** (+257 optional) |

Optional operations are capabilities a driver may implement but is not required
to; see the sections marked "optional capability". They are counted separately
Expand Down
Loading
Loading