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

Enable constraint disableServiceAccountKeyCreation on project #242

Open
k9ert opened this issue Jan 7, 2025 · 0 comments
Open

Enable constraint disableServiceAccountKeyCreation on project #242

k9ert opened this issue Jan 7, 2025 · 0 comments

Comments

@k9ert
Copy link

k9ert commented Jan 7, 2025

If you terraform a new project based on a organsiation which is unaltered, you will get an issue like this in the bootstrap-phase:

➜  inception git:(kn/tf-fix-01) gcloud iam service-accounts keys create inception-sa-creds.json \
  --iam-account=${inception_email}
ERROR: (gcloud.iam.service-accounts.keys.create) FAILED_PRECONDITION: Key creation is not allowed on this service account.
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
  violations:
  - description: Key creation is not allowed on this service account.
    subject: projects/stgtest01/serviceAccounts/[email protected]?configvalue=mynameprefix-inception-tf%40stgtest01.iam.gserviceaccount.com
    type: constraints/iam.disableServiceAccountKeyCreation
➜  inception git:(kn/tf-fix-01)

So this is coming from an organisational constraint which can be disabled like this:

gcloud org-policies delete iam.disableServiceAccountKeyCreation --organization=ORGANIZATION_ID

However, this is creating a security hole which should be fixed after the platform phase (maybe even after the inception-phase).
Manually, that contraint can be activated again like this:

gcloud resource-manager org-policies enable-enforce constraints/iam.disableServiceAccountKeyCreation --project=PROJECT_ID

Via terraform, it can probably get activated like this:

resource "google_project_organization_policy" "disable_sa_key_creation" {
  project    = google_project.my_project.project_id
  constraint = "constraints/iam.disableServiceAccountKeyCreation"

  boolean_policy {
    enforced = true
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant