TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How can I create a webserver that runs Git commands securely?

8 点作者 orhunp_大约 2 年前
Hi, I&#x27;m currently writing a webserver (REST API) which will run certain git commands such as &quot;git clone&quot; when a repository link is given via endpoint. I&#x27;m wondering how can I make this secure. There are a couple of security flaws that I could think of:<p>- cloning a huge repository will take a long time (how can I check the repository size?)<p>- cloning a couple of repositories at the same time might make the server slow<p>- running shell commands on the actual system might be dangerous<p>First thing I thought of was running these git commands in Docker. But I&#x27;m not sure that&#x27;s applicable since everything will be running inside Docker anyways. What would be the best way of doing this?

3 条评论

ggeorgovassilis大约 2 年前
Look at <a href="https:&#x2F;&#x2F;nodered.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nodered.org&#x2F;</a> , many people use it for automating stuff.<p>The DIY version:<p>I&#x27;m sure there are better ways, but that&#x27;s how I would do it:<p>&gt; how can I check the repository size?<p>[1] <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;8185276&#x2F;find-size-of-git-repository" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;8185276&#x2F;find-size-of-git...</a><p>&gt; cloning a couple of repositories at the same time might make the server slow<p>long running operations must run asynchronously. I would implement that as: client sends HTTP request to the server, server responds with a job ID and creates a temp directory with a random name containing information about the job (eg parameters). A scheduler (cron?) picks up the job, changes status, executes it. The scheduler can decide on parallelisation. The scheduler must run as a low-privileged user, possibly in a container as you suggested. The client needs to poll the server for job status.<p>&gt; running shell commands on the actual system might be dangerous<p>The method described earlier partly mitigates that as the process doesn&#x27;t run in the web server. I would create special job types (eg. one shell script for checking out, one for committing, one for pushing etc) and sanitise arguments (eg. no weird characters allowed). Running each job run in a sub directory of its own limits spill-over.
评论 #35371989 未加载
cookiengineer大约 2 年前
Don&#x27;t run web services as root.<p>Use net capabilities if you need tcp port bindings below 1024.<p>I&#x27;d also recommend running the git commands inside a forked process with another user in the same group (which has limited access to the filesystem). Alternatively use the git user&#x2F;group and add the web service daemon user to the git group.<p>Also check that your linux distribution doesn&#x27;t have binaries with the sticky flag set which could be used for privilege escalation. Double-check the list of gtfobins against your system&#x27;s installed packages&#x2F;binaries.<p>[1] <a href="https:&#x2F;&#x2F;gtfobins.github.com" rel="nofollow">https:&#x2F;&#x2F;gtfobins.github.com</a>
lesserknowndan大约 2 年前
Look into using ‘sudo’. Sudo is not just for running things as root. It can also be used to allow a web service (Apache+PHP) to call a specific program (git) as a specific user (e.g. nobody).
评论 #35383646 未加载
评论 #35370919 未加载