# Runbooks

Pick what happened. The steps are in the order to do them.

Source: https://ha-barkley.github.io/security/runbooks/

From HASC, the Home Assistant Security Controls for integrations, cards and apps. A community catalog, not an official Home Assistant or Open Home Foundation project.

Each control has an ID, cited as HASC-CI-4, and a level from 1 to 3. "Level marker" means anyone can check the control from outside the project, and levels are graded on those controls only.

## Your answers

Some steps depend on these answers. Those steps say which answer they're for.

- What happened? "Someone reported a vulnerability", "Someone got into my GitHub account", "A token or key leaked" or "A bad release went out"

## Look at the report

*Only for: Someone reported a vulnerability*

Keep it private until the fix is out, so nobody can use it against your users in the meantime.

### Accept the report as a draft advisory

*Level 1*

A report sent through private vulnerability reporting is on your repository's Security and quality tab, under Advisories. You can ask the reporter questions there, reject it, or choose **Accept and open as draft**, which keeps it private ([GitHub's docs](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/managing-privately-reported-security-vulnerabilities)). If the report came another way, such as an email, start a draft advisory yourself on the same page and copy the details in.

### POL-4: When a report comes in

*Level 1*

**When a report comes in,** fix it in the advisory's private fork, release the fix, then publish the advisory. You can request a CVE from the advisory. If your code is also published as a package on PyPI or npm, Dependabot then alerts the projects that depend on it.

> Publishing the advisory deletes its private fork, so merge the fix first ([GitHub's docs](https://docs.github.com/en/code-security/security-advisories/working-with-repository-security-advisories/publishing-a-repository-security-advisory)).

## Afterwards

*Only for: Someone reported a vulnerability*

If the report didn't come through GitHub, set these up so the next one does.

### POL-1: Turn on private vulnerability reporting

*Level 1*

Settings → Advanced Security → Private vulnerability reporting → Enable. People then get a "Report a vulnerability" button on your Security and quality tab, and their report reaches you privately. You can ask questions, reject it, or accept it as a draft advisory to work in.

### POL-2: Add a SECURITY.md

*Level 1 · Level marker*

**Add a SECURITY.md** that points to it. In an organization, one `SECURITY.md` in its public `.github` repository covers every repository that doesn't have its own (see [Organizations](https://ha-barkley.github.io/security/controls/organizations/)).

`SECURITY.md`

```
# Security policy

## Reporting a problem

Please don't open a public issue. Report it privately through
GitHub: https://github.com/OWNER/REPO/security/advisories/new

I'll reply within 7 days and keep you posted until it's fixed.

## Supported versions

Only the latest release gets security fixes.
```

### REPO-2: Turn off blank issues and link the private report

*Level 1*

`.github/ISSUE_TEMPLATE/config.yml`

```
blank_issues_enabled: false
contact_links:
  - name: Report a security problem
    url: https://github.com/OWNER/REPO/security/advisories/new
    about: Please report security problems privately, not as an issue.
```

## Lock them out

*Only for: Someone got into my GitHub account*

Do these first, from a device you trust. If you can't sign in, or someone changed your email or two-factor settings, contact GitHub Support ([GitHub's docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/preventing-unauthorized-access)).

### Change your password and check your email addresses

*Level 1*

Settings → Password and authentication, then Settings → Emails. Remove any address you didn't add.

### ACC-1: Turn on two-factor login with a passkey or a security key

*Level 1*

**Why:** A common way to take over an account is a page that looks like a real login. A password and an authenticator code work on any site you type them into, and a lookalike can pass them straight on to the real one. A passkey or security key only works on the site it was made for. In 2025, phishing like this was used to publish malware from maintainers' accounts on both PyPI and npm ([how it happened](https://ha-barkley.github.io/security/attacks/#phishing)).

Settings → Password and authentication. An authenticator app is fine as a second method. Avoid SMS. Store the recovery codes somewhere offline.

> A lookalike login page can pass on an authenticator app's code as well as your password. Add a passkey or a security key, and generate new recovery codes on the same page.

