Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AWS::IoT::MitigationAction #15

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 23 additions & 0 deletions aws-iot-mitigationaction/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# macOS
.DS_Store
._*

# Maven outputs
.classpath

# IntelliJ
*.iml
.idea
out.java
out/
.settings
.project

# auto-generated files
target/

# our logs
rpdk.log

# contains credentials
sam-tests/
17 changes: 17 additions & 0 deletions aws-iot-mitigationaction/.rpdk-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"typeName": "AWS::IoT::MitigationAction",
"language": "java",
"runtime": "java8",
"entrypoint": "com.amazonaws.iot.mitigationaction.HandlerWrapper::handleRequest",
"testEntrypoint": "com.amazonaws.iot.mitigationaction.HandlerWrapper::testEntrypoint",
"settings": {
"namespace": [
"com",
"amazonaws",
"iot",
"mitigationaction"
],
"codegen_template_path": "guided_aws",
"protocolVersion": "2.0.0"
}
}
23 changes: 23 additions & 0 deletions aws-iot-mitigationaction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AWS::IoT::MitigationAction

## Running Contract Tests

You can execute the following commands to run the tests.
You will need to have docker installed and running.

```bash
# Create a CloudFormation stack with contract test dependencies (an IAM Role)
aws cloudformation deploy \
--stack-name cfn-contract-test-dependencies-mitigation-action \
--template-file packaging_additional_published_artifacts/contract_test_dependencies.yml \
--capabilities CAPABILITY_IAM \
--region us-east-1
# Package the code with Maven
mvn package
# Start SAM which will execute lambdas in Docker
sam local start-lambda
# In a separate terminal, run the contract tests
cfn test --enforce-timeout 240
# Execute a single test
cfn test --enforce-timeout 240 -- -k <testname>
```
253 changes: 253 additions & 0 deletions aws-iot-mitigationaction/aws-iot-mitigationaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON files are showing big delta because of fixing indentation using pre-commit hook.

"typeName": "AWS::IoT::MitigationAction",
"description": "Mitigation actions can be used to take actions to mitigate issues that were found during an audit.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mitigation Action isn't specific to Audit, now even ML Detect uses it. So lets paraphrase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-iot.git",
"definitions": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add "additionalProperties": false for all entries with type=object

