What you need
Before you can request a token, three values must exist. All three come from Strata Cloud Manager.A TSG must have a service account before you can make any API call against it. If a tenant has no service account of its own, a service account belonging to one of its ancestor TSGs can be used instead. See Token scope within a TSG hierarchy.One TSG may have many service accounts, and one service account may have many tokens.
Tenant service group and tenant are used interchangeably; there is no functional difference between them.
Create a service account
Service accounts are created in Strata Cloud Manager, through Common Services Identity & Access. A service account is not tied to a specific user.1
Open Identity & Access
Sign in to Strata Cloud Manager and go to System Settings > Identity & Access.
2
Select the tenant
Choose the tenant the service account belongs to.A service account added to a parent tenant is automatically added to all of that tenant’s children, which is how a parent manages its children. Add it to a child tenant instead if you do not want that inheritance.Creating service accounts in different tenant service groups lets you assign different roles for different access permissions, and keeps the audit trail readable.
3
Add the identity
Select Add (or Add Identity), then set Identity Type to Service Account.Give it a unique and meaningful Service Account Name. Optionally add a Service Account Contact email and a Description. The contact person is not added as a user.
4
Save the client credentials
Select Next. The Client Credentials screen shows the Client ID and Client Secret.
5
Note the TSG ID
Select Next. The display name of the service account is formatted as
<ServiceAccountName>@<tsg_id>.iam.panserviceaccount.com.Every service account of a parent tenant carries the parent TSG ID, and every service account of a child tenant carries the child TSG ID. Take note of the tsg_id, because you pass it on every token request.6
Assign a role
On the Assign Roles screen, select the scope (for example All Apps & Services) and assign the role the service account needs. A service account with no role assignment cannot obtain a token.Grant the narrowest role that covers the Admin API operations you intend to automate. A custom role needs
iam.service_account and iam.custom_role permissions if the account will manage identities itself.7
Submit
Save to create the service account. You now have the Client ID, Client Secret and TSG ID needed to request a token.
Request an access token
Exchange the service account credentials for an access token withPOST /oauth2/access_token.
The endpoint uses basic auth, with the Client ID as the username and the Client Secret as the password, and takes the TSG ID in the scope field:
Request an access token
scope, or to one of its ancestors.
A successful response carries the token and its lifetime in seconds:
Access tokens have a lifespan of 15 minutes. Read
expires_in rather than hard-coding the number, cache the token in memory for the life of that window, and refresh it about a minute before it lapses. Requesting a fresh token per API call is unnecessary; carrying one across a long-running job is what fails.Call an Admin API endpoint
Send the token as a bearer token. Every Admin API endpoint takes the same header; the base URL and path for each one are shown on its own reference page.Token scope within a TSG hierarchy
A token issued for one TSG cannot be used against another. If you have a tenant, Tenant 1A, with a service account named1a_svc, then a token obtained through 1a_svc reaches Tenant 1A and nothing else.
When you run multiple tenants you organise them as a hierarchy of TSGs. Creating a dedicated service account for every TSG and tenant in that hierarchy is the simplest arrangement, but it is not necessary. A service account belonging to a TSG can name any descendant of that TSG when it requests a token.
Consider a root TSG A with two tenants, and a child TSG B with two more:
Assume a_svc and b_svc were created with the superuser role on TSG A and TSG B respectively. Then:
a_svccan request a token for any TSG ID in the hierarchy, because every TSG and tenant shown is a descendant of TSG A.b_svccan request tokens for TSG B, Tenant 1B and Tenant 2B, its own descendants.b_svccannot request a token for TSG A, Tenant 1A or Tenant 2A. Those are its ancestor and its peers.- Tenants 1A, 2A, 1B and 2B hold no service accounts of their own, so only the service accounts of their parent TSGs can obtain tokens for them.
The TSG IDs used in the examples on this page are deliberately fake. Real TSG IDs are 10-digit integers, such as
1000000001.Grant cross-hierarchy access with an access policy
b_svc cannot obtain a token for Tenant 1A, because Tenant 1A sits outside its subtree. Where you need exactly that, create an access policy on Tenant 1A naming the Client ID of b_svc as the principal. The policy overrides the hierarchy restriction for that one pairing.
You can do this from the multitenant UI, or with the Identity and Access Management create an access policy API. The following grants b_svc superuser permissions on Tenant 1A, represented here by TSG ID 18:
Grant b_svc access to Tenant 1A
15 in the example above.
The same endpoint grants a person a role on a tenant, with their email address as the principal. Three fields make up a policy:
GET /iam/v1/access_policies lists the policies on the tenant your token is scoped to, and DELETE /iam/v1/access_policies/{id} removes one. A duplicate POST returns 409, so the call is safe to retry.
Older Palo Alto Networks documentation shows this endpoint as
https://api.sase.paloaltonetworks.com/access_policies. https://api.strata.paloaltonetworks.com/iam/v1/access_policies is the current host and path.Check your token
If the credentials baked into a token are not the ones you expect, the Admin API rejects the request and the error reports an invalid authorisation code. Paste the token into jwt.io to decode it and read the claims back. The decoded payload shows thetsg_id the token was issued for, which is the fastest way to confirm you are hitting the tenant you think you are, and an access claim listing the roles the service account holds on it.
Common failures
Related
Admin API introduction
What the Admin API manages, and the permissions model behind it
Inference API authentication
Gateway API keys and JWT authentication for inference requests
Errors
Admin API error codes and what they mean
Audit logs
Every administrative action, attributed to the principal that made it

