Skip to content

Cannot access serial port inside a component

0

At first I was getting permission denied error trying to open a serial port (/dev/ttyS0) with a python script. Then I realized that the permission denied message was caused by gg_user not added to dialout group. However, I still cannot open serial port to write to after I added gg_user was added.

Serial.isOpen() returns false even though I can create the object Serial. Is it not allowed for a component to access local resource directly? I found some documentation with access local resources with lambada functions in v1, but I am using v2. My script runs fine outside of Greengrass. Thank you in advance.

Edited by: jcai on Mar 8, 2021 12:47 PM

asked 5 years ago515 views
4 Answers
0

By default Greengrass will run your component using ggc_user as the user and ggc_group as the group. Adding ggc_user to the tty group won't be sufficient because it isn't running using the dialout group, but as ggc_group. You can replicate Greengrass's behavior using sudo like "sudo -u ggc_user -g ggc_group -E <your command>". To address this you can setup your component to run using the dialout group, or to use all of the user's groups. To do this, create a new deployment and edit the runWith configuration for the component so that posixUser key is "ggc_user". This will run your component as ggc_user with all of that users's groups. To run with a specific group, use "ggc_user:<group name>".

Cheers,
Michael

AWS
EXPERT
answered 5 years ago
0

Thank you very much for your answer. That make sense. So what is the recommended practice with accessing local resources? For example, if I need access to system directories, such as /opt, do I give gcc_user root access? or run the component as "root"? Thanks!

answered 5 years ago
0

The best solution would be to change the directory's permissions so that the user has the minimum access that it can while still allowing it to do what is necessary. Sometime running as root is necessary which you should use the RequiresPrivilege keyword in the recipe to do (see: https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html#recipe-format). However, try to avoid running as root when you can for the best security posture.

Cheers,
Michael

AWS
EXPERT
answered 5 years ago
0

Thank you very much!

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.