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

fix: Allow sagemaker to have the proper IAM permission to autostop itself #515

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Resources:
Action:
- 'sts:AssumeRole'
Resource: 'arn:aws:iam::*:role/swb-*'
- Effect: Allow
Action:
- sagemaker:DescribeNotebookInstance
- sagemaker:StopNotebookInstance
Resource: '*'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we restrict the resource here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the reference be - !Ref BasicNotebookInstance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we can reference it because the notebook is created after this policy is created. More info here. Also since this is a permission boundary I think it's ok to have a broader resource section here. In the actual Sagemaker IAM role, we do scope the permission down to just the notebook.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's what I was trying to understand. If the IAM policy can reference the instance then why can't permission boundary policy do the same.

I think it's ok to have a broader resource section here. In the actual Sagemaker IAM role, we do scope the permission down to just the notebook.

Yeah, that's why I approved the change. But I am still curious if it could have been done just like we did with IAM policy

IAMRole:
Type: 'AWS::IAM::Role'
Properties:
Expand Down Expand Up @@ -175,7 +180,7 @@ Resources:
chmod a+x /usr/local/bin/autostop.py
IDLE_TIME=`expr ${AutoStopIdleTimeInMinutes} \* 60`
echo "Starting the SageMaker autostop script in cron"
(crontab -l 2>/dev/null; echo "5 * * * * /usr/bin/python /usr/local/bin/autostop.py --time $IDLE_TIME --ignore-connections") | crontab -
(crontab -l 2>/dev/null; echo "*/1 * * * * /usr/bin/python /usr/local/bin/autostop.py --time $IDLE_TIME --ignore-connections >> /var/log/autostop.log") | crontab -
fi

Outputs:
Expand Down
2 changes: 1 addition & 1 deletion main/solution/backend/config/infra/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ envStatusPollHandler:
description: Handles status polling for sc environments
events:
- schedule:
rate: rate(3 minutes)
rate: rate(1 minute)
description: 'Invokes the lambda function that polls and synchronize environment status.'
environment:
APP_CUSTOM_USER_AGENT: ${self:custom.settings.customUserAgent}
Expand Down