EntraID Secrets Removal → Ivanti Automation
Overview
This automation removes expired secrets and certificates from EntraID App Registrations, triggered automatically via Ivanti ITSM tasks.
When an EntraID secret or certificate expires, an Ivanti task is created to remove the credential. This playbook: - Authenticates to EntraID using appropriate credentials - Removes secrets via Azure RM modules - Removes certificates via Microsoft Graph removeKey API with certificate-based authentication - Updates the Ivanti task with success or failure status - Closes the task automatically on success or reassigns on failure
High-Level Flow
- Ivanti task is created for secret/certificate removal
- Ansible Automation Platform triggers this playbook
- Playbook retrieves task details from Ivanti
- Authenticates to EntraID (production or onderwijs tenant)
- Determines removal method based on SecretType:
- Secret: Direct removal via Azure RM module
- Certificate: Certificate-based auth + removeKey API
- Updates Ivanti task:
- Success: Close task with resolution
- Failure: Add note and reassign to Systeemsoftware
Execution Flow
sequenceDiagram
participant Ivanti as Ivanti ITSM
participant AAP as Ansible Automation
participant PWS as Passwordstate
participant EntraID as EntraID/Azure
participant Graph as Microsoft Graph API
Ivanti->>AAP: Trigger removal task
AAP->>Ivanti: Get task details
Ivanti-->>AAP: Task info (AppID, SecretID, SecretType)
AAP->>PWS: Get EntraID credentials
PWS-->>AAP: Service Principal credentials
alt SecretType == "Secret"
AAP->>EntraID: azure_rm_adpassword (state: absent)
EntraID-->>AAP: Secret removed
AAP->>Ivanti: Close task (success)
else SecretType == "Certificaat"
AAP->>PWS: Get PKI credentials
PWS-->>AAP: PKI system credentials
AAP->>PWS: Get certificate entry
PWS-->>AAP: Certificate metadata
AAP->>PWS: Query database for PFX
PWS-->>AAP: Document ID
AAP->>PWS: Download PFX file
PWS-->>AAP: Certificate PFX
AAP->>AAP: Generate client_assertion JWT<br/>(using current certificate)
AAP->>EntraID: Get access token<br/>(certificate auth)
EntraID-->>AAP: Access token
AAP->>AAP: Generate PoP token<br/>(Proof-of-Possession)
AAP->>Graph: POST /removeKey<br/>(with PoP proof)
Graph-->>AAP: Certificate removed (204)
AAP->>Ivanti: Close task (success)
end
alt Failure
AAP->>Ivanti: Add note with error
AAP->>Ivanti: Reassign to Systeemsoftware
end
Components
Ivanti ITSM
Task Creation
Automated task creation when secrets/certificates expire
Task parameters include:
- AppDisplayName: Display name of the App Registration
- AppID: Application (client) ID
- SecretID: Key ID of the secret or certificate to remove
- SecretType: "Secret", "Certificaat", or "Cert"
- Onderwijs: "Yes" for education tenant, "No" for production
Passwordstate
Credential Storage
Multiple credential sources:
- Production EntraID: Sys_Azure_AppRegs_PR (list 8620)
- Onderwijs EntraID: Sys_Azure_OND_Admin (list 8620)
- PKI credentials: sys_srvaapwin_pki (list 8620)
- Database credentials: sys_pws_ansible_read (list 8620)
- Certificate entries: List 6691 (EntraID ServicePrincipal Certificaten)
EntraID / Microsoft Graph
Removal Methods
Two different approaches based on credential type: - Secrets: Azure RM module with direct removal - Certificates: Graph API removeKey with certificate authentication
Tenant Configuration
Production Tenant (Default)
- Tenant ID:
c3c1e6bb-1ebf-4335-ad13-3419266a9781 - Tenant Name: gentplus.onmicrosoft.com
- Subscription: 9f3c9e4f-7451-44cc-80c0-258e49e49192
Onderwijs Tenant
- Tenant ID:
c32c6912-0c85-4d02-8d38-51da93512d64 - Tenant Name: onderwijsstadgent.onmicrosoft.com
- Subscription: 638468ab-6418-4403-8c17-5a03453d5489
Tenant is automatically selected based on Onderwijs parameter from Ivanti task.
Removal Process
Secret Removal (SecretType: "Secret")
Simple direct removal using Azure modules:
- Get EntraID credentials from Passwordstate
- Lookup App Registration by AppID
- Remove secret using
azure_rm_adpassword: - app_id: Application ID
- key_id: Secret ID to remove
- state: absent
- Mark success if removal completes
No additional authentication required - uses service principal credentials directly.
Certificate Removal (SecretType: "Certificaat" or "Cert")
Complex removal using certificate-based authentication:
- Retrieve Certificate Information
- Get PKI credentials from Passwordstate
- Retrieve certificate entry from Passwordstate (list 6691)
- Query Passwordstate database for PFX document ID
-
Download current certificate PFX file
-
Generate Authentication Tokens
- Generate
client_assertionJWT using current certificate - Obtain access token from EntraID using certificate authentication
-
Generate Proof-of-Possession (PoP) token for removeKey API
-
Remove Certificate
-
Call Microsoft Graph removeKey API:
- Endpoint:
POST /applications/{id}/removeKey - Headers: Bearer token
- Body: keyId + PoP proof
- Expected response: 204 No Content
- Endpoint:
-
Verify Success
- HTTP 204 = success
- Any other status = failure with error message
Why certificate authentication? Microsoft requires proof of possession of the current certificate before allowing removal via the removeKey API. This prevents unauthorized removal of certificates.
Error Handling
Rescue Block
Catches any errors during removal process:
- Sets secret_removal_success: false
- Captures error message in noteError
Always Block
Executes regardless of success or failure:
- Validate SecretType
- Only "Secret", "Certificaat", "Cert" are supported
-
Invalid types set appropriate error message
-
Update Success Status
-
If
remove_sp_secret.changed == true: mark as successful -
Handle Failures
- Reassign task to Systeemsoftware team
-
Add note to task with error details
-
Handle Success
- Close task with resolution message
- Log 1 minute time spent
Required Python Script
The playbook requires generate_jwt_token.py for certificate removal to create JWT tokens:
For client_assertion:
- TOKEN_TYPE: "client_assertion"
- PFX_PATH: Path to current certificate PFX
- PFX_PASSWORD: Certificate password
- TENANT_ID: Azure tenant ID
- CLIENT_ID: Application (client) ID
For PoP token:
- TOKEN_TYPE: "pop"
- PFX_PATH: Path to current certificate PFX
- PFX_PASSWORD: Certificate password
- TENANT_ID: Azure tenant ID
- SUB_ID: Application object ID
- ISS_ID: Application object ID
- AUD: 00000002-0000-0000-c000-000000000000
Integration with Ivanti
Task Input
Retrieved via d09.ivanti_itsm.verwerk_task role, provides:
- task_info.servicereq_params.AppDisplayName
- task_info.servicereq_params.AppID
- task_info.servicereq_params.SecretID
- task_info.servicereq_params.SecretType
- task_info.servicereq_params.Onderwijs
- task_info.AssignmentID (task number)
- task_info.RecId (record ID for notes)
Task Output
On Success:
- Close task using d09.ivanti_itsm.close_task
- Resolution: "Expired secret for {AppDisplayName} removed"
- Time spent: 1 minute
On Failure:
- Reassign task using d09.ivanti_itsm.assign_task to Systeemsoftware
- Add note using d09.ivanti_itsm.add_note:
- Subject: "{SecretType} removal failed"
- Body: Error message from noteError
- Category: Status Update
- Time spent: 1 minute
Idempotency & Safety
- Uses
ignore_errors: trueon removal operations to prevent playbook failure - Success is tracked via
secret_removal_successvariable - Always block ensures Ivanti task is updated regardless of outcome
- Certificate authentication prevents unauthorized removals
- No destructive actions on failure - task is reassigned for manual review
Benefits
- Fully automated cleanup of expired credentials
- Secure certificate removal using proof-of-possession
- Multi-tenant support (production and onderwijs)
- Automatic task closure on success
- Clear error handling and manual escalation on failure
- Audit trail via Ivanti task notes
- Reduces manual overhead for credential lifecycle management
Notes
- Secret removal uses simpler Azure RM module approach
- Certificate removal requires the current certificate to generate PoP token
- Failed removals are reassigned to Systeemsoftware for manual intervention
- All credentials retrieved from Passwordstate are marked
no_log: true - Database queries are used to retrieve PFX documents from Passwordstate
- Supports both "Certificaat" and "Cert" as valid SecretType values for certificates