# Secure a new organization

From your own account to an organization that gives every new repository the same security settings. Do it before you create any repositories in it.

Source: https://ha-barkley.github.io/security/walk-throughs/new-organization/

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.

- How many repositories will it hold? "One" or "Several apps"
- Are you moving repositories in from your own account? "No" or "Yes"

## Secure your own account first

Whoever holds an owner's login controls the organization and every repository in it. If you've done these already, they're ticked.

### 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.

### 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.

### 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.

## Create the organization

Settings made here apply to everyone you add later, so set them while it's just you.

### ORG-1: Secure your own account first, then create the organization from it

*Level 1*

Settings → Organizations → New organization, on the free plan. Whoever holds an owner's login controls the organization, so do the steps in [Your GitHub account](https://ha-barkley.github.io/security/controls/account/) before this one.

### ORG-2: Require two-factor login for everyone

*Level 1*

In the organization's Settings → Authentication security, turn on the two-factor requirement. GitHub removes anyone who doesn't have it, and you can add them back once they've set it up.

### ORG-3: Decide who the owners are

*Level 1*

If you work alone, one owner is fine, but losing your login then means losing the organization. Keep your recovery codes offline and set up a second way to sign in. It also helps to write down who could take over. If others work with you, make two people you trust owners and everyone else a member.

### ORG-4: Limit what members can do

*Level 1*

In the organization's Settings, open Member privileges.

- Base permission: *Read*, which is the default. Give write access per repository instead.
- Repository creation: untick *Public* and *Private*, so only owners create repositories. Members can create both by default.
- Admin repository permissions: untick *Repository deletion and transfer*, so only owners can delete or move a repository.
- Pages creation: untick *Public*, so only owners can publish a website under the organization's name.

## Set what every new repository gets

Do this before you create any repositories. The default configuration only reaches repositories created after you set it.

### ORG-5: Create a security configuration for every repository, new ones included

*Level 1*

In the organization's Settings, open Advanced Security → Configurations → New configuration. Most features start enabled. Change these:

- Name: your organization's name followed by "Baseline", such as "my-org Baseline".
- Dependabot alerts → Security updates: *Enabled*.
- Dependabot alerts → Malware alerts: *Enabled*.
- Policy → Use as default for newly created repositories: *Public*.
- Policy → Enforce configuration: keep *Enforce for repository owners*, so nobody can turn a feature off in one repository.

If several people have write access, also set Bypass privileges and each Prevent direct alert dismissals, so one person can't push a secret or dismiss an alert alone. Leave the rest as it starts.

Choose Save configuration. Saving doesn't apply it to the repositories you already have, so apply it next:

1. On the Configurations page, choose the pencil beside your new configuration.
2. Set Apply to: *All repositories*, and check that Allow repository owners to modify features is *Off*.
3. Choose Review, then Save and enable.

These features are free for public repositories. On a paid plan with GitHub Advanced Security, private repositories are billed per active committer, and the review screen shows how many licenses it would use. Choose *All* for new repositories only if you mean to pay for them. A repository you move in later needs the configuration applied by hand.

### ORG-6: Set an Actions policy

*Level 2*

Settings → Actions → General.

- Allow only actions created by GitHub, plus the ones you list, such as `home-assistant/*` and `hacs/*`.
- Turn on *Require actions to be pinned to a full-length commit SHA*. Workflows that use a tag or a branch, like `@v7` or `@main`, then fail, so pin them first and let Dependabot keep the SHAs current.
- Under Workflow permissions, choose read-only access, so a workflow without its own `permissions` block can't write.
- Untick *Allow GitHub Actions to create and approve pull requests*.

### Plan to pin actions in every workflow

*Level 2*

With SHA pinning required, a workflow that uses a tag like `@v7` or a branch like `@main` fails. When you copy a workflow from these controls, swap each tag for the full commit SHA from the action's releases page. Dependabot then keeps them current ([Pin actions to a full commit SHA](https://ha-barkley.github.io/security/controls/ci/#ci-10)).

## Share files across your apps

*Only for: Several apps*

One security policy and one set of issue settings for every app, and a starting point for each new one.

### ORG-7: If the organization holds several apps, add a public `.github` repository with default community files

*Level 1*

A `SECURITY.md` and `.github/ISSUE_TEMPLATE/config.yml` there show on every repository that doesn't have its own, and that `SECURITY.md` counts as each of those repositories' security policy for level 1. Use the files from [Security policy](https://ha-barkley.github.io/security/controls/security-policy/) and [Repository basics](https://ha-barkley.github.io/security/controls/repository/), with the organization's name in place of a single repository. Some tools only read a repository's own files, so the template below carries a copy too.

### ORG-8: If the organization holds several apps, start new ones from a template repository

*Level 2*

Add the files every new app should start with, then tick Settings → General → Template repository.

- `SECURITY.md`, issue forms and a `.gitignore` with secret patterns
- `.github/dependabot.yml` with a 7-day cooldown
- The security workflow from [Checks in CI](https://ha-barkley.github.io/security/controls/ci/), with actions pinned by SHA
- The release workflow from [Releases](https://ha-barkley.github.io/security/controls/releases/)

A template only copies files. Each new repository still needs its own rulesets for main and tags. Set them up once, export them (Settings → Rules → Rulesets, then Export on each ruleset), and import them into the next repository with New ruleset → Import a ruleset. The bypass list isn't exported, so add it again.

## Move your repositories in

*Only for: Yes*

Move one repository at a time, and check it before you move the next.

### ORG-9: If you move an existing repository in

*Level 1*

**If you move an existing repository in,** check what depends on its old address. GitHub redirects links, clones and the Marketplace's entry, but only until someone creates a repository with the old name. Container images on ghcr.io keep their old path, so update the image name in your app's config. Then apply the security configuration to the repository.

## Check it worked

A throwaway repository shows whether new repositories really get your settings.

### Create a test repository and look at its settings

*Level 1*

Its Settings → Advanced Security page should show the organization's configuration, with Dependabot alerts, secret scanning, push protection, private reporting and CodeQL turned on. If you set an Actions policy, its Settings → Actions → General page should show it too. Delete the test repository afterwards.

## Next

Next, create the organization's first repository. [Secure a new project](https://ha-barkley.github.io/security/walk-throughs/new-project/) walks you through it.
