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

audit: strip etags from json output, fix bq access dump #2089

Merged
merged 4 commits into from
May 24, 2021

Conversation

spiffxp
Copy link
Member

@spiffxp spiffxp commented May 24, 2021

Fixes: #2029
Fixes: #2062

See commits for details

It's tough to test these out locally without hacking the script. I opted not to refactor into functions to allow for faster/easier testing as part of this PR, will save that for followup

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 24, 2021
@k8s-ci-robot k8s-ci-robot added the area/audit Audit of project resources, audit followup issues, code in audit/ label May 24, 2021
@k8s-ci-robot k8s-ci-robot requested review from nikhita and thockin May 24, 2021 19:04
@k8s-ci-robot k8s-ci-robot added wg/k8s-infra size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 24, 2021
@ameukam
Copy link
Member

ameukam commented May 24, 2021

/lgtm
/hold
Remove hold when ready.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 24, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2021
@spiffxp
Copy link
Member Author

spiffxp commented May 24, 2021

/hold
I'm manually hacking the script a bit and am going to update the audit results in a separate commit

@spiffxp
Copy link
Member Author

spiffxp commented May 24, 2021

Waiting for #2074 to merge so I can rebase on top of it and maybe update audit results before the next audit PR

spiffxp added 4 commits May 24, 2021 16:27
Do this by add a format_gcloud_json function, and passing all gcloud (or
bq, gsutil) output through it.

Format calls so the argument to use json output and the pass through the
function are on the same line to make it clear this should be used
everywhere json output is used.

NOTE: in reformatting the `bq` calls to make this change, I switched
away from prettyjson format, since jq will do the prettifying for us.
However, this means that keys will be stored in a slightly different
order than before.
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 24, 2021
@spiffxp
Copy link
Member Author

spiffxp commented May 24, 2021

/hold cancel
The last commit contains results from running with the following patch applied, which limits to a hardcoded list of projects

diff --git a/audit/audit-gcp.sh b/audit/audit-gcp.sh
index 700077cb..d14f94e7 100755
--- a/audit/audit-gcp.sh
+++ b/audit/audit-gcp.sh
@@ -25,6 +25,7 @@ function format_gcloud_json() {
   jq 'delpaths([path(..|.etag?|select(.))])'
 }

+if false; then
 echo "# Removing existing audit files"
 rm -rf org_kubernetes.io
 rm -rf projects
@@ -47,16 +48,20 @@ gcloud \
     --format=json | format_gcloud_json \
     > "org_kubernetes.io/iam.json"

+fi
 echo "## Iterating over Projects"
 gcloud \
     projects list \
     --filter="parent.id=${CNCF_GCP_ORG}" \
     --format="value(name, projectNumber)" \
 | sort \
+| grep -E '^(k8s-artifacts-prod|k8s-cip-test-prod|k8s-conform|k8s-gsuite|k8s-infra-e2e-scale-project|k8s-infra-ii-sandbox|k8s-infra-prow-build|k8s-infra-prow-build-trusted|k8s-infra-public-pii|kubernetes-public)' \
 | while read -r PROJECT NUM; do
     export CLOUDSDK_CORE_PROJECT="${PROJECT}"

     echo "### Auditing Project ${PROJECT}"
+
+    rm -rf "projects/${PROJECT}"
     mkdir -p "projects/${PROJECT}"

     gcloud \

The list of projects was everything that had files under bigquery or secrets

find audit | grep -E '/(secrets|bigquery)/' | cut -d/ -f3 | sort | uniq | xargs printf "%s|"; echo

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 24, 2021
@spiffxp
Copy link
Member Author

spiffxp commented May 24, 2021

/cc @ameukam @dims
Would like to land this before next run of the audit job if possible

@k8s-ci-robot k8s-ci-robot requested review from ameukam and dims May 24, 2021 21:00
@dims
Copy link
Member

dims commented May 24, 2021

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit e13012c into kubernetes:main May 24, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone May 24, 2021
@spiffxp spiffxp deleted the audit-no-etags branch May 25, 2021 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/audit Audit of project resources, audit followup issues, code in audit/ cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

audit: ensure no etags for dumped resources BigQuery datasets are not reported in the daily audit report
4 participants