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

initial workload identity addition #307

Closed

Conversation

milesmatthias
Copy link
Contributor

No description provided.

@morgante morgante self-assigned this Nov 6, 2019
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

Code LGTM, just need to:

  • Fix CI tests
  • Add the new test fixture to the Cloud Build tests

@milesmatthias
Copy link
Contributor Author

milesmatthias commented Nov 25, 2019

I thought I did add the workload identity tests to CI by adding it to the kitchen.yml: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/pull/307/files#diff-d3fbd21bc6be7ce4531c27a82b2619de ?

Nevermind, I see where I need to add this.

@milesmatthias
Copy link
Contributor Author

And CI is failing because of a different test, not mine, so I'll look at it, but it may be most efficient to review with whoever wrote those tests.

subnetwork = var.subnetwork
ip_range_pods = var.ip_range_pods
ip_range_services = var.ip_range_services
service_account = "create"
Copy link
Member

@bharathkkb bharathkkb Dec 7, 2019

Choose a reason for hiding this comment

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

I had to add identity_namespace = "${module.example-project.project_id}.svc.id.goog" to have workload identity enabled with //modules/beta-public-cluster/.
Otherwise workload identity fails with Error 400: Identity namespace does not exist (proj-id.svc.id.goog)

cluster_type = "simple-zonal"
}

provider "google" {
Copy link
Member

Choose a reason for hiding this comment

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

I think we need the kubernetes provider also initialized here like:

provider "kubernetes" {
  version                = "~> 1.10"
  host                   = module.gke.endpoint
  cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}

Without this kubernetes provider will try to use the credentials from kubectl.

@milesmatthias
Copy link
Contributor Author

@morgante I'm having trouble finding where the CI tools set which IAM credentials it's using to run tests. I'm running into these errors when running in cloudbuild:

Error: Error creating Network: googleapi: Error 403: Required 'compute.networks.create' permission for 'projects/ci-gke-dcf1/global/networks/cft-gke-test-9u5a', forbidden
       
on network.tf line 27, in resource "google_compute_network" "main":
27: resource "google_compute_network" "main" {
       
Error: Error creating service account: googleapi: Error 403: Permission iam.serviceAccounts.create is required to perform this operation on project projects/ci-gke-dcf1., forbidden
       
on ../../../sa.tf line 37, in resource "google_service_account" "
37: resource "google_service_account" "cluster_service_account" {

Any advice would be appreciated.

@bharathkkb
Copy link
Member

@milesmatthias I received 403s on my PR yesterday as well. This is due to terraform-google-modules/terraform-google-project-factory#333
Prepare stage for GKE seems to be using ~> 2.18 bumping it to 2.20.1 seems to fix prepare for me.
https://github.com/bharathkkb/terraform-google-kubernetes-engine/blob/8d568de156660d8fc7d049d9645c7b25a0311d64/test/setup/versions.tf#L22

@milesmatthias
Copy link
Contributor Author

I may need to bring in some of @bharathkkb's work from #381 to get this working... It seems IAM permissions in this CI test environment are misconfigured for this repo.

@milesmatthias
Copy link
Contributor Author

@morgante would love any thoughts you have here to help unblock me. Thanks!

@morgante
Copy link
Contributor

@milesmatthias Try rebasing on master. The key changes have been merged already.

@milesmatthias
Copy link
Contributor Author

Doing those tests here: #391

@milesmatthias
Copy link
Contributor Author

@morgante with updating from master, the integration service account doesn't have the right perms, even though we're giving it SA admin role in test/setup:

       Error: serviceaccounts is forbidden: User "system:anonymous" cannot create resource "serviceaccounts" in API group "" in the namespace "default"
       
         on ../../../modules/workload-identity/main.tf line 31, in resource "kubernetes_service_account" "main":
         31: resource "kubernetes_service_account" "main" {

Why is cloudbuild running as system:anonymous?

@morgante
Copy link
Contributor

morgante commented Jan 8, 2020

I think it might be because we authenticate the Kubernetes provider using the CA certificate?

Could you try creating a separate Kubernetes provider config specific to the workload identity test?

@bharathkkb
Copy link
Member

@milesmatthias can I help in anyway to push this out? I have been planning to use this submodule in a project

@morgante
Copy link
Contributor

@bharathkkb Since @milesmatthias isn't working with Google anymore, it might be a good idea for you to take this over and (a) fix merge conflicts + (b) get tests passing.

@bharathkkb
Copy link
Member

@morgante sg, I will do that

@bharathkkb
Copy link
Member

closed via #417

@bharathkkb bharathkkb closed this Feb 7, 2020
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

Successfully merging this pull request may close these issues.

3 participants