This page shows you how to configure Identity-Aware Proxy (IAP) to use Workforce Identity Federation. For an overview of using Workforce Identity Federation with IAP, see External identities.
Configure IAP with Workforce Identity Federation for an application
Configuring IAP with Workforce Identity Federation includes the following main tasks:
Set up a workforce pool and provider.
Create an OAuth client ID and secret.
Enable IAP and configure it to use Workforce Identity Federation.
Set up a workforce pool and provider
To set up a workforce pool and provider, follow the instructions for one of the following providers:
When setting the session duration time, refer to Manage IAP with Workforce Identity Federation sessions.
If you want to map an email address from a third-party IdP to
Google Cloud, you must add an attribute mapping in your workforce
pool provider for google.email. Example: google.email=assertion.email.
Create an OAuth client ID and secret
Follow the instructions to create an OAuth client ID and secret under a project in the same organization as the workforce pool that you will be using for this configuration. The project does not have to be the same project that the IAP-secured resource is in. When creating the OAuth client ID and secret, do the following:
Use a placeholder for the redirect URI when creating the client ID. After you create the client ID, run
describean OAuth client to get the generatedclientID.When you have the
clientID, runupdatean OAuth client to updateallowed-redirect-uristo the following:https://iap.googleapis.com/v1/oauth/clientIds/$CLIENT_ID:handleRedirect.Where
CLIENT_IDis theclientIDretrieved in the previous step.After you create the client secret, run
describean OAuth client credentials to get the generatedclientSecret.
Save the clientId and clientSecret because you will need them in later
steps.
Enable IAP to use Workforce Identity Federation
To enable IAP with Workforce Identity Federation, complete the following steps.
Enable IAP
Enable IAP on the resource.
console
In the Google Cloud console, open the IAP page.
Go to the IAP pageSelect a project. The project must be in the same organization as the workforce pool that you created earlier. The project doesn't have to be the project that you created the OAuth client ID and secret in.
Click the Applications tab, and then locate the application that you want to restrict access to using IAP.
In the IAP column, toggle the switch to On.
gcloud
To use the gcloud CLI to enable IAP, follow the procedures for the applicable service:
API
Create a
settings.jsonfile.cat << EOF > settings.json { "iap": { "enabled":true, } } EOF-
Enable IAP on App Engine.
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://appengine.googleapis.com/v1/apps/PROJECT_ID?updateMask=iap.enabled"To enable IAP on Compute Engine, use the following URL:
https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/REGION/backendServices/BACKEND_SERVICE_NAME?updateMask=iap.enabled.
Update the IAP settings
To configure IAP to use Workforce Identity Federation, you must configure the following settings:
WorkforceIdentitySettings: The OAuth client ID and secret created earlier.IdentitySources: The identity source.
For more information, see the IAP APIs.
gcloud
Using the following example as a reference, create an
iap_settings.yamlfile.CLIENT_ID=clientId CLIENT_SECRET=clientSecret WORKFORCE_POOL_NAME=locations/global/workforcePools/test-pool cat <<EOF > iap_settings.yaml access_settings: identity_sources: ["WORKFORCE_IDENTITY_FEDERATION"] workforce_identity_settings: workforce_pools: ["$WORKFORCE_POOL_NAME"] oauth2: client_id: "$CLIENT_ID" client_secret: "$CLIENT_SECRET" EOFRun the following command to update the IAP settings for your resource.
gcloud iap settings set iap_settings.yaml --project=PROJECT --resource-type=RESOURCE_TYPE --service=SERVICEReplace the following:
PROJECT: The project ID.
RESOURCE_TYPE: The IAP resource type. The resource type must be
cloud-run(Preview),app-engine,iap_web,compute,organization, orfolder. For thecloud-runresource type, use the--regionflag to indicate the region where your Cloud Run service is deployed.SERVICE: The service name. This is optional for both
app-engineandcompute.
For details on the command, see
gcloud iap settings set.
API
Using the following example as a reference, create an
iap_settings.jsonsettings file.CLIENT_ID=clientId CLIENT_SECRET=clientSecret WORKFORCE_POOL_NAME=locations/global/workforcePools/test-pool cat <<EOF > iap_settings.json { "access_settings": { "identity_sources": ["WORKFORCE_IDENTITY_FEDERATION"], "workforce_identity_settings": { "workforce_pools": ["$WORKFORCE_POOL_NAME"], "oauth2": { "client_id": "$CLIENT_ID", "client_secret": "$CLIENT_SECRET", } } } } EOFUse the gcloud CLI to get the name of the resource, and then copy the
RESOURCE_NAMEfrom the output because you will need it in the following step.gcloud iap settings get \ --project=PROJECT \ --resource-type=RESOURCE_TYPE \ --service=SERVICEReplace the following:
PROJECT: The project ID.
RESOURCE_TYPE: The IAP resource type. The resource type must be
appengine,iap_web,compute,organization,folder, orcloud_run-$REGION(Preview), where $REGION is the region in which your Cloud Run service is deployed.SERVICE: The service name. This is optional for both
app-engineandcompute.
Replace
RESOURCE_NAMEin the following command with theRESOURCE_NAMEfrom the previous step.curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @iap_settings.json \ "https://iap.googleapis.com/v1/RESOURCE_NAME:iapSettings?updateMask=iapSettings.accessSettings.identitySources,iapSettings.accessSettings.workforceIdentitySettings.workforcePools,iapSettings.accessSettings.workforceIdentitySettings.oauth2.clientId,iapSettings.accessSettings.workforceIdentitySettings.oauth2.clientSecret"
Grant access to IAP-secured resources
To access an IAP-secured resource, end users must have the IAP-Secured Web App User role on the resource. You can grant the IAP-Secured Web App User role to a single user (principal) or a set of users (principal set, which maps to a group, a specific attribute, or an entire pool of users).
Unrestricted access to IAP-secured resources is not supported.
console
In the Google Cloud console, open the IAP page.
Go to the IAP pageSelect the resource you want to secure with IAP.
Click Add Principal, and then add the principal identifiers of the groups or individuals to which you want to grant an Identity and Access Management (IAM) role for the resource.
In Assign roles, select IAP-Secured Web App User.
Click Add.
gcloud
Run the following command.
gcloud iap web add-iam-policy-binding \
--member=PRINCIPAL_IDENTIFIER \
--role='roles/iap.httpsResourceAccessor' \
--project=PROJECT_ID \
--resource-type=RESOURCE_TYPE \
--service=SERVICE \
--condition=CONDITION
Replace the following:
PRINCIPAL_IDENTIFIER: The principal identifier.
PROJECT_ID: The project ID.
- RESOURCE_TYPE: The IAP resource
type, which can be
app-engineorbackend-services.
SERVICE: (Optional) The service name.
CONDITION: (Optional) IAM conditions. Following is an example condition configured with access levels:
expression="accessPolicies/12345678/accessLevels/iap_test_access_level" in request.auth.access_levels,title=iap-test-access-level,description=only access on weekdays
API
This method is not recommended because it touches the entire IAM policy of a resource. An error could remove the policy from a resource.
Obtain the existing IAM policy bindings.
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d {} \ "https://iap.googleapis.com/v1/RESOURCE_NAME:getIamPolicy" -o iam_policy_bindings.jsonReplace the RESOURCE_NAME with the RESOURCE_NAME that you obtained in an earlier step.
To the
iam_policy_bindings.jsonfile that you obtained from the previous step, remove the version and etag lines, and add the binding that you want to add for the principal identifier. For more information, see Understanding allow policies.{ "bindings": [ { // existing bindings }, { "role": "roles/iap.httpsResourceAccessor", "members": [ "principal://iam.googleapis.com/locations/global/workforcePools/iap-test-pool/subject/iap-test-subject" ], "condition": { "expression": "\"accessPolicies/12345678/accessLevels/iap_test_access_level\" in request.auth.access_levels", "title": "iap-test-access-level", "description": "only access on weekdays" } } ] }Update the IAM policy bindings.
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "{"policy":$(cat iam_policy_bindings.json)}" \ "https://iap.googleapis.com/v1/RESOURCE_NAME:setIamPolicy"Replace the RESOURCE_NAME with the RESOURCE_NAME that you obtained in an earlier step.
See GetIamPolicy and SetIamPolicy for more information.
(Optional) Set up context-aware access
Optionally, you can set up context-aware access rules for advanced authorization.
To set up access levels, see Creating and applying access levels. Access levels based on device information are not available when using Workforce Identity Federation. You can still use request-context-based access levels with conditions on IP address, and time and date.
Programmatic authentication
IAP supports service account JWT authentication for applications configured with Workforce Identity Federation. For instructions, see Authenticating with a service account JWT.
Limitations when working with workforce pools
When using Workforce Identity Federation, consider the following limitations:
The following limitations apply when using IAP with Workforce Identity Federation:
For each IAP-enabled application, only one workforce pool can be configured, and the workforce pool can contain only one provider.
The workforce pool, OAuth client ID and secret, and the IAP-enabled applications must all be in the same organization.
Access levels for device-related information are not supported.
Only the following IAP settings configurations are supported:
Only the following user and Workforce Identity Federation claims are passed in the IAP signed header JWT payload:
sub: A unique identifier for the user, prefixed withsts.google.com:.email: Propagated only when there is agoogle.email=assertion.emailmapping specified when you create the workforce pool provider. For more information, see Attribute mappings.workforce_identity.workforce_pool_name: The workforce pool name in the formatlocations/global/workforcePools/WORKFORCE_POOL_ID.workforce_identity.iam_principal: The IAM principal identifier in the formatprincipal://iam.googleapis.com/locations/global/workforcePools/WORKFORCE_POOL_ID/subject/SUBJECT_ATTRIBUTE_VALUE.
Programmatic access with Workforce Identity Federation is only supported for Google service accounts.
Troubleshooting
For troubleshooting information, see Troubleshooting and frequently asked questions.