Skip to content

Commit

Permalink
Handle deleted: prefix when deduplicating IAM member map (#2819)
Browse files Browse the repository at this point in the history
Merged PR #2819.
  • Loading branch information
slevenick authored and modular-magician committed Dec 11, 2019
1 parent 463f8df commit 249ad77
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
17 changes: 14 additions & 3 deletions third_party/terraform/utils/iam.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,21 @@ func createIamBindingsMap(bindings []*cloudresourcemanager.Binding) map[iamBindi
// <type> is case sensitive
// <value> isn't
// so let's lowercase the value and leave the type alone
pieces := strings.SplitN(m, ":", 2)
if len(pieces) > 1 {
pieces[1] = strings.ToLower(pieces[1])
// since Dec '19 members can be prefixed with "deleted:" to indicate the principal
// has been deleted
var pieces []string
if strings.HasPrefix(m, "deleted:") {
pieces = strings.SplitN(m, ":", 3)
if len(pieces) > 2 {
pieces[2] = strings.ToLower(pieces[2])
}
} else {
pieces = strings.SplitN(m, ":", 2)
if len(pieces) > 1 {
pieces[1] = strings.ToLower(pieces[1])
}
}

m = strings.Join(pieces, ":")

// Add the member
Expand Down
29 changes: 29 additions & 0 deletions third_party/terraform/utils/iam_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,35 @@ func TestIamCreateIamBindingsMap(t *testing.T) {
iamBindingKey{"role-3", conditionKey{}}: {"user-3": {}},
},
},
{
input: []*cloudresourcemanager.Binding{
{
Role: "role-1",
Members: []string{"deleted:serviceAccount:user-1", "user-2"},
},
{
Role: "role-2",
Members: []string{"deleted:user:user-1"},
},
{
Role: "role-1",
Members: []string{"serviceAccount:user-3"},
},
{
Role: "role-2",
Members: []string{"user-2"},
},
{
Role: "role-3",
Members: []string{"user-3"},
},
},
expect: map[iamBindingKey]map[string]struct{}{
iamBindingKey{"role-1", conditionKey{}}: {"deleted:serviceAccount:user-1": {}, "user-2": {}, "serviceAccount:user-3": {}},
iamBindingKey{"role-2", conditionKey{}}: {"deleted:user:user-1": {}, "user-2": {}},
iamBindingKey{"role-3", conditionKey{}}: {"user-3": {}},
},
},
<% unless version == 'ga' -%>
{
input: []*cloudresourcemanager.Binding{
Expand Down

0 comments on commit 249ad77

Please sign in to comment.