Repository navigation
fix(python): support Super Admin OAuth/ADC/DWD split sessions and fix… - #80
Merged
nsamarakkody merged 1 commit intoOct 11, 2026
Merged
Conversation
… DLP import sanitization in cep_policy_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes authentication failures (
HTTP 403 PERMISSION_DENIED: Error(7001)/unauthorized_client) and payload sanitization issues when exporting or importing Chrome Enterprise Premium (CEP) DLP Rules, Detectors, Context-Aware Access (CAA) levels, and BeyondCorp Secure Gateways inPython/cep_policy_manager.py.Root Cause
Error(7001)):cloudidentity.googleapis.com/v1/policiesandv1beta1/policiesstrictly require a Google Workspace Super Administrator identity when reading or mutatingrule.dlp.*anddetector.*policies.get_session()used a singleAuthorizedSessionand, when--use-service-accountwas passed, calledservice_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)without asubjectparameter and withcloud-platformbundled into the same credential request:subject, the caller is the GCP Service Account (*@*.iam.gserviceaccount.com), which is not a Workspace Super Admin and is rejected by Cloud Identity withHTTP 403 Error(7001).subject(Domain-Wide Delegation), requestinghttps://www.googleapis.com/auth/cloud-platformalongsidecloud-identity.policiescauses Google's OAuth token endpoint to fail withunauthorized_clientunless the customer authorizes fullcloud-platformin Workspace DWD—whereas GCP Access Context Manager (accesscontextmanager.googleapis.com) and BeyondCorp (beyondcorp.googleapis.com) expect direct GCP IAM authentication as the Service Account itself without DWD.clean_policy_for_import():policy_obj.copy()performed a shallow copy, mutating nested dictionaries (setting.value,action) in-place during import.--ou-id orgUnits/03ph8a2z...or--group-id groups/01abc...produced invalid doubled prefixes (orgUnits/orgUnits/...) inpolicyQuery.orgUnitand CELorgUnitId(...)expressions.--group-idoverrides inclean_policy_for_import().ORGANIZATION_IDIs Unconfigured:export_environment()andimport_environment()aborted the entire run ifget_access_policy_id()failed, preventing users who only manage Chrome DLP Rules & Detectors from running the tool without a GCP Organization Access Policy.Key Changes
get_sessions()):DLP_SCOPES(cloud-identity.policies,cloud-identity.policies.readonly) fromGCP_SCOPES(cloud-platform).(dlp_session, gcp_session)while preserving backwards compatibility forget_session().token_cep.pickle, then~/.config/gcloud/application_default_credentials.json(authorized_usercredentials fromgcloud auth application-default login --client-id-file=client_secrets.json ...), then falls back toInstalledAppFlowwithclient_secrets.json. HandlesRefreshErrorgracefully.--access-token(orCEP_ACCESS_TOKEN/TF_VAR_access_token), which can be combined with--use-service-accountso DLP uses the Super Admin bearer token while ACM/BeyondCorp use the Service Account.--subject(orCEP_IMPERSONATE_SUBJECT) sodlp_sessionimpersonates the Workspace Super Admin using onlyDLP_SCOPES, whilegcp_sessionauthenticates directly as the Service Account usingGCP_SCOPES._log_dlp_403_hint()):HTTP 403 Error(7001).clean_policy_for_import()):copy.deepcopy(policy_obj)to avoid mutating input dicts.CUSTOMER_ID(customers/...), stripsorgUnits/andgroups/prefixes via.removeprefix(), and supports--group-idon detectors.ORGANIZATION_IDoraccess_policy_idis unavailable.--key-file,--subject,--access-token,--client-secrets,--token-file,--customer,--org-id, and--project-id.