Skip to content

Save last used IP address to personal access tokens

What does this MR do and why?

We thought it would be useful for audit purposes to showcase the IP address of computers that use a personal access token. We are only storing the last 5 distinct IPs to a new table in the database called personal_access_token_last_used_ips. Then, we display those 5 IPs on the PAT tokens table on the frontend. This feature is behind a feature flag called pat_ip. If the number of IP addresses exceeds 5, then we delete the previous IP addresses for a token using the following query:

@personal_access_token
        .last_used_ips
        .order(created_at: :asc)
        .limit(ip_count - NUM_IPS_TO_STORE)
        .delete_all

Related to #428577.

Alternative approaches

  • We considered using audit events for saving the last used IP address. Downside of this approach:
    • this would create an audit event for every API request which would generate too much data
    • we also prefer displaying the IP address in the PAT / PrAT / GrAT table, not in admin events
    • PAT are not scoped to a group, so it would only be available in the audit events of the instance admin panel.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
image image

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #428577

Edited by Rohit Kala

Merge request reports

Loading