Redirect git URL

27 views
Skip to first unread message

Marcos Schratzenstaller

unread,
Sep 20, 2022, 12:06:42 PM9/20/22
to gitolite
Hello everyone! We are using gitolite in a production environment and as of today, we have this structure to access our repos using git:

git@<mydomain>:/production/<repository>.git

This is all working as expected and repos are being created in ~/git/repositories/production/<repository>.git. That's fine and we would like to keep this storage configuration BUT at this very moment, we would love to remove that prefix /production.

Essentially, what we would love to have would be a way of redirecting the git command location that would respond to git@<mydomain>:<repository>.git but gitolite would keep looking for repositories inside the same directory, which would be  ~/git/repositories/production/<repository>.git so in the end, if people tries to access git@<mydomain>:/production/<repository>.git OR git@<mydomain>:<repository>.git gitolite would work and provide the repository transparently.

We could use an NGINX analogy here. If we were talking about an NGINX server, we would like to have a rewrite rule from :/production/<repository>.git to :<repository>.git without changing storage or even the configuration inside the /conf/accounts/* (although I know that this is highly unlikely to be possible).

I am aware that this might not even involve gitolite configuration and probably this would be handled in the sshd config, so if you have by any chance an idea on how to achieve that, please LMK :)

Thank you all in advance for your help :)

Sitaram Chamarty

unread,
Sep 20, 2022, 12:51:25 PM9/20/22
to Marcos Schratzenstaller, gitolite
On Tue, Sep 20, 2022 at 05:59:56AM -0700, Marcos Schratzenstaller wrote:
> Hello everyone! We are using gitolite in a production environment and as of
> today, we have this structure to access our repos using git:
>
> git@<mydomain>:*/production/*<repository>.git
>
> This is all working as expected and repos are being created in
> ~/git/repositories/production/<repository>.git. That's fine and we would
> like to keep this storage configuration BUT at this very moment, we would
> love to remove that prefix */production*.
>
> Essentially, what we would love to have would be a way of redirecting the
> git command location that would respond to git@<mydomain>:<repository>.git
> but gitolite would keep looking for repositories inside the same directory,
> which would be ~/git/repositories/production/<repository>.git so in the
> end, if people tries to access git@<mydomain>:*/production/*<repository>.git
> OR git@<mydomain>:<repository>.git gitolite would work and provide the
> repository transparently.
>
> We could use an NGINX analogy here. If we were talking about an NGINX
> server, we would like to have a rewrite rule from
> :/production/<repository>.git to :<repository>.git without changing storage
> or even the configuration inside the /conf/accounts/* (although I know that
> this is highly unlikely to be possible).
>
> I am aware that this might not even involve gitolite configuration and
> probably this would be handled in the sshd config, so if you have by any
> chance an idea on how to achieve that, please LMK :)

It may be possible to handle in ssh config but it would
interfere with gitolite in some ways that would need to be
considered (and lots of testing)

What you need is something similar to 'Alias.pm' (see
https://github.com/sitaramc/gitolite/blob/master/src/lib/Gitolite/Triggers/Alias.pm)

Alias itself cannot be used since you want the actual repos to
be in "production/foo" but be refered either as "production/foo"
or just "foo". (Alias.pm would have worked if you wanted the
actual repo to be "foo" but be refered either way).

The following code, untested, but replacing the core of the
current Alias.pm, *should* work. If you have no use for the
actual Alias.pm you could override it with this code (see
https://gitolite.com/gitolite/non-core.html#for-your-non-core-programs)

sub input {
my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
my $user = $ARGV[0] || '@all'; # user name is undocumented for now

if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /(?:$git_commands) '\/?(\S+)'$/ ) {
my $repo = $1;
( my $norm = $repo ) =~ s/\.git$//; # normalised repo name
chdir $rc{GL_REPO_BASE};

return if -d "$norm.git";
return unless -d "production/$norm.git";

$ENV{SSH_ORIGINAL_COMMAND} =~ s/'\/?$repo'/'production\/$repo'/;
}

}

Note that INPUT triggers are one of only two things in gitolite
that *must* be written in perl, so feel free to ask if you need
more help.

Reply all
Reply to author
Forward
0 new messages