Skip to content

Commit 5bebc1a

Browse files
authored
Code drop of security group rotation email bot (#2)
This implements a bot that emails the security group when new draft advisories show up in the llvm security group repo. This bot @s people who are currently oncall. To this end, it also introduces a yaml file (and supporting Python script) to define and extend the rotation. For running this, Github Actions presents a few challenges: 1. All bot runs are public - observable changes in logs/etc could disclose security issues prior to us publishing them. 2. This requires non-committed state (mostly "what advisories have been emailed about already?") So for now, the plan is just to run on one of my machines - I already run llvmbb-monitor with reasonable uptime; adding to that isn't hard. See https://github.com/gburgessiv/test-gha for development history (though it's entirely just me hacking on my own with no input ;) )
1 parent d2e2065 commit 5bebc1a

File tree

16 files changed

+1302
-0
lines changed

16 files changed

+1302
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Set up Repo Environment'
2+
description: 'Sets up Python and its deps'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Set up Python
7+
uses: actions/setup-python@v5
8+
with:
9+
python-version: '3.11'
10+
- name: Install dependencies
11+
run: |
12+
python -m pip install --upgrade pip
13+
pip install -r requirements.txt
14+
shell: bash
15+
working-directory: ./email-rotation

.github/workflows/run-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.py'
7+
- '**/*.yaml'
8+
- '.github/**'
9+
10+
jobs:
11+
run_tests:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up repo environment
18+
uses: ./.github/actions/setup-repo-env
19+
20+
- name: Run email script tests
21+
run: python3 email_about_issues_test.py
22+
working-directory: ./email-rotation
23+
24+
- name: Run rotation extension tests
25+
run: python3 extend_rotation_test.py
26+
working-directory: ./email-rotation
27+
28+
- name: Run yaml verification test
29+
run: python3 verify_yaml_files_test.py
30+
working-directory: ./email-rotation
31+
32+
- name: Run pyright
33+
run: pyright *.py
34+
working-directory: ./email-rotation
35+
36+
- name: Run mypy
37+
run: mypy . --explicit-package-bases --strict
38+
working-directory: ./email-rotation
39+
40+
- name: Run isort
41+
run: isort . --check-only
42+
working-directory: ./email-rotation
43+
44+
- name: Run black
45+
run: black . --check
46+
working-directory: ./email-rotation

email-rotation/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/__pycache__
2+
github-token
3+
secrets
4+
state.json

email-rotation/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM debian:stable-slim
2+
LABEL maintainer="George Burgess <[email protected]>"
3+
4+
# Grab the packages
5+
RUN apt-get update
6+
RUN apt-get install -y python3 python3-requests python3-yaml
7+
8+
ENV LANG=C.UTF-8
9+
10+
# Rootn't
11+
RUN \
12+
useradd email-bot && \
13+
mkdir /home/email-bot && \
14+
chown email-bot:email-bot /home/email-bot
15+
16+
USER email-bot
17+
WORKDIR /home/email-bot
18+
19+
# Example build'n'run invocation:
20+
# docker build -t llvm-security-group-emails . && docker run --rm -it -v $PWD:/home/email-bot/llvm-security-repo/email-rotation llvm-security-group-emails
21+
#
22+
# Example `secrets` file:
23+
24+
# export GITHUB_REPOSITORY=llvm/llvm-security-repo
25+
# export GITHUB_TOKEN=[redacted]
26+
# export GMAIL_PASSWORD=[redacted]
27+
28+
CMD ["bash", "-c", "cd llvm-security-repo && . secrets && exec ./email_about_issues.py --state-file=state.json --debug"]

email-rotation/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This directory implements an oncall rotation for security issues, essentially.
2+
3+
Relevant files (ignoring tests) are:
4+
5+
- `rotation-members.yaml`, which is the set of all members currently on the
6+
security group who are eligible for this rotation.
7+
8+
- `rotation.yaml`, which specifies the rotation. This is generally extended by
9+
`rotation-members.yaml`, though can be edited by humans (e.g., to remove
10+
people from rotations, swap with others, etc.)
11+
12+
- `email_about_issues.py` actually emails about the issues; it's run on
13+
a machine through a Docker image produced by the `Dockerfile`.
14+
The `docker run` invocation looks like:
15+
```
16+
docker run --rm -it -v $PWD:/home/email-bot/llvm-security-repo llvm-security-group-emails
17+
```
18+
- `extend_rotation.py` extends the `rotation.yaml` file automatically. This
19+
script only appends to the rotation, and takes into account who's already been
20+
in the rotation recently when creating new rotation instances.

email-rotation/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)