Skip to content

Protected Branches - Design - #2369

Merged
johnnyaug merged 21 commits into
masterfrom
design/protected_branches
Sep 30, 2021
Merged

johnnyaug merged 21 commits into
masterfrom
design/protected_branches

Conversation

@johnnyaug

@johnnyaug johnnyaug commented Aug 15, 2021 •

Copy link
Copy Markdown
Contributor

Design suggestions for #2181


## Requirements

1. As a lakeFS user, I should be able to mark branches as "protected" - from the UI, CLI and API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread design/protected-branches.md Outdated

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any backdoor? admin privileges? force options?

Comment thread design/protected-branches.md Resolved
Comment thread design/protected-branches.md Resolved
Comment thread design/protected-branches.md Resolved
Comment thread design/protected-branches.md Resolved
@johnnyaug johnnyaug changed the title initial design- protected branches Protected Branches - Design Aug 16, 2021

@arielshaqed arielshaqed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@johnnyaug

Copy link
Copy Markdown
Contributor Author

@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.
However, my concern is that it will be harder for users to grasp and understand. I tried to sum it up to a short paragraph in the doc - please let me know if I got the gist of it.

@guy-har

guy-har commented Aug 17, 2021

Copy link
Copy Markdown
Contributor

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.

Comment thread design/protected-branches.md Resolved
Comment thread design/protected-branches.md Outdated

* 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. 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.
  2. 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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we audit changes? (Do we?)

@arielshaqed arielshaqed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.).
  2. 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the merge_only constraint type? If so, perhaps it should be stated more like

{
  "...": "...",
  "commit": false
}

Comment thread design/protected-branches.md Outdated
[
{
"branch_name_pattern": "main",
"constraints": ["merge_only"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the recurrence of questions around this (most recently #2491), we need to add some more definitive explanation of this decision.

I believe that this is a dependency on #2406.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned on Slack, #2491 is a design choice for implementing #2406.

I don't think there's a dependency here on any of them

@arielshaqed

Copy link
Copy Markdown
Contributor

Rethinking, I should be more agile about this one:

1. 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.).

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.

2. The policy syntax seems arbitrary and inconsistent with other policy types in the system.

This still holds, and I would like to understand more about the policy syntax.

@arielshaqed arielshaqed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@johnnyaug
johnnyaug merged commit 1c70146 into master Sep 30, 2021
@johnnyaug
johnnyaug deleted the design/protected_branches branch September 30, 2021 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants