Skip to content

Conversation

hoxhaeris
Copy link
Contributor

@hoxhaeris hoxhaeris commented Oct 17, 2025

Enable Dry-Run Mode for GitHub Apps

Summary

This PR fixes a limitation where GitHub Apps could not use dry-run mode in Peribolos. Previously, attempting to run peribolos without the --confirm flag while using GitHub App authentication would fail with: not requesting GitHub App access_token in dry-run mode.
The allowInDryRun flag includes mechanical enforcement via hardcoded allowlist to prevent accidental misuse.

Problem

GitHub Apps authenticate differently than personal access tokens:

  1. Apps need to fetch installation tokens via POST request to /app/installations/{id}/access_tokens
  2. These tokens are required for all subsequent API calls, including read-only GET requests
  3. The existing dry-run mode blocked all non-GET requests, including token fetching
  4. This made it impossible to use dry-run mode with GitHub Apps

Solution

Introduce an allowInDryRun flag on the request struct to selectively allow specific read-only operations that enable other reads (specifically: GitHub App token acquisition) while keeping all actual mutations blocked.

Why This Works

  • Token fetching is effectively read-only: No state changes in org/repos/teams/members
  • Token enables reads: Required for all API calls, including GETs
  • Mutations still blocked: All POST/PUT/PATCH/DELETE to resources remain blocked in dry-run mode
  • Time-limited: Installation tokens expire after 1 hour
  • Matches user expectations: Dry-run = "see what would change" without making changes

Usage

With GitHub Apps

# Dry-run mode (preview changes)
./peribolos \
  --github-app-id=2126429 \
  --github-app-private-key-path=/path/to/key.pem \
  --config-path=config.yaml \
  --require-self=false \
  --min-admins=2 \
  --fix-org \
  --fix-org-members \
  --fix-teams
  # No --confirm flag = dry-run mode

# Apply changes
./peribolos \
  --github-app-id=2126429 \
  --github-app-private-key-path=/path/to/key.pem \
  --config-path=config.yaml \
  --require-self=false \
  --min-admins=2 \
  --fix-org \
  --fix-org-members \
  --fix-teams \
  --confirm

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 17, 2025
Copy link

netlify bot commented Oct 17, 2025

Deploy Preview for k8s-prow ready!

Name Link
🔨 Latest commit 19eb059
🔍 Latest deploy log https://app.netlify.com/projects/k8s-prow/deploys/68f615cf677a0600089860a8
😎 Deploy Preview https://deploy-preview-530--k8s-prow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hoxhaeris
Once this PR has been reviewed and has the lgtm label, please assign cblecker for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 17, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @hoxhaeris. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 17, 2025
@hoxhaeris hoxhaeris changed the title Peribolos: add support for github app Peribolos: enable dry-run mode for GitHub Apps Oct 17, 2025
@hoxhaeris
Copy link
Contributor Author

/cc @bradmwilliams
/cc @petr-muller

@k8s-ci-robot
Copy link
Contributor

@hoxhaeris: GitHub didn't allow me to request PR reviews from the following users: bradmwilliams.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @bradmwilliams
/cc @petr-muller

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@petr-muller
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 20, 2025
@hoxhaeris hoxhaeris force-pushed the add_support_github_app branch from ecd8eea to 19eb059 Compare October 20, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants