Post

Understanding identity in git repositories

Understanding identity in git repositories

Can you guess who I am?1 šŸ˜ˆ It turns out distributed identity management is an oxymoron. Hereā€™s what you can know and how to stay sane(ish) through your code audit. This is an expanded set of slides and resources since shown live on 14 June 2024 at BSides Boulder 2024 (YouTube recording).

šŸŖ» Overview here, if you missed it! šŸŖ»

Identity in git and in your central remote are not connected to each other. Reliably linking these two completely independent identities can be tricky in any code audit. If you take nothing else away from this presentation, let it be this one graphic.

flowchart LR
    subgraph who
    A(fa:fa-user<br>developer)
    end
    A --> B(fa:fa-laptop-code<br>files)
    B --> C(fab:fa-git-alt<br>git repo<br>local)
    subgraph also who
    D(fab:fa-github fab:fa-gitlab fab:fa-bitbucket<br>git repo<br>remote)
    end
    C --> D

Who you say you are

Git thinks you are who you say you are. It canā€™t create a commit without a name and email address to use. This tiny bit of friction in user experience is so well-known that the major platforms for remote repository hosting2 all prompt you to set this up first. Hereā€™s an example of that ā€œfirst screenā€ after creating an empty repo:

git-setup-light git-setup-dark literally any remote hosting platform, because git isnā€™t always friendly

Those magic shell commands update the ~/.gitconfig file (because of the --global flag) with your name and email address. Hereā€™s what that snippet looks like in that file:

1
2
3
[user]
    name = Natalie Somersall
    email = some-natalie@chainguard.dev

ā€¦ yeah, thatā€™s it.

Except itā€™s not.

Remember all git configuration can vary in scope between system-wide, per-user (~/.gitconfig), or per-repository (~/.git/config) with the same order of resolution outlined above. This is phenomenally useful to users needing multiple identities. As an example, I use a personal SSH key and my gmail account for open source work on a few repos (local) and OIDC signing with my work identity for my job by default (global). My name, email address, and signing method are all different between these two identities.

None of this needs a remote hosting platform to work. Itā€™s all built into git.

It can also change on each commit because why not add another dimension to prove identity? This means on some level, all of our logs in a git repository are built on individually self-attested data. Letā€™s make a suspicious commit. šŸ˜ˆ

1
2
3
4
5
6
7
8
9
10
11
12
13
$ git commit -m "just adding some warezzz" --author="Maintainer <not-my-email@gnail.co>"
[main 71010a8] just adding some warezzz
 Author: Maintainer <not-my-email@gnail.co>
 1 file changed, 2 insertions(+), 1 deletion(-)


$ git log --author="Maintainer"
commit 71010a87f84eab30375d0ee80098d597dc8f3d9b (HEAD -> main)
Author: Maintainer <not-my-email@gnail.co>
Date:   Mon Jun 10 16:43:18 2024 -0600

    just adding some warezzz
(END)

In the end, all data in git log comes from commit data. So how can we prove anything about this commit?

Papers, please

Letā€™s see what happens when we push this weird commit to our remote. Checking the repoā€™s commit history, thereā€™s even more silliness going on.

suspicious-commit-light suspicious-commit-dark what on earth is going on here?!

Now weā€™re getting into how git interacts with a remote (repo hosting service, such as GitHub or GitLab) and how that remote interacts with identity.

It appears that some-natalie committed a change authored by Maintainer. Itā€™s not uncommon to add authors to commits. Itā€™s frequently used to pull in work from other remote sources like a different git remote or email patches, sharing credit with others across these gaps. Apart from the childish commit message, nothing seems wrong here.

But why is it verified? And who are these users?

BYOI - bring your own identity

As weā€™ve seen so far, identity is messy. Git necessitates bringing your own identity, which is antithetical to proving who did something. It is true that Maintainer wrote the code and created their commit to the git repository. However, the credentials that committed and pushed that code to the remote belonged to the some-natalie account.

The account that pushed the code exists on the remote. The remote repository hosting service (GitHub, GitLab, etc.) can3 then do neat things such as:

  • Be gated by your company VPN infrastructure
  • Use single sign-on (SSO) with the company external identity provider
  • Control the account lifecycle with SCIM (system for cross-domain identity management)
  • Enforce cryptographic signing of code changes with a secondary form of identity - a key!
  • Integrate with your audit tooling for logging and alerting
  • ā€¦ and more I canā€™t remember offhand ā€¦

