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

Add IAM role filters #49

Merged
merged 2 commits into from
Nov 23, 2017
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
8 changes: 8 additions & 0 deletions resources/iam-role-policie-attachements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/service/iam"
)
Expand Down Expand Up @@ -42,6 +43,13 @@ func (n *IamNuke) ListRolePolicyAttachements() ([]Resource, error) {
return resources, nil
}

func (e *IamRolePolicyAttachement) Filter() error {
if strings.HasPrefix(e.policyArn, "arn:aws:iam::aws:policy/aws-service-role/") {
return fmt.Errorf("cannot detach from service roles")
}
return nil
}

func (e *IamRolePolicyAttachement) Remove() error {
_, err := e.svc.DetachRolePolicy(
&iam.DetachRolePolicyInput{
Expand Down
16 changes: 15 additions & 1 deletion resources/iam-roles.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package resources

import "github.com/aws/aws-sdk-go/service/iam"
import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/service/iam"
)

type IamRole struct {
svc *iam.IAM
name string
path string
}

func (n *IamNuke) ListRoles() ([]Resource, error) {
Expand All @@ -18,12 +24,20 @@ func (n *IamNuke) ListRoles() ([]Resource, error) {
resources = append(resources, &IamRole{
svc: n.Service,
name: *out.RoleName,
path: *out.Path,
})
}

return resources, nil
}

func (e *IamRole) Filter() error {
if strings.HasPrefix(e.path, "/aws-service-role/") {
return fmt.Errorf("cannot delete service roles")
}
return nil
}

func (e *IamRole) Remove() error {
_, err := e.svc.DeleteRole(&iam.DeleteRoleInput{
RoleName: &e.name,
Expand Down