Problem with authorization in Gitea 1.15.x

Drone has limit of 500 characters to store user token in “users” table. Latest Gitea can issue token that is longer than that as result even after authorizing in drone, user session is created but old token is uses as result accessing any build will show 404 error.

Drone will log error: cannot update user: pq: value too long for type character varying(500)

I was able to fix problem on my instance by changing drone database using SQL:

alter table users alter column user_oauth_token type bytea using convert_to(user_oauth_token, 'LATIN1');
alter table users alter column user_oauth_refresh type bytea using convert_to(user_oauth_refresh, 'LATIN1');

I ran into the same issue. I’m not sure though if it’s a good idea to change the type of a column…?
Instead I just increased the length of the character varying columns:

alter table users alter column user_oauth_token type character varying(32767);
alter table users alter column user_oauth_refresh type character varying(32767);
1 Like

Please note that newer versions of Drone use blob types (bytea for postgres) for storing the auth token and refresh token (via this patch). If you have an older version of Drone, you should upgrade to the latest version of Drone and then manually update the column types as shown above. Caveat that the ALTER TABLE statement above is for postgres and will need to be adjusted if you are using sqlite or mysql.

We are positive though that the report you closed as duplicate was not related, since the issue only exists for some repositories.


I couldn’t figure out the necessary changes for SQLite (the column is a TEXT and that doesn’t have a size restriction and I could validate that the token in the column contains >500 characters and was not truncated). Still, I get the could not read Username error for private repos.

Since I have a very small Drone instance, I just decided to try and start from scratch; deleted the entire database file, restarted the Drone container, re-authorized and re-enabled the repository, but I still get the same error.

It works when I turn my organization and repo in Gitea public temporarily.

What am I missing?

Thank you,

(Gitea: 1.15.2, Drone: 2.7.2 [extrapolated from the fact that I’m using drone/drone:2 and pulled and redeployed and according to Dockerhub 2 was updated at the same time as 2.7.2 4 days ago])