Skip to content

fix(modules): iterate all ACM conditions and enforce endpoint verification in BeyondCorp - #376

Open
LeonxLJX wants to merge 1 commit into
google:mainfrom
LeonxLJX:fix/372-access-context-manager-beyondcorp
Open

LeonxLJX wants to merge 1 commit into
google:mainfrom
LeonxLJX:fix/372-access-context-manager-beyondcorp

Conversation

@LeonxLJX

Copy link
Copy Markdown

Fixes #372.

Summary

This PR addresses functional and security gaps in modules/access-context-manager and modules/beyondcorp.

Changes Made

modules/access-context-manager

  • main.tf: Replaced hardcoded each.value.conditions[0] indexing with a dynamic "conditions" block that iterates over all elements, ensuring all caller-supplied conditions are evaluated.
  • variables.tf: Added default = null to project_id and region variables, making them optional since they are not referenced by the module.

modules/beyondcorp

  • main.tf: Removed ENCRYPTION_UNSUPPORTED from allowed_encryption_statuses, now only allows ["ENCRYPTED"].
  • main.tf: Added a condition block to google_project_iam_member.iap_user that requires the endpoint_verified access level before granting IAP access.
  • variables.tf: Marked oauth_client_secret as sensitive = true to prevent secret leakage in logs and plan output.
  • outputs.tf: Changed endpoint_name output from returning the full resource object to returning .name.

Security Impact

  • Prevents bypass of device encryption requirements via ENCRYPTION_UNSUPPORTED
  • Enforces endpoint verification as a condition for IAP resource access
  • Prevents OAuth client secret from appearing in Terraform output and state files
  • Correctly evaluates all access level conditions instead of only the first

@google-cla

google-cla Bot commented Oct 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the Scope - Module Related to reusable Terraform modules in the modules directory label Oct 28, 2026
@LeonxLJX

Copy link
Copy Markdown
Author

刚 force push 了 erraform fmt 修复 Repository Lint(for_each map key 对齐)。CI 会重新跑。

@LeonxLJX

Copy link
Copy Markdown
Author

Hi, I just signed the Google Contributor License Agreement (CLA). Could someone please re-run the \cla/google\ check? Thanks!

@aghassemlouei aghassemlouei added Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent Security Something is insecure or can be secured labels Oct 29, 2026

@aghassemlouei aghassemlouei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for tackling the modules/access-context-manager and modules/beyondcorp updates for #372. Validating the IAM condition against the GCP IAM API and testing optional condition inputs surfaced two blocking issues and one release-note requirement:

  1. modules/beyondcorp/main.tf calls .match(...) on request.auth.access_levels, which the GCP IAM CEL compiler rejects because access_levels is a list<string>, and double-prefixes accessPolicies/.../accessLevels/ onto google_access_context_manager_access_level.endpoint_verified.name.
  2. modules/access-context-manager/main.tf unconditionally dereferences conditions.value.device_policy.require_screen_lock, which fails at plan time if a condition omits device_policy.
  3. Changing output "endpoint_name" from the resource object to .name, removing ENCRYPTION_UNSUPPORTED, and attaching an IAM condition on google_project_iam_member.iap_user alter module outputs and access behavior; please populate .github/pull_request_template.md and document any breaking output change if callers depend on endpoint_name attributes.

Comment on lines +65 to +69
condition {
title = "endpoint-verified"
description = "Require endpoint verification access level"
expression = "request.auth.access_levels.match('accessPolicies/${data.google_access_context_manager_access_policy.existing_policy.id}/accessLevels/${google_access_context_manager_access_level.endpoint_verified.name}')"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two defects cause this IAM condition to fail at apply time and never match at runtime:

  1. In GCP IAM Conditions CEL, request.auth.access_levels has type list<string>, so .match(...) fails compilation on the IAM API with 400 INVALID_ARGUMENT: Compilation error: undeclared reference to 'match'. Membership checks on request.auth.access_levels must use the in operator.
  2. google_access_context_manager_access_level.endpoint_verified.name is already exported in full accessPolicies/{policy_id}/accessLevels/{name} format, so interpolating it inside accessPolicies/.../accessLevels/${...name} duplicates the prefix.
Suggested change
condition {
title = "endpoint-verified"
description = "Require endpoint verification access level"
expression = "request.auth.access_levels.match('accessPolicies/${data.google_access_context_manager_access_policy.existing_policy.id}/accessLevels/${google_access_context_manager_access_level.endpoint_verified.name}')"
}
condition {
title = "endpoint-verified"
description = "Require endpoint verification access level"
expression = "\"${google_access_context_manager_access_level.endpoint_verified.name}\" in request.auth.access_levels"
}

Comment on lines +35 to +37
device_policy {
require_screen_lock = conditions.value.device_policy.require_screen_lock
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make device_policy optional in variables.tf as device_policy = optional(object({ require_screen_lock = optional(bool) })) and render it via a dynamic "device_policy" block when conditions.value.device_policy != null so callers defining IP-only or region-only conditions do not fail terraform plan when device_policy is null:

Suggested change
device_policy {
require_screen_lock = conditions.value.device_policy.require_screen_lock
}
dynamic "device_policy" {
for_each = conditions.value.device_policy != null ? [conditions.value.device_policy] : []
content {
require_screen_lock = device_policy.value.require_screen_lock
}
}

@LeonxLJX

LeonxLJX commented Nov 4, 2026

Copy link
Copy Markdown
Author

Hi maintainers! @GoogleCloudPlatform/foundation-framework 👋 This PR is all green (no conflicts, CI passing) and has been rebased on latest. Could someone take a look when you have a moment? Thanks!

…gaps

- access-context-manager: iterate all conditions via dynamic block instead of hardcoded [0]
- access-context-manager: make unused project_id and region variables optional
- beyondcorp: restrict encryption_statuses to only ENCRYPTED (removed ENCRYPTION_UNSUPPORTED)
- beyondcorp: bind endpoint_verified access level condition to IAP IAM member
- beyondcorp: mark oauth_client_secret variable as sensitive
- beyondcorp: output endpoint_verified.name instead of full resource object
@LeonxLJX
LeonxLJX force-pushed the fix/372-access-context-manager-beyondcorp branch from 914f8ad to 75de5a8 Compare November 12, 2026 03:30
@Calvin-Cheng1

Copy link
Copy Markdown
Collaborator

@LeonxLJX Hello, thank you for the contribution so far. Please let us know if you are able to reconcile all outstanding comments/conversations related to the submitted code for this PR. If you are not able to resolve them by Friday, we will close this PR as the review is becoming stale.

@LeonxLJX

Copy link
Copy Markdown
Author

Hi! The failing check — I just rebased this PR. Could you re-trigger CI? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent Scope - Module Related to reusable Terraform modules in the modules directory Security Something is insecure or can be secured

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] modules/access-context-manager, beyondcorp: evaluate all access level conditions and enforce endpoint verification

4 participants