Skip to content

listPolicies functions fixed #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager github.com/ihoe

# Copy the controller-manager into a thin image
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y ca-certificates

WORKDIR /root/
COPY --from=builder /go/src/github.com/ihoegen/iam-role-manager/manager .
ENTRYPOINT ["./manager"]
74 changes: 56 additions & 18 deletions pkg/controller/iamrole/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,39 @@ func isArn(policy string) bool {
// Paginate over inline policies
func (i *IAMClient) listInlinePolicies(roleName string) ([]string, error) {
var policyNamesPointers []*string
isTruncated := true
marker := "1"
for isTruncated {
currentPolicies, err := i.Client.ListRolePolicies(&iam.ListRolePoliciesInput{
currentPolicies, err := i.Client.ListRolePolicies(&iam.ListRolePoliciesInput{
RoleName: &roleName,
Marker: &marker,
})
if err != nil {
return nil, err
}
policyNamesPointers = append(policyNamesPointers, currentPolicies.PolicyNames...)
marker = *currentPolicies.Marker
isTruncated = *currentPolicies.IsTruncated
}
isTruncated := *currentPolicies.IsTruncated
if isTruncated == true {
policyNamesPointers = append(policyNamesPointers, currentPolicies.PolicyNames...)
marker := *currentPolicies.Marker
for isTruncated {
currentPolicies, err := i.Client.ListRolePolicies(&iam.ListRolePoliciesInput{
RoleName: &roleName,
Marker: &marker,
})
if err != nil {
return nil, err
}
policyNamesPointers = append(policyNamesPointers, currentPolicies.PolicyNames...)
isTruncated = *currentPolicies.IsTruncated
if isTruncated == true {
marker = *currentPolicies.Marker
}
}
} else {
currentPolicies, err := i.Client.ListRolePolicies(&iam.ListRolePoliciesInput{
RoleName: &roleName,
})
if err != nil {
return nil, err
}
policyNamesPointers = append(policyNamesPointers, currentPolicies.PolicyNames...)
}
var policyNameValues []string
for _, val := range policyNamesPointers {
policyNameValues = append(policyNameValues, *val)
Expand All @@ -268,20 +287,39 @@ func (i *IAMClient) listInlinePolicies(roleName string) ([]string, error) {
// Paginate over attached policies
func (i *IAMClient) listAttachedPolicies(roleName string) ([]iam.AttachedPolicy, error) {
var policyPointers []*iam.AttachedPolicy
isTruncated := true
marker := "1"
for isTruncated {
currentPolicies, err := i.Client.ListAttachedRolePolicies(&iam.ListAttachedRolePoliciesInput{
currentPolicies, err := i.Client.ListAttachedRolePolicies(&iam.ListAttachedRolePoliciesInput{
RoleName: &roleName,
Marker: &marker,
})
if err != nil {
return nil, err
}
policyPointers = append(policyPointers, currentPolicies.AttachedPolicies...)
marker = *currentPolicies.Marker
isTruncated = *currentPolicies.IsTruncated
}
isTruncated := *currentPolicies.IsTruncated
if isTruncated == true {
policyPointers = append(policyPointers, currentPolicies.AttachedPolicies...)
marker := *currentPolicies.Marker
for isTruncated {
currentPolicies, err := i.Client.ListAttachedRolePolicies(&iam.ListAttachedRolePoliciesInput{
RoleName: &roleName,
Marker: &marker,
})
if err != nil {
return nil, err
}
policyPointers = append(policyPointers, currentPolicies.AttachedPolicies...)
isTruncated = *currentPolicies.IsTruncated
if isTruncated == true {
marker = *currentPolicies.Marker
}
}
} else {
currentPolicies, err := i.Client.ListAttachedRolePolicies(&iam.ListAttachedRolePoliciesInput{
RoleName: &roleName,
})
if err != nil {
return nil, err
}
policyPointers = append(policyPointers, currentPolicies.AttachedPolicies...)
}
var policyNameValues []iam.AttachedPolicy
for _, val := range policyPointers {
policyNameValues = append(policyNameValues, *val)
Expand Down