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

infra/gcp: disable containerscanning and test-infra-trusted prow access for staging and release projects #2016

Merged
merged 9 commits into from
May 20, 2021

Conversation

spiffxp
Copy link
Member

@spiffxp spiffxp commented May 7, 2021

This is an attempt at making some progress on the audit followup issue to ensure we don't have random services enabled #1887

It's also more directly motivated by ensuring that containerscanning is disabled for #1963

EDIT: I'm going to cap this off before it gets too sprawling. See individual commits for details.

Brief summary:

  • Nice to have stuff
    • split out services-related functions into lib_services.sh, rename ensure_api to ensure_services
    • add comments to and organize the top of lib.sh
    • reorganize ensure-staging-storage.sh into functions, as has been done for ensure-organization.sh and ensure-main-project.sh
  • Disable container scanning
    • remove from required staging project services
    • explicitly disable via new ensure_disabled_services
  • Starting to sprawl

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 7, 2021
@k8s-ci-robot k8s-ci-robot requested review from dims and nikhita May 7, 2021 16:33
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 7, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 20, 2021
@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

/cc @ameukam
more bash bending

/cc @cpanato
mostly as FYI for the direction I'm heading with 346a1d2, if you're interested in picking up from there

@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

#2067 is starting to pick up the results of me running some of these scripts while developing/testing this

./infra/gcp/ensure-staging-storage.sh cluster-api-gcp kubetest2
./infra/gcp/ensure-release-projects.sh k8s-release

I'm going to kick off a run of ensure-staging-storage.sh as I'm confident based on testing, but will refrain from running the rest until review.

@spiffxp spiffxp changed the title [wip] infra/gcp: prune some GCP services infra/gcp: disable containerscanning and test-infra-trusted prow access for staging and release projects May 20, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 20, 2021
Comment on lines +135 to +136
color 6 "Ensuring k8s-prow / test-infra-trusted can no longer use GCB in project: ${PROJECT}"
ensure_removed_google_prow_bindings "${PROJECT}" "${GCB_BUCKET}"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure but this part is applied once. Why do it ever time the script is used ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is to remove this in a follow-up PR. I was starting to get lazy by this point so I didn't go as far as making a "bindings to remove" array like I did in ensure-organizations.

@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

#2067 now reflects all changes for release and staging projects

@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

/hold
I'm finding typos in infra/gcp/ensure-env-cip-auditor.sh

@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 20, 2021
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 20, 2021
spiffxp added 9 commits May 20, 2021 17:14
Describe the reason includes are sourced in the way they are

Pull more constants into lib.sh and organize them by "purpose" and then
alphabetically within. The following were added to lib, or scripts were
modified to use these:

- RELEASE_ADMINS, RELEASE_WRITERS, RELEASE_VIEWERS
- PROW_GOOGLE_TRUSTED_SERVICE_ACCOUNT (formerly PROW_SVCACCT)
- PROW_BUILD_SERVICE_ACCOUNT
- PROW_TRUSTED_BUILD_CLUSTER_PROJECTS
- PROW_UNTRUSTED_BUILD_CLUSTER_PROJECTS

Shellcheck complains that some of these aren't used within lib.sh and
should be exported if they're used elsewhere. Going to intentially hold
off on that for now, it may turn out not all of these need to be
"global", or that there's a better place to store these.
This was broken by a missing PROJECT_ID variable (probably by me in a
previous attempt to refactor into functions)

Fixed that, and did some other misc fixes:

- move services to a readonly constant up top
- use `project` instead of `project_id`
- fix shellcheck nits
- avoid funcname hardcode on args checks
Planning to overhaul ensure_services_only, so move service-related
functions into their own lib_service.sh

Moved the following over:

- enable_api
- _plan_enabled_services
- ensure_only_services
specifically:

- write the .jq file used by ensure_only_services only once
- fix shellcheck nits
- enable_api now supports N services; will rename in later commit
Since the gcloud command is `gcloud services` let's drop the API
nomenclature, and pluralize to reflect that N services can be enabled at
once now.

Add a corresponding ensure_disabled_services function with a scary
warning.

While following the the rename, I also refactored to use lists of
services if relevant, for:

- ensure-prod-storage.sh
- ensure-prod-storage-gclb.sh
- ensure-env-cip-auditor.sh
Following a pattern that I've used for ensure-main-project.sh and
ensure-organization.sh that involves moving everything into functions or
readonly constants, and then an entrypoint at the bottom.

So the entrypoint is no longer a massive for loop and blocks of code,
but instead ensure_staging_projects, which calls:

- ensure_staging_project for each repo, which calls:
  - ensure_staging_gcs_bucket
  - ensure_staging_gcr_repo
  - ensure_staging_gcb
  - staging_special_case__k8s_staging_foo (if it exists)
- ensure_release_manager_special_cases

I commented functions heavily, and dropped comments if the logging
statement was basically saying the same thing.

Other changes:

- Stop using empower_prow, prep for using service-account per-project
- Change ensure_staging_gcb_builder_service_account to also grant
  write access to GCS and GCR directly from that service account
There are no longer any jobs that run in test-infra-trusted using the
deployer serviceaccount.  Revoke that serviceaccount's access to any
of the k8s-staging* or k8s-release* projects
Since I still don't trust ensure_only_services to do the right thing by
default, and I know we want to disable the containerscanning service,
add support for explicitly disabling services.
@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

Well, I did more than fix the typo. Tried to rebase changes to make a little more sense. But I'm done adding anything more to this PR for real. The summary up top is still correct.

@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

Here's what I have run from HEAD of this PR so far

@spiffxp
Copy link
Member Author

spiffxp commented May 20, 2021

/hold cancel

@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 20, 2021
@ameukam
Copy link
Member

ameukam commented May 20, 2021

/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 20, 2021
@k8s-ci-robot k8s-ci-robot merged commit f8c4dbe into kubernetes:main May 20, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone May 20, 2021
@spiffxp spiffxp deleted the prune-services branch May 20, 2021 22:31
@cpanato
Copy link
Member

cpanato commented May 21, 2021

late /lgtm

@ameukam
Copy link
Member

ameukam commented Jun 4, 2021

Related to : #516

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. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants