Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,31 @@ APP_OKTA_SYNC_RULES=[{"name":"sync-eng","okta_group_pattern":"^github-eng-.*","s
# slack (optional; the token and channel are required together)
APP_SLACK_TOKEN=xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_SLACK_CHANNEL=C01234ABCDE
# the slash command: the signing secret turns it on, and only these slack
# user ids may run its actions
# APP_SLACK_SIGNING_SECRET=0123456789abcdef0123456789abcdef
# APP_SLACK_COMMAND_ALLOWED_USERS=U01234ABCDE,U05678FGHIJ
# APP_SLACK_COMMAND=/github-ops
# slack app setup (optional): serves /slack/setup to create and install the
# slack app and saves its token and signing secret where the github app
# installer saves credentials (STORAGE_MODE); disable it once installed
# APP_SLACK_SETUP_ENABLED=true
# APP_SLACK_APP_NAME=GitHub Ops
# per notification type; each falls back to APP_SLACK_CHANNEL
# APP_SLACK_CHANNEL_PR_BYPASS=C01234ABCDE
# APP_SLACK_CHANNEL_OKTA_SYNC=C01234ABCDE
# APP_SLACK_CHANNEL_ORPHANED_USERS=C01234ABCDE
# APP_SLACK_CHANNEL_SECURITY_ALERTS=C01234ABCDE
# footer for pr bypass notifications, in slack mrkdwn
# APP_SLACK_FOOTER_NOTE_PR_BYPASS=_Please review the <https://example.com/policy|security policy>._

# reports (optional): every-run posts every report after every run; daily
# posts a report when it changes, and otherwise once a day, at the first run
# after the daily time
# APP_REPORT_REPEAT=daily
# APP_REPORT_DAILY_TIME=09:00
# APP_REPORT_TIMEZONE=America/New_York
# where daily reports remember what they last posted: an ssm path (required
# in lambda) or a file; the server keeps it in memory without either
# APP_STATE_SSM_PREFIX=/github-ops-app/state/
# APP_STATE_FILE=./.local/state.json
14 changes: 9 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
## Architecture Overview
- **Deployment**: HTTP server (container, K8s, VM) or AWS Lambda; both serve the same router
- **GitHub**: GitHub App (JWT + installation tokens); created by hand or with the github-app-setup-go installer
- **Features**: Okta group sync, PR compliance monitoring, stale security alert reports, Slack notifications (all optional)
- **Features**: Okta group sync, PR compliance monitoring, stale security alert reports, Slack notifications, a Slack slash command and setup page (all optional)
- **Entry points**:
- `cmd/server/main.go` - HTTP server with graceful shutdown
- `cmd/lambda/` - Lambda adapter: API Gateway HTTP API (2.0) requests and EventBridge scheduled events
- `cmd/lambda/` - Lambda adapter: API Gateway HTTP API (2.0) requests, EventBridge scheduled events, and its own async invocations for jobs started from Slack
- `cmd/sample/main.go` - **DO NOT RUN** (requires live credentials)
- **Packages**:
- `internal/service/` - composition root shared by both entry points: github-app-setup-go runtime (load, retry, reload), health and installer routes, swaps the app on reload
- `internal/app/` - the application: builds clients from config, router (`/webhooks`, admin, `/scheduled/{action}`), feature handlers
- `internal/service/` - composition root shared by both entry points: github-app-setup-go runtime (load, retry, reload), health, installer, and Slack setup routes, swaps the app on reload
- `internal/app/` - the application: builds clients from config, router (`/webhooks`, `/slack/commands`, admin, `/scheduled/{action}`), feature handlers, report posting (every run, or on change and daily)
- `internal/config/` - reads and validates all configuration; resolves SSM parameter ARNs
- `internal/domain/` - shared types, interfaces, and error kinds; imports no internal package
- `internal/github/client/` - GitHub API client: auth, PR compliance, teams, security alerts
Expand All @@ -19,6 +19,8 @@
- `internal/teamsync/` - Okta group to GitHub team sync and orphaned user detection
- `internal/notifiers/` - Slack messages
- `internal/setup/` - GitHub App manifest and installer credential store
- `internal/slackapp/` - Slack app manifest and `/slack/setup` (create from manifest, OAuth install, saves credentials where the installer does)
- `internal/state/` - small records that outlive a run (what each report last posted): memory, file, or SSM
- `internal/fakes/` - in-memory domain fakes for tests
- **Tests**: unit tests beside each package; `e2e/` runs `fixtures/scenarios.json` against the real service with mock GitHub, Okta, and Slack servers

Expand Down Expand Up @@ -88,7 +90,9 @@ live credentials and make real API calls to GitHub/Okta/Slack.
- Webhooks are always signature-checked; there is no unsigned mode
- Admin endpoints require `APP_ADMIN_TOKEN` (constant-time compare) and are disabled without it
- Only events from `APP_GITHUB_ORG` are acted on
- Escape GitHub and Okta text in Slack mrkdwn with `escape`/`link` in `internal/notifiers`
- Escape GitHub and Okta text in Slack mrkdwn with `Escape`/`link` in `internal/notifiers`
- Slash commands are signature-checked (`APP_SLACK_SIGNING_SECRET`); only users in `APP_SLACK_COMMAND_ALLOWED_USERS` may run actions, and replies never include error details
- The Slack setup never replaces an installed app's credentials or moves it to another workspace
- Validate GitHub logins (`domain.IsValidGitHubLogin`) before putting them in API paths
- Auth headers are only sent to the configured GitHub API host

Expand Down
126 changes: 100 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ AWS Lambda function.
with one click, using
[github-app-setup-go](https://github.com/cruxstack/github-app-setup-go)
- **Slack notifications** - Reports for each feature, in per-feature channels
- **Slack app setup** - Optionally create and install the Slack app from a
setup page, with its slash command and icon
- **Slack slash command** - Let allowed users resync Okta groups or post the
security alerts report on demand
- **Quiet reports** - Run the checks as often as you like, and post a report
when it changes, and otherwise once a day

## Quick Start

Expand Down Expand Up @@ -62,6 +68,9 @@ curl -X POST -H "Authorization: Bearer $APP_ADMIN_TOKEN" \
https://github-ops.example.com/scheduled/okta-sync
```

To check often without a message every time, set `APP_REPORT_REPEAT=daily`
(see [Reports](#reports)).

### AWS Lambda

```bash
Expand All @@ -76,19 +85,23 @@ API Gateway delivers webhooks and EventBridge runs the scheduled actions. See

Every route is served under `APP_BASE_PATH`, if set.

| Method | Path | Auth | Description |
| ------ | ---------------------------- | -------------- | ------------------------------------ |
| POST | `/webhooks` | Signature | GitHub webhooks |
| GET | `/healthz` | None | Liveness; always `200` |
| GET | `/readyz` | None | `200` once the configuration loads |
| POST | `/scheduled/okta-sync` | Admin token | Sync Okta groups to teams |
| POST | `/scheduled/security-alerts` | Admin token | Report stale security alerts |
| POST | `/scheduled/slack-test` | Admin token | Send a sample of every notification |
| GET | `/server/status` | Admin token | Status and enabled features |
| GET | `/server/config` | Admin token | Configuration, secrets redacted |
| GET | `/setup` | None | GitHub App installer, when enabled |
| Method | Path | Auth | Description |
| ------ | ---------------------------- | --------------- | ----------------------------------- |
| POST | `/webhooks` | Signature | GitHub webhooks |
| GET | `/healthz` | None | Liveness; always `200` |
| GET | `/readyz` | None | `200` once the configuration loads |
| POST | `/scheduled/okta-sync` | Admin token | Sync Okta groups to teams |
| POST | `/scheduled/security-alerts` | Admin token | Report stale security alerts |
| POST | `/scheduled/slack-test` | Admin token | Send a sample of every notification |
| GET | `/server/status` | Admin token | Status and enabled features |
| GET | `/server/config` | Admin token | Configuration, secrets redacted |
| GET | `/setup` | None | GitHub App installer, when enabled |
| POST | `/slack/commands` | Slack signature | The slash command, when enabled |
| GET | `/slack/setup` | None | Slack app setup, when enabled |

Webhooks must carry a valid `X-Hub-Signature-256`; there is no unsigned mode.
Slash commands must carry a valid `X-Slack-Signature` signed in the last five
minutes.
The admin endpoints require `Authorization: Bearer <APP_ADMIN_TOKEN>` and are
disabled when no admin token is set. Webhooks from organizations other than
`APP_GITHUB_ORG` are ignored.
Expand Down Expand Up @@ -175,17 +188,44 @@ have no severity and count as high.

### Slack (optional)

The token and channel are required together.

| Variable | Description |
| ----------------------------------- | ----------------------------------------- |
| `APP_SLACK_TOKEN` | Bot token (`xoxb-...`) |
| `APP_SLACK_CHANNEL` | Default channel ID |
| `APP_SLACK_CHANNEL_PR_BYPASS` | Channel for PR bypass reports |
| `APP_SLACK_CHANNEL_OKTA_SYNC` | Channel for sync reports |
| `APP_SLACK_CHANNEL_ORPHANED_USERS` | Channel for orphaned user reports |
| `APP_SLACK_CHANNEL_SECURITY_ALERTS` | Channel for security alert reports |
| `APP_SLACK_FOOTER_NOTE_PR_BYPASS` | Footer for PR bypass reports, in mrkdwn |
The token and channel are required together. The signing secret turns on the
slash command, whose actions only the allowed users may run.

| Variable | Description |
| ----------------------------------- | ----------------------------------------------- |
| `APP_SLACK_TOKEN` | Bot token (`xoxb-...`) |
| `APP_SLACK_CHANNEL` | Default channel ID |
| `APP_SLACK_CHANNEL_PR_BYPASS` | Channel for PR bypass reports |
| `APP_SLACK_CHANNEL_OKTA_SYNC` | Channel for sync reports |
| `APP_SLACK_CHANNEL_ORPHANED_USERS` | Channel for orphaned user reports |
| `APP_SLACK_CHANNEL_SECURITY_ALERTS` | Channel for security alert reports |
| `APP_SLACK_FOOTER_NOTE_PR_BYPASS` | Footer for PR bypass reports, in mrkdwn |
| `APP_SLACK_SIGNING_SECRET` | Signing secret; turns on the slash command |
| `APP_SLACK_COMMAND_ALLOWED_USERS` | Slack user IDs that may run its actions |
| `APP_SLACK_COMMAND` | Slash command (default: `/github-ops`) |
| `APP_SLACK_APP_NAME` | App name the setup gives it (`GitHub Ops`) |
| `APP_SLACK_SETUP_ENABLED` | `true` to serve `/slack/setup` |

The setup page creates the Slack app from a manifest, installs it, and saves
the token and signing secret where the GitHub App installer saves its
credentials (`STORAGE_MODE`), then loads them without a restart. While it is
enabled, Slack stays off instead of failing until the token and channel are
set. See [Slack Setup](docs/slack-setup.md#option-a-setup-page).

### Reports (optional)

| Variable | Description |
| ----------------------- | -------------------------------------------------------- |
| `APP_REPORT_REPEAT` | `every-run` (default) or `daily` |
| `APP_REPORT_DAILY_TIME` | When the day's unchanged reports are due (`09:00`) |
| `APP_REPORT_TIMEZONE` | Time zone of the daily time (default: `UTC`) |
| `APP_STATE_SSM_PREFIX` | SSM path for report state, such as `/github-ops/state/` |
| `APP_STATE_FILE` | Or a file for report state (server only) |

With `daily`, the app remembers what each report last posted. In Lambda it
needs `APP_STATE_SSM_PREFIX`, and the role needs `ssm:GetParameter` and
`ssm:PutParameter` on it; the server keeps it in memory unless a state file or
prefix is set. See [Reports](#reports).

### Service

Expand Down Expand Up @@ -278,8 +318,8 @@ ignored.

### Okta Sync

1. **Trigger**: the schedule, or a `team` or `membership` webhook from a
person, not a bot, about a team a rule manages
1. **Trigger**: the schedule, the slash command, or a `team` or `membership`
webhook from a person, not a bot, about a team a rule manages
2. **Fetch**: read the Okta groups each rule matches, with their members
3. **Map**: derive each group's GitHub team, creating it if allowed
4. **Sync**: add and remove team members to match the group
Expand Down Expand Up @@ -309,14 +349,42 @@ pass, as on GitHub.

### Security Alerts

1. **Trigger**: the schedule
1. **Trigger**: the schedule, or the slash command
2. **Fetch**: read every page of open Dependabot, code scanning, and secret
scanning alerts in the organization, oldest first
3. **Filter**: keep alerts older than the minimum age at or above the minimum
severity
4. **Report**: post the alerts by repository to Slack, with any source that
failed

### Reports

The Okta sync, orphaned users, and security alerts reports post after every
run by default. With `APP_REPORT_REPEAT=daily`, run the checks as often as
you like, such as hourly; a report posts when:

- the run added or removed team members;
- it differs from the one last posted, such as a new alert, a newly orphaned
user, or a team that started or stopped failing; or
- it hasn't posted since the day's `APP_REPORT_DAILY_TIME`, at the first run
on or after it.

Alert ages and error messages don't count as changes, so a report doesn't
repost each day an alert ages or each time a failing API words its error
differently. A report with nothing in it, such as no stale alerts, never
posts, but is remembered, so the report posts again when something comes back.
A run someone asked for with the slash command always posts.

### Slash Command

`/github-ops sync` runs the Okta sync now and `/github-ops security-alerts`
posts the security alerts report now. Each answers at once, runs afterwards,
posts its report to the usual channel, and then replies to who asked with a
summary. Anyone can run `/github-ops help`; only the users in
`APP_SLACK_COMMAND_ALLOWED_USERS` may run the rest. In Lambda, the job runs
in an asynchronous invocation of the function, so its role needs
`lambda:InvokeFunction` on itself.

## Development

```bash
Expand All @@ -343,7 +411,13 @@ to cover a new behavior.
[permissions](docs/github-app-setup.md#permissions).
- **Group not found from Okta**: check the domain, scopes, and the group name.
- **No Slack messages**: check the token has `chat:write` and the bot is in
the channel, or add `chat:write.public`.
the channel, or add `chat:write.public`. With `APP_REPORT_REPEAT=daily`, an
unchanged report posts once a day.
- **Slash command fails with `dispatch_failed`**: Slack can't reach
`/slack/commands`, or `APP_SLACK_SIGNING_SECRET` is wrong or unset; the
service logs rejected signatures.
- **"You aren't allowed to run"**: add the Slack user ID from the reply to
`APP_SLACK_COMMAND_ALLOWED_USERS`.

Upgrading from v0? See [Upgrading to v1](docs/upgrading-to-v1.md).

Expand Down
9 changes: 9 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package assets holds files built into the binary.
package assets

import _ "embed"

// SlackIcon is the Slack app's icon, a 1024x1024 PNG.
//
//go:embed slack/icon.png
var SlackIcon []byte
27 changes: 22 additions & 5 deletions assets/slack/manifest.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"_metadata": {
"major_version": 2,
"minor_version": 1
},
"display_information": {
"name": "GitHub Ops Bot",
"description": "GitHub automation bot with user sync and compliance monitoring",
"name": "GitHub Ops",
"description": "Okta team sync, PR compliance, and security alert reports for GitHub.",
"background_color": "#10203B"
},
"features": {
"bot_user": {
"display_name": "GitHub Ops Bot",
"display_name": "GitHub Ops",
"always_online": false
}
},
"slash_commands": [
{
"command": "/github-ops",
"url": "https://github-ops.example.com/slack/commands",
"description": "Resync Okta groups or post the security alerts report now",
"usage_hint": "sync | security-alerts | help",
"should_escape": false
}
]
},
"oauth_config": {
"redirect_urls": [
"https://github-ops.example.com/slack/oauth/callback"
],
"scopes": {
"bot": [
"chat:write",
"chat:write.public"
"chat:write.public",
"commands"
]
}
},
Expand Down
Loading