forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up unused bindings in iam (kubeflow#319)
* clean up unused bindings in iam * fix * request body change * address comment * delete unused members for each binding * fix pylint * add unit test for trim bindings logic
- Loading branch information
1 parent
7e28288
commit 89bbe15
Showing
3 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import print_function | ||
|
||
import unittest | ||
|
||
from kubeflow.testing import cleanup_ci | ||
import os | ||
import yaml | ||
|
||
class CleanupCiTest(unittest.TestCase): | ||
def setUp(self): | ||
self.test_dir = os.path.join(os.path.dirname(__file__), "test-data") | ||
|
||
def test_wait_for_workflow(self): | ||
with open(os.path.join(self.test_dir, "iam_bindings.yaml")) as bd: | ||
iam_bindings = yaml.load(bd) | ||
self.assertTrue(len(iam_bindings['bindings']) == 3) | ||
members = iam_bindings['bindings'][0]['members'] | ||
for act in ['my-other-app@appspot.gserviceaccount.com', | ||
'kfctl-in-use@kubeflow-ci.iam.gserviceaccount.com', | ||
'kfctl-expired@kubeflow-ci.iam.gserviceaccount.com']: | ||
self.assertTrue('serviceAccount:' + act in members) | ||
cleanup_ci.trim_unused_bindings(iam_bindings, | ||
['kfctl-in-use@kubeflow-ci.iam.gserviceaccount.com']) | ||
# One binding is deleted as it lost all members. | ||
self.assertTrue(len(iam_bindings['bindings']) == 2) | ||
trimed_members = iam_bindings['bindings'][0]['members'] | ||
# binding to non-match service account still exists as it is not created by ci tests. | ||
self.assertTrue( | ||
'serviceAccount:my-other-app@appspot.gserviceaccount.com'in trimed_members) | ||
# binding to existing service account still exists. | ||
self.assertTrue( | ||
'serviceAccount:kfctl-in-use@kubeflow-ci.iam.gserviceaccount.com' in trimed_members) | ||
# binding to unexist service account is deleted. | ||
self.assertTrue( | ||
'serviceAccount:kfctl-expired@kubeflow-ci.iam.gserviceaccount.com' not in trimed_members) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
bindings: | ||
- members: | ||
- user:mike@example.com | ||
- group:admins@example.com | ||
- domain:google.com | ||
- serviceAccount:my-other-app@appspot.gserviceaccount.com | ||
- serviceAccount:kfctl-in-use@kubeflow-ci.iam.gserviceaccount.com | ||
- serviceAccount:kfctl-expired@kubeflow-ci.iam.gserviceaccount.com | ||
role: roles/owner | ||
- members: | ||
- user:mike@example.com | ||
role: roles/viewer | ||
- members: | ||
- serviceAccount:kfctl-expired@kubeflow-ci.iam.gserviceaccount.com | ||
role: roles/editor |