Pushing to git via https gives error 22, cloning works fine

I've got git running on a FreeBSD 12.1 setup on my linode. After the upgrade from 12.0 to 12.1 via FreeBSD-update I can clone from the git server via https method but I can not push changes back to it, I'm getting an error 22. This error I've googled as common, but none of the fixes have helped. I'm using Apache 2.4 as a web server and not seeing anything in my http error logs. I've uninstalled git completely and reinstalled it twice with no effect. Suggestions welcome, I do not believe this is a FreeBSD-specific issue.

2 Replies

Got the issue fixed, or at least worked around.
I'm getting an error 22 when atempting to push to a git server over
https using http-backend and authentication. The issue seems to be an
error in my configuration below. If I checkout with:

https://git.domain.com/reponame.git

it works, this shouldn't because if I then try to push to that url I
get the error 22. To fix it I have to do:

https://git.domain.com/git/reponame.git

this asks for authentication when pulling from the repo and again for
pushing local changes/modifications back to it.

The url https://git.domain.com/git/reponame.git is correct while the
configuration allows https://git.domain.com/reponame.git I need to
stop this behavior since atempting to push back to it results in an
error, and only allow authenticated clones/pulls and/or authenticated
pushes back to https://git.domain.name/git/reponame.git

Here's my configuration:

cat git.conf

# The git.host.name.com http virtual host
<virtualhost *:80="">
DocumentRoot /usr/local/www/git/repos
ServerName git.host.name.com
ServerAdmin webmaster@host.name.com
ErrorLog /var/log/git-httpd-error.log
CustomLog /var/log/git-httpd-access.log combined</virtualhost>

### Redirect all http urls to https #
<ifmodule mod_rewrite.c=""> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301] </ifmodule>

# OPTIONAL: Completely deny pushing over HTTP
<locationmatch "git-receive-pack"=""> Require all denied </locationmatch>

# The git.host.name.com https virtual host
<virtualhost *:443="">
DocumentRoot /usr/local/www/git/repos
ServerName git.host.name.com
ServerAdmin webmaster@host.name.com
ErrorLog /var/log/git-httpd-error.log
CustomLog /var/log/git-httpd-access.log combined</virtualhost>

# Uncomment the below 2 lines when deploy http2
H2Direct on
Protocols h2 h2c http/1.1

SSLEngine on
SSLCertificateFile "/usr/local/etc/ssl/acme.sh/host.name.com/fullchain.crt"
SSLCertificateKeyFile
"/usr/local/etc/ssl/acme.sh/host.name.com/private/server-ec256.key"
SSLCACertificateFile "/usr/local/etc/ssl/acme.sh/host.name.com/cacert.crt"

# HSTS (mod_headers is required) (15768000 seconds = 6 months)
Header always set Strict-Transport-Security "max-age=15768000"

<directory "="" git="" local="" repos"="" usr="" www="">
Options +ExecCGI
SSLRequireSSL
AllowOverride None</directory>

AuthType Basic
AuthName "Private Git Access"
AuthUserFile "/usr/local/etc/apache24/git-auth-file"
AuthGroupFile "/usr/local/etc/apache24/git-htgroup-file"
Require valid-user
<if "%{query_string}="~" %{request_uri}="~" git-receive-pack$#"="" m#="" m#service="git-receive-pack#" ||=""> Require group gitwrite </if>

ScriptAlias /git /usr/local/libexec/git-core/git-http-backend
<directory "="" git-core"="" libexec="" local="" usr="">
SetEnv GIT_PROJECT_ROOT /usr/local/www/git/repos
SetEnv GIT_HTTP_EXPORT_ALL
# For anonymous write
#SetEnv REMOTE_USER anonymousweb
Options +ExecCGI
SSLRequireSSL</directory>

AuthType Basic
AuthName "Private Git Access"
AuthUserFile "/usr/local/etc/apache24/git-auth-file"
AuthGroupFile "/usr/local/etc/apache24/git-htgroup-file"
Require valid-user
<if "%{query_string}="~" %{request_uri}="~" git-receive-pack$#"="" m#="" m#service="git-receive-pack#" ||=""> Require group gitwrite </if>

# gitweb
Alias /gitweb "/usr/local/www/gitweb"

<directory "="" gitweb"="" local="" usr="" www="">
DirectoryIndex gitweb.cgi
Options ExecCGI
SSLRequireSSL</directory>

AuthType Basic
AuthName "Private Gitweb Access"
AuthUserFile "/usr/local/etc/apache24/git-auth-file"
Require valid-user

<files gitweb.cgi=""> SetHandler cgi-script </files>
SetEnv GITWEB_CONFIG /usr/local/etc/gitweb.conf

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct