Skip to content

Commit 2db4320

Browse files
committed
revise adr to support ssh
1 parent f858c22 commit 2db4320

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

adrs/0153-checkout-v2.md

+59-9
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
2727
event. Otherwise, defaults to `master`.
2828
token:
2929
description: >
30-
Auth token used to fetch the repository. The token is stored in the local
31-
git config, which enables your scripts to run authenticated git commands.
32-
The post-job step removes the token from the git config. [Learn more about
33-
creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
30+
Personal access token (PAT) used to fetch the repository. The PAT is configured
31+
with the local git config, which enables your scripts to run authenticated git
32+
commands. The post-job step removes the PAT. [Learn more about creating and using
33+
encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
3434
default: ${{ github.token }}
35+
ssh-key:
36+
description: >
37+
SSH key used to fetch the repository. SSH key is configured with the local
38+
git config, which enables your scripts to run authenticated git commands.
39+
The post-job step removes the SSH key. [Learn more about creating and using
40+
encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
41+
ssh-known-hosts:
42+
description: >
43+
Known hosts in addition to the user and global host key database. The public
44+
SSH keys for a host may be obtained using the utility `ssh-keyscan`. For example,
45+
`ssh-keyscan github.com`. The public key for github.com is always implicitly added.
46+
ssh-strict:
47+
description: 'Whether to perform strict host key checking'
48+
default: true
3549
persist-credentials:
36-
description: 'Whether to persist the token in the git config'
50+
description: 'Whether to configure the token or SSH key with the local git config'
3751
default: true
3852
path:
3953
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
@@ -49,6 +63,7 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
4963
```
5064
5165
Note:
66+
- SSH support is new
5267
- `persist-credentials` is new
5368
- `path` behavior is different (refer [below](#path) for details)
5469
- `submodules` was removed (error if specified; add later if needed)
@@ -63,19 +78,54 @@ Note:
6378

6479
### Persist credentials
6580

66-
Persist the token in the git config (http.extraheader). This will allow users to script authenticated git commands, like `git fetch`.
81+
The credentials will be persisted on disk. This will allow users to script authenticated git commands, like `git fetch`.
6782

68-
A post script will remove the credentials from the git config (cleanup for self-hosted).
83+
A post script will remove the credentials (cleanup for self-hosted).
6984

7085
Users may opt-out by specifying `persist-credentials: false`
7186

7287
Note:
7388
- Users scripting `git commit` may need to set the username and email. The service does not provide any reasonable default value. Users can add `git config user.name <NAME>` and `git config user.email <EMAIL>`. We will document this guidance.
74-
- The auth header (stored in the repo's git config), is scoped to all of github `http.https://github.com/.extraheader`
89+
90+
#### PAT
91+
92+
When using the `${{github.token}}` or a PAT, the token will be persisted in the local git config. The config key `http.https://github.com/.extraheader` enables an auth header to be specified on all authenticated commands `AUTHORIZATION: basic <BASE64_U:P>`.
93+
94+
Note:
95+
- The auth header is scoped to all of github `http.https://github.com/.extraheader`
7596
- Additional public remotes also just work.
7697
- If users want to authenticate to an additional private remote, they should provide the `token` input.
7798
- Lines up if we add submodule support in the future. Don't need to worry about calculating relative URLs. Just works, although needs to be persisted in each submodule git config.
78-
- Users opt out of persisted credentials (`persist-credentials: false`), or can script the removal themselves (`git config --unset-all http.https://github.com/.extraheader`).
99+
100+
#### SSH key
101+
102+
The SSH key will be written to disk under the `$RUNNER_TEMP` directory. The SSH key will
103+
be removed by the action's post-job hook. Additionally, RUNNER_TEMP is cleared by the
104+
runner between jobs.
105+
106+
The SSH key must be written with strict file permissions. The SSH client requires the file
107+
to be read/write for the user, and not accessible by others.
108+
109+
The user host key database (`~/.ssh/known_hosts`) will be copied to a unique file under
110+
`$RUNNER_TEMP`. And values from the input `ssh-known-hosts` will be added to the file.
111+
112+
The SSH command will be overridden for the local git config:
113+
114+
```sh
115+
git config core.sshCommand 'ssh -i "$RUNNER_TEMP/path-to-ssh-key" -o StrictHostKeyChecking=yes -o CheckHostIP=no -o "UserKnownHostsFile=$RUNNER_TEMP/path-to-known-hosts"'
116+
```
117+
118+
When the input `ssh-strict` is set to `false`, the options `CheckHostIP` and `StrictHostKeyChecking` will not be overridden.
119+
120+
Note:
121+
- When `ssh-strict` is set to `true` (default), the SSH option `CheckHostIP` can safely be disabled.
122+
Strict host checking verifies the server's public key. Therefore, IP verification is unnecessary
123+
and noisy. For example:
124+
> Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
125+
- Since GIT_SSH_COMMAND overrides core.sshCommand, temporarily set the env var when fetching the repo. When creds
126+
are persisted, core.sshCommand is leveraged to avoid multiple checkout steps stomping over each other.
127+
- Modify actions/runner to mount RUNNER_TEMP to enable scripting authenticated git commands from a container action.
128+
- Refer [here](https://linux.die.net/man/5/ssh_config) for SSH config details.
79129

80130
### Fetch behavior
81131

0 commit comments

Comments
 (0)