-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Policies is a new concept which let you allowing teams to do some actions and reject member who are not part of those teams. Current actions supported are `pull_request` and `ok_to_test` (more to come in the future) See the documentation attached to this PullRequest for more description on how to use this feature. Signed-off-by: Chmouel Boudjnah <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,105 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
title: Policy on actions | ||
weight: 9 | ||
--- | ||
# Policy on Pipeline as Code actions | ||
|
||
Pipelines as Code has the concepts of Policy to let you control an action allowed | ||
to be executed by a set of users belonging to a Team on an Organisation as | ||
defined on GitHub or other Git Providers (only GitHub and Gitea is supported at | ||
the moment). | ||
|
||
## List of actions supported | ||
|
||
* `pull_request` - This action is triggering the CI on Pipelines as Code, | ||
specifying a team will only allow the members of the team to trigger the CI | ||
and will not allow other members regadless if they are Owners or Collaborators | ||
of the repository or the Organization. The OWNERS file is still taken into | ||
account and will as well allow the members of the OWNERS file to trigger the | ||
CI. | ||
* `ok_to_test` - This action will let a user belonging to the allowed team to | ||
issue a `/ok-to-test` comment on a Pull Request to trigger the CI on | ||
Pipelines as Code, this let running the CI on Pull Request contributed by a | ||
non collaborator of the repository or the organisation. This apply to the | ||
`/test` and `/retest` commands as well. This take precendence on the | ||
`pull_request` action. | ||
|
||
## Configuring the Policy on the Repository CR | ||
|
||
To configure the Policy on the Repository CR you need to add the following to the setting of the Repository CR: | ||
|
||
```yaml | ||
apiVersion: "pipelinesascode.tekton.dev/v1alpha1" | ||
kind: Repository | ||
metadata: | ||
name: repository1 | ||
spec: | ||
url: "https://github.com/org/repo" | ||
settings: | ||
policy: | ||
ok_to_test: | ||
- ci-admins | ||
pull_request: | ||
- ci-users | ||
``` | ||
Users in `ci-admins` team will be able to let other users run the CI on the pull | ||
request and users in `ci-users` team will be able to run the CI on their own | ||
pull request. | ||
|
||
## Configuring teams on GitHub | ||
|
||
You will need to configure the GitHub Apps on your organisation to use this | ||
feature. | ||
|
||
See the documentation on GitHub to configure the teams: | ||
|
||
<https://docs.github.com/en/organizations/organizing-members-into-teams/about-teams> | ||
|
||
## Configuring teams on Gitea | ||
|
||
Teams on Gitea are configured on the Organization level. No documentation is | ||
available but you can look at the GitHub documentation to get an idea of how to | ||
configure it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package policy | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type Result int | ||
|
||
const ( | ||
ResultNotSet Result = 0 | ||
ResultAllowed Result = 1 | ||
ResultDisallowed Result = 2 | ||
) | ||
|
||
type Policy struct { | ||
Settings *v1alpha1.Settings | ||
Event *info.Event | ||
VCX provider.Interface | ||
Logger *zap.SugaredLogger | ||
} | ||
|
||
func (p *Policy) IsAllowed(ctx context.Context, tType info.TriggerType) (Result, error) { | ||
if p.Settings == nil || p.Settings.Policy == nil { | ||
return ResultNotSet, nil | ||
} | ||
|
||
var sType []string | ||
switch tType { | ||
// NOTE: This make /retest /ok-to-test /test bound to the same policy, which is fine from a security standpoint but maybe we want to refind | ||
case info.TriggerTypeOkToTest, info.TriggerTypeRetest: | ||
sType = p.Settings.Policy.OkToTest | ||
case info.TriggerTypePullRequest: | ||
sType = p.Settings.Policy.PullRequest | ||
// NOTE: not supported yet, will imp if it gets requested and reasonable to implement | ||
case info.TriggerTypePush, info.TriggerTypeCancel, info.TriggerTypeCheckSuiteRerequested, info.TriggerTypeCheckRunRerequested: | ||
return ResultNotSet, nil | ||
default: | ||
return ResultNotSet, nil | ||
} | ||
|
||
if len(sType) == 0 { | ||
return ResultNotSet, nil | ||
} | ||
|
||
allowed, reason := p.VCX.CheckPolicyAllowing(ctx, p.Event, sType) | ||
reasonMsg := fmt.Sprintf("policy check: %s, %s", string(tType), reason) | ||
if reason != "" { | ||
p.Logger.Info(reasonMsg) | ||
} | ||
if allowed { | ||
return ResultAllowed, nil | ||
} | ||
return ResultDisallowed, fmt.Errorf(reasonMsg) | ||
} |
Oops, something went wrong.