mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
* feat(config): add compliance evaluation loop, retention, and pagination Replace the hardcoded INSUFFICIENT_DATA compliance with real aggregation over evaluations reported via PutEvaluations / PutExternalEvaluation: - New actions (13): PutEvaluations, PutExternalEvaluation, DeleteEvaluationResults, DescribeComplianceByResource, GetComplianceDetailsByConfigRule, GetComplianceDetailsByResource, GetComplianceSummaryByConfigRule, GetComplianceSummaryByResourceType, DeleteConfigurationRecorder, DeleteDeliveryChannel, PutRetentionConfiguration, DescribeRetentionConfigurations, DeleteRetentionConfiguration - PutConfigRule now round-trips the full AWS rule shape (Description, Scope, SourceDetails, InputParameters, MaximumExecutionFrequency, EvaluationModes) instead of silently dropping fields - Evaluations persist to config-evaluations.json and are cascade-deleted with their rule; retention persists to config-retention.json - NextToken/Limit pagination on describe/get operations with AWS page sizes and InvalidNextTokenException/InvalidLimitException validation - DescribeConfigRules with an unknown name now fails with NoSuchConfigRuleException, matching AWS - boto3 compatibility suite: tests/test_config.py Since Floci performs no Lambda invocation, PutEvaluations accepts the config rule name as the ResultToken; documented in the service doc's deviations section. * fix: honor Limit field in Config pagination requests * fix(config): enforce the modeled rule enums and the ComplianceTypes filter shape PutConfigRule now deserializes the whole modeled ConfigRule and stores it, so Source.Owner, MaximumExecutionFrequency, ConfigRuleState and EvaluationModes[].Mode were persisted and echoed back verbatim — a rule AWS would have rejected with InvalidParameterValueException read back as a valid one. The ComplianceTypes filter on the four compliance reads was likewise unchecked: an unmodeled value or a list longer than the shape's max of 3 simply matched nothing, which a caller reads as an empty result rather than as a rejection. * fix(config): validate the nested SourceDetails enums and Scope cardinality The stored ConfigRule carries SourceDetails, whose EventSource (aws.config only), MessageType and MaximumExecutionFrequency are all enum-typed, and a Scope whose ComplianceResourceTypes list is capped at 100. All four were persisted and echoed back by DescribeConfigRules verbatim, one level below the members the previous commit checked. * fix(config): reject a missing ConfigRuleName on DeleteConfigRule store.remove(ruleName) throws NullPointerException on the backing ConcurrentHashMap when ruleName is null (the handler passes null when ConfigRuleName is absent from the request), producing a 500 instead of the modeled NoSuchConfigRuleException. Guard on isBlank(ruleName) first, matching the existing requireRule() idiom used by the sibling evaluation operations for the same field. * fix(config): keep the newest evaluation when PutEvaluations reorders storeEvaluations() unconditionally overwrote the stored compliance result for a resource/rule pair, so an older evaluation arriving after a newer one (e.g. an out-of-order Lambda invocation) regressed compliance details, aggregates, and summaries back to the stale value. Compare against the stored OrderingTimestamp and skip the incoming evaluation when it is older than what is already recorded. * fix(config): make PutEvaluations atomic per resource/rule key storeEvaluations() read the current evaluation with a plain get() and wrote the new one with a separate put(), so two concurrent PutEvaluations calls for the same resource could both read the old value before either wrote, letting an older OrderingTimestamp win the race regardless of arrival order. Replace the read-then-write with ConcurrentHashMap.compute(), which is atomic per key. Added a stress test exercising 16 concurrent writers per resource key across 100 attempts; it passes reliably under the fix. The race window in the prior get/put shape is narrow enough (a handful of nanoseconds between the two calls) that it did not reproduce deterministically under test scheduling even with that much contention -- the fix is justified by the non-atomic read-then-write shape itself, not by a forced failure. * fix(config): enforce DescribeConfigRules' 25-name limit ConfigRuleNames is modeled with Maximum 25 items (confirmed against botocore's config service-2.json) but describeConfigRules had no size check, so 26+ names were processed instead of rejected with InvalidParameterValueException like every other array-size limit this PR already enforces. * fix(config): close the DeleteConfigRule/PutEvaluations deletion race PutEvaluations (and PutExternalEvaluation, DeleteEvaluationResults) checked a rule's existence via requireRule and then wrote to the evaluations map as two separate steps. If DeleteConfigRule ran in between -- removing the rule and its evaluation bucket -- the pending PutEvaluations call would recreate the bucket via computeIfAbsent after the delete, orphaning evaluations under the deleted rule's name. A later rule created with that same name would then inherit the deleted rule's compliance details and evaluation status. Guard the check-then-act with a per-rule monitor (ruleKey(region, ruleName)), matching the lockFor()-keyed-monitor idiom already used by DocDbService for the identical class of race between a tag update and a delete. Added a stress test racing PutEvaluations against DeleteConfigRule across 200 attempts, then recreating the rule under the same name and asserting a clean (INSUFFICIENT_DATA) evaluation state. It passes under the fix; as with the earlier PutEvaluations-ordering race, it did not reproduce RED against the pre-fix code even under that much contention -- the race window between the existence check and the map write is too narrow to hit deterministically without injecting an artificial delay into production code. The fix is justified by the non-atomic check-then-act shape itself, confirmed by reading the code.
6.5 KiB
6.5 KiB
AWS Config
Protocol: JSON 1.1 (X-Amz-Target: StarlingDoveService.*)
Endpoint: POST http://localhost:4566/
Supported Actions
Config Rules
| Action | Description |
|---|---|
PutConfigRule |
Create or update a config rule (full rule shape round-trips: description, scope, source details, input parameters, execution frequency, evaluation modes) |
DeleteConfigRule |
Delete a config rule and its evaluation results |
DescribeConfigRules |
List config rules, optionally filtered by name, paginated via NextToken |
DescribeConfigRuleEvaluationStatus |
Get evaluation status for config rules |
StartConfigRulesEvaluation |
Trigger evaluation for config rules |
Compliance & Evaluations
| Action | Description |
|---|---|
PutEvaluations |
Report evaluation results for a config rule (supports TestMode) |
PutExternalEvaluation |
Report a single external evaluation for a config rule |
DeleteEvaluationResults |
Delete all evaluation results for a config rule |
DescribeComplianceByConfigRule |
Get rule-level compliance aggregated from reported evaluations |
DescribeComplianceByResource |
Get resource-level compliance aggregated across rules |
GetComplianceDetailsByConfigRule |
List the evaluation results recorded for a rule |
GetComplianceDetailsByResource |
List the evaluation results recorded for a resource |
GetComplianceSummaryByConfigRule |
Count compliant and non-compliant rules |
GetComplianceSummaryByResourceType |
Count compliant and non-compliant resources, grouped by type |
Configuration Recorder
| Action | Description |
|---|---|
PutConfigurationRecorder |
Create or update a configuration recorder |
DescribeConfigurationRecorders |
List configuration recorders |
DeleteConfigurationRecorder |
Delete a configuration recorder |
StartConfigurationRecorder |
Start recording configuration changes |
StopConfigurationRecorder |
Stop recording configuration changes |
DescribeConfigurationRecorderStatus |
Get the status of configuration recorders |
Delivery Channel
| Action | Description |
|---|---|
PutDeliveryChannel |
Create or update a delivery channel |
DescribeDeliveryChannels |
List delivery channels |
DeleteDeliveryChannel |
Delete a delivery channel (fails while the recorder is running) |
Retention Configuration
| Action | Description |
|---|---|
PutRetentionConfiguration |
Set the retention period (30-2557 days) |
DescribeRetentionConfigurations |
List retention configurations |
DeleteRetentionConfiguration |
Delete the retention configuration |
Conformance Packs
| Action | Description |
|---|---|
PutConformancePack |
Create or update a conformance pack |
DeleteConformancePack |
Delete a conformance pack |
DescribeConformancePacks |
List conformance packs, paginated via Limit/NextToken |
DescribeConformancePackStatus |
Get the deployment status of conformance packs |
Tagging
| Action | Description |
|---|---|
TagResource |
Add tags to a Config resource |
UntagResource |
Remove tags from a Config resource |
ListTagsForResource |
List tags on a Config resource |
Configuration
| Variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_CONFIGSERVICE_ENABLED |
true |
Enable or disable the service |
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
# Create a config rule
aws configservice put-config-rule --config-rule '{
"ConfigRuleName": "s3-bucket-versioning",
"Description": "Checks that versioning is enabled",
"Scope": {"ComplianceResourceTypes": ["AWS::S3::Bucket"]},
"Source": {
"Owner": "AWS",
"SourceIdentifier": "S3_BUCKET_VERSIONING_ENABLED"
}
}'
# List config rules
aws configservice describe-config-rules
# Report evaluation results (the ResultToken is the rule name, see Deviations)
aws configservice put-evaluations \
--result-token s3-bucket-versioning \
--evaluations '[{
"ComplianceResourceType": "AWS::S3::Bucket",
"ComplianceResourceId": "my-bucket",
"ComplianceType": "NON_COMPLIANT",
"Annotation": "Versioning is suspended",
"OrderingTimestamp": 1700000000.0
}]'
# Rule compliance now reflects the reported evaluations
aws configservice describe-compliance-by-config-rule \
--config-rule-names s3-bucket-versioning
# Inspect per-resource evaluation results
aws configservice get-compliance-details-by-config-rule \
--config-rule-name s3-bucket-versioning
# Set the retention period
aws configservice put-retention-configuration --retention-period-in-days 365
# Create a configuration recorder
aws configservice put-configuration-recorder --configuration-recorder '{
"name": "default",
"roleARN": "arn:aws:iam::012345678901:role/config-role",
"recordingGroup": {
"allSupported": true,
"includeGlobalResourceTypes": true
}
}'
# Start recording
aws configservice start-configuration-recorder --configuration-recorder-name default
# Check recorder status
aws configservice describe-configuration-recorder-status
# Create a conformance pack
aws configservice put-conformance-pack \
--conformance-pack-name my-pack \
--template-body "Resources: {}"
# List conformance packs
aws configservice describe-conformance-packs
# Tag a resource
aws configservice tag-resource \
--resource-arn arn:aws:config:us-east-1:000000000000:config-rule/config-rule-abc123 \
--tags Key=env,Value=dev
# Delete a config rule
aws configservice delete-config-rule --config-rule-name s3-bucket-versioning
Deviations
!!! note
Compliance is driven entirely by evaluations reported through PutEvaluations and
PutExternalEvaluation — Floci does not record resource configurations or run rule
evaluations itself. Until an evaluation is reported, compliance returns
INSUFFICIENT_DATA.
- **ResultToken**: real AWS hands custom rules an opaque token inside the evaluation
event. Floci has no evaluation event, so `PutEvaluations` expects the config rule
name as the token (a `<rule-name>:<suffix>` form is also accepted).
- `StartConfigRulesEvaluation` marks the rule as invoked but does not call the rule's
Lambda function.
- `FirstActivatedTime` and invocation timestamps are runtime state and are not
persisted across restarts.
- `DescribeConfigRules` and `DescribeComplianceByConfigRule` use a fixed page size
of 25.
- Configuration recorders and delivery channels are stored and validated, but no
configuration items or snapshots are produced.
- Conformance pack status is always `CREATE_SUCCESSFUL`; pack templates are stored,
not evaluated.