Repository navigation
Protected Branches - Design - #2369
Conversation
|
|
||
| ## Requirements | ||
|
|
||
| 1. As a lakeFS user, I should be able to mark branches as "protected" - from the UI, CLI and API. |
There was a problem hiding this comment.
My thoughts about "branch protection":
Branch protection is a repository-level set of rules that we check for specific operations.
The user can define a rule that matches zero to many branches, patterns like: "dev-*" that apply a specific set of constraints.
One of the constraints is 'merge only' - which allows only merge operations on the branch.
As repository wide operations we should keep them at the same level as we keep retention (think it is option two here).
|
|
||
| 1. As a lakeFS user, I should be able to mark branches as "protected" - from the UI, CLI and API. | ||
| 1. Protected branches cannot be directly committed to. Only merges are allowed into protected branches. | ||
| 1. Commits to protected branches should fail with a meaningful error message. |
There was a problem hiding this comment.
Any backdoor? admin privileges? force options?
arielshaqed
left a comment
There was a problem hiding this comment.
As discussed F2F, I believe that the way to add this feature is not to add more metadata but rather to use what we already have. (So not like GitHub branch protection in this sense but rather like their (and our!) actions.) Adding metadata means that you must take care of, among other things:
- Authorization
- Audit
- Branch matching
- Ordering with respect to actions
- Historical behaviour (e.g. committing becomes non-hermetic, the fact that you could commit at ref X yesterday does not means that you can commit there today!)
All this because it adds a new concept, and now the users and we need to understand how that concept interacts with other concepts in the system. And users cannot modify the branch protection feature, so we will have to do it for them. (For instance, almost every branch protection feature on GitHub today at https://github.com/treeverse/lakeFS/settings/branch_protection_rules/17304120 would require a lakeFS user to add an action; arguably already having an action makes adding these features easier not harder.) So for any of these features AFAICS we would just send them a new action to install (or they would). And now you have two audit logs: one for "lakefs branch protection", one for "extra branch protections that got added as actions". And the user needs to understand how everything interacts.
I would like to suggest a different underlying implementation, that in turn influences the behaviour with respect to most of the above. Add a pre-commit action that prevents some commits. E.g. it looks at its branch name, and if the branch name matches one of a bunch of regexps / wildcards / ... then it fails the commit.
- Users get authorization through existing lakefs IAM permissions to edit these files.
- Users get their audit using
lakectl log .... As a bonus, the log "Add branch protection" appears in the same log, users can see when it happened. - Branch matching is entirely flexible and written in a language the user might know (bash, Python, ...).
- Ordering with respect to actions is the ordering of actions.
- Behaviour is hermetic and reproducible.
This implementation can still happen from the GUI! E.g. press a button, it adds a commit to the default branch with an activity that does the configured matching or modifies that commit.
|
@arielshaqed, I understand the desire to create less places where configuration is done. I also completely see the elegance of using an existing solution like Hooks. |
|
I believe that staging must be blocked, otherwise the branch isn't really protected. If we choose to block staging on protected branches using hooks might complicate things more than making them simple. |
|
|
||
| * In Graveler, before every Staging Manager write operation (Set, Drop, DropKey) - fetch the rules. | ||
| * If the branch name matches a rule, fail the operation with a dedicated error type. | ||
| * Each of these operations should allow a force flag. |
There was a problem hiding this comment.
This is obviously necessary, so it also has to work with all the ways to write to staging. Otherwise for most use-cases there is no way to force writes -- almost nothing uses the lakeFS API.
- How does the user make this work with the S3 gateway? We should consider e.g. whacky-coding something into the branch name on the S3 path (or on the repo?), so that I can change my Spark job to force-write.
- How does the user configure this with the Spark HadoopFS? We should consider e.g. a similar coding on the lakefs path.
|
|
||
| ### Descision | ||
|
|
||
| After a meeting discussing the matter, we decided to go with suggestion #1, but to add a repository-level settings feature to be used in order to store the branch protection rules. See the [issue](https://github.com/treeverse/lakeFS/issues/2406). |
There was a problem hiding this comment.
How do we audit changes? (Do we?)
Co-authored-by: arielshaqed <[email protected]>
arielshaqed
left a comment
There was a problem hiding this comment.
- AFAICT this design depends on #2406. If we do not want to hold its approval subject to approving that one, then we should advance on #2406 at least as far as giving the semantics that that design will provide (e.g. consistency, performance, audit, authorization, etc.).
- The policy syntax seems arbitrary and inconsistent with other policy types in the system.
|
|
||
| * When performing a commit, the protection rules of the repository will be fetched from the storage. | ||
| * Right before executing the pre-commit hooks, check whether the branch name matches any of the protection rules. | ||
| * If so, the commit will fail with a dedicated error type. |
There was a problem hiding this comment.
Is this the merge_only constraint type? If so, perhaps it should be stated more like
{
"...": "...",
"commit": false
}| [ | ||
| { | ||
| "branch_name_pattern": "main", | ||
| "constraints": ["merge_only"] |
There was a problem hiding this comment.
The "Runtime" design below seems to talk in terms of capabilities, and uses different "constraints".
I suspect that there are really capabilities hiding here too, maybe this should be an object denying some of them?
|
|
||
| ### Decision | ||
|
|
||
| After a meeting discussing the matter, we decided to go with suggestion #1, but to add a repository-level settings feature to be used in order to store the branch protection rules. See the [issue](https://github.com/treeverse/lakeFS/issues/2406). |
|
Rethinking, I should be more agile about this one:
In practice #2406 is not a blocker for this design. We can pick whichever solution there and get this solution with corresponding solutions. And we can decide there as long as we are aware of the effects here. So one of these does block the other... but we can choose which one! It is safe to commit to decisions in this PR and then use that to guide our decisions in that PR. Or vice versa, to commit to decisions there and then use that to guide our decisions here.
This still holds, and I would like to understand more about the policy syntax. |
arielshaqed
left a comment
There was a problem hiding this comment.
Cool!
It occurs to me that if a branch becomes protected while its staging are is nonempty, then things get weird. We may want to warn users of this in some way, e.g. when changing blocked_actions to block commits.
Design suggestions for #2181