How I configure my Git identities
benji.dog
benji.dog
[includeIf "hasconfig:remote.*.url:gh-work:**/**"]
path = ~/.gitconfig.d/gh-work.inc
So, any git repo cloned with the ssh identity defined under `gh-work` will take on the config of `gh-work.inc`, which includes the git identity, and also the same signing key as in the ssh config.Essentially, the name `gh-work` becomes the distinguishing element in both my ssh identity and my git identity, and I find this easier to think about.
To check if it's working correctly you can run:
git remote get-url origin
git config --get user.emailI mean, it seems to me that any script that tries to do something with git remote URL, should deal with any string that git thinks is a valid remote URL. `ssh-host-name:owner/repo` is not exactly an edge case.
Just keep a .gitconfig in your HOME with aliases for your identities. Then just after initializing/cloning the repo do git config-company or git config-personal
er453r@r7:~$ cat ~/.gitconfig
[user]
useConfigOnly = true
[alias]
config-personal = !echo CONFIG-PERSONAL && \
git config --local user.email 'personal@email.com' && \
git config --local user.name 'personal' && \
git config --local core.sshCommand 'ssh -i ~/.ssh/id_rsa_personal'
config-company = !echo OLD CONFIG-COMPANY && \
git config --local user.email 'official@comapny.io' && \
git config --local user.name 'Name Surname' && \
git config --local core.sshCommand 'ssh -i ~/.ssh/id_rsa_company'I just like this workflow better since it is totally directory/remote agnostic (compared to the article).
Just use whatever suits you best :)
I'm sorry, I don't want to be mean but this has got to be the worst way Ive seen someone try to solve this. I want to cry skimming it. Why would anyone do this and think it's simpler? Wew, gotta just leave this one alone.
It was super unhelpful when trying to do version control forensics. But if I'm being generous, I think maybe he was trying to remind everyone that anyone can put anything in their identity config, and we shouldn't trust whatever is in there for all that much.
Is that "/" an "and", or an "or"? I'd expect only e-mail has to match, leaving you free to change the user name.
I just did a test with four commits with a signature matching both on user and email, only on email, only on user, and in none of them and:
From GitHub, it validates signatures with the email registered in the commit: If the signature matches the key registered for the GitHub user with that email address, it says "Verified" in a green box. If it doesn't , it says "Unverified" in a yellow box.
So GitHub "Verified" two commits: the one that matches all the fields and the one that only matches the email.
From git CLI, it depends on your configuration.
If you do a `git log --show-signature` at first it will complain with `error: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification`. You need to set up a file with your trusted ssh signatures.
Once you set that up, it will verify ALL correctly signed commits, even if they don't match the commit email address. Seems like the signature and the commit can have different emails, so to speak: "commited by fake@email.com and signed by real@email.com. The signature is valid by real@email.com".
Example I did, changing the email addresses:
git show --show-signature 11906e1
commit 11906e14155ae08b7e7e23f26aa9c04913ade5dd
Good "git" signature for good@email.com with ED25519 key SHA256:9uU6+7pNNzwVEKTecpJE4Bmm2WXaqZXMZRLe9rJZ0ZY
Author: fake name <fake@email.com>
Date: Mon Nov 25 13:36:28 2024 +0100So a fiction character is maaybe OK, as long as it is clearly fictional name and no one else in the company does that; but other stuff, like actually impersonating other co-workers would be very bad, and should eventually leave to firing.
Anyway, if you simply[1] require commits to be signed with GPG, and enlist what GPG identities are acceptable, you are pretty much set (and you can instead rely on the signature instead of the author/committer metadata to identify the actual author).
[1] "Simply" and GPG signing don't always go hand-in-hand, I admit.
Just put this in your ~/.gitconfig (or ~/.config/git/personal as in the article)
[core]
sshCommand = /usr/bin/ssh -o IdentitiesOnly=yes -i ~/.ssh/IdentityFile2 -a
This makes submodules easy without the `insteadOf`Yes, there are other ways to do it. Just as there are other ways to enter a building besides just opening the door.
It's the one tool that works consistently across multiple projects.
lol, you’re an ass
Host customer-github
Hostname github.com
IdentityFile ~/.ssh/customer_rsa
User git
All I have to do is use the alias in any git clone command and I'm done.Aside: I use NixOS with home-manager (on linux and mac), which makes this trivial [1]. Added the following lines to my home-manager config:
programs.git = {
enable = true;
...
includes = [
{
condition = "hasconfig:remote.*.url:git@github.com:<work>/**";
contents = {
user.email = "<work email>";
};
}
];
}
[1]: https://nix-community.github.io/home-manager/options.xhtml#o...Curiosity got the better of me so I looked it up at https://nix-community.github.io/home-manager/ and it indeed does purport to provide benefits I guessed at and then some.
Whether that's better than just manually managing things yourself is altogether a different matter.
In TFA the author must set up two configurations: the .gitconfig, and the file which is included in the .gitconfig. Home-manager does this automatically through one config parameter. That is what I was pleased with and wanted to share.
You’re risking putting yourself in a whole lot of trouble by using a personal machine for work.
Care to elaborate in what circumstances is it a problem and why?
Edit: I mostly asked the parent poster to provide more context and avoid general assertions like "a whole lot of trouble". Risks are indeed tangible, but if we are unable to enumerate them, we are mostly spreading FUD instead of educating.
(Contractual terms between an employee/contractor and employer/company is what ensures there is no abuse for the most part)
Using separate directories makes improper deletion likely.
Using separate computers with full-disk encryption and shredding procedures makes proper deletion a happy path.
It's not that you cannot properly isolate environments on a single computer.
It's that a single computer is, unless you're a Qubes/BSD/Hypervisor fanatic, not very isolated at all.
So if/when your personal computer gets compromised because of a browser zero-day, your work's intellectual property is potentially compromised.
When you combine that with likely not deleting files properly (or at all), the window of opportunity for IP theft is much bigger.
When you further add the complete unlikeliness that former employees/contractors will report that their personal computers were compromised after having neglected to properly purge your intellectual property, the case for buying your employees/contractors dedicated machinery becomes a no-brainer. Simply from a corporate risk perspective.
It's not a practical problem, but a principal + legal problem.
Companies both have to have a set of "processes" in place for legal/compliance reasons, and an employee is liable if they do something that's outside the recommended practice (like using a personal device when forbidden by such policies).
Still, the focus should be on liability and ensuring compliance with legal terms, and an employee needs to make sure they do that. In some cases, that's easier done with a separate computer. In others (when there is no direct spelled-out requirement), downsides of using a separate device outweight the benefits of making compliance with legal terms easier.
As a side note, a browser zero-day is probably even more likely to target work computers, so that example is pretty bad — company data remaining on personal devices by accident is where the problem really is.
- If you're a contractor, risk of leaking other clients' assets (running `tree` in the wrong folder while screensharing or more subtle variations);
- Shredder policy, done with the work = destroy hardware (though I don't think companies with shredder policy would incentivise personal laptops, you never know)
When it comes to "assets", companies make a big fuss about leaking them, but in reality, it's totally irrelevant. I.e. witness Windows OS source code being leaked: Microsoft wasn't affected at all. Leaking short/mid-term plans would probably have a bigger effect (abuse on the stock market, beating a competitor to the market on their big bet...).
There’s no milder way to put this; you’re delusional.
For example, please let me know of any one's company leaked source code and how someone has used that to their advantage and become amazingly successful in the same market?
So nope: I am saying that not all companies have the same policies, nor the same risks, and that this is a legal liability that totally depends on the terms of engagement.
As for leaking assets, maybe it does not affect the company at large, but that literally does not matter for this discussion. It will definitely affect your relationship, most often negatively.
And in any case, my usage of assets was clearly general, substitute the example for "clicking on the wrong stored tab while screensharing" can just as well lead you to leaking a plan.
The same goes for putting anything personal on a company issued device, such as signing into your private email.
It is a problem in all circumstances. The problems may not always manifest, but if they do, you’ll be in deep trouble.
Problems range from the mild; company has mandatory tooling that takes control of your machine. To the extreme; offices get raided and equipment seized indiscriminately.
General assertions are fine. The exercise of whether to follow them up with research is left as an exercise to the reader.
When you stop working for an employer/customer and you are legally required to purge all files.
Having everything work-related on a dedicated machine makes purging all files very easy.
Not having everything work-related on a dedicated machine makes purging all files questionable.
This also assumes you never-ever used a personal device to access any of them either (they might be in caches or Trash/Recycle Bin) — and I agree that to satisfy such a legal requirement, you probably don't want to be using a personal device to access them at all.
Keeping things separate has some upsides, but also some downsides (multiple devices to lug around) — depending on their situation, everybody should choose their own compromise (granted, some engagement contracts will make that choice for you).
E.g. choice of computer dictates choice of activity, I won't accidentally work on something when I'm not supposed to.
I've had paid-for open source gigs, and I have a bunch of open source work spread out on a bunch of machines.
Downsides are:
- The bag gets heavy when I have multiple events for separate customers/events on the same day
- For stuff that is shared between computers (e.g. open source projects), I can forget to git push
I've tried to put my machines on the same VPN for some convenience wrt. file sync.Fortunately, the most locked off machines never need for other computers to connect to them.
And yes, this came as a customer requirement, but I've decided to grow with the choice.
I don't trust process isolation on a single computer very much.
After configuring the identities you just need to run
$ git su Personal
$ git su Work
And all the identity configuration (email, name, SSH key and optionally PGP key) will be set up into the repo's .git/config file.Saved me a ton of time.
https://github.com/dolmen/github-keygen
12 years old, but still actively maintained.
I suddenly felt a deep connection with the author. It is not only me.
I promise you, my dear drafts, that one day, I will set you free to see the world!
* use a dedicated work machine and
* also want to version control your dotfiles (including ~/.config/git/) and
* don't want to leak your work repository organisation via your dotfiles,
you can instead add something like
[include]
path = work.gitconfig
which will override any settings above it and also fail gracefully/silently if work.gitconfig does not exist. # file ~/.gitconfig
[includeIf "gitdir:~/src/"]
path = /Users/metabeard/.config/git/.gitconfig-personal
[includeIf "gitdir:~/dev/"]
path = /Users/metabeard/.config/git/.gitconfig-work
and # file .config/git/.gitconfig-personal and .config/git/.gitconfig-work
# both are very similar with different email and signingkey
[user]
name = Meta Beard
email = email@metabeard.me
signingkey = ssh-rsa xxx==
[gpg]
format = ssh
[gpg "ssh"]
program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
[commit]
gpgsign = trueThe private bits are all in the same place: if one is compromised, so are the rest.
However if you're worried about this then you should probably be using a hardware token anyway - something that supports SSH authentication via FIDO2, GPG, or smart card interface.
Curious though that the compliance rules are strict enough it warrants distinct keypairs, but not that strict for the devs to use dedicated hardware.
If you have a GitHub Enterprise user for internal code development, that GitHub Enterprise user is restricted from interacting outside of the GitHub Enterprise/ If you also need to contribute to OSS projects as part of your job, you have to use a different GitHub user, and therefore a different keypair.
Your signing key for personal projects probably has a different temporality.
What does this achieve exactly?
git clone gitlab.com/acme-corp/project-name
I could use: git clone work:project-name
But this kinda broke `includeIf` since it store the `insteadOf` remote url directly. I then had to convert existing repositories to use the `insteadOf` url.I wrote a little bit about it here: https://bentinata.com/log/git-insteadof-includeif
Did you say that just so we could imagine the world where you published it earlier?
Thanks anyway, and nice site!
Based on that and your 1.44MB Club, you might find Neat CSS interesting. :P
My Neat CSS websites will almost always fit on a floppy and I have a case of old floppies right here in my closet. The Neat CSS home page is only about 12k. Things get bigger when you start adding images, of course.
Edit: Hmm it seems to ask me over and over again for my password for a key at every pull or push. Maybe this method somehow disables memorizing the SSH identity?
I ended up creating a "SSH environment" manager 4 years ago to help with this: https://github.com/theonejb/sshenv
It's worked wonderfully for me since then, and it's something I use almost daily.
One thing though: what’s the point of using separate keys for work/personal/github/gitlab? I fail to see a practical and security advantage over using one key (per workstation).
In fact, I was one of not too many who used separate account for work, and people didn’t understand it, wondering why the hassle.
These days I prefer to use local VMs to compartmentalize different areas of work (personal, consulting, etc) so my git config is plain and simple. Lately I’ve been doing mostly consulting work around open-source so I’ve been using my primary GH account for the most part, but separate VMs allow me to use a different key (account) without advanced git config incantations.
Currently dealing with a difficult setup where we have subrepos (so just using an `~/.ssh/config` alias for github.com:org does not work), some dependencies downloaded with CMake CPM, and working in a vscode devcontainer.
For many of the companies that I've worked at, the laptops were taken home to be used as personal computers at the end of the day and this was a well-known thing and I was often looked at weird when I said I had another laptop.
One time I took the wrong laptop in and had to work on my personal laptop in the office. It wasn't so much fun that day.
In my case, company I worked for got acquired by a larger corp. Things happening as they usually do, I ended up having two different e-mails/identities/SSO credentials - me@old.company and me@new.corp. Most of the code I worked on was stuck on old company's infra, but new repos were developed on the acquiring corp's infra, so for years, I had to maintain two different SSH / Git identities too, and use appropriate one for a given repo.
Is a `dotfiles` repo personal? I don't usually push to my own repos from my work machines, but I do want to pull and push config updates while not disclosing my work email there or rewrite commits all the time (it's not secret, I just don't want it there).
Even if I'm in my work profile and I need to do something in an org called `acmecorp`, I will create @acmecorp-identifier to do that.
This is just a very long experience...
* Security policies for work things have a blast radius of just that employer
* OSS things have a lifetime beyond the life of an employment / contract
* Source control elsewhere (GitHub / GitLab / Bitbucket / Gitea / Forgejo / etc) all has a local blast radius, and if a provider / org forces changes (roll your keys!) then the impact is limited to just that provider
* When something changes ownership (i.e. an org), the impact to me is low
It seems much more sane.
I think of a single git identity across multiple orgs as a bit of a smell.
... time to go change my security questions
I'm not a fan of mixing identities, like for example mixing a personal identity[2] with a work identity[1].
[1]: Git.
[2]: OS user.