Security hardening
Expert
Why this matters
Most repository security is a short list of settings, and most breaches come from the items nobody turned on. You may not own the settings, but noticing that they are missing is a genuine contribution, and the list is short enough to check in ten minutes.
The list, in order of value
| Control | Prevents | Where |
|---|---|---|
| Two-factor authentication, enforced | Account takeover, the commonest cause of everything else | Organization or group settings |
| Protected default branch | Direct pushes, force pushes, deletion | Protected branches or a ruleset |
| Required review | One person shipping anything unseen | Approval rules or a ruleset |
| Required status checks | Merging something known to be broken | Branch rules (lesson 14.7) |
| Secret scanning | A leaked credential staying live | Platform security settings |
| Token expiry and least privilege | A forgotten credential with wide access | Personal and project token settings |
| Dependency alerts | Running a library with a known vulnerability | Security settings |
| Audit log review | Nobody noticing a change to any of the above | Organization settings |
The order is deliberate. Two-factor authentication and a protected default branch prevent more real incidents than everything below them combined.
Credential hygiene
The habits, from Section 8 and lesson 9.12:
- The least powerful credential that works: a read-only deploy key beats a personal token for a build server.
- An expiry on everything, so a forgotten credential expires rather than lingering.
- A periodic review of your own tokens and keys, and of the project's.
- Never a personal token in automation, because it carries all your access and dies with your account.
- Rotate on any doubt. Revoking is instant; the alternative is hoping.
Secret scanning
Both platforms scan pushes and repository content for patterns that look like credentials, and can alert or block. Two things worth understanding:
- Detection is not prevention. By the time a scanner alerts, the secret has been pushed and must be treated as leaked: rotate it first, then clean history if you must (lesson 8.7).
- Push protection, where available, refuses the push instead, which is the version that actually prevents the incident. It is worth asking for.
A local pre-commit hook adds a third layer, one second after the mistake (lesson 18.4), with the usual caveat that it can be skipped.
Dependency alerts
Both platforms read your dependency files and warn about known vulnerabilities, and both can open a merge or pull request that updates the version.
For a non-developer the useful contribution is not the fix, it is the process: making sure someone owns the alerts, that the automated update requests are reviewed rather than accumulating, and that the changelog entry says what changed. An ignored alert queue is worse than no alerts, because it looks like coverage.
Audit logs
An audit log records who changed what, and it is the control that makes the others durable: a protected branch that someone quietly unprotected is not a control.
| Question | Answered by |
|---|---|
| Who removed the branch protection? | The organization or group audit events |
| Who added this member, and when? | Membership events |
| Who created that token? | Token and key events |
Who force-pushed to main? |
Repository events, where recorded |
Access is usually limited to owners, and retention varies by plan. The practical version for everyone else: if a rule you rely on disappears, ask, because the log will say.
What you can do without owning the settings
A short and genuinely useful list:
- Read the settings you can see. Rulesets are visible to anyone with read access on GitHub; protected branches are visible on GitLab.
- Ask about the gaps, once, in writing: two-factor enforcement, a protected default branch, required review, secret scanning.
- Fix your own half: token expiry, least privilege, two-factor, signed commits (lesson 18.3).
- Add a pre-commit secret check for yourself, and propose it for the project.
- Watch the alert queues and raise it when they grow.
Written once, politely, in an issue, that list is a contribution most teams welcome and few people make.
How to do it
The local half:
$ git config --global commit.gpgsign true
$ git config --global gpg.format ssh
$ cat .gitignoreAnd the check nobody runs often enough: read your own tokens and keys on both platforms, and delete what you cannot explain.
Nothing security-specific beyond storing its own token in the keychain (lesson 15.3). Extensions have repository access, so install deliberately.
The same, plus Settings → Version Control → Git → Protected branches, a local guard against force-pushing (lesson 16.10).
Settings → Repository → Protected branches and Push rules; Secure → Security configuration for scanning; Settings → Access tokens for project tokens; group Settings → General → Permissions for two-factor enforcement; Secure → Audit events where the plan includes it.
Settings → Rules → Rulesets; Settings → Code security for secret scanning, push protection and Dependabot alerts; organization Settings → Authentication security for required two-factor; the organization's Audit log.
Common mistakes
- Treating detection as prevention. A secret-scanning alert means it already leaked; rotate first.
- Cleaning history and not rotating the credential. The clean-up is optional; the rotation is not.
- Tokens with no expiry.
- A personal token in CI.
- Alert queues nobody owns, which look like coverage and are not.
- Relying on a hook as a control (lesson 18.4).
- Assuming someone senior has checked. Often nobody has, which is why the ten-minute review is worth doing.
Try it yourself
Goal: review a real project's settings and write the gaps down.
- On a project you contribute to, list what you can see: protected branches or rulesets, required reviews, required checks.
- Check whether secret scanning and dependency alerts are on, if you can see them.
- Review your own tokens and keys on that platform, and delete anything you cannot explain.
- Set an expiry on every token you keep.
- Write the gaps as one short issue: what is missing, and one sentence each on what it prevents.
Expected result: a shorter personal credential list, and one issue that a maintainer can act on.
Show solution
Step 5 is the deliverable. Security suggestions land badly when they read as criticism and well when they read as a checklist with reasons. One sentence per item, no adjectives, and an offer to help with the parts you can do yourself, is the version that gets things enabled.