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

Create custom IAM role for each cluster #13

Merged
merged 7 commits into from
Oct 9, 2019
Merged

Create custom IAM role for each cluster #13

merged 7 commits into from
Oct 9, 2019

Conversation

tenyo
Copy link
Contributor

@tenyo tenyo commented Sep 26, 2019

This PR adds support for creating/deleting IAM roles. The creation orchestration workflow changes slightly so it will now create a separate IAM role for each cluster instead of using the same default role for all services. This way ECS services in the same cluster can decrypt their own secrets (in SSM Parameter Store) but not secrets belonging to other clusters.

@tenyo tenyo added the WIP label Sep 26, 2019
@tenyo tenyo removed the WIP label Sep 30, 2019
Copy link
Contributor

@fishnix fishnix left a comment

Choose a reason for hiding this comment

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

This looks really good! I think we should shoot for 80% coverage on the libraries. It looks like just the one method (that should probably end up in the handler or orchestration) isn't covered.

ok  	github.com/YaleSpinup/ecs-api/iam	0.019s	coverage: 66.2% of statements

Except for that and the few return signature changes, I think this looks good to go. Thanks!

Comment on lines 75 to 77
// if ecsService.DefaultExecutionRoleArn != "" {
// orchestration.DefaultExecutionRoleArn = aws.String(ecsService.DefaultExecutionRoleArn)
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

👀

iam/errors.go Outdated
if aerr, ok := errors.Cause(err).(awserr.Error); ok {
switch aerr.Code() {
case

Copy link
Contributor

Choose a reason for hiding this comment

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

👀 ✂️

Copy link
Contributor

Choose a reason for hiding this comment

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

and below

iam/errors.go Outdated
iam.ErrCodeEntityAlreadyExistsException:

return apierror.New(apierror.ErrConflict, msg, aerr)

Copy link
Contributor

Choose a reason for hiding this comment

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

👀 ✂️ and below

iam/iam.go Outdated
}

// DefaultTaskExecutionRole generates the default role (if it doesn't exist) for ECS task execution and returns the ARN
func (i *IAM) DefaultTaskExecutionRole(ctx context.Context, path string) (*string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would return string unless you use the nil value

}

return roleOutput.Role.Arn, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this orchestration doesn't belong here ultimately, but its probably okay for now.

iam/role.go Outdated
}

// DeleteRole handles deleting an IAM role
func (i *IAM) DeleteRole(ctx context.Context, input *iam.DeleteRoleInput) (*iam.DeleteRoleOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just return error

type DeleteRoleOutput struct {
    // contains filtered or unexported fields
}

iam/role.go Outdated
)

// CreateRole handles creating an IAM role
func (i *IAM) CreateRole(ctx context.Context, input *iam.CreateRoleInput) (*iam.CreateRoleOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just return *iam.Role, error

type CreateRoleOutput struct {

    // A structure containing details about the new role.
    //
    // Role is a required field
    Role *Role `type:"structure" required:"true"`
    // contains filtered or unexported fields
}

iam/role.go Outdated
}

// PutRolePolicy handles attaching an inline policy to IAM role
func (i *IAM) PutRolePolicy(ctx context.Context, input *iam.PutRolePolicyInput) (*iam.PutRolePolicyOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just return error

type PutRolePolicyOutput struct {
    // contains filtered or unexported fields
}

type Orchestrator struct {
// https://docs.aws.amazon.com/sdk-for-go/api/service/ecs/#ECS
ECS *ecs.ECS
// https://docs.aws.amazon.com/sdk-for-go/api/service/iam/#IAM
IAM iam.IAM
// IAM iamiface.IAMAPI
Copy link
Contributor

Choose a reason for hiding this comment

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

👀

}

input.TaskDefinition.ExecutionRoleArn = roleARN
}
Copy link
Contributor

Choose a reason for hiding this comment

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

#thatwaseasy 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅

@tenyo
Copy link
Contributor Author

tenyo commented Oct 3, 2019

ok  	github.com/YaleSpinup/ecs-api/iam	0.019s	coverage: 87.8% of statements

Copy link
Contributor

@fishnix fishnix left a comment

Choose a reason for hiding this comment

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

looks good 👍

@tenyo tenyo merged commit be0a1e3 into master Oct 9, 2019
@fishnix fishnix deleted the tg_custom_role branch March 28, 2021 11:42
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.

2 participants