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

BigQuery datasets are not reported in the daily audit report #2029

Closed
ameukam opened this issue May 10, 2021 · 9 comments · Fixed by #2089
Closed

BigQuery datasets are not reported in the daily audit report #2029

ameukam opened this issue May 10, 2021 · 9 comments · Fixed by #2089
Assignees
Labels
area/audit Audit of project resources, audit followup issues, code in audit/ priority/backlog Higher priority than priority/awaiting-more-evidence.
Milestone

Comments

@ameukam
Copy link
Member

ameukam commented May 10, 2021

I noticed some BQ datasets of some projects are not reported in the daily audit. Like k8s-artificats-prod:

 gcloud alpha bq datasets list --project k8s-artifacts-prod
ID                               LOCATION
k8s-artifacts-prod:gcs_logs      US
k8s-artifacts-prod:http_lb_logs  US
gcloud alpha bq datasets describe http_lb_logs --project k8s-artifacts-prod
access:
- role: WRITER
  userByEmail: [email protected]
- role: OWNER
  specialGroup: projectWriters
- role: OWNER
  userByEmail: [email protected]
creationTime: '1595435572438'
datasetReference:
  datasetId: http_lb_logs
  projectId: k8s-artifacts-prod
etag: lJiP3Wus3wsAFvTNYpvLaw==
id: k8s-artifacts-prod:http_lb_logs
kind: bigquery#dataset
lastModifiedTime: '1595435572438'
location: US
selfLink: https://bigquery.googleapis.com/bigquery/v2/projects/k8s-artifacts-prod/datasets/http_lb_logs
type: DEFAULT

The current report is empty: https://github.com/kubernetes/k8s.io/blob/main/audit/projects/k8s-artifacts-prod/services/bigquery/bigquery.datasets.json

It would great to have them part of the daily report.

/assign @spiffxp @thockin
cc @hh

@ameukam ameukam added the area/audit Audit of project resources, audit followup issues, code in audit/ label May 10, 2021
@ameukam ameukam added the priority/backlog Higher priority than priority/awaiting-more-evidence. label May 10, 2021
@spiffxp
Copy link
Member

spiffxp commented May 25, 2021

/reopen
Still not being reported per the latest audit PR, ref: #2094 (review)

@k8s-ci-robot
Copy link
Contributor

@spiffxp: Reopened this issue.

In response to this:

/reopen
Still not being reported per the latest audit PR

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.

@k8s-ci-robot k8s-ci-robot reopened this May 25, 2021
@spiffxp
Copy link
Member

spiffxp commented May 25, 2021

Looking at the audit PR more closely, the Kubernetes-public resources weren't deleted.

I'm guessing this means roles/viewer can see them:

And the auditor service account has that role for kubernetes-public:

"members": [
"group:[email protected]",
"group:[email protected]",
"group:[email protected]",
"group:[email protected]",
"serviceAccount:[email protected]"
],
"role": "roles/viewer"

But not for the organization

Which makes me wonder if, just like org admins get roles/owner + a custom role for supplementary stuff, we should do the same for auditors.

Or, see if there's a way to give audit.viewer read access to everything it needs to export metadata about big query datasets (as there is with GCS)

@spiffxp
Copy link
Member

spiffxp commented May 25, 2021

Using #2100 to test

First run, I get an error

 ./audit/audit-gcp.sh k8s-infra-ii-sandbox
Exporting GCP project: k8s-infra-ii-sandbox
  Removing existing audit files for project: k8s-infra-ii-sandbox
  Exporting project description for project: k8s-infra-ii-sandbox
  Exporting IAM policy for project: k8s-infra-ii-sandbox
  Exporting IAM serviceaccounts for project: k8s-infra-ii-sandbox
  Exporting IAM roles for project: k8s-infra-ii-sandbox
  Exporting enabled services for project: k8s-infra-ii-sandbox
  Exporting resources for all enabled services for project: k8s-infra-ii-sandbox
    Exporting resources for service: bigquery, project: k8s-infra-ii-sandbox
      parse error: Invalid numeric literal at line 2, column 8
      Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
      BrokenPipeError: [Errno 32] Broken pipe

Next run works though

$ ./audit/audit-gcp.sh k8s-infra-ii-sandbox
Exporting GCP project: k8s-infra-ii-sandbox
  Removing existing audit files for project: k8s-infra-ii-sandbox
  Exporting project description for project: k8s-infra-ii-sandbox
  Exporting IAM policy for project: k8s-infra-ii-sandbox
  Exporting IAM serviceaccounts for project: k8s-infra-ii-sandbox
  Exporting IAM roles for project: k8s-infra-ii-sandbox
  Exporting enabled services for project: k8s-infra-ii-sandbox
  Exporting resources for all enabled services for project: k8s-infra-ii-sandbox
    Exporting resources for service: bigquery, project: k8s-infra-ii-sandbox
    Exporting resources for service: bigqueryconnection, project: k8s-infra-ii-sandbox
      WARN: Unaudited service bigqueryconnection enabled in project: k8s-infra-ii-sandbox
    Exporting resources for service: bigquerydatatransfer, project: k8s-infra-ii-sandbox
      WARN: Unaudited service bigquerydatatransfer enabled in project: k8s-infra-ii-sandbox
# ...
$ git diff
$

That's kicking loose a comment about bq I've seen somewhere in test-infra's codebase...

@spiffxp
Copy link
Member

spiffxp commented May 25, 2021

Found it: https://github.com/kubernetes/test-infra/blob/4d5c4c788bcee23a9323ca6f10563a08afb822f6/metrics/bigquery.py#L154-L157

    # the 'bq show' command is called as a hack to dodge the config prompts that bq presents    
    # the first time it is run. A newline is passed to stdin to skip the prompt for default project    
    # when the service account in use has access to multiple projects.    
    check(['bq', 'show'], stdin='\n')

@spiffxp
Copy link
Member

spiffxp commented May 26, 2021

#2100 added a bq show to try and work around this

Unfortunately it broke the ci job. #2104 will fix

@spiffxp
Copy link
Member

spiffxp commented Jun 11, 2021

/close
They're now reported, e.g. https://github.com/kubernetes/k8s.io/blob/main/audit/projects/kubernetes-public/services/bigquery/bigquery.datasets.kubernetes_public_billing.access.json

@k8s-ci-robot
Copy link
Contributor

@spiffxp: Closing this issue.

In response to this:

/close
They're now reported, e.g. https://github.com/kubernetes/k8s.io/blob/main/audit/projects/kubernetes-public/services/bigquery/bigquery.datasets.kubernetes_public_billing.access.json

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.

@spiffxp
Copy link
Member

spiffxp commented Jun 11, 2021

/milestone v1.22

@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/audit Audit of project resources, audit followup issues, code in audit/ priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants