-
Notifications
You must be signed in to change notification settings - Fork 828
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
Initial Auditing Configuration and Usage of the kubernetes.io GCP Organization #213
Conversation
hh
commented
Apr 3, 2019
•
edited by thockin
Loading
edited by thockin
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Initial audit of a policy change: https://kubernetes.slack.com/messages/CCK68P2Q2/convo/C09QZ4DQB-1554150053.006600/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great starting point
* Audit report | ||
|
||
How to automate: | ||
* How do we audit for iam changes as they happen, rather than polling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could (once this is working as we want and once we have our cluster up) run this as a CronJob daily or even hourly, posting any deltas to slack or something
audit/audit.sh
Outdated
do | ||
gcloud organizations get-iam-policy $CNCF_GCP_ORG --format=$format \ | ||
> cncf-org-policy.$format | ||
gcloud projects get-iam-policy kubernetes-public --format=$format \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than "kubernetes-public" shouldn't we be doing a loop over all projects?
e.g.
gcloud projects list \
--filter "parent.id=758905017065" \
--format "value(name, projectNumber)" \
| while read NAME NUM; do \
gcloud projects get-iam-policy $NAME --format=$format > $NAME.policy.$format
gcloud iam roles list --project=$NAME --format=$format > $NAME.roles.$format
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I vote for JSON - much easier to visually verify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently doing json and yaml, I can remove yaml if you like.
audit/audit.sh
Outdated
mkdir -p buckets | ||
for BUCKET in `gsutil ls -p kubernetes-public | awk -F/ '{print $3}'` | ||
do | ||
gsutil ls -r gs://$BUCKET/ > buckets/$BUCKET.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to audit the contents of buckets, or just permissions? This will trigger a lot of updates -- e.g. billing is dumped at least daily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just permissions are fine, I think there are object/file/folder specific permissions that can be set.
We may need a way to capture these or set a remove the ability to set per file perms and only have bucket level.
Thoughts?
e25e19f
to
d8718f6
Compare
Ping on this. As we start expanding scope, the fully formed version of this would make me feel better... |
@thockin to take a final pass on this |
|
||
# gcloud organizations describe $CNCF_GCP_ORG 2>&1 | ||
# ERROR: (gcloud.organizations.describe) | ||
# User [[email protected]] does not have permission to access organization [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thockin Can we add 'gcloud.organizations.describe' to the k8s-infra-gcp-auditors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the permission name. I added 'Organization Viewer' which seems to have the right permissions. Try it and let me know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you try this again?
@@ -0,0 +1,358 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the dev-cluster-turnup has a many more services enabled than our primary one.
for service in `gcloud services list --filter state:ENABLED --format=json \ | ||
| jq -r .[].config.name | sed s:.googleapis.com::` | ||
do | ||
case $service in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do a bit of iterating over the services. How far do we want to dig into the configuration of each.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am less concerned about service configs than IAM and access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Dumping the entire config is a bit out of scope, but I added it the documentation/TODO completeness later.
/cc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a form of this committed soon, so we can use it as we turn more things on? Then iterate..
this has grown quite a lot, do we need to open up a new PR? |
Since adding a few new projects the case statement iterating over services has more unhandled services.
|
These are the new perms and the commands are commented out in audit-gcp under each TODO:
|
I'm keen with merging as is and evolving. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: spiffxp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly very minor comments - would love to get this in and then do a group review of the data.
@@ -0,0 +1,100 @@ | |||
#!/bin/bash | |||
# set -x -e | |||
CNCF_GCP_ORG=758905017065 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could source infra/gcp/lib.sh
if there are any more utilities to re-use. This is unlikely to change :)
|
||
# gcloud organizations describe $CNCF_GCP_ORG 2>&1 | ||
# ERROR: (gcloud.organizations.describe) | ||
# User [[email protected]] does not have permission to access organization [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you try this again?
@@ -0,0 +1,100 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need copyright header
| while read PROJECT NUM; do \ | ||
export CLOUDSDK_CORE_PROJECT=$PROJECT | ||
echo "### Auditing Project: ${PROJECT} ###" | ||
mkdir -p $PROJECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this assumes CWD is the script's root, maybe we should check that and print a warning if it is not?
storage-api.googleapis.com) | ||
echo TODO: Add storage.buckets.get for auditors | ||
echo ...to kubernetes_public_billing and any newer buckets... | ||
echo TODO: Ensure bucket-policy-only, for simplicity in Auditing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do set bucketpolicyonly
now. We do not set logging and we do not set cors. Should we?
@@ -0,0 +1,156 @@ | |||
gs://kubernetes_public_billing/billing--2019-01-10.csv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should not be dumping bucket contents or VM names or anything that is likely to be constantly changing. Unlikely that any 2 audits could produce the same data for this.
#### gsutil cors get gs://$BUCKET/ | ||
#### gsutil logging get gs://$BUCKET/ | ||
gsutil iam get gs://$BUCKET/ > $PROJECT/buckets/$BUCKET.iam.json | ||
gsutil ls -r gs://$BUCKET/ > $PROJECT/buckets/$BUCKET.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not do this - it will be always changing
compute) | ||
echo TODO: $service Needs compute.projects.get | ||
#### gcloud compute project-info describe | ||
#### gcloud compute instances list --format=$format > $PROJECT/services/compute.instances.$format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not list VMs - they will change as clusters get upgraded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disks are somewhat dubiously useful, too. Clusters seems OK
echo Processing: $service | ||
mkdir -p dns | ||
gcloud dns project-info describe $PROJECT --format=$format > $PROJECT/services/dns.info.$format | ||
gcloud dns managed-zones list --format=$format > $PROJECT/services/dns.zones.$format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above - audit should catch metadata, not data
@@ -0,0 +1,33 @@ | |||
{ | |||
"bindings": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graveyard is going away, so we can nuke all these files
/assign @hh |
merge and iterate |
Ping - I think it's back in your court, @hh |
/hold |
/hold cancel |
/retest |