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

backups: include clusterroles/bindings that reference serviceaccounts #470

Merged
merged 1 commit into from
May 9, 2018

Conversation

skriss
Copy link
Contributor

@skriss skriss commented May 2, 2018

Signed-off-by: Steve Kriss [email protected]

Fixes #339

Add a backup item action for serviceaccounts that looks for clusterrolebindings that have the SA as a subject, and includes the clusterrolebinding & associated clusterrole in the list of additional items to backup.

@skriss skriss force-pushed the backup-cluster-roles-and-bindings branch 2 times, most recently from b482958 to 5084517 Compare May 2, 2018 20:44
@skriss skriss added the Bug label May 2, 2018
@skriss skriss force-pushed the backup-cluster-roles-and-bindings branch from 5084517 to dfe5b01 Compare May 2, 2018 20:51
@skriss skriss requested review from ncdc and nrb May 2, 2018 20:51
a.log.Info("Running serviceAccountAction")
defer a.log.Info("Done running serviceAccountAction")

crbList, err := a.client.List(metav1.ListOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use a real client here. Doing so would mean that we list all ClusterRoleBindings in the entire cluster every time we see a ServiceAccount.

We should either look into using a Lister from a SharedInformer, or caching the list per Backup UID (with something like a 15 minute expiration).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good point. I'll look into one of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just fetch the ClusterRoleBindings in the action's constructor and store them for the life of the action since actions are created anew for each backup - WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@skriss skriss force-pushed the backup-cluster-roles-and-bindings branch from dfe5b01 to b94f10d Compare May 4, 2018 16:43
@ncdc
Copy link
Contributor

ncdc commented May 9, 2018

LGTM, although we should probably add some logging indicating what's going on. We could either do it per plugin (when adding additional items), or globally in the item backupper.

@skriss skriss force-pushed the backup-cluster-roles-and-bindings branch from b94f10d to 5598567 Compare May 9, 2018 16:49
@skriss
Copy link
Contributor Author

skriss commented May 9, 2018

Added logging in the action (some of the other actions already do this, plus can include more context there on why the additional items are being included).

for _, roleBinding := range a.roleBindings {
for _, subj := range roleBinding.Subjects {
if subj.Kind == rbac.ServiceAccountKind && subj.Namespace == namespace && subj.Name == name {
a.log.Infof("Adding clusterrole %s and clusterrolebinding %s to additionalItems since serviceaccount %s/%s is a subject",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the logging down to the bindings and roles loops, separately. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this comment. I had it there first then moved it :) I thought it was more informative to have the CR and CRB in the same log statement since they're linked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that you might run into the same clusterrrole for multiple clusterrolebindings for a single serviceaccount, but this is fine as it is.

// serviceAccountAction implements ItemAction.
type serviceAccountAction struct {
log logrus.FieldLogger
roleBindings []rbac.ClusterRoleBinding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late comment, but could you call this clusterRoleBindings? Every time I see roleBindings, I think of the non-cluster scoped version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@skriss skriss force-pushed the backup-cluster-roles-and-bindings branch from 5598567 to 041cfc2 Compare May 9, 2018 17:04
@ncdc
Copy link
Contributor

ncdc commented May 9, 2018

LGTM

@ncdc ncdc merged commit ea83ed3 into vmware-tanzu:master May 9, 2018
@skriss skriss deleted the backup-cluster-roles-and-bindings branch May 9, 2018 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants