Commit a211bab
authored
Add support for GitHub enterprise-managed user accounts (#1190)
Add support for GitHub [enterprise-manage users
(EMU)](https://docs.github.com/en/enterprise-cloud@latest/admin/identity-and-access-management/using-enterprise-managed-users-for-iam/about-enterprise-managed-users)
to the GitHub host provider.
Accounts in an 'EMU' enterprise/business are siloed from the regular,
public GitHub.com accounts. EMU accounts are identified by the
`_shortcode` suffix, where the `shortcode` is a moniker for the
enterprise/business, for example `alice_contoso`.
When asked to recall credentials for the GitHub.com host we now attempt
to filter stored accounts by the `shortcode`, given information provided
in `WWW-Authenticate` headers from upcoming versions of Git that support
these headers (as of
gitgitgadget/git@92c56da).
The format of the header is:
```
WWW-Authenticate: Basic realm="GitHub" [domain_hint="X"] [enterprise_hint="Y"]
```
..where `X` is the shortcode, and `Y` is the enterprise name.
If multiple accounts are available for the given 'domain' then we
present an account selection prompt. Users can avoid this prompt in the
case of multiple user accounts by specifying the desired account in the
remote URL (e.g. `https://alice@github.com/mona/test` to always use the
`alice` account).
Note that GitHub.com does not yet return such `WWW-Authenticate`
headers, except always `Basic realm="GitHub"`, so this may be subject to
fixes later. In the case of `realm="GitHub"`, i.e., public accounts,
there is no change.
### Testing
To test the new behaviour before GitHub.com returns such headers, it's
possible to fake the server response using
[`mitmproxy`](https://mitmproxy.org) and the following script:
```python
"""Add an HTTP header to each response."""
class AddHeader:
# initialize a dict with shortcodes and paths
def __init__(self):
org1 = ("domain1", "enterprise1")
org2 = ("domain2", "enterprise2")
self.orgMap = {
"org1" : enterprise1,
"org2" : enterprise1,
"org3" : enterprise2,
}
def response(self, flow):
if flow.response.status_code == 401:
# lookup the correct shortcode based on the org
org = flow.request.path.split("/")[1]
if org not in self.orgMap:
return
domain_hint = self.orgMap[org][0]
enterprise_hint = self.orgMap[org][1]
# build the header
header = "Basic realm=\"GitHub\" enterprise_hint=\"" + enterprise_hint + "\" domain_hint=\"" + domain_hint + "\""
# set the header
flow.response.headers["WWW-Authenticate"] = header
addons = [
AddHeader()
]
```
Replace `orgN` with the org names that are backed by an EMU Enterprise,
and fill `domainN` for the shortcode, and `enterpriseN` for the
enterprise slug/name.
Configure Git to use the proxy and run `mitmproxy` with the `--scripts`
argument:
```shell
git config --global http.proxy 'http://127.0.0.1:8080'
mitmproxy --scripts <SCRIPT>
```
Now all Git interactions that touch `orgN` will include the
`domain_hint` and `enterprise_hint`s as defined.
I use these two helpful aliases to quickly add and remove the local
proxy from Git's config:
```shell
[alias]
mitm = "!f(){ git config --global http.proxy 'http://127.0.0.1:8080'; }; f"
unmitm = "!f(){ git config --global --unset http.proxy; }; f"
```7 files changed
+558
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
437 | 458 | | |
438 | 459 | | |
439 | 460 | | |
| |||
863 | 884 | | |
864 | 885 | | |
865 | 886 | | |
| 887 | + | |
866 | 888 | | |
867 | 889 | | |
868 | 890 | | |
| |||
877 | 899 | | |
878 | 900 | | |
879 | 901 | | |
| 902 | + | |
880 | 903 | | |
881 | 904 | | |
882 | 905 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
528 | 555 | | |
529 | 556 | | |
530 | 557 | | |
| |||
964 | 991 | | |
965 | 992 | | |
966 | 993 | | |
| 994 | + | |
967 | 995 | | |
968 | 996 | | |
969 | 997 | | |
| |||
991 | 1019 | | |
992 | 1020 | | |
993 | 1021 | | |
| 1022 | + | |
994 | 1023 | | |
995 | 1024 | | |
996 | 1025 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
0 commit comments