"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The tag's key.",
"minLength": 1,
"maxLength": 128
},
"Value": {
"type": "string",
"description": "The tag's value.",
"minLength": 1,
"maxLength": 256
}
},
"required": [
"Value",
"Key"
],
"additionalProperties": false
},
"ActionParams": {
"type": "object",
"description": "The set of parameters for this mitigation action. You can specify only one type of parameter (in other words, you can apply only one action for each defined mitigation action).",
"properties": {
"AddThingsToThingGroupParams": {
"$ref": "#/definitions/AddThingsToThingGroupParams"
},
"EnableIoTLoggingParams": {
"$ref": "#/definitions/EnableIoTLoggingParams"
},
"PublishFindingToSnsParams": {
"$ref": "#/definitions/PublishFindingToSnsParams"
},
"ReplaceDefaultPolicyVersionParams": {
"$ref": "#/definitions/ReplaceDefaultPolicyVersionParams"
},
"UpdateCACertificateParams": {
"$ref": "#/definitions/UpdateCACertificateParams"
},
"UpdateDeviceCertificateParams": {
"$ref": "#/definitions/UpdateDeviceCertificateParams"
}
},
"additionalProperties": false
},
"AddThingsToThingGroupParams": {
"description": "Parameters to define a mitigation action that moves devices associated with a certificate to one or more specified thing groups, typically for quarantine.",
"type": "object",
"properties": {
"OverrideDynamicGroups": {
"type": "boolean",
"description": "Specifies if this mitigation action can move the things that triggered the mitigation action out of one or more dynamic thing groups."
},
"ThingGroupNames": {
"description": "The list of groups to which you want to add the things that triggered the mitigation action.",
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"minItems": 1,
"maxItems": 10,
"insertionOrder": false
}
},
"required": [
"ThingGroupNames"
],
"additionalProperties": false
},
"EnableIoTLoggingParams": {
"description": "Parameters to define a mitigation action that enables AWS IoT logging at a specified level of detail.",
"type": "object",
"properties": {
"LogLevel": {
"type": "string",
"enum": [
"DEBUG",
"INFO",
"ERROR",
"WARN"
],
"description": " Specifies which types of information are logged."
},
"RoleArnForLogging": {
"description": " The ARN of the IAM role used for logging.",
"type": "string",
"minLength": 20,
"maxLength": 2048
}
},
"required": [
"LogLevel",
"RoleArnForLogging"
],
"additionalProperties": false
},
"PublishFindingToSnsParams": {
"type": "object",
"description": "Parameters, to define a mitigation action that publishes findings to Amazon SNS. You can implement your own custom actions in response to the Amazon SNS messages.",
"properties": {
"TopicArn": {
"type": "string",
"description": "The ARN of the topic to which you want to publish the findings.",
"minLength": 20,
"maxLength": 2048
}
},
"required": [
"TopicArn"
],
"additionalProperties": false
},
"ReplaceDefaultPolicyVersionParams": {
"type": "object",
"description": "Parameters to define a mitigation action that adds a blank policy to restrict permissions.",
"properties": {
"TemplateName": {
"type": "string",
"enum": [
"BLANK_POLICY"
]
}
},
"required": [
"TemplateName"
],
"additionalProperties": false
},
"UpdateCACertificateParams": {
"type": "object",
"description": "Parameters to define a mitigation action that changes the state of the CA certificate to inactive.s",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo s/inactive.s/inactive./g

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"properties": {
"Action": {
"type": "string",
"enum": [
"DEACTIVATE"
]
}
},
"required": [
"Action"
],
"additionalProperties": false
},
"UpdateDeviceCertificateParams": {
"type": "object",
"description": "Parameters to define a mitigation action that changes the state of the device certificate to inactive.",
"properties": {
"Action": {
"type": "string",
"enum": [
"DEACTIVATE"
]
}
},
"required": [
"Action"
],
"additionalProperties": false
}
},
"properties": {
"ActionName": {
"description": "A unique identifier for the mitigation action.",
"type": "string",
"pattern": "[a-zA-Z0-9:_-]+",
"minLength": 1,
"maxLength": 128
},
"RoleArn": {
"type": "string"
},
"Tags": {
"type": "array",
"maxItems": 50,
"uniqueItems": true,
"insertionOrder": false,
"description": "An array of key-value pairs to apply to this resource.",
"items": {
"$ref": "#/definitions/Tag"
}
},
"ActionParams": {
"$ref": "#/definitions/ActionParams"
},
"MitigationActionArn": {
"type": "string"
},
"MitigationActionId": {
"type": "string"
}
},
"additionalProperties": false,
"primaryIdentifier": [
"/properties/ActionName"
],
"required": [
"RoleArn",
"ActionParams"
],
"createOnlyProperties": [
"/properties/ActionName"
],
"readOnlyProperties": [
"/properties/MitigationActionArn",
"/properties/MitigationActionId"
],
"handlers": {
"create": {
"permissions": [
"iot:CreateMitigationAction",
"iam:PassRole"
]
},
"read": {
"permissions": [
"iot:DescribeMitigationAction",
"iot:ListTagsForResource"
]
},
"update": {
"permissions": [
"iot:UpdateMitigationAction",
"iot:ListTagsForResource",
"iot:UntagResource",
"iot:TagResource",
"iam:PassRole"
]
},
"delete": {
"permissions": [
"iot:DescribeMitigationAction",
"iot:DeleteMitigationAction"
]
},
"list": {
"permissions": [
"iot:ListMitigationActions"
]
}
}
}
15 changes: 15 additions & 0 deletions aws-iot-mitigationaction/inputs/inputs_1_create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ActionName": "CfnContractTest",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be nice to have a test for every single action that we support, else how do you know that the definition of one of the actions isn't broken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an integ test for them in the integ test package.

"RoleArn": "{{RoleForDeviceDefenderAuditArn}}",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use "Audit" in names of even the test resource. Reason being MitigationActions isn't specific to Audit anymore (it's a common resource to both Audit/Detect)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

"ActionParams": {
"PublishFindingToSnsParams": {
"TopicArn": "{{TopicForDeviceDefenderAuditCreateArn}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

}
},
"Tags": [
{
"Key": "testTagKey",
"Value": "tagValue"
}
]
}
10 changes: 10 additions & 0 deletions aws-iot-mitigationaction/inputs/inputs_1_invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ActionName": "CfnContractTest",
"RoleArn": "{{RoleForDeviceDefenderAuditArn}}",
"ActionParams": {
"PublishFindingToSnsParams": {
"TopicArn": "{{TopicForDeviceDefenderAuditCreateArn}}"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, do not use Audit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

},
"MitigationActionId": "This is a read only property"
}
9 changes: 9 additions & 0 deletions aws-iot-mitigationaction/inputs/inputs_1_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ActionName": "CfnContractTest",
"RoleArn": "{{RoleForDeviceDefenderAuditArn}}",
"ActionParams": {
"PublishFindingToSnsParams": {
"TopicArn": "{{TopicForDeviceDefenderAuditUpdateArn}}"
}
}
}
1 change: 1 addition & 0 deletions aws-iot-mitigationaction/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
Loading