LoginSignup
0
0

More than 3 years have passed since last update.

GCP のプロジェクトを保護する

Last updated at Posted at 2019-09-06

調べた動機

  • プロジェクトも分けて請求アカウント分けたり BigQuery のカスタムコストを分けたりしたくなりました
  • 色々な理由でプロジェクトを分ける運用にするとプロジェクトが大量になり始めます
  • 不要になったプロジェクトを整理したりとか消すこともあるでしょう
  • プロジェクトの作成から自動化した時のバグとか、人為的ミスでのプロジェクト削除とかで必要なプロジェクトが消えたら目も当てられません...
  • どんなに削除権限を持ってるユーザーでも特定のプロジェクトの削除操作は禁止したい!

結論

  • gcloud alpha resource-manager liens create するだけ!

試しにやってみた

$ docker run --rm -it --name gcloud -w /operation google/cloud-sdk bash

% gcloud auth login
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_account&response_type=code&client_id=xxxxxxxxxxx.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&access_type=offline


Enter verification code: 4/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

WARNING: `gcloud auth login` no longer writes application default credentials.
If you need to use ADC, see:
  gcloud auth application-default --help

You are now logged in as [user@example.com].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID


To take a quick anonymous survey, run:
  $ gcloud alpha survey

% gcloud alpha resource-manager liens create --project pj-example --reason="This project must not be deleted" --restrictions="resourcemanager.projects.delete"

% gcloud projects delete pj-example
Your project will be deleted.

Do you want to continue (Y/n)?  Y

ERROR: (gcloud.projects.delete) FAILED_PRECONDITION: A lien to prevent deletion was placed on the project by [user@example.com]. Remove the lien to allow deletion.
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
  violations:
  - description: A lien to prevent deletion was placed on the project by [user@example.com].
      Remove the lien to allow deletion.
    subject: liens/pxxxxxxxxxxxxx-lxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    type: LIEN
  • lien が理由でプロジェクト削除できないことはわかる
  • lien で設定した readon はわからない (現状)
  • 公式ドキュメントLast updated December 13, 2017. なんだけどいつまで alpha なんだろうか

メモ

  • そのうち他にも permission を指定してみる
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0