Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update .asf.yaml to protect release branches #14226

Merged
merged 3 commits into from
Feb 15, 2022

Conversation

michaeljmarshall
Copy link
Member

Motivation

Many of our current Pulsar branches are not protected. They are vulnerable to accidental force pushes. We should not allow for any modification of history on our release branches.

Further, it is important to update this check because we currently have several status checks that are not required. If a committer were not paying close attention, they could accidentally merge a PR that is not passing all tests. Here is an example: #14158 (comment).

I followed the instructions here https://cwiki.apache.org/confluence/display/INFRA/Git+-+.asf.yaml+features#Git.asf.yamlfeatures-BranchProtection when drafting this PR.

Modifications

Verifying this change

I opened this ASF Infra Jira ticket https://issues.apache.org/jira/browse/INFRA-22833 to discuss the current protections for our branches.

Checking with ASF infra is important because otherwise we could overwrite current protections:

NB (1): Enabling any of the above checks overrides what you may have set previously, so you'll need to add all the existing checks to your .asf.yaml to reproduce any that Infra set manually for you.

Does this pull request potentially affect one of the following parts:

This PR only affects the GitHub repo management.

Documentation

We don't need documentation for this feature. The git history should be sufficient.

.asf.yaml Outdated Show resolved Hide resolved
.asf.yaml Outdated
Comment on lines 54 to 88
- CI - Cancel duplicate workflows
- CI - CPP, Python Tests
- CI - CPP build on CentOS 7
- CI - CPP build on Windows
- Auto Labeling
- CI - Go Functions style check
- CI - Go Functions Tests
- CI - Integration - Backwards Compatibility
- CI - Integration - Cli
- CI - Integration - Function & IO
- CI - Integration - Messaging
- CI - Integration - Process
- CI - Integration - Pulsar-IO Sinks and Sources
- CI - Integration - Pulsar-IO Oracle Source
- CI - Integration - Schema
- CI - Integration - Sql
- CI - Integration - Standalone
- CI - Integration - Thread
- CI - Integration - Tiered FileSystem
- CI - Integration - Tiered JCloud
- CI - Integration - Transaction
- CI - Misc
- CI - Maven Dependency Cache Update
- CI - Pulsar Website build
- Pulsar Bot
- CI - Python - Build 3.9 client
- CI - Shade - Test
- CI - Unit
- CI - Unit - Brokers - Broker Group
- CI - Unit - Brokers - Client Api
- CI - Unit - Brokers - Client Impl
- CI - Unit - Broker - JDK8
- CI - Unit - Brokers - Other
- CI - Unit - Proxy
Copy link
Member Author

Choose a reason for hiding this comment

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

Please let me know if any of these CI jobs are not supposed to be required. Thanks!

.asf.yaml Outdated Show resolved Hide resolved
.asf.yaml Outdated
- CI - CPP build on CentOS 7
- CI - CPP build on Windows
- Auto Labeling
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be removed, it's not a check.

.asf.yaml Outdated
Comment on lines 77 to 79
- CI - Pulsar Website build
- Pulsar Bot
Copy link
Member

Choose a reason for hiding this comment

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

Those three can remove I think

@lhotari
Copy link
Member

lhotari commented Feb 11, 2022

btw. it's possible to find out currently protected branches with this GitHub API call

❯ curl -s https://api.github.com/repos/apache/pulsar/branches |jq -r '.[] | select(.protected) | .name'
asf-site
branch-1.15
branch-1.16
branch-1.17
branch-1.18
master

@lhotari
Copy link
Member

lhotari commented Feb 11, 2022

Getting current required status checks:

❯ curl -s -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/apache/pulsar/branches/master | jq .protection
{
  "enabled": true,
  "required_status_checks": {
    "enforcement_level": "non_admins",
    "contexts": [
      "License check",
      "backwards-compatibility",
      "cli",
      "cpp-tests",
      "function-state",
      "messaging",
      "process",
      "schema",
      "sql",
      "standalone",
      "thread",
      "tiered-filesystem",
      "tiered-jcloud",
      "unit-tests"
    ],
    "checks": [
      {
        "context": "License check",
        "app_id": null
      },
      {
        "context": "backwards-compatibility",
        "app_id": null
      },
      {
        "context": "cli",
        "app_id": null
      },
      {
        "context": "cpp-tests",
        "app_id": null
      },
      {
        "context": "function-state",
        "app_id": null
      },
      {
        "context": "messaging",
        "app_id": null
      },
      {
        "context": "process",
        "app_id": null
      },
      {
        "context": "schema",
        "app_id": null
      },
      {
        "context": "sql",
        "app_id": null
      },
      {
        "context": "standalone",
        "app_id": null
      },
      {
        "context": "thread",
        "app_id": null
      },
      {
        "context": "tiered-filesystem",
        "app_id": null
      },
      {
        "context": "tiered-jcloud",
        "app_id": null
      },
      {
        "context": "unit-tests",
        "app_id": null
      }
    ]
  }
}

GitHub API docs: https://docs.github.com/en/rest/reference/branches#get-branch-protection

.asf.yaml Outdated
Comment on lines 49 to 51
# found in the "name:" field of ./github/workflows/*.yaml files
# Note: here is the list of intentionally excluded contexts:
Copy link
Member

Choose a reason for hiding this comment

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

