Serveride Git将分支创建限制为特定用户

发布于 2025-01-26 04:34:20 字数 519 浏览 1 评论 0原文

我认为这需要使用某种类型的git挂钩来完成。

在我们的中央git服务器(每个人都合并到)上 - 我们有特殊(保留的)分支名称,例如:以Release _开头的任何分支只能由CM Team成员制作,作为正式发布过程的一部分。

我还需要阻止任何人一旦创建该分支,就不会将其释放到该分支后,只能以某种形式读取该释放分支

,这不是出于恶意的原因,只是为了停止愚蠢的错误 - 我们都是人类和该死的,狗屎发生只是想避免并停止愚蠢的错误,然后他们在屁股上咬一支球队,而我们有问题。

我的问题是,我可以创建什么git规则或钩子,以防止这种类型的错误发生。并且可以用“力量推动”来解决这个问题吗? (这就是为什么我认为服务器端是需要强制执行的),

如果可能的话,您能指出一个示例吗? (这与SVN并不是一件难事 - 我们从哪里开始,而要问我这个问题的权力,我还不能回答)

请注意:我认为这确实需要在服务器上侧面,原因:挂钩需要支持所有用户Windows和Linux,我不希望有人尝试修复/升级/偶然的任何这些类型的安全挂钩...(这些事情永远不会发生...)

I'm thinking this needs to be done with some type of git hook.

On our central git server (where everybody merges to) - we have special (reserved) branch names, for example: any branch starting with RELEASE_ shall only be made by the CM team members as part of a formal release process.

I also need to block anyone from accidently commiting to that branch once it is created, ie: once a RELEASE has been made that RELEASE branch shall be read only in some form

This is not for malicious reasons, its just to stop stupid mistakes - we are all human and damn, shit happens just want to avoid and stop stupid mistakes before they bite the team in the ass and we have problems.

My question is, what GIT rule or hook can I create that will prevent this type of mistake from happening. And can this be worked around with a 'force push'? (this is why I am thinking the server side is where it needs to be enforced)

If this is possible, can you point met to an example? (This is not a hard thing to do with SVN - where we are comming from, and the powers that be are asking this question of me and I can't answer that yet)

NOTE: I think this really needs to be on the server side, reason: The hook needs to support all users, both windows and linux and I dont' want somebody to try to fix/upgrade/whatever these types of security hooks on accident... (that stuff never happens right...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2025-02-02 04:34:20

您可以使用预先接收器进行操作,并使用SSH(或其他OS介导的)身份,或者如果您需要真正的安全使用使用签名的提交,但是这里的尴尬之源在您现有的工作流程中:它旨在适合约束。不再适用。

尽管如此,在这些约束中使git工作并不难,并且可能很难让您的团队采用新的,不熟悉的工作流程,因此,这是我在审查入站投入提交的事前的种子:

#!/bin/bash --
# pre-receive hook to vet all inbound commits not in existing history

# collect all non-deleted tips, *[^0]* is any string w/ a nonzero
while read old new ref; do
    incoming+=("$old $new $ref")
    [[ $new = *[^0]* ]] && news="$news $new"
done

# vet each commit, id's via here-doc to keep shell environ access
while read commit; do
    check $commit here || hookrc=1
done <<EOD
$(  git rev-list $news --not --all  )
EOD

exit $hookrc

而且很容易扩展这一点。您要的任何方向。使用SSH进行可能需要授权和可行的想法的推送是

if [[ $ref = refs/heads/RELEASE_* && ! -w update-release ]]
then hookrc=1; echo updating $ref needs authorization $USER does not have
fi

您通过控制对存储库中该文件的写入访问来控制这些参考的更新。将授权用户添加到文件的组或ACL中,完成。

但是,为每个团队提供自己管理的回购更容易。发行团队有一个发行仓库,他们可以获取任何想要的东西,并称其为他们想要的东西,但是没有其他人可以完全更新它。质量保证团队有一个传入的存储库,任何人都可以推动,他们基于在那里显示的内容来控制集成测试。这些都不需要使主要项目存储库混乱,它是针对重要的内容,当前易于拍摄的发布标签和维护基准提示。

You can do it with a pre-receive and either use ssh (or other OS-mediated) identities or if you need real security use signed commits, but the real source of awkwardness here is in your existing workflow: it's designed to fit within constraints that no longer apply.

Still, it's not hard to make Git work within those constraints, and probably a lot harder to get your to team adopt a new, unfamiliar workflow, so here's my seed pre-receive for vetting inbound commits:

#!/bin/bash --
# pre-receive hook to vet all inbound commits not in existing history

# collect all non-deleted tips, *[^0]* is any string w/ a nonzero
while read old new ref; do
    incoming+=("$old $new $ref")
    [[ $new = *[^0]* ]] && news="$news $new"
done

# vet each commit, id's via here-doc to keep shell environ access
while read commit; do
    check $commit here || hookrc=1
done <<EOD
$(  git rev-list $news --not --all  )
EOD

exit $hookrc

and it's easy enough to extend that in any direction you please. Use ssh for pushes that might need authorization and a workable idea is

if [[ $ref = refs/heads/RELEASE_* && ! -w update-release ]]
then hookrc=1; echo updating $ref needs authorization $USER does not have
fi

where you control updates on those refs by controlling write access to that file in the repo. Add authorized users to the file's group or acl, done.

But it's even easier to give each team a repo they administer themselves. The release team has a release repo, they can fetch anything they want to it and call it what they want, but nobody else can update it at all. The QA team has an incoming repo to which anyone can push and they control integration testing based off what shows up there. None of that needs to be cluttering up the main project repo, it's for the really important stuff, currently-shipping release tags and the maintenance-base tip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文