Schedule infrastructure reviews with GitHub Actions
Submit an approved Terraform or Kubernetes file to Xajbar on a recurring schedule.
Create an Infrastructure configuration ingest token in the review workspace. Give the token an asset label that identifies the file, then save it as the GitHub Actions secret XAJBAR_INFRA_REVIEW_TOKEN in the repository.
Choose a UTF-8 Terraform .tf file or Kubernetes .yaml file that the repository owner has approved for recurring review. Remove inline credentials, Kubernetes Secret resources, and customer data before enabling this workflow. Use a dedicated, sanitized manifest if the source file cannot be shared in full.
Add .github/workflows/xajbar-infrastructure.yml to the protected default branch. Replace infra/service.yaml with the approved repository-relative path. The example runs daily at 02:17 UTC. Use Run workflow in GitHub Actions to verify the first submission from the default branch.
name: Xajbar infrastructure evidence review
on:
schedule:
- cron: "17 2 * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
submit:
if: github.event_name == 'schedule' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
timeout-minutes: 5
env:
GH_TOKEN: ${{ github.token }}
XAJBAR_INFRA_REVIEW_TOKEN: ${{ secrets.XAJBAR_INFRA_REVIEW_TOKEN }}
REVIEW_PATH: infra/service.yaml
steps:
- name: Read and submit the approved file
shell: bash
run: |
set -euo pipefail
python3 - <<'PY'
import base64
import json
import os
import subprocess
import urllib.error
import urllib.parse
import urllib.request
import uuid
path = os.environ["REVIEW_PATH"]
repo = os.environ["GITHUB_REPOSITORY"]
commit = os.environ["GITHUB_SHA"]
endpoint = f"repos/{repo}/contents/{urllib.parse.quote(path)}"
source = subprocess.run(
["gh", "api", "--method", "GET", endpoint, "--raw-field", f"ref={commit}"],
check=True,
capture_output=True,
text=True,
)
file = json.loads(source.stdout)
if not isinstance(file, dict) or file.get("type") != "file" or file.get("encoding") != "base64":
raise SystemExit("Choose one plain Terraform or Kubernetes file for review.")
try:
encoded = "".join(file["content"].split())
evidence = base64.b64decode(encoded, validate=True).decode("utf-8")
except (AttributeError, ValueError, KeyError):
raise SystemExit("The approved file could not be read as UTF-8.") from None
if not evidence.strip() or len(evidence.encode("utf-16-le")) // 2 > 80_000:
raise SystemExit("The approved file must be nonempty and at most 80,000 UTF-16 code units.")
run_id = os.environ["GITHUB_RUN_ID"]
scope = f"xajbar:infrastructure:{repo}:{run_id}:{path}"
snapshot_id = str(uuid.uuid5(uuid.NAMESPACE_URL, scope))
request = urllib.request.Request(
"https://xajbar.imbios.dev/api/review-ingest",
data=json.dumps({"id": snapshot_id, "evidence": evidence}, ensure_ascii=False).encode(),
headers={
"Authorization": "Bearer " + os.environ["XAJBAR_INFRA_REVIEW_TOKEN"],
"Content-Type": "application/json",
},
method="POST",
)
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args, **kwargs):
return None
try:
with urllib.request.build_opener(NoRedirect()).open(request, timeout=30) as response:
report = json.load(response)
except urllib.error.HTTPError as error:
raise SystemExit(f"Xajbar rejected the snapshot (HTTP {error.code}).") from None
print(f"Xajbar saved review {report['id']} with {report['findings']} findings.")
PYThe workflow reads one file at the commit selected by GitHub. It needs repository read access and does not check out or execute repository code. Keep the path fixed in the workflow so a manual run cannot substitute a different file. GitHub can delay scheduled runs during periods of high load. GitHub Actions schedule · GitHub repository contents API
In Xajbar, open Review history and search for the asset label. Every scheduled run creates a snapshot, even when the file is unchanged. Re-running that same GitHub Actions run returns the existing report. Review newly reported findings and verify previously reported items before closing them. Replace the ingest token before its 90-day expiration to keep intake running.