This isn't correct information. See #14226 (comment) for the current information. The contexts gets passed as-is in the asfgit python code. I'll check where to get the correct context names.

Copy link
Member

Choose a reason for hiding this comment

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

list of context names: #14226 (comment) .

The context name is the name of the job in the workflow yaml file. It's not the name of the workflow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for finding this. I struggled to find documentation on this piece, and determined it was the name based on the the way the GitHub UI takes input. This makes much more sense.

@lhotari
Copy link
Member

lhotari commented Feb 11, 2022

Here's a list of the correct context names for required_status_checks:

❯ curl -s "https://api.github.com/repos/apache/pulsar/commits/$(curl -s https://api.github.com/repos/apache/pulsar/pulls/14147 | jq -r .head.sha)/check-runs" |jq -r '.check_runs | .[] | .name'
labeling
action-runner
unit-tests
unit-tests
pulsar-ci-test (group3)
pulsar-ci-test (group2)
pulsar-ci-test (group1)
cli
unit-tests
unit-tests
tiered-filesystem
owasp-dep-check
sql
messaging
shade-check
process
tiered-jcloud
function-state
schema
transaction
cpp-tests
pulsar-io
thread
License check
standalone
build
unit-tests
backwards-compatibility
unit-tests
pulsar-io

Some workflows have duplicate names. I guess that's fine, but the only issue it causes it that you cannot distinguish a specific workflow.

@lhotari
Copy link
Member

lhotari commented Feb 11, 2022

Listing job names, requires yq (brew install yq):

for f in .github/workflows/*.yaml; do FILE=$f yq eval -o j '.jobs | to_entries | {"file": env(FILE),"id":.[].key, "name":.[].value.name}' $f; done

The name of the job is the id if the name is empty or unspecified. for example

{
  "file": ".github/workflows/ci-license.yaml",
  "id": "license-check",
  "name": "License check"
}

and in comparison

{
  "file": ".github/workflows/ci-owasp-dep-check.yaml",
  "id": "owasp-dep-check",
  "name": null
}

matrix jobs are an exception. if the name isn't specified, the matrix variable will be part of the name, for example for file .github/workflows/ci-unit-broker-broker-gp.yaml, the generated names are:

pulsar-ci-test (group3)
pulsar-ci-test (group2)
pulsar-ci-test (group1)

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

@michaeljmarshall
Copy link
Member Author

Some workflows have duplicate names. I guess that's fine, but the only issue it causes it that you cannot distinguish a specific workflow.

@lhotari - this could be a feature in the sense that all duplicate names get the same treatment. For example, if all "unit tests" are named the same, they'll all be required. In the GitHub UI, they are visibly different because the top level name field is associated with the check. I left the duplicates in place for now. Please take a look and let me know what you think. Thanks.

Copy link
Member

@dave2wave dave2wave left a comment

Choose a reason for hiding this comment

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

I'm told that while wildcards are not possible globs may be possible, but I think that would need to be tested with the GitHub API

@michaeljmarshall
Copy link
Member Author

@dave2wave - that makes sense to me. I'd expect to just need branch-*. I will test it out and update this PR if that works.

@michaeljmarshall
Copy link
Member Author

michaeljmarshall commented Feb 11, 2022

@dave2wave - as far as I can tell, it's not possible to set wildcard protections using the REST API. It's only possible with the GraphQL API. @lhotari found the GitBox code https://github.com/apache/infrastructure-puppet/blob/deployment/modules/gitbox/files/asfgit/asfyaml.py#L278-L302, and it looks to me like it currently uses the REST API.

Source: https://github.saobby.my.eu.orgmunity/t/rest-api-v3-wildcard-branch-protection/13593/13

EDIT: add wildcard in first sentence.

@dave2wave
Copy link
Member

@michaeljmarshall The API used by .asf.yaml very likely predates the GraphQL. Changing the API would be a larger project and impacts every project that uses .asf.yaml which is a large proportion of ASF projects. If anyone is interested in helping ASF Infra I can connect you. (Note that one given is that everything with Infra must be Python and for templates EZT is preferred.)

@michaeljmarshall
Copy link
Member Author

@dave2wave - sorry, I forgot a word in my last message. I meant to say it's not possible to set wildcard permissions via the REST API. This will work as is. We will just have to update the release process to include adding branch protections to new branches.

@dave2wave
Copy link
Member

Sure. If a volunteer wished to implement wildcard branch protection update then you would start by rewriting https://github.com/apache/infrastructure-puppet/blob/deployment/modules/gitbox/files/asfgit/asfyaml.py#L257-L391

.asf.yaml Show resolved Hide resolved
@michaeljmarshall
Copy link
Member Author

@lhotari - can you take another look? Thanks.

@lhotari lhotari merged commit aa9f42c into apache:master Feb 15, 2022
@michaeljmarshall michaeljmarshall deleted the protect-our-branches branch February 15, 2022 16:36
michaeljmarshall added a commit that referenced this pull request Feb 17, 2022
This addition ensures that `branch-2.10` is protected from force pushes. See #14226 for more information.
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
* Update .asf.yaml to protect release branches

* Remove protections and required runs based on review

* Fix context names and document changes
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
This addition ensures that `branch-2.10` is protected from force pushes. See apache#14226 for more information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build doc-not-needed Your PR changes do not impact docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants