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

aws-iot: How to attach an IoT Policy to a Thing Group #26166

Open
2 tasks
lautip opened this issue Jun 29, 2023 · 8 comments
Open
2 tasks

aws-iot: How to attach an IoT Policy to a Thing Group #26166

lautip opened this issue Jun 29, 2023 · 8 comments
Labels
@aws-cdk/aws-iot Related to AWS IoT effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@lautip
Copy link

lautip commented Jun 29, 2023

Describe the feature

IoT Core allows to attach an IoT Policy to a Thing Group, but 'CfnPolicyPrincipalAttachment' fails at deploy time if we the pass principal as CfnThingGroup..attrArn.
The error message is:
12:12:40 PM | CREATE_FAILED | AWS::IoT::PolicyPrincipalAttachment | quarPolicyAttachment
The given ARN does not represent a cert (Service: AWSIot; Status Code: 400; Error Code: InvalidRequestException; Request ID: 8018ecbf-38ff-4493-93c8-6e3a183abb0b; Proxy: null)****

Use Case

User wants to attach an IoT Policy to a Thing Group.
One common case is to create a Quarantine group used to isolate Things with unexpected behaviour.

Proposed Solution

CfnPolicyPrincipalAttachment to accept a Thing Group ARN for a Static Group.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

aws-cdk@2.85.0

Environment details (OS name and version, etc.)

Clou9 on Linux

@lautip lautip added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iot Related to AWS IoT label Jun 29, 2023
@pahud
Copy link
Contributor

pahud commented Jun 29, 2023

Thanks for the report.

IoT Core allows to attach an IoT Policy to a Thing Group

Do you have any document link about this?

And, can you share your CDK code that returns the error? It sounds like a limit from cloudformation so we need to make sure it does support.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2023
@lautip
Copy link
Author

lautip commented Jun 30, 2023

Doc:
look for "Attach or detach a policy to or from a group." in https://docs.aws.amazon.com/iot/latest/developerguide/thing-groups.html

@lautip
Copy link
Author

lautip commented Jun 30, 2023

My code:

// Create thing groups
const publishersThingGroup = new aws_iot.CfnThingGroup(this, "publishersThingGroup", {
thingGroupName: 'cognienPublishers',
thingGroupProperties: { thingGroupDescription: 'Members of this group will be allowed to publish on specific topics' },
});

// Create IoT Policy
const publishersPolicyDoc = {
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: [
"iot:Publish"
],
Resource: [ "*" ]
}
]
};

const publishersPolicy = new aws_iot.CfnPolicy(this, 'publishersPolicy', {
policyName: "cognienPublishersPolicy",
policyDocument: publishersPolicyDoc,
});

//Attach policy to Group
const pubPolicyAttachment = new aws_iot.CfnPolicyPrincipalAttachment(this, "pubPolicyAttachment", {
policyName: publishersPolicy.policyName || "",
principal: publishersThingGroup.attrArn,
});

pubPolicyAttachment is throwing the error at deploy time.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 30, 2023
@yamatatsu
Copy link
Contributor

As far as I know, unfortunately CloudFormation AWS::IoT::ThingPrincipalAttachment cannot attach to a ThingGroup. So we need to use CLI or web console.

@raziza
Copy link

raziza commented Jul 19, 2023

Added a new feature request for it: here

@khushail khushail added the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Jul 19, 2023
@khushail
Copy link
Contributor

Hi @raziza , I have marked this appropriately to be taken up by the cloudfomation team. Please feel free to reach out to Cloudformation team for inclusion of this issue by following the guidelines mentioned in their coverage roadmap.

@tim-finnigan
Copy link

Linking related issue: #18872

@PITPL-Chetan-Porwal
Copy link

        AttachPolicyRequest attachPolicyRequest = new AttachPolicyRequest()
                .withPolicyName(policyName)
                .withTarget(createThingResult.getThingName());
        awsIot.attachPolicy(attachPolicyRequest);

After using the above code facing the below all permission are enabled and checked its perfectly without SDK policy will attach.
com.amazonaws.services.iot.model.InvalidRequestException: Invalid Target (Service: AWSIot; Status Code: 400; Error Code: InvalidRequestException; Request ID: cd9b955e-0b17-4cf1-b493-4f696e1367dd; Proxy: null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iot Related to AWS IoT effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

7 participants