I cannot programmatically setup users in a Docker container

Gitea 1.4.1 (Dockerized)

I’m trying to setup a Docker container, “ready to go”, bootstrapped out-of-the-box with users. Unfortunately, I can’t work out how to add users, given the current options…

  1. Install screen - I’d like to setup the users programatically as part of an automatic deployment (so this won’t work)
  2. Use the gitea shell command - I don’t have access to the container shell remotely (unless I setup an ssh server :frowning_face: )
  3. REST API - requires an existing user account to be specified, otherwise I get 403 Forbidden (chicken and egg problem, no users exist)

Questions:

  • Are there any other options?
  • Does Gitea have a default admin account?
  • Does the REST API accept a SECRET_KEY HTTP header as an authentication mechanism?

I could use OAuth…
I could “roll my own” Dockerfile to setup a default user account…

but I wanted to check there wasn’t a supported method out there already.

docker-compose.yml

version: '3'
services:
  web:
    image: gitea/gitea:1.4.1
    restart: always
    volumes:
      - web_data:/data
    ports:
      - "3000:3000"
      - "22:22"
    environment:
      APP_NAME: myapp
      RUN_MODE: prod
      DISABLE_REGISTRATION: "true"
      SECRET_KEY: password123
      INSTALL_LOCK: "true"

volumes:
  web_data:

You could use this from your host to create your admin user:
docker exec -it <container-name> /app/gitea/gitea admin create-user

But I don’t know any other solution for this right now.

1 Like

Thanks @daviian

I’m going down the path of extending the docker container, so that I can setup a default admin user account.

i.e. Dockerfile

FROM gitea/gitea:1.4.1
COPY ./app.ini /data/gitea/conf/app.ini
RUN /app/gitea/gitea admin create-user --name admin --password admin123 --email admin@mountain-pass.com.au --admin 

Only problem, is now I’m getting the following error:

CreateUser: name is reserved [name: admin]

  • Does that mean that an admin account already exists?
  • If so, what is the password?
  • Also, is there anyway to bootstrap the database tables?

CreateUser: no such table: user

The name admin is reservered as it is used in certain urls. You have to choose another name.

What exactly do you mean by “bootstrap” the database?

@daviian, re: “bootstrap” - I’m getting an error when I try to add a user, before gitea has been run for the first time.

./gitea admin create-user --name admin --password admin123 --email admin@mountain-pass.com.au --admin
...
CreateUser: no such table: user

So I assume what is happening, is the command is trying to insert a user record straight into the database table, but the database table hasn’t been setup yet…

Is there anyway I can setup the tables (before running gitea)?

e.g. perhaps using gitea-db.sql from the backup/restore process? (incidently, I tried to get hold of a copy of gitea-db.sql from my current system using ./gitea dump, but the file wasn’t created. :frowning_face:. No samples available in the source code either.)

Hi nick,

Unfortunately there is currently no way to setup the tables before actually running gitea.
However I like the idea to have a cli command that only performs the initial database steps including migrations.

Would you mind creating a feature request on github? :slight_smile:

Regarding the dump command. There’s an open PR to reimplement that, see https://github.com/go-gitea/gitea/pull/2917

Best regards
daviian

@daviian - here it is! :smile:

@daviian … and here’s a workaround/solution.