Make user GitHub teams available at PR creation and comment events

We are currently tightening our security policies on certain actions in Spacelift. One of our focus is to reach the plan phase of a proposed run only after an approval of a codeowner.
So far we succeeded testing adding a label on a stack that basically contains a list of GitHub teams based off of the actual CODEOWNERS, this way Spacelift on any action in the stack can access to the GitHub team that owns the stack and the code it tracks.
Then we created an approval policy that waits for an approval from the codeowners. Once a PR is created and thus a proposed run is triggered and starts, then evaluates something in the lines of:

requires_approval if { not creator_is_codeowner } ## Creator is a code owner if their GitHub teams overlap with codeowner_teams creator_is_codeowner if { some session_team in input.session.teams some codeowner_team_group in codeowner_teams session_team in codeowner_team_group } ## Auto-approve: creator is code owner approve if not requires_approval ## Approve: someone from the owning team reviewed in Spacelift approve if { count(input.reviews.current.rejections) == 0 requires_approval some review in input.reviews.current.approvals some session_team in review.session.teams some codeowner_team_group in codeowner_teams session_team in codeowner_team_group }

TL;DR if the author of the PR is not a codeowner (i.e. doesn't belong to a github team the the stack is labeled with), then requires an approval of a codeowner.
The parts that work:

  • The approval policy is evaluated before the plan phase

    :white_check_mark:
  • The approval policy lets the run continue and finish only after a codeowner approval

    :white_check_mark:

The parts that we would like to have but are not supported by Spacelift (to the best of our knowledge)

  • At the PR creation event and evaluation of the approval policy this block is in the approval policy:

... "commit": { "author": "AUTHOR_USERNAME", "branch": "BRANCH_NAME", "created_at": 1785152807000000000, "exist_on_tracked_branch": false, "hash": "HASH", "message": "Test codeowners approval", "tag": "", "url": "https://github.com/ORG/REPO/commit/COMMIT_HASH" }, ... "creator_session": { "admin": "", "creator_ip": "", "idp_subject": "", "login": "", "machine": true, "name": "", "teams": [] } ...

No way of getting author teams

:x:
  • Also if we want to read an event via a push policy, such as a comment like /spacelift approve I see that also no teams are available from the commentor

    :x:
Workaround
Use some rego http call to enhance the metadata ourselves during the approval policy (not great to add variability to an otherwise deterministic policy enforcement framework). Use some GitHub actions setup where after a comment or PR creation an automated comment with the metadata is posted in the PR to be consumed by the Spacelift policies.
Problem
We want to ease the run approval workflow to work within GitHub without having to switch to Spacelift UI

Please authenticate to join the conversation.

Upvoters
Status

πŸ‘€ In Review

Board

πŸ’‘ Feature Requests

Tags

Policies

Date

About 14 hours ago

Subscribe to post

Get notified by email when there are changes.