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 grant roles/bigquery.jobUser and roles/(viewer|writer|owner) functionalities #11

Merged
merged 21 commits into from
Aug 24, 2020

Conversation

hirosassa
Copy link
Owner

@hirosassa hirosassa commented Aug 9, 2020

What is this PR?

fix #12

I implemented following two functionalities:

  1. refactor original permit sub-command to permit dataset
  2. grant roles/bigquery.jobUser role for each users on permit dataset sub-commnad
  3. add permit project sub-command that permits project-wide permissions like roles/viewer

@hirosassa
Copy link
Owner Author

@snowhork I want to discuss about naming of subcommands!

hirosassa and others added 10 commits August 10, 2020 14:23
* implement cache auto refresh

* fix typo

* fix

* change to cacherefreshhour

Co-authored-by: hirohito-sasakawa <hirohito-sasakawa@m3.com>
* fix bug on cache refresh flag

* remove

Co-authored-by: hirohito-sasakawa <hirohito-sasakawa@m3.com>
@hirosassa hirosassa changed the title WIP: Add grant roles/bigquery.jobUser and roles/(viewer|writer|owner) functionalities Add grant roles/bigquery.jobUser and roles/(viewer|writer|owner) functionalities Aug 16, 2020
READER = "READER"
WRITER = "WRITER"
OWNER = "OWNER"
)
Copy link
Owner Author

Choose a reason for hiding this comment

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

moved constants here

}
}
return false
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

original permit command moved here

}
}
return false
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

sub-sub-command thant grants project role

"github.com/spf13/cobra"
"google.golang.org/api/bigquery/v2"
"google.golang.org/api/iterator"

"github.com/hirosassa/bqiam/metadata"
Copy link
Owner Author

Choose a reason for hiding this comment

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

import ordering

`,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

permit sub-command initialization

cmd.AddCommand(
newPermitProjectCmd(),
newPermitDatasetCmd(),
)
Copy link
Owner Author

Choose a reason for hiding this comment

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

adds project and dataset sub-sub-commands

reader := bufio.NewReader(os.Stdin)
res, err := reader.ReadString('\n')
return cmd
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

Initialization of permit project command

cmd.Flags().StringSliceP("users", "u", []string{}, "Specify user email(s)")
cmd.Flags().StringSliceP("datasets", "d", []string{}, "Specify dataset(s)")

return cmd
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

initialization of permit dataset command

return fmt.Errorf("failed to permit: %s", err)
}

return nil
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

implementation of the permit dataset command

fmt.Printf("Permit %s to %s access as %s\n", user, dataset, role)
}
if err != nil {
return fmt.Errorf("failed to permit: %s", err)
}

return nil
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

implementation of the permit project command

@hirosassa
Copy link
Owner Author

hirosassa commented Aug 16, 2020

@snowhork I implemented a set of sub-sub-commands (permit dataset and permit project).
(Since I refactored the code structure, the diff is huge, sorry)

Please review.

Copy link
Contributor

@snowhork snowhork left a comment

Choose a reason for hiding this comment

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

Please check for service accounts.

cmd/permit.go Outdated
For example:

bqiam permit dataset READER -p bq-project-id -u user1@email.com -u user2@email.com -d dataset1 -d dataset2
bqiam permit project VIEWER -p bq-project-id -u user1@email.com
Copy link
Contributor

Choose a reason for hiding this comment

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

I think bqiam permit project READER

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed!

return fmt.Errorf("%s already has a role: %s, project: %s", user, role, project)
}

cmd := fmt.Sprintf("gcloud projects add-iam-policy-binding %s --member user:%s --role %s", project, user, role)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we apply to Service accounts?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I fixed and tested for SAs manually.

@hirosassa
Copy link
Owner Author

@snowhork I fixed your suggestions. plz review

@snowhork
Copy link
Contributor

@hirosassa LGTM. I've checked the behaviour by SA too. Thanks!!

@hirosassa hirosassa merged commit 8745d02 into master Aug 24, 2020
@hirosassa hirosassa deleted the add-permission-job-user branch August 24, 2020 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grant bigquery.jobUser and project-(viewer|writer|owner)
2 participants