-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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!
api/handlers_orchestration.go
Outdated
// if ecsService.DefaultExecutionRoleArn != "" { | ||
// orchestration.DefaultExecutionRoleArn = aws.String(ecsService.DefaultExecutionRoleArn) | ||
// } |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 ✂️
There was a problem hiding this comment.
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) | ||
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
}
orchestration/orchestration.go
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
} | ||
|
||
input.TaskDefinition.ExecutionRoleArn = roleARN | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#thatwaseasy 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good 👍
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.