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

pass gcp identity in #543

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion infra/examples-dev/aws-all/google-workspace-variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ variable "google_workspace_gcp_project_id" {
description = "string ID of GCP project that will host oauth clients for Google Workspace API connectors; must exist"
}

variable "google_workspace_gcp_tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (GCP SA/user terraform is running as, if already known. If omitted, will attempt to detect; detection is known to fail in GCP Cloud Shell."
default = null
}

variable "google_workspace_terraform_sa_account_email" {
type = string
description = "Email of GCP service account that will be used to provision GCP resources. Leave 'null' to use application default for you environment."
Expand Down Expand Up @@ -35,4 +41,4 @@ locals {
(!local.validate_google_workspace_gcp_project_id
? local.validate_google_workspace_gcp_project_id_message
: ""))
}
}
1 change: 1 addition & 0 deletions infra/examples-dev/aws-all/google-workspace.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module "worklytics_connectors_google_workspace" {
environment_id = var.environment_name
enabled_connectors = var.enabled_connectors
gcp_project_id = var.google_workspace_gcp_project_id
gcp_tf_runner_email = var.google_workspace_terraform_sa_account_email
google_workspace_example_user = var.google_workspace_example_user
google_workspace_example_admin = var.google_workspace_example_admin
}
Expand Down
2 changes: 1 addition & 1 deletion infra/examples-dev/gcp/google-workspace-variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ locals {
(!local.validate_google_workspace_gcp_project_id
? local.validate_google_workspace_gcp_project_id_message
: ""))
}
}
1 change: 1 addition & 0 deletions infra/examples-dev/gcp/google-workspace.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module "worklytics_connectors_google_workspace" {
environment_id = var.environment_name
enabled_connectors = var.enabled_connectors
gcp_project_id = var.google_workspace_gcp_project_id
gcp_tf_runner_email = var.google_workspace_terraform_sa_account_email
google_workspace_example_user = var.google_workspace_example_user
google_workspace_example_admin = var.google_workspace_example_admin
}
Expand Down
1 change: 1 addition & 0 deletions infra/examples-dev/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module "psoxy" {
custom_bulk_connector_arguments = var.custom_bulk_connector_arguments
lookup_tables = var.lookup_tables
custom_artifacts_bucket_name = var.custom_artifacts_bucket_name
tf_runner_email = try(coalesce(var.gcp_tf_runner_email, var.gcp_terraform_sa_account_email), null)
todos_as_local_files = var.todos_as_local_files
todo_step = local.max_auth_todo_step
}
Expand Down
6 changes: 6 additions & 0 deletions infra/examples-dev/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ variable "gcp_terraform_sa_account_email" {
}
}

variable "gcp_tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (GCP SA/user terraform is running as, if already known. If omitted, will attempt to detect; detection is known to fail in GCP Cloud Shell."
default = null
}

