(aws-iot-actions): SNS-Topic-Action missing master-key policies
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When creating an SNS topic action with a master-key the action does not work, because it does not have the permission to use the KMS-Key.
### Expected Behavior
I would expect the action to work.
### Current Behavior
It does not work, because of missing KMS-Key permissions.
### Reproduction Steps
```python
# kms_key
sns_topic = aws_sns.Topic(self, 'MyTopic', master_key=kms_key)
aws_iot_alpha.TopicRule(
self,
f'MyTopicRule',
actions=[
iot_actions.SnsTopicAction(
sns_topic,
message_format=iot_actions.SnsActionMessageFormat.RAW,
)
],
error_action=iot_actions.CloudWatchLogsAction(
aws_logs.LogGroup(self, 'ErrorTopicRuleMyAction')
),
sql=iot.IotSql.from_string_as_ver20160323(
f'SELECT * FROM "$aws/events/presence/connected/#"'
),
)
```
### Possible Solution
I did not look into the source code yet, but I guess it should be possible to grant the required permissions to the sns topic action role.
The following is a workaround I currently use:
```python
# kms_key
# iam_role
ksm_key.grant_encrypt_decrypt(iam_role)
sns_topic = aws_sns.Topic(self, 'MyTopic', master_key=kms_key)
aws_iot_alpha.TopicRule(
self,
f'MyTopicRule',
actions=[
iot_actions.SnsTopicAction(
sns_topic,
message_format=iot_actions.SnsActionMessageFormat.RAW,
role= iam_role
)
],
error_action=iot_actions.CloudWatchLogsAction(
aws_logs.LogGroup(self, 'ErrorTopicRuleMyAction')
),
sql=iot.IotSql.from_string_as_ver20160323(
f'SELECT * FROM "$aws/events/presence/connected/#"'
),
)
```
### Additional Information/Context
_No response_
### CDK CLI Version
2.70
### Framework Version
_No response_
### Node.js Version
16.15.0
### OS
MacOS
### Language
Python
### Language Version
3.9
### Other information
_No response_
Contributor guide
Research direction
Start at the SnsTopicAction entry point and trace how its role is granted permissions when the SNS topic has a master_key. Compare that path with the workaround's grant_encrypt_decrypt call; done means a topic action using a KMS key works without manually granting the role, with coverage for that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100