Skip to content

fix: remove unrestrictive principal * from KMS policy tests. #712

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

Merged
merged 30 commits into from
Mar 21, 2019

Conversation

mvsusp
Copy link
Contributor

@mvsusp mvsusp commented Mar 19, 2019

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated the changelog with a description of my changes (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

"Statement": [
{{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {{
"AWS": "*"
"AWS": {principal}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not grant to account root instead of a role? that way any entity in the account should get these permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Granting to the account was my first attempt, unfortunately KMS permissions don't propagate to the assumed role when we do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw, the account root is already one of the principals in the list.


def _create_kms_key(kms_client,
account_id,
role_arn=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

why accept a role name and a role arn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are three principals that need to be created: the account root, the role that is running the tests, and the role that will be used by SageMaker. Example:

            "Principal": {
                "AWS": [
                    "arn:aws:iam::142577830533:role/SageMakerRole",
                    "arn:aws:sts::142577830533:assumed-role/DevBuildStackPDX-PullRequestBuildRole4B40B95C-G4AE4UBWNU2K/AWSCodeBuild-fe90a41f-9006-4ccc-918c-437c0f5b26d2",
                    "arn:aws:iam::142577830533:root"
                ]
            },

role_arn=None,
sagemaker_role='SageMakerRole'):
if role_arn:
principal = PRINCIPAL_TEMPLATE.format(account_id=account_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

is the idea here a policy that allows the root account, some role arn, plus another role constructed from the sagemaker_role name? why not simplify that and just require test environments be set up correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked with @jesterhazy offline. We didn't find an easier way to simplify this test without breaking running tests outside the CI.

@laurenyu
Copy link
Contributor

don't forget to change the PR title to include the appropriate prefix with our new release process (#705 was merged)

@mvsusp mvsusp changed the title Remove unrestrictive principal * from KMS policy tests. fix: remove unrestrictive principal * from KMS policy tests. Mar 20, 2019
@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

from botocore import exceptions

KEY_ALIAS = "SageMakerIntegTestKmsKey"
PRINCIPAL_TEMPLATE = '["{account_id}", "{role_arn}", "arn:aws:iam::{account_id}:role/{' \
'sagemaker_role}"] '
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like an awkward way to break the line. maybe instead do it right before the role arn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

def test_server_side_encryption(sagemaker_session):

bucket_with_kms, kms_key = kms_utils.get_or_create_bucket_with_encryption(sagemaker_session.boto_session)
bucket_with_kms, kms_key = kms_utils.get_or_create_bucket_with_encryption(sagemaker_session.boto_session,
'SageMakerRole')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm starting to think this role should be a constant somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

laurenyu
laurenyu previously approved these changes Mar 21, 2019
@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mvsusp mvsusp merged commit cd2b23d into aws:master Mar 21, 2019
@mvsusp mvsusp deleted the mvs-fix-principal branch March 21, 2019 23:03
mizanfiu pushed a commit to mizanfiu/sagemaker-python-sdk that referenced this pull request Dec 13, 2022
Co-authored-by: Zhenshan Jin <[email protected]>
Co-authored-by: Judy Heflin <[email protected]>
Co-authored-by: Zhenshan Jin <[email protected]>

@Zhenshan-Jin
feature: add create model card (aws#663) 

@Zhenshan-Jin
feature: add read update delete model card (aws#671) 

@Zhenshan-Jin
feature: model overview and training details autodiscovery (aws#674) 

@Zhenshan-Jin
feature: add metrics for training and evaluation details (aws#680) 

@Zhenshan-Jin
feature: model card export & list model card version history (aws#688) 

@Zhenshan-Jin
fix: batch update model card and bugs fixes (aws#712) 

@Zhenshan-Jin
@judyheflin
documentation: Amazon SageMaker Model Cards Python SDK documentation (aws#716)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants