diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a611fa8 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +# GitHub requires explicit Write permission for CODEOWNERS teams. +* @agentnameservice/tsc-owners diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..62edd45 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,17 @@ +name: Bug report +description: Report a reproducible problem. Use private vulnerability reporting for security issues. +body: + - type: textarea + id: problem + attributes: + label: What happened? + description: Include the affected version and the behavior you expected. + validations: + required: true + - type: textarea + id: reproduce + attributes: + label: How can we reproduce it? + description: Provide a minimal example with credentials and personal information removed. + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/change.yml b/.github/ISSUE_TEMPLATE/change.yml new file mode 100644 index 0000000..f93d01f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/change.yml @@ -0,0 +1,16 @@ +name: Change request +description: Discuss a change before opening a pull request. +body: + - type: textarea + id: problem + attributes: + label: What problem should this solve? + validations: + required: true + - type: textarea + id: proposal + attributes: + label: What change do you suggest? + description: Describe the behavior and any alternatives. Formal proposals follow the governance repository's proposal process. + validations: + required: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..65ba876 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + open-pull-requests-limit: 5 + - package-ecosystem: npm + directory: / + schedule: + interval: weekly + open-pull-requests-limit: 5 diff --git a/.github/workflows/contribution-policy-local.yml b/.github/workflows/contribution-policy-local.yml new file mode 100644 index 0000000..0306340 --- /dev/null +++ b/.github/workflows/contribution-policy-local.yml @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 +name: Check contribution metadata + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled, ready_for_review] + +permissions: + contents: read + +jobs: + contribution: + uses: ./.github/workflows/contribution-policy.yml diff --git a/.github/workflows/contribution-policy.yml b/.github/workflows/contribution-policy.yml new file mode 100644 index 0000000..74019b7 --- /dev/null +++ b/.github/workflows/contribution-policy.yml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: Apache-2.0 +name: Contribution policy + +on: + workflow_call: + inputs: + specification: + description: Require exactly one of editorial or normative on specification PRs + type: boolean + default: false + +permissions: + contents: read + +jobs: + metadata: + name: Contribution policy + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + # No checkout and no interpolation of contributor-controlled text into shell code. + - name: Check PR metadata + env: + SPECIFICATION_REPOSITORY: ${{ inputs.specification }} + run: | + python3 - <<'PY' + import json, os, re, sys + with open(os.environ['GITHUB_EVENT_PATH']) as handle: + event = json.load(handle) + pr = event.get('pull_request') + if pr is None: + raise SystemExit('This workflow requires a pull request.') + errors = [] + if not re.match(r'^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|spec)(\([^\r\n()]+\))?!?: \S', pr['title']): + errors.append('Use a Conventional Commit PR title, such as docs: explain the setup.') + body = re.sub(r'', '', pr.get('body') or '') + if not re.search(r'\b(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s+(?:#\d+|[\w.-]+/[\w.-]+#\d+|https://github\.com/[\w.-]+/[\w.-]+/issues/\d+)\b', body, re.I): + errors.append('Link a real issue using Fixes, Closes, or Resolves.') + if os.environ['SPECIFICATION_REPOSITORY'] == 'true': + labels = {label['name'] for label in pr.get('labels', [])} + if len(labels & {'editorial', 'normative'}) != 1: + errors.append('Apply exactly one specification label: editorial or normative.') + for error in errors: + print(error) + sys.exit(bool(errors)) + PY diff --git a/.github/workflows/manage-repository.yml b/.github/workflows/manage-repository.yml new file mode 100644 index 0000000..6f8deb5 --- /dev/null +++ b/.github/workflows/manage-repository.yml @@ -0,0 +1,106 @@ +# SPDX-License-Identifier: Apache-2.0 +name: Manage repository + +on: + workflow_dispatch: + inputs: + operation: + description: Inspect settings, prepare a configuration PR, or pause management + type: choice + options: [Inspect repository, Enroll or update, Pause management] + default: Inspect repository + repository: + description: Repository name within agentnameservice + type: string + required: true + required_checks: + description: Optional CI check names separated by semicolons; blank keeps/imports existing requirements + type: string + bootstrap_access: + description: Keep tsc-owners approval and merge access during setup; new repositories start enabled + type: choice + options: [Keep current, Enable, Remove] + default: Keep current + issue: + description: Issue number in .github for this change (not needed for Inspect) + type: string + signoff: + description: Your own Full Name , published in the commit (not needed for Inspect) + type: string + certify_dco: + description: I certify the DCO and authorize my supplied sign-off on this configuration change + type: boolean + default: false + +permissions: + contents: read + +concurrency: + group: repository-request-${{ inputs.repository }} + cancel-in-progress: false + +jobs: + request: + if: >- + github.repository == 'agentnameservice/.github' && + github.ref == 'refs/heads/main' && + vars.ORG_MANAGEMENT_ENABLED == 'true' + runs-on: ubuntu-latest + timeout-minutes: 15 + environment: org-management + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + - run: npm ci --ignore-scripts --no-audit --no-fund + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: read + with: + client-id: ${{ secrets.ORG_APP_CLIENT_ID }} + private-key: ${{ secrets.ORG_APP_PRIVATE_KEY }} + owner: agentnameservice + permission-administration: read + permission-contents: read + permission-members: read + permission-checks: read + permission-statuses: read + permission-pull-requests: read + permission-issues: read + - name: Inspect and prepare the request + id: prepare + env: + GH_TOKEN: ${{ steps.read.outputs.token }} + REQUESTER: ${{ github.triggering_actor }} + run: node scripts/manage-repository.mjs + - name: Validate generated configuration + if: steps.prepare.outputs.changed == 'true' + run: npm run validate + - name: Create a token limited to configuration PRs + if: steps.prepare.outputs.changed == 'true' + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: write + with: + client-id: ${{ secrets.ORG_APP_CLIENT_ID }} + private-key: ${{ secrets.ORG_APP_PRIVATE_KEY }} + owner: agentnameservice + repositories: .github + permission-contents: write + permission-pull-requests: write + - name: Open or update the configuration PR + if: steps.prepare.outputs.changed == 'true' + uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 + with: + token: ${{ steps.write.outputs.token }} + base: main + branch: ${{ steps.prepare.outputs.branch }} + title: ${{ steps.prepare.outputs.title }} + body-path: reports/request.md + author: ${{ steps.prepare.outputs.author }} + commit-message: ${{ steps.prepare.outputs.commit_message }} + signoff: false + add-paths: | + safe-settings/ + peribolos.yml diff --git a/.github/workflows/org-management.yml b/.github/workflows/org-management.yml new file mode 100644 index 0000000..f7310c5 --- /dev/null +++ b/.github/workflows/org-management.yml @@ -0,0 +1,105 @@ +# SPDX-License-Identifier: Apache-2.0 +name: Organization management + +on: + workflow_dispatch: + inputs: + mode: + description: Preview changes or apply the reviewed configuration + type: choice + options: [preview, apply] + default: preview + push: + branches: [main] + schedule: + - cron: '23 */6 * * *' + +env: + PERIBOLOS_IMAGE: us-docker.pkg.dev/k8s-infra-prow/images/peribolos@sha256:b8dfdf7af7dc16d1a4b0f3efb760e6468f098f7e5f0fdd6f8271a07f17cba6d2 # v20261028-c06373a3e + +permissions: + contents: read + +concurrency: + group: organization-management + cancel-in-progress: false + +jobs: + synchronize: + if: >- + github.repository == 'agentnameservice/.github' && + github.ref == 'refs/heads/main' && + vars.ORG_MANAGEMENT_ENABLED == 'true' + environment: org-management + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + APPLY: ${{ (github.event_name == 'workflow_dispatch' && inputs.mode == 'apply') || (github.event_name != 'workflow_dispatch' && vars.ORG_AUTO_APPLY == 'true') }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + - run: npm ci --ignore-scripts --no-audit --no-fund + - run: npm run validate + - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + id: token + with: + client-id: ${{ secrets.ORG_APP_CLIENT_ID }} + private-key: ${{ secrets.ORG_APP_PRIVATE_KEY }} + owner: agentnameservice + permission-members: read + permission-contents: read + - name: Verify manual apply requester + if: github.event_name == 'workflow_dispatch' && env.APPLY == 'true' + env: + GH_TOKEN: ${{ steps.token.outputs.token }} + REQUESTER: ${{ github.triggering_actor }} + run: node --input-type=module -e "import {github,owner} from './scripts/github.mjs'; await owner(github(),process.env.REQUESTER)" + - name: Prepare the App key for Peribolos + env: + APP_KEY: ${{ secrets.ORG_APP_PRIVATE_KEY }} + run: | + umask 077 + printf '%s\n' "$APP_KEY" > "$RUNNER_TEMP/org-app.pem" + - name: Reconcile teams and membership + env: + APP_ID: ${{ secrets.ORG_APP_ID }} + run: | + args=(--config-path=/workspace/peribolos.yml --github-app-id="$APP_ID" --github-app-private-key-path=/key.pem --fix-teams --fix-team-members --maximum-removal-delta=0) + if [ "$APPLY" = true ]; then args+=(--confirm); fi + docker run --rm --user "$(id -u):$(id -g)" -v "$GITHUB_WORKSPACE:/workspace:ro" -v "$RUNNER_TEMP/org-app.pem:/key.pem:ro" "$PERIBOLOS_IMAGE" "${args[@]}" + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: github-community-projects/safe-settings + ref: a9a1f366ad6a738b55682d346d94f8d6c4893b09 # 3.0.0 + path: .safe-settings + persist-credentials: false + - run: npm ci --ignore-scripts --omit=dev --no-audit --no-fund + working-directory: .safe-settings + - name: Run the documented Safe Settings synchronizer + id: settings + working-directory: .safe-settings + env: + GH_ORG: agentnameservice + ADMIN_REPO: .github + CONFIG_PATH: safe-settings + DEPLOYMENT_CONFIG_FILE: ${{ github.workspace }}/safe-settings/deployment-settings.yml + APP_ID: ${{ secrets.ORG_APP_ID }} + PRIVATE_KEY: ${{ secrets.ORG_APP_PRIVATE_KEY }} + FULL_SYNC_NOP: ${{ env.APPLY != 'true' }} + CREATE_PR_COMMENT: 'false' + CREATE_ERROR_ISSUE: 'false' + run: npm run full-sync + - name: Reconcile team repository access after protections succeed + env: + APP_ID: ${{ secrets.ORG_APP_ID }} + run: | + args=(--config-path=/workspace/peribolos.yml --github-app-id="$APP_ID" --github-app-private-key-path=/key.pem --fix-teams --fix-team-repos --maximum-removal-delta=0) + if [ "$APPLY" = true ]; then args+=(--confirm); fi + docker run --rm --user "$(id -u):$(id -g)" -v "$GITHUB_WORKSPACE:/workspace:ro" -v "$RUNNER_TEMP/org-app.pem:/key.pem:ro" "$PERIBOLOS_IMAGE" "${args[@]}" + - name: Remove temporary App key + if: always() + run: rm -f "$RUNNER_TEMP/org-app.pem" diff --git a/.github/workflows/validate-org-config.yml b/.github/workflows/validate-org-config.yml new file mode 100644 index 0000000..63dba79 --- /dev/null +++ b/.github/workflows/validate-org-config.yml @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 +name: Validate organization configuration +on: + pull_request: + push: + branches: [main] +permissions: + contents: read +jobs: + validate: + name: Validate organization configuration + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + - run: npm ci --ignore-scripts --no-audit --no-fund + - run: npm run validate + - run: npm test + - run: python3 -m unittest discover -s tests -v diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f33f3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__/ +*.pyc +reports/ +.safe-settings/ +.venv/ +.DS_Store +node_modules/ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..9701aa6 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,9 @@ +# Code of conduct + +ANS follows the [LF Projects Code of Conduct](https://lfprojects.org/policies/code-of-conduct/). +It applies to participation in the project's repositories and community spaces. + +Report conduct concerns confidentially to the Manager of LF Projects at +[manager@lfprojects.org](mailto:manager@lfprojects.org). Include what happened, +when and where, and relevant supporting information. Do not publish sensitive +reports in a GitHub issue. The linked policy describes the reporting process. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0a77503 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing to ANS + +These guidelines apply across `agentnameservice`. Read the affected repository's +README for its build and test commands. Find reviewers through the +[organization teams](https://github.com/orgs/agentnameservice/teams), or ask in +your pull request. +Repository-specific contribution instructions may add requirements. + +## Pull requests + +Open a tracking issue and reference it with a closing keyword such as `Fixes +#123`. Use a [Conventional Commits](https://www.conventionalcommits.org/) title. +Explain the change and how you tested it, and complete the PR template. For +changes in `ans-spec` or `trust-index-spec`, use exactly one of the +`editorial` or `normative` labels. + +## Developer Certificate of Origin + +Sign off every contribution commit with `git commit --signoff`, certifying the +[Developer Certificate of Origin](https://developercertificate.org/). The DCO +certification belongs to the human contributor, who is responsible for the +contribution's rights, licensing and correctness. The organization DCO App +checks pull requests. + +## AI-assisted contributions + +AI-assisted contributions are welcome with disclosure. Name the tool and model +in the PR's **AI assistance** section, for example `Assisted-by: Tool (model)`. +Review and test generated changes. AI assistance does not replace human DCO +certification or responsibility for the contribution. + +Follow [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md). Report vulnerabilities privately +as described in [SECURITY.md](SECURITY.md). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..05bfad0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,10 @@ +The organization-management software, configuration and tests added in this +repository are licensed under the Apache License, Version 2.0. See +LICENSES/Apache-2.0.txt. + +The accompanying documentation and roster templates are licensed under the +Creative Commons Attribution 4.0 International License. See +LICENSES/CC-BY-4.0.txt. + +This follows Section 7 of the ANS Charter. Pre-existing and third-party +materials retain their applicable licenses and notices. diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt new file mode 100644 index 0000000..137069b --- /dev/null +++ b/LICENSES/Apache-2.0.txt @@ -0,0 +1,73 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..4ea99c2 --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,395 @@ +Attribution 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution 4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution 4.0 International Public License ("Public License"). To the +extent this Public License may be interpreted as a contract, You are +granted the Licensed Rights in consideration of Your acceptance of +these terms and conditions, and the Licensor grants You such rights in +consideration of benefits the Licensor receives from making the +Licensed Material available under these terms and conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + d. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + e. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + f. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + g. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + h. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + i. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + j. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + k. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part; and + + b. produce, reproduce, and Share Adapted Material. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + 4. If You Share Adapted Material You produce, the Adapter's + License You apply must not prevent recipients of the Adapted + Material from complying with this Public License. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material; and + + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 0000000..7ec3b30 --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,5 @@ +# Maintainers + +The [tsc-owners team](https://github.com/orgs/agentnameservice/teams/tsc-owners) +maintains this repository. Membership and access are defined in +[peribolos.yml](peribolos.yml); propose changes through a pull request. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b7f95b --- /dev/null +++ b/README.md @@ -0,0 +1,105 @@ +# ANS organization management + +GitHub Actions runs [Peribolos](https://github.com/kubernetes-sigs/prow/tree/main/cmd/peribolos) +for teams and access, and [Safe Settings](https://github.com/github-community-projects/safe-settings) +for repository protections. No server or Kubernetes cluster is required. + +## Making changes + +| Change | Where | +| --- | --- | +| Teams, members and repository access | [peribolos.yml](peribolos.yml) | +| Enroll, update or pause repository settings | **Actions → Manage repository** | +| Shared protections | [defaults.yml](safe-settings/suborgs/defaults.yml) | +| Organization Owners and invitations | GitHub organization settings | + +Open a PR for membership changes in `peribolos.yml`, with the affected project's +approvals required by governance. Its `members` and +`maintainers` are GitHub team roles; both receive the team's repository access. +Keep governance decisions in governance documents and GitHub access in this +configuration. Repository Maintainer pages link here instead of copying rosters. + +Reviewer team slugs use the `-reviewers` suffix and Write access. Peribolos +keys use team display names; the form resolves their GitHub slugs for CODEOWNERS +without renaming teams or adding Reviewers to merge allowlists. + +The repository form imports existing checks, preserves their App bindings, and +opens a PR for the native YAML changes. Maintainers merge pull requests directly; +required checks must pass on a branch that is up to date with the default branch. +The form preserves signature requirements and unrelated protections. Repositories +with merge queues must remove them before enrollment because queue pushes cannot +satisfy the Maintainer-only update restriction. + +**Bootstrap access → Keep current** preserves the existing choice and enables +`tsc-owners` approval/merge access for new enrollments. Select **Remove** only +after the handoff is approved. DCO, CI and review requirements still apply. +DCO checks require the DCO App (ID `1861`); a workflow job named `DCO` cannot +satisfy that requirement. + +Maintainer teams are exempt from the separate update-only gate so they can use +the normal merge button. The baseline and CI rulesets have no exemptions, so +pull requests, approvals, up-to-date checks and DCO remain mandatory. Exemptions +do not create bypass audit entries for the update gate; PR history records the +merging user. + +## Running the automation + +Install the organization-owned App on the repositories listed in `peribolos.yml`. +It needs repository Administration, Contents, Checks, Issues and Pull requests +write access; Commit statuses read access; and organization Members write access. +Safe Settings creates a final check run when applying changes, so Checks write +is required even with PR comments disabled. Webhooks are disabled. Governance +can remain private. + +| Setting | Location | +| --- | --- | +| `ORG_APP_ID`, `ORG_APP_CLIENT_ID` | Repository Actions secrets | +| `ORG_APP_PRIVATE_KEY` | Secret in the `org-management` environment, restricted to `main` | +| `ORG_MANAGEMENT_ENABLED` | Repository variable; `false` stops management | +| `ORG_AUTO_APPLY` | Repository variable; `true` applies on pushes and the schedule | + +Before activation, complete the approved legacy-access cutover and verify that +every live team is declared in `peribolos.yml`. The DCO App validates sign-offs; +repositories do not need a workflow to stand in for that check. + +Run **Organization management → preview**, review the plan, then use **apply**. +Keep automatic apply off until the first run is verified. Teams and memberships +are reconciled first, protections next, and repository grants last. A failed +protection step stops the grant step. + +Peribolos does not manage org Owners, org-wide membership, repository lifecycle, +or direct collaborators. It preserves team names. `--maximum-removal-delta=0` +fails the entire run when any existing team is absent from `peribolos.yml`. +Declare or retire undeclared teams before running preview or apply; membership +and grant changes follow the reviewed YAML. +Manual changes to managed teams are reconciled to that configuration. + +Peribolos's [native dump](https://github.com/kubernetes-sigs/prow/blob/main/site/content/en/docs/components/cli-tools/peribolos.md#initial-seed) +can capture existing teams. Review its `orgs.agentnameservice.teams` section and +retain approved pending invitations; raw billing/contact metadata stays outside +this repository. Safe Settings provides a [native repository exporter](https://github.com/github-community-projects/safe-settings#generating-settings-from-existing-configuration). + +Only repositories in [the settings scope](safe-settings/deployment-settings.yml) +receive Safe Settings changes. [Repository configs](safe-settings/repos) can be +prepared before enrollment. Pausing settings leaves existing access unchanged. + +Publish the shared workflow and governance documents before adopting repository +callers and links. Land each repository's `MAINTAINERS.md`, CODEOWNERS and required +CI support before enrollment. Create the `editorial` and `normative` labels +before enabling the contribution-policy workflow in either specification +repository; the shared defaults maintain those labels after enrollment. + +`homebrew-ans` and `scoop-ans` are excluded from protection management because +GoReleaser publishes their generated package updates directly to `main`. +Their Maintainer team access is still managed through Peribolos. + +## Development + +```sh +npm ci --ignore-scripts +npm run validate +npm test +python3 -m unittest discover -s tests -v +``` + +See [CONTRIBUTING.md](CONTRIBUTING.md) and [GitHub's App documentation](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..132f2fe --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,12 @@ +# Security + +Use **Report a vulnerability** under the affected repository's Security tab. +For specification vulnerabilities, use the +[ans-spec reporting form](https://github.com/agentnameservice/ans-spec/security/advisories/new). +For this repository, use [private reporting](https://github.com/agentnameservice/.github/security/advisories/new). + +Include the affected version, reproduction steps, impact, and any proposed fix. +Do not post vulnerability details or credentials in a public issue, PR or chat. +Repository administrators receive the report and coordinate privately with the +relevant Maintainers. Follow supported-version guidance in the affected repo; +the default supported line is its latest minor release. diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..04c3d61 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,261 @@ +{ + "name": "ans-org-management", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ans-org-management", + "dependencies": { + "@octokit/rest": "22.0.1", + "js-yaml": "4.3.1" + }, + "engines": { + "node": ">=24" + } + }, + "node_modules/@octokit/auth-token": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-6.0.0.tgz", + "integrity": "sha512-P4YJBPdPSpWTQ1NU4XYdvHvXJJDxM6YwpS0FZHRgP7YFkdVxsWcpWGy/NVqlAA7PcPCnMacXlRm1y2PFZRWL/w==", + "license": "MIT", + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/core": { + "version": "7.0.8", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-7.0.8.tgz", + "integrity": "sha512-L7y8eYc+AwxGr2PWI4WFt1VG4TiJ66c26BD16mXpYIlXxG0SMigM1+m4aTSlYyBr5BlQsGAlz8uDCoZN4SEMcg==", + "license": "MIT", + "dependencies": { + "@octokit/auth-token": "^6.0.0", + "@octokit/graphql": "^9.0.5", + "@octokit/request": "^10.0.16", + "@octokit/request-error": "^7.1.2", + "@octokit/types": "^18.0.0", + "before-after-hook": "^4.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/endpoint": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-11.0.5.tgz", + "integrity": "sha512-iXa654H3yFafF/ieHkukfbgWo2rmXD2ceD0ZOtrPhw1bc3FDch1d9N/TNs0FQ1/cIbwb7kspUX8jzIs8nzb9DQ==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^18.0.0", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/graphql": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-9.0.5.tgz", + "integrity": "sha512-bt/hm03LeU6Vy7FwTrkkC9p3XGT/lBwClglMqxBSe5/q0E5CdJTXeAqEI0vlw89/LF/G6tryTIH8HirZ3prMVg==", + "license": "MIT", + "dependencies": { + "@octokit/request": "^10.0.16", + "@octokit/types": "^18.0.0", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "29.0.1", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-29.0.1.tgz", + "integrity": "sha512-9qWOMFNxxLokERcms42rU0PTLqQmVs7g5E41TI4mCOxmpFayD1rfC7XxOL55cG9MBZLFlC31BrR37myMKardwg==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-14.0.0.tgz", + "integrity": "sha512-fNVRE7ufJiAA3XUrha2omTA39M6IXIc6GIZLvlbsm8QOQCYvpq/LkMNGyFlB1d8hTDzsAXa3OKtybdMAYsV/fw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": { + "version": "27.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-27.0.0.tgz", + "integrity": "sha512-whrdktVs1h6gtR+09+QsNk2+FO+49j6ga1c55YZudfEG+oKJVvJLQi3zkOm5JjiUXAagWK2tI2kTGKJ2Ys7MGA==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-16.0.0.tgz", + "integrity": "sha512-sKq+9r1Mm4efXW1FCk7hFSeJo4QKreL/tTbR0rz/qx/r1Oa2VV83LTA/H/MuCOX7uCIJmQVRKBcbmWoySjAnSg==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^27.0.0" + } + }, + "node_modules/@octokit/plugin-request-log": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-6.0.0.tgz", + "integrity": "sha512-UkOzeEN3W91/eBq9sPZNQ7sUBvYCqYbrrD8gTbBuGtHEuycE4/awMXcYvx6sVYo7LypPhmQwwpUe4Yyu4QZN5Q==", + "license": "MIT", + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-17.0.0.tgz", + "integrity": "sha512-B5yCyIlOJFPqUUeiD0cnBJwWJO8lkJs5d8+ze9QDP6SvfiXSz1BF+91+0MeI1d2yxgOhU/O+CvtiZ9jSkHhFAw==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^16.0.0" + }, + "engines": { + "node": ">= 20" + }, + "peerDependencies": { + "@octokit/core": ">=6" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": { + "version": "27.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-27.0.0.tgz", + "integrity": "sha512-whrdktVs1h6gtR+09+QsNk2+FO+49j6ga1c55YZudfEG+oKJVvJLQi3zkOm5JjiUXAagWK2tI2kTGKJ2Ys7MGA==", + "license": "MIT" + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-16.0.0.tgz", + "integrity": "sha512-sKq+9r1Mm4efXW1FCk7hFSeJo4QKreL/tTbR0rz/qx/r1Oa2VV83LTA/H/MuCOX7uCIJmQVRKBcbmWoySjAnSg==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^27.0.0" + } + }, + "node_modules/@octokit/request": { + "version": "10.0.16", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.16.tgz", + "integrity": "sha512-A0zWGjHzISIb+9ccG8s0dq7LKO5zVpJLRICjgUb+sJxEWqn8RUHB1rD3AE51+PECvXHIxqZ1VVvs4fHTSD9nUQ==", + "license": "MIT", + "dependencies": { + "@octokit/endpoint": "^11.0.5", + "@octokit/request-error": "^7.1.2", + "@octokit/types": "^18.0.0", + "content-type": "^3.0.0", + "json-with-bigint": "^3.5.12", + "universal-user-agent": "^7.0.2" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/request-error": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-7.1.2.tgz", + "integrity": "sha512-XZRuT3xZ84D3gYErI1DZvhJ33dCWVV6uzBtWkaBB4TvA/L6eOeTZodxLFVB44bBEEo3vEx7y00UfX1tBLrtLRg==", + "license": "MIT", + "dependencies": { + "@octokit/types": "^18.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/rest": { + "version": "22.0.1", + "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-22.0.1.tgz", + "integrity": "sha512-Jzbhzl3CEexhnivb1iQ0KJ7s5vvjMWcmRtq5aUsKmKDrRW6z3r84ngmiFKFvpZjpiU/9/S6ITPFRpn5s/3uQJw==", + "license": "MIT", + "dependencies": { + "@octokit/core": "^7.0.6", + "@octokit/plugin-paginate-rest": "^14.0.0", + "@octokit/plugin-request-log": "^6.0.0", + "@octokit/plugin-rest-endpoint-methods": "^17.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@octokit/types": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-18.0.0.tgz", + "integrity": "sha512-l6bAF43PNxkJp6g+W4PjoUSSkxHomXw2nOum5CTftJz1NlV3vu93NImgOYtLf6CbBUb5j+fiuzW0PPQ5JTSvZA==", + "license": "MIT", + "dependencies": { + "@octokit/openapi-types": "^29.0.1" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "license": "Python-2.0" + }, + "node_modules/before-after-hook": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz", + "integrity": "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ==", + "license": "Apache-2.0" + }, + "node_modules/content-type": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-3.1.1.tgz", + "integrity": "sha512-GW4qUsfFo59d0HbUibDlWv5wPz+vAAcaTWbKIuKCf0JkC7wWkSyf8f13IpXn5JkeMlB2P8iTSSIjwXljorg2vA==", + "license": "MIT", + "engines": { + "node": ">=22" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/js-yaml": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", + "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-with-bigint": { + "version": "3.5.12", + "resolved": "https://registry.npmjs.org/json-with-bigint/-/json-with-bigint-3.5.12.tgz", + "integrity": "sha512-uwbF/wSSuOgC7qqlq27Xp5B6a2MHVug3t0idZdTqu0JnlFvgJuH7ju+KAk/J06C7GfhoYy2gnb9wz2INqcne7w==", + "license": "MIT" + }, + "node_modules/universal-user-agent": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.3.tgz", + "integrity": "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A==", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..02de69b --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "ans-org-management", + "private": true, + "type": "module", + "engines": { "node": ">=24" }, + "scripts": { "test": "node --test tests/*.test.mjs", "validate": "node scripts/validate.mjs" }, + "dependencies": { "@octokit/rest": "22.0.1", "js-yaml": "4.3.1" } +} diff --git a/peribolos.yml b/peribolos.yml new file mode 100644 index 0000000..28e021d --- /dev/null +++ b/peribolos.yml @@ -0,0 +1,143 @@ +orgs: + agentnameservice: + teams: + ans-gateway-auth-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + privacy: closed + repos: + ans-gateway-auth: write + ans-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + members: + - jhateley-godaddy + privacy: closed + repos: + ans: write + ans-openshell-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + privacy: closed + repos: + ans-openshell: write + sdk-go-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + privacy: closed + repos: + ans-sdk-go: write + homebrew-ans: write + scoop-ans: write + sdk-java-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - kperry-godaddy + members: + - jhateley-godaddy + privacy: closed + repos: + ans-sdk-java: write + sdk-java-reviewers: + description: 'ANS governance roster: repository Reviewers' + members: + - bchen-godaddy + privacy: closed + repos: + ans-sdk-java: write + sdk-rust-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + privacy: closed + repos: + ans-sdk-rust: write + spec-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + - scourtney-godaddy + privacy: closed + repos: + ans-spec: write + trust-index-spec-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - csnitker-godaddy + - kperry-godaddy + members: + - cyen-godaddy + privacy: closed + repos: + trust-index-spec: write + trust-index-spec-reviewers: + description: 'ANS governance roster: repository Reviewers' + members: + - chou-godaddy + privacy: closed + repos: + trust-index-spec: write + trust-maintainers: + description: 'ANS governance roster: repository Maintainers' + maintainers: + - kperry-godaddy + members: + - cyen-godaddy + privacy: closed + repos: + agent-trust-discovery: write + trust-reviewers: + description: 'ANS governance roster: repository Reviewers' + members: + - chou-godaddy + privacy: closed + repos: + agent-trust-discovery: write + tsc: + description: 'ANS governance roster: TSC voting members' + maintainers: + - csnitker-godaddy + - kperry-godaddy + - scourtney-godaddy + privacy: closed + repos: + agent-trust-discovery: write + ans: write + ans-gateway-auth: write + ans-openshell: write + ans-spec: write + ans-sdk-go: write + ans-sdk-java: write + ans-sdk-rust: write + governance: write + trust-index-spec: write + members: + - kantorcodes + - kenhuangus + tsc-owners: + description: Organization configuration administrators + maintainers: + - csnitker-godaddy + - kperry-godaddy + privacy: closed + repos: + .github: write + agent-trust-discovery: write + ans: write + ans-gateway-auth: write + ans-openshell: write + ans-spec: write + ans-sdk-go: write + ans-sdk-java: write + ans-sdk-rust: write + trust-index-spec: write diff --git a/safe-settings/deployment-settings.yml b/safe-settings/deployment-settings.yml new file mode 100644 index 0000000..436bfdb --- /dev/null +++ b/safe-settings/deployment-settings.yml @@ -0,0 +1,7 @@ +restrictedRepos: + include: + - .github + # GoReleaser publishes generated package updates directly to main. + exclude: + - homebrew-ans + - scoop-ans diff --git a/safe-settings/repos/.github.yml b/safe-settings/repos/.github.yml new file mode 100644 index 0000000..a8e0681 --- /dev/null +++ b/safe-settings/repos/.github.yml @@ -0,0 +1,31 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: ['~DEFAULT_BRANCH'] + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: DCO + integration_id: 1861 + - context: Validate organization configuration + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: ['~DEFAULT_BRANCH'] + exclude: [] + bypass_actors: + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/agent-trust-discovery.yml b/safe-settings/repos/agent-trust-discovery.yml new file mode 100644 index 0000000..bbd1146 --- /dev/null +++ b/safe-settings/repos/agent-trust-discovery.yml @@ -0,0 +1,38 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: build & test + integration_id: 15368 + - context: DCO + integration_id: 1861 + - context: lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: trust-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-gateway-auth.yml b/safe-settings/repos/ans-gateway-auth.yml new file mode 100644 index 0000000..42bfe85 --- /dev/null +++ b/safe-settings/repos/ans-gateway-auth.yml @@ -0,0 +1,42 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: Build & Test + integration_id: 15368 + - context: DCO + integration_id: 1861 + - context: Known vulnerabilities + integration_id: 15368 + - context: Lint + integration_id: 15368 + - context: Validate agentgateway recipes + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: ans-gateway-auth-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-openshell.yml b/safe-settings/repos/ans-openshell.yml new file mode 100644 index 0000000..a401f11 --- /dev/null +++ b/safe-settings/repos/ans-openshell.yml @@ -0,0 +1,48 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: Build & Test + integration_id: 15368 + - context: Container images & Helm chart (ans-ocsf-hydrator) + integration_id: 15368 + - context: Container images & Helm chart (ans-openshell-interceptor) + integration_id: 15368 + - context: Container images & Helm chart (ans-openshell-middleware) + integration_id: 15368 + - context: Container images & Helm chart (ans-reference-callee) + integration_id: 15368 + - context: DCO + integration_id: 1861 + - context: Generated bindings match protos + integration_id: 15368 + - context: Lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: ans-openshell-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-sdk-go.yml b/safe-settings/repos/ans-sdk-go.yml new file mode 100644 index 0000000..7a8572e --- /dev/null +++ b/safe-settings/repos/ans-sdk-go.yml @@ -0,0 +1,38 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: Build & Test + integration_id: 15368 + - context: DCO + integration_id: 1861 + - context: Lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: sdk-go-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-sdk-java.yml b/safe-settings/repos/ans-sdk-java.yml new file mode 100644 index 0000000..336e5ed --- /dev/null +++ b/safe-settings/repos/ans-sdk-java.yml @@ -0,0 +1,36 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: Build & Test + integration_id: 15368 + - context: DCO + integration_id: 1861 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: sdk-java-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-sdk-rust.yml b/safe-settings/repos/ans-sdk-rust.yml new file mode 100644 index 0000000..b461534 --- /dev/null +++ b/safe-settings/repos/ans-sdk-rust.yml @@ -0,0 +1,58 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: Build + integration_id: 15368 + - context: Clippy + integration_id: 15368 + - context: Clippy (fast-verify) + integration_id: 15368 + - context: Coverage (90% threshold) + integration_id: 15368 + - context: DCO + integration_id: 1861 + - context: Dependency Compliance + integration_id: 15368 + - context: Documentation + integration_id: 15368 + - context: Format + integration_id: 15368 + - context: MSRV (1.88, fast-verify) + integration_id: 15368 + - context: MSRV (1.88) + integration_id: 15368 + - context: Security Audit + integration_id: 15368 + - context: Test + integration_id: 15368 + - context: Test (fast-verify) + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: sdk-rust-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans-spec.yml b/safe-settings/repos/ans-spec.yml new file mode 100644 index 0000000..b45a7ec --- /dev/null +++ b/safe-settings/repos/ans-spec.yml @@ -0,0 +1,36 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: DCO + integration_id: 1861 + - context: Lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: spec-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/ans.yml b/safe-settings/repos/ans.yml new file mode 100644 index 0000000..253ee18 --- /dev/null +++ b/safe-settings/repos/ans.yml @@ -0,0 +1,38 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: DCO + integration_id: 1861 + - context: Build & Test + integration_id: 15368 + - context: Lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: ans-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/repos/trust-index-spec.yml b/safe-settings/repos/trust-index-spec.yml new file mode 100644 index 0000000..90e195b --- /dev/null +++ b/safe-settings/repos/trust-index-spec.yml @@ -0,0 +1,36 @@ +rulesets: + - name: ANS repository checks + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: [] + rules: + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: DCO + integration_id: 1861 + - context: Lint + integration_id: 15368 + - name: ANS Maintainer merges + target: branch + enforcement: active + conditions: + ref_name: + include: + - ~DEFAULT_BRANCH + exclude: [] + bypass_actors: + - actor_type: Team + name: trust-index-spec-maintainers + bypass_mode: exempt + - actor_type: Team + name: tsc-owners + bypass_mode: exempt + rules: + - type: update diff --git a/safe-settings/settings.yml b/safe-settings/settings.yml new file mode 100644 index 0000000..20d0863 --- /dev/null +++ b/safe-settings/settings.yml @@ -0,0 +1,14 @@ +# Native Safe Settings controls. Shared policy is in suborgs/defaults.yml. +ruleset_scope: repo + +disable_plugins: + - repository + - archive + - branches + - teams + - collaborators + - app_installations + - custom_repository_roles + +# Preserve existing labels and repository rulesets. +additive_plugins: [labels, rulesets] diff --git a/safe-settings/suborgs/defaults.yml b/safe-settings/suborgs/defaults.yml new file mode 100644 index 0000000..b9457ac --- /dev/null +++ b/safe-settings/suborgs/defaults.yml @@ -0,0 +1,44 @@ +# Repository rulesets: additive protections on GitHub Free public repos. +suborgrepos: ['*', '.*'] +ruleset_scope: repo + +rulesets: + - name: ANS baseline + target: branch + enforcement: active + conditions: + ref_name: + include: ['~DEFAULT_BRANCH'] + exclude: [] + bypass_actors: [] + rules: + - type: deletion + - type: non_fast_forward + - type: pull_request + parameters: + required_approving_review_count: 1 + dismiss_stale_reviews_on_push: true + require_code_owner_review: true + require_last_push_approval: false + required_review_thread_resolution: true + - type: required_status_checks + parameters: + strict_required_status_checks_policy: true + required_status_checks: + - context: DCO + integration_id: 1861 + +labels: + include: + - name: editorial + color: '0075ca' + description: No normative specification change + - name: normative + color: d93f0b + description: Changes a specification requirement + - name: stale + color: ededed + description: Awaiting author response under the ANS inactivity policy + - name: needs-info + color: d876e3 + description: Additional information is needed diff --git a/scripts/config.mjs b/scripts/config.mjs new file mode 100644 index 0000000..e30c3c0 --- /dev/null +++ b/scripts/config.mjs @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: Apache-2.0 +import fs from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import yaml from "js-yaml"; + +export const ROOT = path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + "..", +); +export const ORG = "agentnameservice"; +export const REPO = ".github"; +export const BASELINE = "ANS baseline"; +export const CHECKS = "ANS repository checks"; +export const DCO_APP = 1861; +export const MERGE = "ANS Maintainer merges"; +export const TSC = "tsc"; +export const BOOTSTRAP = "tsc-owners"; +export const loginPattern = /^[a-z\d](?:[a-z\d-]{0,37}[a-z\d])?$/i; +export const teamPattern = /^[a-z\d]+(?:-[a-z\d]+)*$/; +export function ensure(value, message) { + if (!value) throw new Error(message); +} +export function repositoryName(value) { + const name = String(value || "") + .trim() + .toLowerCase(); + ensure( + name === ".github" || /^[a-z\d][a-z\d_.-]*$/.test(name), + "Use a repository name within agentnameservice", + ); + ensure(name !== "governance-archieve", "The historical archive is excluded"); + return name; +} +export async function readYaml(file) { + return yaml.load(await fs.readFile(file, "utf8")); +} +export async function writeYaml(file, value) { + await fs.mkdir(path.dirname(file), { recursive: true }); + await fs.writeFile(file, yaml.dump(value, { lineWidth: 100, noRefs: true })); +} +export function access(name, config) { + repositoryName(name); + const actors = + config.rulesets?.find((r) => r.name === MERGE)?.bypass_actors || []; + ensure( + actors.every( + (a) => + a.actor_type === "Team" && + a.bypass_mode === "exempt" && + teamPattern.test(a.name), + ), + `${name}: merge exemptions must use named teams on the update-only gate`, + ); + const mergers = actors.map((a) => a.name); + const bootstrap = name !== REPO && mergers.includes(BOOTSTRAP); + const primary = mergers.filter((team) => name === REPO || team !== BOOTSTRAP); + ensure( + primary.length === 1 && new Set(mergers).size === mergers.length, + `${name}: declare one Maintainer team and optional bootstrap access`, + ); + ensure( + name === "governance" + ? primary[0] === TSC + : name === REPO + ? primary[0] === BOOTSTRAP + : ![TSC, BOOTSTRAP].includes(primary[0]), + `${name}: use the repository's merge team`, + ); + return { maintainers: primary[0], bootstrap }; +} +export async function configuration(root = ROOT) { + const settings = await readYaml( + path.join(root, "safe-settings/settings.yml"), + ); + const defaults = await readYaml( + path.join(root, "safe-settings/suborgs/defaults.yml"), + ); + const deployment = await readYaml( + path.join(root, "safe-settings/deployment-settings.yml"), + ); + const included = deployment.restrictedRepos?.include; + ensure( + Array.isArray(included) && included.every((n) => repositoryName(n) === n), + "Explicitly include only repositories ready for settings management", + ); + const peribolos = await readYaml(path.join(root, "peribolos.yml")); + ensure( + Object.keys(peribolos.orgs || {}).join() === ORG && + Object.keys(peribolos.orgs[ORG]).join() === "teams", + "Peribolos manages only ANS teams; org settings and Owners stay in GitHub", + ); + const directory = path.join(root, "safe-settings/repos"); + const repositories = Object.create(null); + for (const file of (await fs.readdir(directory)) + .filter((f) => f.endsWith(".yml")) + .sort()) { + const name = repositoryName(file.slice(0, -4)); + ensure(file === name + ".yml", "Use canonical lowercase filenames"); + repositories[name] = await readYaml(path.join(directory, file)); + access(name, repositories[name]); + } + return { + settings, + defaults, + deployment, + included: new Set(included), + peribolos, + repositories, + }; +} diff --git a/scripts/github.mjs b/scripts/github.mjs new file mode 100644 index 0000000..6008e58 --- /dev/null +++ b/scripts/github.mjs @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: Apache-2.0 +import { Octokit } from "@octokit/rest"; +import { ORG, REPO, ensure, loginPattern, repositoryName } from "./config.mjs"; + +export function github() { + return new Octokit({ auth: process.env.GH_TOKEN }); +} +export async function optional(call) { + try { + return await call(); + } catch (error) { + if (error.status === 404) return null; + throw error; + } +} +export async function textFile(gh, repo, file, ref) { + const result = await optional(() => + gh.rest.repos.getContent({ owner: ORG, repo, path: file, ref }), + ); + if (!result) return null; + ensure( + result.data.type === "file" && result.data.encoding === "base64", + `Expected a normal file: ${repo}/${file}`, + ); + return Buffer.from(result.data.content, "base64").toString("utf8"); +} +export async function publicRepository(gh, name) { + repositoryName(name); + const { data } = await gh.rest.repos.get({ owner: ORG, repo: name }); + ensure( + data.full_name.toLowerCase() === `${ORG}/${name}` && + !data.private && + !data.archived && + !data.fork, + `${name}: must be public, active, non-forked, and owned by ANS`, + ); + return data; +} +export async function head(gh, repo, branch) { + const { data } = await gh.rest.git.getRef({ + owner: ORG, + repo, + ref: `heads/${branch}`, + }); + return data.object.sha; +} +export async function owner(gh, actor) { + ensure(loginPattern.test(actor || ""), "Invalid requester"); + const { data } = await gh.rest.orgs.getMembershipForUser({ + org: ORG, + username: actor, + }); + ensure( + data.state === "active" && data.role === "admin", + "An organization owner must make this request", + ); +} +export function trustedWorkflow() { + ensure( + process.env.GITHUB_REPOSITORY === `${ORG}/${REPO}` && + process.env.GITHUB_REF === "refs/heads/main", + "Run this workflow on agentnameservice/.github main", + ); +} diff --git a/scripts/manage-repository.mjs b/scripts/manage-repository.mjs new file mode 100644 index 0000000..69e4fef --- /dev/null +++ b/scripts/manage-repository.mjs @@ -0,0 +1,426 @@ +// SPDX-License-Identifier: Apache-2.0 +import fs from "node:fs/promises"; +import path from "node:path"; +import { createHash } from "node:crypto"; +import { pathToFileURL } from "node:url"; +import { + ROOT, + ORG, + REPO, + CHECKS, + DCO_APP, + MERGE, + TSC, + BOOTSTRAP, + access, + configuration, + ensure, + repositoryName, + writeYaml, +} from "./config.mjs"; +import { + github, + optional, + owner, + publicRepository, + head, + textFile, + trustedWorkflow, +} from "./github.mjs"; + +export function signoff(inputs) { + ensure( + String(inputs.certify_dco) === "true", + "Certify the DCO before requesting a commit", + ); + const value = String(inputs.signoff || "").trim(); + ensure( + /^[^<>\x00-\x1f]{2,120} <[^<>\s@]+@[^<>\s@]+\.[^<>\s@]+>$/.test(value), + "Supply your own Full Name ; it will appear in the commit", + ); + return value; +} + +export async function observedChecks(gh, repo, sha) { + const prs = await gh.rest.pulls.list({ + owner: ORG, + repo, + state: "all", + sort: "updated", + direction: "desc", + per_page: 5, + }); + const checks = new Set(); + for (const ref of new Set([sha, ...prs.data.map((p) => p.head.sha)])) { + const runs = await gh.paginate(gh.rest.checks.listForRef, { + owner: ORG, + repo, + ref, + per_page: 100, + }); + const statuses = await gh.paginate(gh.rest.repos.listCommitStatusesForRef, { + owner: ORG, + repo, + ref, + per_page: 100, + }); + runs.forEach((c) => checks.add(c.name)); + statuses.forEach((c) => checks.add(c.context)); + } + return [...checks].sort(); +} + +export function codeOwnerEntries(text) { + return (text || "") + .split(/\r?\n/) + .map((line) => line.replace(/\s+#.*$/, "").trim()) + .filter((line) => line && !line.startsWith("#")) + .map((line) => line.split(/\s+/)); +} + +export async function prepare(gh, config, inputs, actor) { + const name = repositoryName(inputs.repository); + ensure( + ["Inspect repository", "Enroll or update", "Pause management"].includes( + inputs.operation, + ), + "Choose a supported operation", + ); + ensure( + !config.deployment.restrictedRepos.exclude?.includes(name), + `${name}: excluded from settings management by deployment-settings.yml`, + ); + await owner(gh, actor); + const info = await publicRepository(gh, name); + const value = structuredClone(config.repositories[name] || {}); + const deployment = structuredClone(config.deployment); + const peribolos = structuredClone(config.peribolos); + let observed = []; + const pending = []; + if (inputs.operation === "Pause management") { + deployment.restrictedRepos.include = [...config.included].filter( + (repo) => repo !== name, + ); + } else { + const sha = await head(gh, name, info.default_branch); + const existing = + ( + await optional(() => + gh.rest.repos.getBranchProtection({ + owner: ORG, + repo: name, + branch: info.default_branch, + }), + ) + )?.data || {}; + const rules = await gh.paginate( + "GET /repos/{owner}/{repo}/rules/branches/{branch}", + { owner: ORG, repo: name, branch: info.default_branch }, + ); + observed = await observedChecks(gh, name, sha); + const owners = await textFile(gh, name, ".github/CODEOWNERS", sha); + const entries = codeOwnerEntries(owners); + const catchall = entries.filter((entry) => entry[0] === "*").at(-1); + const liveTeams = await gh.paginate(gh.rest.teams.list, { + org: ORG, + per_page: 100, + }); + const reviewers = []; + for (const [displayName, settings] of Object.entries( + peribolos.orgs[ORG].teams, + )) { + if (settings.repos?.[name] !== "write") continue; + const team = liveTeams.find((team) => team.name === displayName); + if (!team) + pending.push( + `Apply team ${displayName} from peribolos.yml before enrollment.`, + ); + else if (team.slug.endsWith("-reviewers")) reviewers.push(team.slug); + } + const candidates = (catchall?.slice(1) || []) + .filter( + (owner) => + owner !== `@${ORG}/${TSC}` && + !reviewers.some((team) => owner === `@${ORG}/${team}`) && + (name === REPO || owner !== `@${ORG}/${BOOTSTRAP}`), + ) + .map( + (owner) => + owner.match(/^@agentnameservice\/([a-z\d]+(?:-[a-z\d]+)*)$/)?.[1], + ); + const mapping = config.repositories[name] + ? access(name, value) + : { + maintainers: + (candidates.length === 1 && candidates[0]) || + { ".github": "tsc-owners", governance: "tsc" }[name] || + `${name.replace(/[^a-z\d]+/g, "-")}-maintainers`, + }; + const bootstrapChoice = inputs.bootstrap_access || "Keep current"; + ensure( + ["Keep current", "Enable", "Remove"].includes(bootstrapChoice), + "Choose a supported bootstrap access option", + ); + mapping.bootstrap = + name !== REPO && + (bootstrapChoice === "Enable" || + (bootstrapChoice === "Keep current" && + (config.repositories[name] ? mapping.bootstrap : true))); + const includeTsc = name !== REPO || catchall?.includes(`@${ORG}/${TSC}`); + const previous = + value.rulesets + ?.find((r) => r.name === CHECKS) + ?.rules?.find((r) => r.type === "required_status_checks")?.parameters + ?.required_status_checks || []; + const required = new Map(); + for (const check of [ + ...previous, + ...(existing.required_status_checks?.contexts || []).map((context) => ({ + context, + })), + ...(existing.required_status_checks?.checks || []).map( + ({ context, app_id }) => ({ + context, + ...(app_id > 0 ? { integration_id: app_id } : {}), + }), + ), + ...rules + .filter((r) => r.type === "required_status_checks") + .flatMap((r) => r.parameters.required_status_checks), + ]) { + const current = required.get(check.context); + ensure( + current?.integration_id == null || + check.integration_id == null || + current.integration_id === check.integration_id, + `Conflicting App bindings for ${check.context}; resolve its existing requirements first`, + ); + required.set( + check.context, + check.integration_id != null + ? { ...current, ...check } + : current || check, + ); + } + const selected = inputs.required_checks?.trim() + ? new Set( + inputs.required_checks + .split(/[;\n]/) + .map((c) => c.trim()) + .filter(Boolean), + ) + : new Set(required.keys()); + selected.add("DCO"); + if (rules.some((rule) => rule.type === "merge_queue")) + pending.push("Remove the merge queue before enrolling; Maintainers merge PRs with up-to-date checks."); + ensure( + required.get("DCO")?.integration_id == null || + required.get("DCO").integration_id === DCO_APP, + "DCO must come from the DCO App; resolve its conflicting App binding first", + ); + required.set("DCO", { context: "DCO", integration_id: DCO_APP }); + const common = { + target: "branch", + enforcement: "active", + conditions: { ref_name: { include: ["~DEFAULT_BRANCH"], exclude: [] } }, + }; + value.rulesets = [ + ...(value.rulesets || []).filter( + (r) => ![CHECKS, MERGE].includes(r.name), + ), + { + name: CHECKS, + ...common, + bypass_actors: [], + rules: [ + { + type: "required_status_checks", + parameters: { + strict_required_status_checks_policy: true, + required_status_checks: [...selected] + .sort() + .map((context) => required.get(context) || { context }), + }, + }, + ], + }, + { + name: MERGE, + ...common, + // Separate rules enforce reviews and checks; these exemptions cover only updates. + bypass_actors: [ + mapping.maintainers, + ...(mapping.bootstrap ? [BOOTSTRAP] : []), + ].map((team) => ({ + actor_type: "Team", + name: team, + bypass_mode: "exempt", + })), + rules: [{ type: "update" }], + }, + ]; + const ownerTeams = [ + ...new Set([ + mapping.maintainers, + ...reviewers, + ...(includeTsc ? [TSC] : []), + ...(mapping.bootstrap ? [BOOTSTRAP] : []), + ]), + ]; + const requiredOwners = ownerTeams.map((team) => `@${ORG}/${team}`); + for (const slug of [ + ...new Set([ + ...ownerTeams, + ...(bootstrapChoice === "Remove" && name !== REPO ? [BOOTSTRAP] : []), + ]), + ]) { + const team = liveTeams.find((team) => team.slug === slug); + const desired = team && peribolos.orgs[ORG].teams[team.name]; + if (!desired) { + pending.push( + `Declare team ${slug} in peribolos.yml and apply its team setup first.`, + ); + continue; + } + desired.repos ||= {}; + if (ownerTeams.includes(slug)) desired.repos[name] = "write"; + else delete desired.repos[name]; + } + if ( + JSON.stringify([...(catchall?.slice(1) || [])].sort()) !== + JSON.stringify([...requiredOwners].sort()) + ) + pending.push(`Merge CODEOWNERS with * ${requiredOwners.join(" ")}.`); + for (const team of [ + includeTsc ? TSC : null, + mapping.bootstrap ? BOOTSTRAP : null, + ].filter(Boolean)) + if (entries.some((entry) => !entry.slice(1).includes(`@${ORG}/${team}`))) + pending.push( + `Include @${ORG}/${team} on every CODEOWNERS rule, including path-specific overrides.`, + ); + if (selected.size < 2) + pending.push( + "Select the actual CI checks from the observed list; requirements are not guessed.", + ); + if ([...selected].some((c) => !observed.includes(c))) + pending.push( + "Run the selected checks on a representative PR before enrolling.", + ); + deployment.restrictedRepos.include = [ + ...new Set([...config.included, name]), + ].sort(); + } + const result = { + name, + value, + deployment, + peribolos, + observed, + pending, + operation: inputs.operation, + }; + result.report = `# ${name}\n\n${inputs.operation}.\n\n`; + if (observed.length) + result.report += + "Observed checks:\n" + + observed.map((c) => "- `" + c.replace(/[\r\n`]/g, " ") + "`").join("\n") + + "\n"; + if (pending.length) + result.report += + "\nSetup needed:\n" + pending.map((p) => "- " + p).join("\n") + "\n"; + if (inputs.operation !== "Inspect repository") { + ensure(!pending.length, result.report); + result.signoff = signoff(inputs); + const issue = String(inputs.issue || "") + .trim() + .replace(/^#/, ""); + ensure( + /^[1-9]\d*$/.test(issue), + "Supply the tracking issue number in .github", + ); + const { data } = await gh.rest.issues.get({ + owner: ORG, + repo: REPO, + issue_number: Number(issue), + }); + ensure(!data.pull_request, "Link an issue, not a pull request"); + result.issue = issue; + } + return result; +} + +async function output(name, value) { + if (!process.env.GITHUB_OUTPUT) return; + const delimiter = "ANS_" + createHash("sha256").update(value).digest("hex"); + await fs.appendFile( + process.env.GITHUB_OUTPUT, + `${name}<<${delimiter}\n${value}\n${delimiter}\n`, + ); +} + +async function main() { + trustedWorkflow(); + ensure( + process.env.GITHUB_EVENT_NAME === "workflow_dispatch", + "Use the management form", + ); + const event = JSON.parse( + await fs.readFile(process.env.GITHUB_EVENT_PATH, "utf8"), + ); + const config = await configuration(); + const result = await prepare( + github(), + config, + event.inputs, + process.env.REQUESTER, + ); + console.log(result.report); + if (process.env.GITHUB_STEP_SUMMARY) + await fs.appendFile(process.env.GITHUB_STEP_SUMMARY, result.report); + const updateRepo = + result.operation !== "Pause management" && + JSON.stringify(config.repositories[result.name]) !== + JSON.stringify(result.value); + const changed = + result.operation !== "Inspect repository" && + (updateRepo || + JSON.stringify(config.deployment) !== JSON.stringify(result.deployment) || + JSON.stringify(config.peribolos) !== JSON.stringify(result.peribolos)); + await output("changed", String(changed)); + if (!changed) return; + if (updateRepo) + await writeYaml( + path.join(ROOT, "safe-settings/repos", result.name + ".yml"), + result.value, + ); + if (JSON.stringify(config.deployment) !== JSON.stringify(result.deployment)) + await writeYaml( + path.join(ROOT, "safe-settings/deployment-settings.yml"), + result.deployment, + ); + if (JSON.stringify(config.peribolos) !== JSON.stringify(result.peribolos)) + await writeYaml(path.join(ROOT, "peribolos.yml"), result.peribolos); + const title = `chore: configure ${result.name}`; + await output("title", title); + await output("branch", "codex/manage-" + result.name.replaceAll(".", "-")); + await output("author", result.signoff); + await output( + "commit_message", + title + "\n\nSigned-off-by: " + result.signoff, + ); + await fs.mkdir(path.join(ROOT, "reports"), { recursive: true }); + await fs.writeFile( + path.join(ROOT, "reports/request.md"), + `## Related issue\n\nFixes #${result.issue}\n\n## Summary\n\n${result.report}\nTeam access is declared in peribolos.yml. Review this configuration change before merging.\n\n## Testing\n\nNative configuration validation runs in CI.\n\n## AI assistance\n\nNo AI is used by this deterministic workflow.\n`, + ); +} +if ( + process.argv[1] && + import.meta.url === pathToFileURL(process.argv[1]).href +) { + main().catch((error) => { + console.error(error.message); + process.exitCode = 1; + }); +} diff --git a/scripts/validate.mjs b/scripts/validate.mjs new file mode 100644 index 0000000..ed51b87 --- /dev/null +++ b/scripts/validate.mjs @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: Apache-2.0 +import { pathToFileURL } from "node:url"; +import { + ORG, + BASELINE, + CHECKS, + DCO_APP, + MERGE, + access, + configuration, + ensure, + loginPattern, +} from "./config.mjs"; + +function active(rule) { + return ( + rule?.target === "branch" && + rule.enforcement === "active" && + JSON.stringify(rule.conditions?.ref_name) === + JSON.stringify({ include: ["~DEFAULT_BRANCH"], exclude: [] }) + ); +} +export function validate(config) { + ensure( + config.defaults.ruleset_scope === "repo" && !config.settings.rulesets, + "Use repository rulesets on GitHub Free", + ); + ensure( + config.defaults.suborgrepos.includes("*") && + config.defaults.suborgrepos.includes(".*"), + "Shared defaults cover enrolled repositories", + ); + const baseline = config.defaults.rulesets.find((r) => r.name === BASELINE); + ensure( + active(baseline) && baseline.bypass_actors?.length === 0, + "The baseline has no bypass actors", + ); + const rules = new Map(baseline.rules.map((r) => [r.type, r])); + const review = rules.get("pull_request")?.parameters; + ensure( + rules.has("deletion") && + rules.has("non_fast_forward") && + review?.required_approving_review_count >= 1 && + review.dismiss_stale_reviews_on_push && + review.require_code_owner_review && + review.required_review_thread_resolution, + "Keep baseline branch and review protections", + ); + const baselineChecks = rules.get("required_status_checks")?.parameters; + ensure( + baselineChecks?.strict_required_status_checks_policy === true && + baselineChecks.required_status_checks.some( + (c) => c.context === "DCO" && c.integration_id === DCO_APP, + ), + "The shared DCO check must require the DCO App and an up-to-date branch", + ); + for (const plugin of [ + "repository", + "archive", + "branches", + "teams", + "collaborators", + "app_installations", + ]) + ensure( + config.settings.disable_plugins.includes(plugin), + `Keep ${plugin} outside Safe Settings ownership`, + ); + ensure( + config.settings.additive_plugins.includes("rulesets") && + config.settings.additive_plugins.includes("labels"), + "Preserve unrelated rules and labels", + ); + const excluded = config.deployment.restrictedRepos.exclude || []; + ensure(Array.isArray(excluded), "Repository exclusions must be a list"); + // Safe Settings prioritizes include over exclude. + ensure( + [...config.included].every((name) => !excluded.includes(name)), + "Keep excluded repositories outside the settings scope", + ); + for (const name of config.included) + ensure( + config.repositories[name], + `${name}: included repositories need a configuration`, + ); + for (const [name, settings] of Object.entries(config.repositories)) { + access(name, settings); + ensure( + !settings.teams && !settings.rulesets.some((r) => r.name === BASELINE), + `${name}: team grants belong in peribolos.yml and baseline rules in defaults.yml`, + ); + const ci = settings.rulesets.find((r) => r.name === CHECKS); + ensure( + active(ci) && + !ci.bypass_actors.length && + ci.rules.length === 1 && + ci.rules[0].type === "required_status_checks", + `${name}: CI requirements have no bypass`, + ); + const checks = ci.rules[0].parameters; + ensure( + checks.strict_required_status_checks_policy === true && + checks.required_status_checks.length && + checks.required_status_checks.every( + (c) => + typeof c.context === "string" && + c.context.trim() && + !/[\x00-\x1f]/.test(c.context), + ), + `${name}: require named CI checks on an up-to-date branch`, + ); + ensure( + checks.required_status_checks.some((c) => c.context === "DCO") && + checks.required_status_checks + .filter((c) => c.context === "DCO") + .every((c) => c.integration_id === DCO_APP), + `${name}: DCO must require the DCO App`, + ); + ensure( + settings.rulesets.every((r) => r.rules.every((rule) => rule.type !== "merge_queue")), + `${name}: Maintainers merge PRs directly with up-to-date checks`, + ); + const gate = settings.rulesets.find((r) => r.name === MERGE); + ensure( + active(gate) && + gate.rules.length === 1 && + gate.rules[0].type === "update" && + !gate.rules[0].parameters?.update_allows_fetch_and_merge, + `${name}: team exemptions must be limited to the update-only gate`, + ); + } + const teams = config.peribolos.orgs[ORG].teams; + ensure( + teams && Object.keys(teams).length, + "Declare the teams managed by Peribolos", + ); + for (const [name, team] of Object.entries(teams)) { + ensure( + [team.members || [], team.maintainers || []].every( + (list) => + Array.isArray(list) && + list.every( + (login) => typeof login === "string" && loginPattern.test(login), + ), + ), + `${name}: team membership must be lists of GitHub logins`, + ); + const members = [...(team.members || []), ...(team.maintainers || [])]; + ensure( + new Set(members).size === members.length, + `${name}: duplicate team membership`, + ); + ensure( + Object.values(team.repos || {}).every((p) => + ["read", "triage", "write", "maintain", "admin"].includes(p), + ), + `${name}: use native Peribolos repository permissions`, + ); + } +} +if ( + process.argv[1] && + import.meta.url === pathToFileURL(process.argv[1]).href +) { + configuration() + .then((config) => { + validate(config); + console.log( + `Validated ${Object.keys(config.repositories).length} repository configurations and Peribolos teams`, + ); + }) + .catch((error) => { + console.error(error.message); + process.exitCode = 1; + }); +} diff --git a/tests/manage.test.mjs b/tests/manage.test.mjs new file mode 100644 index 0000000..354929f --- /dev/null +++ b/tests/manage.test.mjs @@ -0,0 +1,516 @@ +// SPDX-License-Identifier: Apache-2.0 +import test from "node:test"; +import assert from "node:assert/strict"; +import { prepare, signoff } from "../scripts/manage-repository.mjs"; +import { configuration, repositoryName } from "../scripts/config.mjs"; +import { validate } from "../scripts/validate.mjs"; + +function config() { + return { + repositories: {}, + included: new Set([".github"]), + deployment: { restrictedRepos: { include: [".github"] } }, + peribolos: { + orgs: { + agentnameservice: { + teams: { + "sample-maintainers": { members: ["alice"], repos: {} }, + tsc: { members: ["bob"], repos: { governance: "write" } }, + "tsc-owners": { + maintainers: ["carol", "dave"], + repos: { ".github": "write" }, + }, + }, + }, + }, + }, + }; +} +const inputs = () => ({ + repository: "sample", + operation: "Enroll or update", + issue: "9", + signoff: "Example Person ", + certify_dco: true, + bootstrap_access: "Remove", +}); +function fake({ + role = "admin", + queued = false, + ci = true, + teamNames = {}, + owners = "* @agentnameservice/sample-maintainers @agentnameservice/tsc", +} = {}) { + return { + rest: { + orgs: { + getMembershipForUser: async () => ({ data: { state: "active", role } }), + }, + repos: { + get: async ({ repo }) => ({ + data: { + full_name: "agentnameservice/" + repo, + private: false, + archived: false, + fork: false, + default_branch: "main", + }, + }), + getBranchProtection: async () => ({ + data: { + required_status_checks: { + contexts: ci ? ["DCO", "test"] : [], + checks: ci ? [{ context: "test", app_id: 15368 }] : [], + }, + }, + }), + getContent: async ({ path }) => { + assert.equal(path, ".github/CODEOWNERS"); + return { + data: { + type: "file", + encoding: "base64", + content: Buffer.from(owners).toString("base64"), + }, + }; + }, + listCommitStatusesForRef: "statuses", + }, + git: { + getRef: async () => ({ data: { object: { sha: "a".repeat(40) } } }), + }, + pulls: { list: async () => ({ data: [] }) }, + checks: { listForRef: "checks" }, + teams: { list: "teams" }, + issues: { get: async () => ({ data: { number: 9 } }) }, + }, + paginate: async (route) => { + if (route === "teams") + return [ + "sample-maintainers", "custom-maintainers", "sample-reviewers", + "other-reviewers", "triage-reviewers", "tsc", "tsc-owners", + ] + .filter((slug) => teamNames[slug] !== null) + .map((slug) => ({ slug, name: teamNames[slug] || slug })); + if (route === "checks") + return [{ name: "DCO" }, { name: "test" }, { name: "build" }]; + if (route.startsWith("GET /repos/") && queued) + return [{ type: "merge_queue" }]; + return []; + }, + }; +} +const checks = (result) => result.value.rulesets[0].rules[0].parameters; + +test("enrollment writes native repository rules and Peribolos grants without changing membership", async () => { + const initial = config(); + const result = await prepare(fake(), initial, inputs(), "requester"); + assert.equal(result.value.teams, undefined); + assert.deepEqual(checks(result).required_status_checks, [ + { context: "DCO", integration_id: 1861 }, + { context: "test", integration_id: 15368 }, + ]); + assert.equal(checks(result).strict_required_status_checks_policy, true); + assert.deepEqual(result.deployment.restrictedRepos.include, [ + ".github", + "sample", + ]); + assert.equal( + result.peribolos.orgs.agentnameservice.teams["sample-maintainers"].repos + .sample, + "write", + ); + assert.equal( + result.peribolos.orgs.agentnameservice.teams.tsc.repos.sample, + "write", + ); + assert.deepEqual( + result.peribolos.orgs.agentnameservice.teams["sample-maintainers"].members, + ["alice"], + ); + assert.deepEqual( + initial.peribolos.orgs.agentnameservice.teams["sample-maintainers"].repos, + {}, + ); +}); + +test("reviewer teams retain review access without becoming the inferred merge team", async () => { + const initial = config(); + const teams = initial.peribolos.orgs.agentnameservice.teams; + teams["custom-maintainers"] = teams["sample-maintainers"]; + delete teams["sample-maintainers"]; + teams["sample-reviewers"] = { members: ["reviewer"], repos: { sample: "write" } }; + teams["other-reviewers"] = { members: ["other"], repos: { other: "write" } }; + teams["triage-reviewers"] = { members: ["triager"], repos: { sample: "triage" } }; + const result = await prepare( + fake({ owners: "* @agentnameservice/custom-maintainers @agentnameservice/sample-reviewers @agentnameservice/tsc" }), + initial, + inputs(), + "requester", + ); + assert.deepEqual(result.pending, []); + assert.deepEqual(result.value.rulesets[1].bypass_actors, [ + { actor_type: "Team", name: "custom-maintainers", bypass_mode: "exempt" }, + ]); + for (const team of ["sample-reviewers", "other-reviewers", "triage-reviewers"]) + assert.deepEqual(result.peribolos.orgs.agentnameservice.teams[team], teams[team]); +}); + +test("configured reviewer routing is required and undeclared owners remain blocked", async () => { + const initial = config(); + initial.peribolos.orgs.agentnameservice.teams["sample-reviewers"] = { + members: ["reviewer"], repos: { sample: "write" }, + }; + for (const owners of [ + "* @agentnameservice/sample-maintainers @agentnameservice/tsc", + "* @agentnameservice/sample-maintainers @agentnameservice/sample-reviewers @agentnameservice/rogue-reviewers @agentnameservice/tsc", + ]) { + const result = await prepare( + fake({ owners }), initial, { ...inputs(), operation: "Inspect repository" }, "requester", + ); + assert.ok(result.pending.includes( + "Merge CODEOWNERS with * @agentnameservice/sample-maintainers @agentnameservice/sample-reviewers @agentnameservice/tsc.", + )); + assert.deepEqual(result.value.rulesets[1].bypass_actors.map(a => a.name), ["sample-maintainers"]); + await assert.rejects( + prepare(fake({ owners }), initial, inputs(), "requester"), + /Merge CODEOWNERS with .*sample-reviewers/, + ); + } +}); + +test("inspection reports queues and enrollment refuses the conflicting merge path", async () => { + const result = await prepare( + fake({ queued: true }), config(), + { ...inputs(), operation: "Inspect repository" }, "requester", + ); + assert.equal(checks(result).strict_required_status_checks_policy, true); + assert.ok(result.pending.some((p) => p.startsWith("Remove the merge queue"))); + await assert.rejects( + prepare(fake({ queued: true }), config(), inputs(), "requester"), + /Remove the merge queue/, + ); +}); + +test("new and imported DCO requirements always use the DCO App", async () => { + for (const ci of [false, true]) { + const result = await prepare( + fake({ ci }), config(), { ...inputs(), required_checks: "build" }, "requester", + ); + assert.deepEqual( + checks(result).required_status_checks.find((c) => c.context === "DCO"), + { context: "DCO", integration_id: 1861 }, + ); + } +}); + +test("updating existing config preserves check App bindings and accepts added checks", async () => { + const first = await prepare(fake(), config(), inputs(), "requester"); + const current = config(); + current.repositories.sample = first.value; + const result = await prepare( + fake(), + current, + { ...inputs(), required_checks: "test;build" }, + "requester", + ); + assert.deepEqual(checks(result).required_status_checks, [ + { context: "DCO", integration_id: 1861 }, + { context: "build" }, + { context: "test", integration_id: 15368 }, + ]); +}); + +test("conflicting check bindings fail instead of dropping an App restriction", async () => { + const gh = fake(); + const old = gh.paginate; + gh.paginate = async (route, args) => + route.startsWith("GET /repos/") + ? [ + { + type: "required_status_checks", + parameters: { + required_status_checks: [{ context: "test", integration_id: 42 }], + }, + }, + ] + : old(route, args); + await assert.rejects( + prepare(gh, config(), inputs(), "requester"), + /Conflicting App bindings/, + ); +}); + +test("bootstrap grants preserve both administrators through the update-only gate", async () => { + const result = await prepare( + fake({ + owners: + "* @agentnameservice/sample-maintainers @agentnameservice/tsc @agentnameservice/tsc-owners", + }), + config(), + { ...inputs(), bootstrap_access: "Keep current" }, + "requester", + ); + assert.deepEqual( + result.value.rulesets[1].bypass_actors.map((a) => [a.name, a.bypass_mode]), + [ + ["sample-maintainers", "exempt"], + ["tsc-owners", "exempt"], + ], + ); + assert.deepEqual(result.value.rulesets[0].bypass_actors, []); + assert.equal( + result.peribolos.orgs.agentnameservice.teams["tsc-owners"].repos.sample, + "write", + ); + assert.deepEqual( + result.peribolos.orgs.agentnameservice.teams["tsc-owners"].maintainers, + ["carol", "dave"], + ); +}); + +test("removing bootstrap access preserves the administrators' other grants", async () => { + const initial = config(); + initial.peribolos.orgs.agentnameservice.teams["tsc-owners"].repos.sample = + "write"; + const result = await prepare(fake(), initial, inputs(), "requester"); + assert.equal( + result.peribolos.orgs.agentnameservice.teams["tsc-owners"].repos.sample, + undefined, + ); + assert.equal( + result.peribolos.orgs.agentnameservice.teams["tsc-owners"].repos[".github"], + "write", + ); +}); + +test("the form uses existing display names rather than renaming teams", async () => { + const initial = config(); + initial.peribolos.orgs.agentnameservice.teams["Sample Maintainers"] = + initial.peribolos.orgs.agentnameservice.teams["sample-maintainers"]; + delete initial.peribolos.orgs.agentnameservice.teams["sample-maintainers"]; + const gh = fake({ teamNames: { "sample-maintainers": "Sample Maintainers" } }); + const result = await prepare(gh, initial, inputs(), "requester"); + assert.equal( + result.peribolos.orgs.agentnameservice.teams["Sample Maintainers"].repos + .sample, + "write", + ); +}); + +test("reviewer display names resolve to live slugs without gaining merge access", async () => { + const initial = config(); + const teams = initial.peribolos.orgs.agentnameservice.teams; + teams["Sample Maintainers"] = teams["sample-maintainers"]; + delete teams["sample-maintainers"]; + teams["Sample Reviewers"] = { members: ["reviewer"], repos: { sample: "write" } }; + const result = await prepare( + fake({ + teamNames: { + "sample-maintainers": "Sample Maintainers", + "sample-reviewers": "Sample Reviewers", + }, + owners: "* @agentnameservice/sample-maintainers @agentnameservice/sample-reviewers @agentnameservice/tsc", + }), + initial, + inputs(), + "requester", + ); + assert.deepEqual(result.pending, []); + assert.deepEqual(result.value.rulesets[1].bypass_actors.map((a) => a.name), [ + "sample-maintainers", + ]); + assert.deepEqual( + result.peribolos.orgs.agentnameservice.teams["Sample Reviewers"], + teams["Sample Reviewers"], + ); + assert.equal(result.peribolos.orgs.agentnameservice.teams["sample-reviewers"], undefined); +}); + +test("a declared reviewer team must exist before enrollment", async () => { + const initial = config(); + initial.peribolos.orgs.agentnameservice.teams["sample-reviewers"] = { + members: ["reviewer"], repos: { sample: "write" }, + }; + await assert.rejects( + prepare( + fake({ teamNames: { "sample-reviewers": null } }), + initial, + inputs(), + "requester", + ), + /Apply team sample-reviewers from peribolos.yml/, + ); +}); + +test("missing team configuration and path ownership stop enrollment", async () => { + const missing = config(); + delete missing.peribolos.orgs.agentnameservice.teams.tsc; + await assert.rejects( + prepare(fake(), missing, inputs(), "requester"), + /Declare team tsc/, + ); + await assert.rejects( + prepare( + fake({ + owners: + "* @agentnameservice/sample-maintainers @agentnameservice/tsc\n/src/ @agentnameservice/sample-maintainers", + }), + config(), + inputs(), + "requester", + ), + /path-specific/, + ); +}); + +test("pause changes only settings scope and leaves team access alone", async () => { + const initial = config(); + initial.included.add("sample"); + initial.deployment.restrictedRepos.include.push("sample"); + const result = await prepare( + fake(), + initial, + { ...inputs(), operation: "Pause management" }, + "requester", + ); + assert.deepEqual(result.deployment.restrictedRepos.include, [".github"]); + assert.deepEqual(result.peribolos, initial.peribolos); +}); + +test("inspection is read-only and publication requires owner authority and DCO", async () => { + const result = await prepare( + fake(), + config(), + { + repository: "sample", + operation: "Inspect repository", + bootstrap_access: "Remove", + }, + "requester", + ); + assert.equal(result.signoff, undefined); + await assert.rejects( + prepare(fake({ role: "member" }), config(), inputs(), "requester"), + /owner/, + ); + for (const value of [ + {}, + { certify_dco: true, signoff: "bot" }, + { certify_dco: true, signoff: "Name \nOther" }, + ]) + assert.throws(() => signoff(value)); + assert.equal(signoff(inputs()), inputs().signoff); +}); + +test("unknown checks and excluded/foreign names cannot be enrolled", async () => { + await assert.rejects( + prepare(fake({ ci: false }), config(), inputs(), "requester"), + /Select the actual CI/, + ); + await assert.rejects( + prepare( + fake(), + config(), + { ...inputs(), required_checks: "never-ran" }, + "requester", + ), + /representative PR/, + ); + for (const name of ["../repo", "other/repo", "governance-archieve", "*"]) + assert.throws(() => repositoryName(name)); +}); + +test("checked-in native configuration satisfies the governance invariants", async () => { + validate(await configuration()); +}); + +test("package repositories remain excluded from protection enrollment", async () => { + const actual = await configuration(); + for (const repository of ["homebrew-ans", "scoop-ans"]) { + await assert.rejects( + prepare(fake(), actual, { ...inputs(), repository }, "requester"), + /excluded from settings management/, + ); + } +}); + +test("explicit exclusions cannot be overridden by the include list", async () => { + for (const repository of ["homebrew-ans", "scoop-ans"]) { + const actual = await configuration(); + actual.included.add(repository); + assert.throws(() => validate(actual), /excluded repositories/); + } +}); + + +test("DCO validation rejects unbound and workflow-supplied checks", async () => { + for (const target of ["baseline", "repository"]) { + for (const binding of [undefined, 15368]) { + const actual = await configuration(); + const rules = target === "baseline" + ? actual.defaults.rulesets[0].rules + : actual.repositories.ans.rulesets[0].rules; + const dco = rules.find((r) => r.type === "required_status_checks") + .parameters.required_status_checks.find((c) => c.context === "DCO"); + if (binding === undefined) delete dco.integration_id; + else dco.integration_id = binding; + assert.throws(() => validate(actual), /DCO.*require.*DCO App/); + } + } +}); + +test("enrollment reports conflicting DCO bindings instead of replacing them", async () => { + const gh = fake(); + const paginate = gh.paginate; + gh.paginate = async (route, args) => route.startsWith("GET /repos/") + ? [{ type: "required_status_checks", parameters: { + required_status_checks: [{ context: "DCO", integration_id: 15368 }], + } }] + : paginate(route, args); + await assert.rejects( + prepare(gh, config(), inputs(), "requester"), + /DCO must come from the DCO App/, + ); +}); + + +test("configuration rejects stale-branch checks and merge queues", async () => { + for (const target of ["baseline", "repository"]) { + const actual = await configuration(); + const rules = target === "baseline" + ? actual.defaults.rulesets[0].rules + : actual.repositories.ans.rulesets[0].rules; + rules.find((r) => r.type === "required_status_checks") + .parameters.strict_required_status_checks_policy = false; + assert.throws(() => validate(actual), /up-to-date branch/); + } + const actual = await configuration(); + actual.repositories.ans.rulesets.push({ name: "Queue", rules: [{ type: "merge_queue" }] }); + assert.throws(() => validate(actual), /Maintainers merge PRs directly/); +}); + +test("merge-team exemptions cannot disable review or required-check enforcement", async () => { + for (const target of ["baseline", "checks", "gate"]) { + const actual = await configuration(); + const gate = actual.repositories.ans.rulesets.find( + (r) => r.name === "ANS Maintainer merges", + ); + assert.ok(gate.bypass_actors.every( + (a) => a.actor_type === "Team" && a.bypass_mode === "exempt", + )); + if (target === "baseline") { + actual.defaults.rulesets[0].bypass_actors = gate.bypass_actors; + assert.throws(() => validate(actual), /baseline has no bypass actors/); + } else if (target === "checks") { + actual.repositories.ans.rulesets[0].bypass_actors = gate.bypass_actors; + assert.throws(() => validate(actual), /CI requirements have no bypass/); + } else { + gate.rules.push({ + type: "pull_request", + parameters: { required_approving_review_count: 1 }, + }); + assert.throws(() => validate(actual), /limited to the update-only gate/); + } + } +}); diff --git a/tests/sdk-pagination.test.mjs b/tests/sdk-pagination.test.mjs new file mode 100644 index 0000000..d25348e --- /dev/null +++ b/tests/sdk-pagination.test.mjs @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +import test from "node:test"; +import assert from "node:assert/strict"; +import { Octokit } from "@octokit/rest"; +import { observedChecks } from "../scripts/manage-repository.mjs"; + +function client(routes) { + return new Octokit({ + request: { + fetch: async (url) => { + const pathname = new URL(String(url)).pathname; + assert.ok( + Object.hasOwn(routes, pathname), + `Unexpected request: ${pathname}`, + ); + const response = new Response(JSON.stringify(routes[pathname]), { + status: 200, + headers: { "content-type": "application/json" }, + }); + Object.defineProperty(response, "url", { value: String(url) }); + return response; + }, + }, + }); +} + +test("real Octokit normalizes check-run collections", async () => { + const gh = client({ + "/repos/agentnameservice/example/pulls": [], + "/repos/agentnameservice/example/commits/main/check-runs": { + total_count: 1, + check_runs: [{ name: "CI" }], + }, + "/repos/agentnameservice/example/commits/main/statuses": [ + { context: "DCO" }, + ], + }); + assert.deepEqual(await observedChecks(gh, "example", "main"), ["CI", "DCO"]); +}); diff --git a/tests/test_contribution_policy.py b/tests/test_contribution_policy.py new file mode 100644 index 0000000..46efcc9 --- /dev/null +++ b/tests/test_contribution_policy.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +WORKFLOW = Path(__file__).resolve().parents[1] / ".github/workflows/contribution-policy.yml" + + +def script(): + source = WORKFLOW.read_text().split("python3 - <<'PY'\n", 1)[1].split(" PY", 1)[0] + return "\n".join(line[10:] for line in source.splitlines()) + + +class ContributionPolicyTests(unittest.TestCase): + def run_policy(self, title="fix: correct a bug", body="Fixes #123", labels=(), specification=False, event_name="pull_request"): + payload = {"pull_request": {"title": title, "body": body, "labels": [{"name": label} for label in labels]}} if event_name == "pull_request" else {} + with tempfile.TemporaryDirectory() as directory: + event = Path(directory) / "event.json" + event.write_text(json.dumps(payload)) + environment = dict(os.environ, GITHUB_EVENT_PATH=str(event), GITHUB_EVENT_NAME=event_name, SPECIFICATION_REPOSITORY=str(specification).lower()) + return subprocess.run([sys.executable, "-c", script()], env=environment, text=True, capture_output=True, check=False) + + def test_valid_pull_request(self): + self.assertEqual(self.run_policy().returncode, 0) + + def test_template_comments_are_not_issue_links(self): + self.assertNotEqual(self.run_policy(body="\nFixes #").returncode, 0) + + def test_normative_and_editorial_are_exclusive(self): + self.assertEqual(self.run_policy(labels=["normative"], specification=True).returncode, 0) + for labels in [[], ["normative", "editorial"]]: + self.assertNotEqual(self.run_policy(labels=labels, specification=True).returncode, 0) + + def test_untrusted_strings_are_data_and_bad_titles_fail(self): + result = self.run_policy(title="fix: $(exit 99)", body="Fixes #123\n`exit 99`") + self.assertEqual(result.returncode, 0) + self.assertNotEqual(self.run_policy(title="please merge").returncode, 0) + + def test_events_without_a_pull_request_are_rejected(self): + for event_name in ["merge_group", "workflow_dispatch"]: + self.assertNotEqual(self.run_policy(event_name=event_name).returncode, 0) diff --git a/workflow-templates/ans-contribution-policy.properties.json b/workflow-templates/ans-contribution-policy.properties.json new file mode 100644 index 0000000..4086f84 --- /dev/null +++ b/workflow-templates/ans-contribution-policy.properties.json @@ -0,0 +1,5 @@ +{ + "name": "ANS contribution policy", + "description": "Check Conventional Commit PR titles, linked issues, and specification labels using the shared ANS policy.", + "categories": ["Automation"] +} diff --git a/workflow-templates/ans-contribution-policy.yml b/workflow-templates/ans-contribution-policy.yml new file mode 100644 index 0000000..7c220f8 --- /dev/null +++ b/workflow-templates/ans-contribution-policy.yml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 +# Select this template in each ANS repository's Actions tab. +# main is intentional for this first-party shared policy; changes require review +# in the protected organization configuration repository. +name: Check contribution metadata + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled, ready_for_review] + +permissions: + contents: read + +jobs: + contribution: + uses: agentnameservice/.github/.github/workflows/contribution-policy.yml@main + with: + specification: ${{ contains(fromJSON('["ans-spec", "trust-index-spec"]'), github.event.repository.name) }}