-
Notifications
You must be signed in to change notification settings - Fork 344
Create IAP for nomad #2573
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
Create IAP for nomad #2573
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,10 @@ locals { | |
| port = var.nomad_port | ||
| } | ||
| groups = [{ group = var.server_instance_group }] | ||
| iap = var.nomad_iap_oauth2_client_id != null ? { | ||
| oauth2_client_id = var.nomad_iap_oauth2_client_id | ||
| oauth2_client_secret = var.nomad_iap_oauth2_client_secret | ||
| } : null | ||
|
cursor[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sensitive backend map breaks plansHigh Severity Including Additional Locations (1)Reviewed by Cursor Bugbot for commit 6c4296f. Configure here. |
||
| } | ||
| } | ||
| health_checked_backends = { for backend_index, backend_value in local.backends : backend_index => backend_value } | ||
|
|
@@ -369,11 +373,30 @@ resource "google_compute_backend_service" "default" { | |
| } | ||
| } | ||
|
|
||
| dynamic "iap" { | ||
| for_each = lookup(each.value, "iap", null) != null ? [each.value.iap] : [] | ||
| content { | ||
| enabled = true | ||
| oauth2_client_id = iap.value["oauth2_client_id"] | ||
| oauth2_client_secret = iap.value["oauth2_client_secret"] | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IAP blocks Nomad API clientsHigh Severity
Reviewed by Cursor Bugbot for commit 1db68f2. Configure here. |
||
| } | ||
|
|
||
| depends_on = [ | ||
| google_compute_health_check.default | ||
| ] | ||
| } | ||
|
|
||
| # IAP IAM binding for Nomad backend | ||
| resource "google_iap_web_backend_service_iam_binding" "nomad_iap" { | ||
| count = var.nomad_iap_oauth2_client_id != null && length(var.nomad_iap_members) > 0 ? 1 : 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IAM binding for IAP is created based on the presence of the client ID and a non-empty members list. However, if the client ID is provided but the client secret is missing, the backend service will fail to enable IAP (or fail to apply), leading to an inconsistent state where an IAM binding exists for a feature that is not correctly configured on the target resource. This condition should be updated to match the logic used for enabling IAP on the backend service. |
||
|
|
||
| project = var.gcp_project_id | ||
| web_backend_service = google_compute_backend_service.default["nomad"].name | ||
| role = "roles/iap.httpsResourceAccessor" | ||
| members = var.nomad_iap_members | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IAP can enable without accessMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 1db68f2. Configure here. |
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IAP API is never enabledMedium Severity
Reviewed by Cursor Bugbot for commit 1db68f2. Configure here. |
||
|
|
||
| resource "google_compute_health_check" "default" { | ||
| for_each = local.health_checked_backends | ||
| name = "${var.prefix}hc-${each.key}" | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IAP configuration for the Nomad backend only checks for the presence of the OAuth2 client ID. If a client ID is provided but the client secret is missing, the backend service resource will attempt to enable IAP with a null secret, which will cause a failure during the Terraform apply phase. The condition should ensure both the client ID and secret are present before enabling the IAP block.