Skip to content

Commit 603abd8

Browse files
committed
Add post about infinite GItLab tokens
1 parent 4f26f52 commit 603abd8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Infinite-expiry access tokens on self-hosted GitLab
3+
tags:
4+
- GitLab
5+
---
6+
7+
The ability to create personal access tokens without expiry was [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/369122) in GitLab 15.4 and [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/392855) in GitLab 16.0. For security reasons, expiring tokens makes sense. However, in many cases I'd much rather set them infinite so I can easily put them in version control and not worry about them expiring. If an attacker can access the token, I've already got bigger problems.
8+
9+
!!! warning
10+
This solution **only** works on self-hosted GitLab. It will not work with [gitlab.com](https://gitlab.com)!
11+
12+
This requires connecting to the database. Exactly how to do that will vary based on your deployment (it's probably `gitlab-psql`).
13+
14+
## 1. Find the token:
15+
16+
```psql
17+
gitlabhq_production=> select * from personal_access_tokens order by created_at desc limit 1;
18+
```
19+
20+
Assuming you just made the token, it should be the latest. If it's not, you'll need to tweak the query.
21+
22+
## 2. Find the id, and confirm it's the right one:
23+
24+
```psql
25+
gitlabhq_production=> select * from personal_access_tokens where id=<id>;
26+
```
27+
28+
You don't want to change the wrong one!
29+
30+
## 3. Increase the date
31+
32+
```psql
33+
update personal_access_tokens set expires_at=expires_at + interval '100 years' where id=<id>;
34+
```
35+
36+
In 100 years, it's someone else's problem.

0 commit comments

Comments
 (0)