Git Product home page Git Product logo

gitdir's Introduction

go-gitdir

Go Report Card Build Status

This project makes it incredibly easy to host a secure git server with a config that can be easily rolled back.

It aims to solve a number of problems other git servers have:

  • Requires no external dependencies other than the binary and git
  • Stores its configuration in a repo managed by itself
  • Doesn't hook into the system's user accounts
  • No vendor lock-in - everything is just a bare git repository

Origins

The main goal of this project is to enable simple git hosting when a full solution like Bitbucket, Github, Gitlab, Gitea, etc is not needed.

This project was inspired by gitolite and gitosis, but also includes a built-in ssh server and some additional flexability. It is not considered stable, but should be usable enough to experiment with.

Thankfully because all the repos are simply stored as bare git repositories, it should be fairly simple to migrate to or from other git hosting solutions. There is no vendor lock-in.

Requirements

Build requirements:

  • Go >= 1.13

Runtime requirements:

  • git (for git-receive-pack and git-upload-pack)

Building

Clone the repository somewhere, outside the GOPATH. Then, from the root of the source tree, run:

go build ./cmd/gitdir

This will create a binary called gitdir.

Running

Server Config

There are a number of environment variables which can be used to configure your go-git-dir instance.

The following are required:

  • GITDIR_BASE_DIR - A directory to store all repositories in. This folder must exist when the service starts up.

The following are optional:

  • GITDIR_BIND_ADDR - The address and port to bind the service to. This defaults to :2222.
  • GITDIR_LOG_READABLE - A true value if the log should be human readable
  • GITDIR_LOG_DEBUG - A true value if debug logging should be enabled
  • GITDIR_ADMIN_USER - The name of an admin user which the server will ensure exists on startup.
  • GITHUB_ADMIN_PUBLIC_KEY - The contents of a public key which will be added to the admin user on startup.

Runtime Config

The runtime config is stored in the "admin" repository. It can be cloned and modified by any admin on the server. In it you can specify groups (groupings of users for config or convenience reasons), repos, and orgs (groupings of repos managed by a person).

Additionally, there are a number of options that can be specified in this file which change the behavior of the server.

  • implicit_repos - allows a user with admin access to that area to create repos by simply pushing to them.
  • user_config_keys - allows users to specify ssh keys in their own config, rather than relying on the main admin config.
  • user_config_repos - allows users to specify repos in their own config, rather than relying on the main admin config.
  • org_config_repos - allows org admins to specify repos in their own config, rather than relying on the main admin config.

Usage

Simply run the built binary with GITDIR_BASE_DIR set and start using it!

On first run, gitdir will push a commit to the admin repo with a sample config as well as generated server ssh keys. These can be updated at any time (even at runtime) but if the server restarts and the keys cannot be loaded, they will be re-generated.

If you set GITDIR_ADMIN_USER and GITHUB_ADMIN_PUBLIC_KEY an admin user will automatically be added to the config.

If you do not set those environment variables, you will need to manually clone the admin repository (at $GITDIR_BASE_DIR/admin/admin) to add a user to config.yml and set them as an admin.

Sample Config

Sample admin config.yml:

users:
  belak:
    is_admin: true
    keys:
      - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDeQfBUWIqpGXS8xCOg/0RKVOGTnzpIdL7r9wK1/xA52 belak@tmp
    repos:
      personal-gitdir: {}

groups:
  admins:
    - belak

repos:
  go-gitdir:
    public: true

    write:
      - $admins
    read:
      - some-other-user

orgs:
  vault:
    admins:
      - $admins
    write:
      - some-org-user
    read:
      - some-other-org-user

    repos:
      the-vault:
        write:
          - some-repo-access-user

options:
  implicit_repos: false
  user_config_keys: true
  user_config_repos: false
  org_config_repos: false

Repo Creation

All repos defined in the config are created when the config is loaded. At runtime, if implicit repos are enabled, trying to access a repo where you have admin access will implicitly create it.

gitdir's People

Contributors

belak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gitdir's Issues

Improve logging

Maybe switch to a system I'm more familiar with, like logrus.

Failed to load SSH server

I get the following error:

bvk@milk:~$ GITDIR_BASE_DIR=/tmp/git ~/go/bin/go-gitdir serve
{"level":"info","time":"2019-10-30T15:27:47-07:00","message":"Starting go-git-dir"}
{"level":"info","time":"2019-10-30T15:27:47-07:00","message":"Reloading"}
{"level":"fatal","error":"ssh: unsupported key type ed25519.PublicKey","time":"2019-10-30T15:27:47-07:00","message":"Failed to load SSH server"}
bvk@milk:~$

bvk@milk:/tmp/git/admin/admin$ git log
commit e24c9cd7a1fe75a6d14b93b36261f08c2770c2a0
Author: root <root@localhost>
Date:   Wed Oct 30 15:26:33 2019 -0700

    Updated ssh keys

commit a608461d301832d3bd9996c962be9e12511157e0
Author: root <root@localhost>
Date:   Wed Oct 30 15:25:36 2019 -0700

    Updated user bvk

commit 094ad53a02c79bf3917c05c3dc7dc18a5cfba829
Author: root <root@localhost>
Date:   Wed Oct 30 15:25:10 2019 -0700

    Updated user bvk
bvk@milk:/tmp/git/admin/admin$

Clean up code

The first version was pushed out pretty quickly - it was built in only a few days. As a result of this, there are a number of things that should be cleaned up:

  • Merge repo and *GitRepo types (or more clearly separate them)
  • All admin repo accesses to the getter functions
  • Don't bother storing the *Config in the context (this is still relevant, unfortunately)
  • Avoid passing config options all over the place (there's not a good way around this)
  • Change to the basedir to make repo creation/lookup simpler

Update Readme

Can you please add some details in the Readme? I want to try the following

a. Create a repo dynamically. I'm not clear what needs to be set in the config file.
b. Add/Remove user to the repo. How do I add/remove a user?

Detailed instructions will be very useful.

unknown location of executable

After running 'go build' as per the install instructions, there doesn't seem to be an executable generated... could you update the README with the location of the resulting binary.

Add more tests

Some of the code was designed with testing in mind, but tests haven't been written yet. It would be worthwhile doing that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.