Skip to content

Instantly share code, notes, and snippets.

@YogSottot
Created June 28, 2024 02:00
Show Gist options
  • Save YogSottot/9cb6f737f8a70334d84a703f064887ca to your computer and use it in GitHub Desktop.
Save YogSottot/9cb6f737f8a70334d84a703f064887ca to your computer and use it in GitHub Desktop.
extend all personal token for gitlab
# https://about.gitlab.com/blog/2023/10/25/access-token-lifetime-limits/
# This script extends the lifetime of all tokens which expire on a specified date, including:
#
# Personal access tokens
# Group access tokens
# Project access tokens
#
# Users that have intentionally set a token to expire on the specified date will have their token lifetimes extended as well.
#
# To use the script:
#
# Rails console session
# Rails Runner
#
# In your terminal window, connect to your instance.
# Copy this entire script, and save it as a file on your instance:
# Name it extend_expiring_tokens.rb.
# If desired, change the expiring_date to a different date.
# The file must be accessible to git:git.
#
# Run this command, changing /path/to/extend_expiring_tokens.rb to the full path to your extend_expiring_tokens.rb file:
#
# sudo gitlab-rails runner /path/to/extend_expiring_tokens.rb
# you can put it in cron
date_range = 12.month
new_expires_at = 12.months.from_now
total_updated = PersonalAccessToken
.not_revoked
.where(expires_at: Date.today .. Date.today + date_range)
.update_all(expires_at: new_expires_at.to_date)
puts "Updated #{total_updated} tokens with new expiry date #{new_expires_at}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment