Guides
Set the API token
The audit log API token is a static token configured to grant your caller service access to the API endpoint.
- As an admin user, go to "App Settings" in the left-hand menu under "Admin."
- Navigate down to the "External access" section.
- Open the entry titled
audit-log-api-access, which is a static token that has been pre-created for you with the recommended settings.
Tip: By default, we use access restrictions to restrict the token's scope to the
audit-logplugin andaudit.log.readpermission. Tokens with different plugin or permission scope will cause API requests to respond with 403 Forbidden.
- In the "Token" section, paste in a secure API token value of your choice for API authentication. Keep this value in a safe place as you won't be able to see it in Portal.
Tip: The token must be at least 8 characters long and not contain spaces. With
node, you can generate a token in the Terminal via the command:node -p 'require("crypto").randomBytes(24).toString("base64")'
- Click "Update item" in the bottom right corner.
- Click "Save" in the bottom right corner and wait for Portal to reload with the new configuration.
Exclude certain events or actors from logs
In Portal’s App Settings, you can configure which combinations of actor and event you want to exclude from being saved to the audit trail. By default, entity-fetch and entity-facets events from all plugin actors are excluded because they are high-volume, low-value read operations. The same events from synthetic test users are also excluded to prevent noise.
Important: Exclusion rules prevent events from being saved to the audit log database entirely. They will still appear in console logs (if the severity level is configured to log), but will not be queryable via the API.
- As an admin user, go to "Plugins" in the left-hand menu under "Admin."
- Find the “Audit Log” plugin card in the list and open it.
- Add or edit exclusion rules in the UI using the configuration format shown in examples below.
- Save your changes.
Example Use Cases
excludeRules:
# Exclude high-volume read operations from all plugins
- actorId: 'plugin:*'
eventId: 'entity-fetch'
# Exclude health check events from monitoring services
- actorId: 'user:default/healthcheck-service'
eventId: 'entity-validate'
# Exclude specific scaffolder dry-run tasks
- actorId: 'plugin:scaffolder'
eventId: 'task'
# Note: This excludes ALL task events. Consider filtering by actionType instead.
Wildcard Patterns
Use wildcards (*) in actorId to exclude patterns of events:
plugin:*- Matches all plugin actorsplugin:search- Matches only the search pluginuser:*/*- Matches any user in any namespaceuser:default/*- Matches any user in the default namespace
Add audit events to custom plugins
Save events taking place in your own custom plugins by integrating the Backstage auditor service.
Integrate auditor service
Declare the auditor service as a plugin dependency:
import {
coreServices,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
export const myPlugin = createBackendPlugin({
pluginId: 'my-plugin',
register(env) {
env.registerInit({
deps: {
auditor: coreServices.auditor,
httpRouter: coreServices.httpRouter,
// ... other dependencies
},
async init({ auditor, httpRouter }) {
// Use the auditor service here
},
});
},
});
Add audit events
Use the createEvent method to generate audit events. For more on how to use the auditor service, see the Auditor Service Backstage documentation (specifically Naming conventions) and the AuditorService source code.
// Basic usage
const event = await auditor.createEvent({
eventId: 'entity.created',
severityLevel: 'high', // 'low' | 'medium' | 'high' | 'critical'
request: req, // Optional: Express request object
meta: {
actionType: 'create',
queryType: 'mutation',
entityRef: 'component:default/my-service',
customField: 'custom-value',
},
});
// Mark as successful (remove 'await' for non-blocking save)
await event.success();
// OR mark as failed with error details
await event.fail({
error: new Error('Operation failed'),
meta: { additionalContext: 'value' },
});
Automatic field extraction
The PortalAuditorService automatically extracts the following information:
- Actor ID & Type: From request credentials (user or service principal)
- Request Method & URL: From the Express request object
- Plugin ID: From the plugin metadata
- Event Time: Current timestamp
Special meta fields
The following fields in the meta object are promoted to dedicated database columns to be queried by the API easily. These fields are removed from the meta JSON blob to avoid duplication.
actionTypequeryTypeentityRef