### ACC-3: Review what can act for you

*Level 1*

**Why:** Every OAuth app, GitHub App, SSH key and signed-in session can act for you without your password, and each is another way into your account. Some were probably added years ago for something you no longer use. After the Shai-Hulud worm, CISA's advice included removing the GitHub Apps and OAuth apps you don't need ([how it happened](https://ha-barkley.github.io/security/attacks/#shai-hulud)).

Settings → Applications (OAuth apps and GitHub Apps), SSH keys, and Sessions. Remove anything you don't recognize or no longer use.

> Sign out every session you don't recognize, and remove every SSH key and app you didn't add. A new password doesn't stop any of them.

### ACC-2: Replace classic personal access tokens with fine-grained ones

*Level 1*

**Why:** A token works for anyone who has a copy, with no password or 2FA, and copies end up in CI secrets, `.env` files and old laptops. A classic token can act on every repository you can reach and never expires. A fine-grained one only reaches the repository and permissions you gave it, until its expiry date. The Shai-Hulud worm collected tokens like these from developers' machines and CI in 2025 ([how it happened](https://ha-barkley.github.io/security/attacks/#shai-hulud)).

Settings → Developer settings → Personal access tokens. Give each token one repository, only the permissions it needs, and an expiry date. Delete tokens you no longer use.

> Delete every token you don't recognize and every token that was on the affected machine, then create new ones.

## Find out what was done

*Only for: Someone got into my GitHub account*

Check what was changed while they had access.

### Read your security log

*Level 1*

Settings → Security log lists what was done with your account in the last 90 days. Look for new tokens, keys, apps and email addresses, and for changes to repositories ([GitHub's docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/reviewing-your-security-log)). In an organization, an owner can also read its audit log, which goes back 180 days ([GitHub's docs](https://docs.github.com/en/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/reviewing-the-audit-log-for-your-organization)).

### Check every repository you can write to

*Level 1*

Look at recent commits on every branch, and at collaborators, deploy keys, webhooks and workflows. If a release or a tag changed, also pick *A bad release went out* above.

### Replace the repositories' secrets

*Level 1*

Anyone who can push a workflow can use a repository's Actions secrets, so treat them as leaked. Get a new credential from wherever each one came from, such as PyPI or npm, update the secret, then revoke the old one.

## Afterwards

*Only for: Someone got into my GitHub account*

With signed commits, a commit pushed with a stolen token shows "Unverified". With no stored secrets, CI has nothing to take.

### ACC-4: Sign your commits

*Level 2 · Level marker*

**Why:** Git lets anyone put any name and email on a commit. A signature can't be made without your key, so signed commits let people tell your work from a commit pushed with a stolen token or written to look like yours. In 2021, two malicious commits were pushed to PHP's source code in the names of two of its core developers ([PHP's announcement](https://news-web.php.net/php.internals/113838)).

An SSH key is the simplest way. You can use the one you already push with.

1. If you don't have an SSH key, run `ssh-keygen -t ed25519`. It saves the public half as `~/.ssh/id_ed25519.pub`.
2. Tell Git to sign every commit and tag with it.
   
   `Terminal`
   
   ```
   git config --global gpg.format ssh
   git config --global user.signingkey ~/.ssh/id_ed25519.pub
   git config --global commit.gpgsign true
   git config --global tag.gpgsign true
   ```
   
   Change the path if your key has a different name.
3. Give GitHub the public key, so it can check your signatures. Until you do, your signed commits show "Unverified". In Settings → SSH and GPG keys, choose New SSH key, set Key type to *Signing Key*, and paste the line that `cat ~/.ssh/id_ed25519.pub` prints. Only share the file ending in `.pub`. The one without `.pub` is your private key. From a terminal, the GitHub CLI can do it instead:
   
   `Terminal`
   
   ```
   gh auth refresh -h github.com -s admin:ssh_signing_key
   gh ssh-key add ~/.ssh/id_ed25519.pub --type signing --title "My laptop"
   ```
   
   A key you already added for pushing has to be added again as a signing key.

Where the private key is kept decides what someone gets if they copy your files or run code on your machine:

| Where the key is                                    | Someone copies your files         | Malware runs as you               | Day to day                                                        |
|-----------------------------------------------------|-----------------------------------|-----------------------------------|-------------------------------------------------------------------|
| A file with no passphrase                           | They have your key                | Can sign                          | Nothing to type                                                   |
| A file with a passphrase, loaded into the SSH agent | Useless without the passphrase    | Can sign while the key is loaded  | Unlock once per login. macOS can keep the passphrase in Keychain. |
| A password manager's SSH agent                      | There's no key file               | Asks before each app uses the key | Approve each app                                                  |
| A security key (`ssh-keygen -t ed25519-sk`)         | The key never leaves the hardware | Needs a touch for every signature | A touch for every commit, so a rebase of 20 commits is 20 touches |

With a password manager, its own instructions give the value for `user.signingkey`. GPG keys work too, with GitHub's GPG instructions.

In a codespace you don't need a key of your own. Turn on Settings → Codespaces → GPG verification for the repositories you trust, and GitHub signs the commits you make there. Commits you make on GitHub's website are signed by GitHub already.

### ACC-5: Then turn on vigilant mode

*Level 2*

**Why:** Signing only helps if an unsigned commit in your name stands out. Without vigilant mode, GitHub shows an unsigned commit with no label, like most commits. With it on, an unsigned commit in your name shows "Unverified".

On the same page, tick "Flag unsigned commits as unverified". Any commit with your name that you didn't sign then shows "Unverified", including one pushed with a stolen token. Wait until a commit you push shows "Verified", or your own commits show "Unverified" too.

### SEC-4: In CI, prefer no secret at all

*Level 2*

Use the built-in `GITHUB_TOKEN` with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

## Revoke it

*Only for: A token or key leaked*

Revoke it before anything else. Cleaning it out of the code or the history can wait.

### SEC-5: If a secret leaks, revoke it first

*Level 1*

Removing it from the history doesn't help, because clones, forks and caches already have a copy. Issue a new key, then clean up the history.

### Check what it was used for

*Level 1*

For a GitHub token, your security log shows what was done with it ([GitHub's docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/reviewing-your-security-log)). For a PyPI or npm token, look at the package's release history for versions you didn't publish. For another service's key, check that service's logs. If a release changed, also pick *A bad release went out* above.

### Find out how it got out

*Level 1*

It might have been a commit, a workflow log or a lost laptop. Fix that too, or the new key can leak the same way.

## Afterwards

*Only for: A token or key leaked*

These keep the next key out of the repository, and leave fewer keys to leak.

### REPO-3: Add a .gitignore

*Level 1*

**Add a .gitignore** before your first commit.

`.gitignore`

```
# Python
__pycache__/
*.py[cod]
.venv/
.pytest_cache/
.ruff_cache/
.coverage

# Node
node_modules/

# Secrets and local settings
.env
.env.*
secrets.yaml
*.pem
*.key

# Editors and OS
.idea/
.DS_Store
```

### CI-3: Turn on secret scanning and push protection

*Level 1*

Settings → Advanced Security. Push protection stops a push that contains a known token format before it reaches GitHub.

### ACC-2: Replace classic personal access tokens with fine-grained ones

*Level 1*

**Why:** A token works for anyone who has a copy, with no password or 2FA, and copies end up in CI secrets, `.env` files and old laptops. A classic token can act on every repository you can reach and never expires. A fine-grained one only reaches the repository and permissions you gave it, until its expiry date. The Shai-Hulud worm collected tokens like these from developers' machines and CI in 2025 ([how it happened](https://ha-barkley.github.io/security/attacks/#shai-hulud)).

Settings → Developer settings → Personal access tokens. Give each token one repository, only the permissions it needs, and an expiry date. Delete tokens you no longer use.

### SEC-4: In CI, prefer no secret at all

*Level 2*

Use the built-in `GITHUB_TOKEN` with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

## Take it down

*Only for: A bad release went out*

If someone else published it, lock them out first. Pick *Someone got into my GitHub account* or *A token or key leaked* above, then come back.

### Work out which versions are bad

*Level 1*

Compare each recent release's files and tag with main. A tag on a commit that isn't on main, or a file your workflow didn't build, is suspect. If your releases are attested, `gh attestation verify` fails for a file your workflow didn't build ([Releases](https://ha-barkley.github.io/security/controls/releases/)).

### Delete the bad releases

*Level 1*

Delete each one, and its tag, on the repository's Releases page. An immutable release can be deleted too, but its tag name can't be used again ([GitHub's docs](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/immutable-releases)). For an app, also delete the image version on the package's page ([GitHub's docs](https://docs.github.com/en/packages/learn-github-packages/deleting-and-restoring-a-package)). If you published to PyPI or npm, remove it there as well.

### Release a fixed version with a higher number

*Level 1*

A higher version than the bad one moves everyone past it on their next update. Build it from main with your release workflow.

### Tell your users

*Level 1*

Publish a security advisory that lists the bad versions and the fixed one ([Security policy](https://ha-barkley.github.io/security/controls/security-policy/#pol-4)), and pin an issue that says the same. If the bad version could have taken something from users, such as passwords or tokens, say what, so they can change it.

## Afterwards

*Only for: A bad release went out*

These tie each release to a workflow run on main, so a release made any other way is easy to spot.

### REL-1: Build and publish releases from a workflow

*Level 3 · Level marker*

**Build and publish releases from a workflow** instead of your laptop. This one zips an integration, refuses a tag that isn't on main, adds a provenance attestation, and publishes the release with the zip in one step.

`.github/workflows/release.yaml`

```
name: Release
on:
  push:
    tags: ["v*"]
permissions:
  contents: write
  id-token: write
  attestations: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - name: Only release code that's on main
        run: git merge-base --is-ancestor "$GITHUB_SHA" origin/main
      - name: Zip the integration
        run: |
          cd custom_components/your_domain
          zip -r "$GITHUB_WORKSPACE/your_domain.zip" .
      - uses: actions/attest-build-provenance@v4
        with:
          subject-path: your_domain.zip
      - name: Publish the release
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh release create "$GITHUB_REF_NAME" your_domain.zip --verify-tag --generate-notes
```

Tell the Marketplace to install the zip with `"zip_release": true` and `"filename": "your_domain.zip"` in `hacs.json`. For a card, build the bundle in the workflow and attach the built file instead.

The "Only release code that's on main" step catches a tag pushed from the wrong branch by mistake. It can't stop someone with write access. The workflow that runs is the one in the tagged commit, so they could tag a commit whose workflow leaves that step out. A tag ruleset with *Restrict creations* stops that, because only the people on its bypass list can create release tags (see [Branch and tag protection](https://ha-barkley.github.io/security/controls/branches-and-tags/)).

### BR-4: Add a tag ruleset for your release tags

*Level 3 (or immutable releases) · Level marker*

Settings → Rules → Rulesets → New tag ruleset.

- Enforcement: *Active*. A disabled ruleset protects nothing.
- Target: `v*`, or however you name versions.
- Turn on *Restrict updates* and *Restrict deletions*, so a published version can't be moved to different code later.
- Turn on *Restrict creations* if only you should cut releases. Then add the Repository admin role to the bypass list, or you won't be able to push new tags either.

### REL-3: Turn on immutable releases

*Level 3 (or a tag ruleset) · Level marker*

**Turn on immutable releases** (Settings → General → Releases), so a published release's files and tag can't be swapped later. It applies to releases you publish after turning it on. Because assets can't be added after publishing, the workflow above creates the release and its file together.

### SEC-4: In CI, prefer no secret at all

*Level 2*

Use the built-in `GITHUB_TOKEN` with the narrowest permissions, and trusted publishing (OpenID Connect) to publish to PyPI or npm instead of a long-lived token.

## Next

When it's over, the [checklist](https://ha-barkley.github.io/security/checklist/) shows what else is missing.