But as shown in the example above, it doesnā€™t seem to matter as much as would reasonably be assumed. The reason is why most regulated industries look similar to this:

flowchart LR
    A(fa:fa-user fa:fa-laptop-code<br>endpoint user identity) <-->|email address| B(fab:fa-github fab:fa-gitlab fab:fa-bitbucket<br>remote user identity)
    subgraph a well-respected boundary with centralized identity
    B <--> |SCIM<br>or<br>SAML| C(fas:fa-address-book<br>identity provider)
    end

While itā€™s true that end users may control their local identity (who you say you are in git), it shouldnā€™t be possible for them to set their external identity4.

Commit signatures

Commit signatures demonstrate that a key signed a particular set of code changes in a tamper-resistant way. Commit signatures do not link authorship and identity. Please repeat that as many times as necessary.

Commit signing is very frequently confused as a control to establish authorship of code changes - eg, Natalieā€™s key didnā€™t sign this code, therefore she didnā€™t write it or didnā€™t push it (or any other combination of these). Itā€™s so common that it is one of the first questions I ask a team to determine their maturity at the start of any assessment readiness exercise.

Commit signing and signature verification link the remote account that pushed the code owns the key that signed those changes. In the example above, the commit was pushed to the remote and signed by some-natalie, but still authored by Maintainer. There are three main ways to sign commits. Some are easier for users to configure, but all provide the same basic functionality.

x.509 signing

This lets users sign commits using their issued x.509 certificates . In our use case, itā€™s within your companyā€™s public key infrastructure . This method also encompasses decentralized trust through user-controlled GPG keys 5, but thatā€™s a topic for another day. It usually combines something a user has (CAC6, smart card, or other hardware-based key) and something theyā€™ll uniquely know (a pin or password to it) to create a tamper-resistant signature on a specific set of changes.

github-gpg-dark github-gpg-light most git repo hosts will let you append .gpg to a userā€™s profile URL to see the public half of their GPG keys for verification

If you have private certificates in your companyā€™s chain (likely), youā€™ll also likely need to self-host your git server. Most SaaS companies arenā€™t keen to add hundreds/thousands/more random certificate authorities from customers.

S/MIME signing

S/MIME is a set of extensions on public-key cryptography for email7. Itā€™s a common practice for many organizations to have this infrastructure in place already. As far as I have seen, S/MIME signing is most commonly used to share trust between disconnected environments that use email patches to move code between them (air-gapped systems). The same caveats about per-user setup and needing to self-host your server to edit trusted CAs apply here.

SSH signing

SSH keys can be used both for authentication to (most) git repo hosts and for commit signing. Some companies have and use infrastructure to manage SSH keys. It is a similar pattern to x.509 certificate signing above with user setup of git to use these keys.

SSH commit signing what I use on my personal projects as a balance of ease of use and validity. I generate SSH keys for commit signing and store them on a Yubikey. Itā€™s a balance of getting out of the need to manage and secure local files, but also simple to setup8.

backstreet-boys Protip - do not make parody Backstreet Boys lyrics to your auditor during the audit.

Mind the gaps

Going back to our diagram, adding a method to tie code changes made on an endpoint to a centralized identity now looks roughly like this:

flowchart LR
    A(fa:fa-user fa:fa-laptop-code<br>endpoint user identity) <-->|email address| B(fab:fa-github fab:fa-gitlab fab:fa-bitbucket<br>remote user identity)
    subgraph a well-respected boundary with centralized identity and cryptography
    B <--> |SCIM<br>or<br>SAML| C(fas:fa-address-book<br>identity provider)
    B <--> |GPG or SSH keys<br>for signature verification| D(fas:fa-key<br>key server)
    end
    A <--> |GPG or SSH keys issued| D

What gaps does this model leave that weā€™ll need to account for in our risk register?

Long-lived secrets

The biggest gap here is pretty well known throughout any other part of IT infrastructure. Each method of commit signing we outlined use long-lived secrets such as PINs for an x.509 certificate card or an SSH private key file that can be compromised. This means it should fall under the same scrutiny as other credentials that can be phished or written on post-it notes in the office.

Time-based validity

It can be difficult to validate if a commit made with a valid-at-the-time-and-not-anymore signature was legit. As an example, when the commit below was made, I was employed at GitHub and this was signed with a valid key associated to my @github.com email address:

github-unverified-light.png github-unverified-dark.png a commit signed with a key that is now expired