variable "environment_name" {
type = string
description = "Qualifier to append to names/ids of resources for psoxy. If not empty, A-Za-z0-9 or - characters only. Max length 10. Useful to distinguish between deployments into same GCP project."
Expand Down
4 changes: 3 additions & 1 deletion infra/modules/gcp-host/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ module "api_connector" {
config_parameter_prefix = local.config_parameter_prefix
invoker_sa_emails = var.worklytics_sa_emails
default_labels = var.default_labels
tf_runner_email = var.tf_runner_email
todos_as_local_files = var.todos_as_local_files

environment_variables = merge(
Expand Down Expand Up @@ -212,6 +213,7 @@ module "bulk_connector" {
input_bucket_name = try(each.value.input_bucket_name, null)
sanitized_bucket_name = try(each.value.sanitized_bucket_name, null)
default_labels = var.default_labels
tf_runner_email = var.tf_runner_email
todos_as_local_files = var.todos_as_local_files
available_memory_mb = coalesce(try(var.custom_bulk_connector_arguments[each.key].available_memory_mb, null), try(each.value.available_memory_mb, null), 512)

Expand Down Expand Up @@ -355,4 +357,4 @@ EOF

output "secrets_to_provision" {
value = local.secrets_writable_by_instance
}
}
6 changes: 6 additions & 0 deletions infra/modules/gcp-host/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}

variable "gcp_project_id" {
type = string
description = "id of GCP project that will host psoxy instance"
Expand Down
2 changes: 2 additions & 0 deletions infra/modules/gcp-psoxy-bulk/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ resource "google_secret_manager_secret_iam_member" "grant_sa_accessor_on_secret"

module "tf_runner" {
source = "../../modules/gcp-tf-runner"

tf_runner_email = var.tf_runner_email
}

# to provision Cloud Function, TF must be able to act as the service account that the function will
Expand Down
6 changes: 6 additions & 0 deletions infra/modules/gcp-psoxy-bulk/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ variable "default_labels" {
default = {}
}

variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}

variable "todos_as_local_files" {
type = bool
description = "whether to render TODOs as flat files"
Expand Down
4 changes: 3 additions & 1 deletion infra/modules/gcp-psoxy-rest/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ locals {

module "tf_runner" {
source = "../../modules/gcp-tf-runner"

tf_runner_email = var.tf_runner_email
}

data "google_service_account" "function" {
Expand Down Expand Up @@ -244,4 +246,4 @@ output "todo" {

output "next_todo_step" {
value = var.todo_step + 1
}
}
8 changes: 7 additions & 1 deletion infra/modules/gcp-psoxy-rest/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ variable "available_memory_mb" {
default = 1024
}

variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}

variable "todos_as_local_files" {
type = bool
description = "whether to render TODOs as flat files"
Expand All @@ -150,4 +156,4 @@ variable "todo_step" {
type = number
description = "of all todos, where does this one logically fall in sequence"
default = 1
}
}
2 changes: 2 additions & 0 deletions infra/modules/gcp-sa-auth-key-aws-secret/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module "tf_runner" {
source = "../../modules/gcp-tf-runner"

tf_runner_email = var.tf_runner_email
}

# grant this directly on SA, jit for when we know it is needed to create keys
Expand Down
6 changes: 6 additions & 0 deletions infra/modules/gcp-sa-auth-key-aws-secret/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ variable "kms_key_id" {
description = "KMS key ID or ARN to use for encrypting secrets. If not provided, secrets will be encrypted by SSM with its keys (controlled by AWS)."
default = null
}

variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}
2 changes: 2 additions & 0 deletions infra/modules/gcp-sa-auth-key-secret-manager/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

module "tf_runner" {
source = "../../modules/gcp-tf-runner"

tf_runner_email = var.tf_runner_email
}

# grant this directly on SA, jit for when we know it is needed to create keys
Expand Down
6 changes: 6 additions & 0 deletions infra/modules/gcp-sa-auth-key-secret-manager/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ variable "replica_regions" {
"us-west1",
]
}

variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}
2 changes: 2 additions & 0 deletions infra/modules/gcp-sa-auth-key/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

module "tf_runner" {
source = "../../modules/gcp-tf-runner"

tf_runner_email = var.tf_runner_email
}

# grant this directly on SA, jit for when we know it is needed to create keys
Expand Down
6 changes: 6 additions & 0 deletions infra/modules/gcp-sa-auth-key/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ variable "rotation_days" {
default = 60
description = "rotation period for the SA key, in days"
}

variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}
4 changes: 1 addition & 3 deletions infra/modules/gcp-tf-runner/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
# times throughout the code base, and includes some hard-coded convention stuff that imho is better
# to have in one place.


# in cloud shell, this seems to return {"email":"", "id":""}
# in any env, this is NEVER the gcp service account configured via provider block
# (eg, google.impersonate_service_account = "terraform@...")
data "google_client_openid_userinfo" "me" {

}

#

# if no 'email' field from 'google_client_openid_userinfo', generate id token for the current user
# and parse email from it.
# such parsing is explicitly allowed by Google; see https://cloud.google.com/docs/authentication/token-types#id
Expand Down Expand Up @@ -52,6 +49,7 @@ locals {

# coalesce failing here implies we failed to detect the auth'd gcp user
authed_user_email = coalesce(
var.tf_runner_email,
try(data.external.identity.result.gcp_terraform_sa_account_email, ""), # "" if no such value
data.google_client_openid_userinfo.me.email,
local.email_from_jwt
Expand Down
5 changes: 5 additions & 0 deletions infra/modules/gcp-tf-runner/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module "google_workspace_connection_auth" {
source = "../../modules/gcp-sa-auth-key"

service_account_id = module.google_workspace_connection[each.key].service_account_id
tf_runner_email = var.gcp_tf_runner_email
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ variable "gcp_project_id" {
description = "id of GCP project that will host OAuth Clients for Google Workspace API connectors"
}

variable "gcp_tf_runner_email" {
type = string
description = "Email address of the Terraform Cloud runner (GCP SA/user terraform is running as, if already known. If omitted, will attempt to detect."
default = null
}

variable "google_workspace_example_user" {
type = string
description = "user to impersonate for Google Workspace API calls (null for none)"
Expand Down