That identity existed as a condition of my employment there. Since I no longer work there, I removed that email and key from my account. Itā€™s now ā€œunverifiedā€ even if it was true at the time. Checking for ā€œunverified now, but was valid at the timeā€ isnā€™t built in to repository hosting platforms. This means we now need to drag another system or two into our scope to prove that the key was valid and the user was able to use it at the time of the commit.

This condition needs to be accounted for when users control their identity independent of employment. It may also occur depending on the platform if accounts are deactivated or removed as needed by policy - check the documentation for all the parts at play.

The best action here is to run an exercise to create an account on your platform, create/sign/push code with a key from the same PKI system to that account, then remove the account following your written offboarding procedures - documenting the user lifecycle with screenshots and any other evidence needed. There are so many systems and configurations in scope for this that itā€™s hard to provide a universal answer.

Bot use and abuse

Deeply understand (and have evidence to back up) the entire lifecycle of the myriad of non-user based authentication methods major repository platforms use. Quite often, enterprise administrators cannot entirely lock down or audit these easily. Offhand, these include:

  • Service accounts
  • OAuth applications
  • CI/CD accounts (sometimes treated separately, some can read/write and others read-only)
  • Deploy keys (SSH keys tied to an individual repository and not users)
  • User-owned credentials that exist outside of an identity provider (eg, an extra SSH key or API tokens)
  • ā€¦ more I might be missing ā€¦

These accounts are often overlooked until itā€™s brought up in an audit. Without the tools to prove account usage and lifecycle, youā€™re left to other controls for mitigation. While other controls are sometimes acceptable (and if youā€™re really lucky), it requires yet more documentation on their implementation, mitigation, and any additional workarounds.

Doing this for CMMC for thousands of users across a mature self-hosted product was many entangled discussions with lots of service owners and assessors, pages upon pages of mitigating control documentation, and DIY code written to actually get the job done and map it to the relevant controls. Perhaps itā€™ll be another post one day.

As an example for how these bot integration identities can be abused, look no further than the best bot on GitHub - the real Dependabot always signs commits in GitHub.com with GitHub keys. Malicious impersonation, such as what Checkmarx discovered in September 2023, is harder to pull off without checking for signed commits (example commit ).

dependabot-dark dependabot-light

The future is bright

Despite all the weirdness we just went over, itā€™s possible to build a robust system of auditing and allowances for maximum developer-friendly features without hating everything about life when your audit comes up. The future of identity and signature verification looks bright.

Using OpenID Connect (OIDC) allows a company to federate both authentication to push code and identity of commit signatures on an endpoint to a central identity provider. This is still new enough that thereā€™s a few methods that folks are trying out. Iā€™m not aware of a large deployment or Authority to Operate (ATO) using this yet, but if Iā€™m wrong, please reach out.

It significantly narrows the window of time a credential could be misused and ties into a central identity (eg, google or aad or whatever) - remember how I said I canā€™t really prove I wrote it, only that my key signed it. If Iā€™m limited to OIDC, the window of time I have to do any mischief is meaningfully constrained - usually 5 minutes or less.

Whatā€™s OIDC again?

OIDC (in plain English ) is a way to consume scoped identities without being an IAM provider. Itā€™s actually quite difficult to write a username/password or other way to authenticate securely to an application - not only do you need to store sensitive data (at least a password), but that system needs maintenance, is user-facing target for abuse/exploitation/shenanigans, and doesnā€™t directly bring the company any money. Itā€™s easier to consume identity securely from someone who does it well instead. Hereā€™s an example where you can use Google, GitHub, GitLab, or another identity provider to use an application:

oidc-dark oidc-light

Tricky bits of OIDC

First, not every git repo hosting service supports using OIDC for logging in. There are ever-changing conditions on which providers are supported by which vendors and what features work on their platform in this configuration. All of that is way out of scope for anything Iā€™d want to talk about today. Just know that support seems to be expanding across the board.

Next, after setting up gitsign to sign your git commits, the lack of support from repository hosting services can lead to a weird situation. I can sign a commit and check it after the fact (in this case, with a GitHub Action), but that green pill-box in the UI to say my commit is ā€œverifiedā€ wonā€™t work. If you sign with one of the supported things (SSH, x.509, etc.), this commit will fail the check but show up as verified.

sigstore-signed-dark sigstore-signed-light signed with OIDC, but appears unverified

sigstore-check-dark sigstore-check-light commit not signed with OIDC, but appears verified with SSH

This discrepancy in expected behavior could be resolved by the repo hosting vendor allowing checks to the public instance of sigstore. Itā€™d be even better as an arbitrary source for this data - allowing companies to BYO certificate infrastructure the same way theyā€™re used to for self-hosted services. In order to provide that log of verification, itā€™d be a simple script wrapping cosign to check each signature against the transparency log.

Edge cases to note

Name squatting

Name squatting is when someone else claims an email address or username for another person. It can be a concern on ā€œfree for allā€ or public services, such as this example on GitHub.com. However, itā€™s normally not a concern worth noting in self-hosted infrastructure. These systems are trivial to gate account creation with an identity provider such as Active Directory9, Okta, etc.

Mailmap files

These files, stored in the projectā€™s root directory as .mailmap by convention, simply map multiple emails to one name. Hereā€™s an example:

1
2
Bob Smith <bob.smith@company.com> Bob Smith <bob_smith@us.company.com>
Alice Jones <alice.jones@company.com> Alice Jones <alice_jones@us.company.com>

Itā€™s useful for tracking multiple emails from one human being. This file is version controlled within the repository and has a well-defined format. The documentation is quite good as well. The support is built in to git, but not the repository hosting services. Iā€™ve never had them come up in an assessment, personally, as I have only seen these controls met by using an identity provider thatā€™s used by the repo hosting service.

Parting thoughts

last-sprint

ā€œDuring this sprint, one of you will merge complete garbageā€ ā€¦ but do you know who? šŸ˜ˆ

That was a lot. It also feels like weā€™ve only scratched the surface of ā€œhard to prove identity problems in git repos that Iā€™ve had to answer forā€. To summarize:

  1. Git requires you bring your own identity. This is hard to do anything with.
  2. Basically every remote repository hosting service can hook into your identity provider. Do this.
  3. Commit signing doesnā€™t prove authorship.
  4. Thereā€™s a bunch of weird edge cases, cool new technologies to make this better, and even more nuances with your platform/integrations/setups than possible to document.
  5. Itā€™s all really hard - IAM, git, endpoint management, certificate management, software ā€¦ itā€™s okay to just live with that.

Identity is hard, so letā€™s change the pace and look at what git is šŸŒŸ phenomenally good at šŸŒŸ - tracking changes in files!

šŸ•µļøā€ā™€ļø Next up - tips, tricks, and footguns to watch out for when looking at what changed in a repository. Part 4: Tips for auditing changes in git


Footnotes

  1. Rumpelstiltskin , as interpreted as a developer by AI.Ā ā†©

  2. Remote repository hosting (eg, GitHub, GitLab, BitBucket, etc.) sometimes get called ā€œgit forgesā€ or ā€œcode forgesā€. I hate this term for reasons I will rant about later. These patterns of identity in an audit are not limited to git, each of these platforms have their own nuances and interactions with other parts of your infrastructure, and in conversation, weā€™ll end up just using the brand name of whatever youā€™re using - eg, back to ā€œGitHub/GitLab/whateverā€.Ā ā†©

  3. These are normally features gated behind paying for an ā€œenterpriseā€ or ā€œbusinessā€ plan šŸ’°Ā ā†©

  4. If a user can mess with their identity in your identity provider, there are much bigger problems to worry about than source code audits.Ā ā†©

  5. The best GPG introduction and setup guide Iā€™ve found is from Ian Atkinson .Ā ā†©

  6. Common Access Card, which is what those smart cards are called within and around the US Federal market. Itā€™s an identity card with many features on it, but most importantly, cryptographic certificate(s) on a chip.Ā ā†©

  7. ā€œEncrypt this emailā€ type functionality that uses the account provided to you by your company likely uses S/MIME under the hood to encrypt and decrypt messages only for the specified recipients. Itā€™s not terribly friendly to set up, but itā€™s simple to use once an IT department sets it up for everyone.Ā ā†©

  8. SSH commit signing this way requires setting up git to use it and your remote host to trust it. The best directions here are a fantastic workshop from Git Merge a few years back by the āœØ amazing āœØ Andy Feller . To store the key on a Yubikey, I used these excellent directions from the incomparable Xe Iaso .Ā ā†©

  9. As of writing, Microsoftā€™s ā€œActive Directoryā€ product is called multiple things depending on your deployment model. Right now, the SaaS version is called ā€œEntraā€ and the only people using that name work at Microsoft still so ā€¦ everyone knows what Active Directory is still. Donā€™t get pedantic, itā€™ll likely get rebranded again soon.Ā ā†©

This post is licensed under CC BY 4.0 by the author.