|
1 | 1 | #![allow(clippy::disallowed_types)]
|
2 | 2 |
|
3 | 3 | use crate::common::{
|
4 |
| - READ_ONLY_GITHUB_TOKEN, SSH_DEPLOY_KEY, TestContext, apply_filters, decode_token, uv_snapshot, |
| 4 | + READ_ONLY_GITHUB_SSH_DEPLOY_KEY, READ_ONLY_GITHUB_TOKEN, TestContext, apply_filters, |
| 5 | + decode_token, uv_snapshot, |
5 | 6 | };
|
6 | 7 | use anyhow::{Ok, Result};
|
7 | 8 | use assert_cmd::assert::OutputAssertExt;
|
@@ -1176,12 +1177,14 @@ fn requirements_txt_https_git_credentials() -> Result<()> {
|
1176 | 1177 | Ok(())
|
1177 | 1178 | }
|
1178 | 1179 |
|
1179 |
| -/// SSH blocks too permissive key files. |
1180 |
| -fn reduce_key_permissions(key_file: &Path) -> Result<()> { |
| 1180 | +/// SSH blocks too permissive key files, so we need to scope permissions for the file to the current |
| 1181 | +/// user. |
| 1182 | +fn reduce_ssh_key_file_permissions(key_file: &Path) -> Result<()> { |
1181 | 1183 | #[cfg(unix)]
|
1182 | 1184 | {
|
1183 | 1185 | use std::fs::Permissions;
|
1184 | 1186 | use std::os::unix::fs::PermissionsExt;
|
| 1187 | + |
1185 | 1188 | fs_err::set_permissions(key_file, Permissions::from_mode(0o400))?;
|
1186 | 1189 | }
|
1187 | 1190 | #[cfg(windows)]
|
@@ -1223,9 +1226,10 @@ fn requirements_txt_ssh_git_username() -> Result<()> {
|
1223 | 1226 |
|
1224 | 1227 | let fake_deploy_key = context.temp_dir.child("fake_deploy_key");
|
1225 | 1228 | fake_deploy_key.write_str("not a key")?;
|
1226 |
| - reduce_key_permissions(&fake_deploy_key)?; |
| 1229 | + reduce_ssh_key_file_permissions(&fake_deploy_key)?; |
1227 | 1230 |
|
1228 |
| - // Ensure that we're loading the key and fail if it isn't present |
| 1231 | + // Ensure that we fail without passing the correct key (and don't go to the dev machine's |
| 1232 | + // credential helper). |
1229 | 1233 | let failing_git_ssh_command = format!(
|
1230 | 1234 | "ssh -i {} -o IdentitiesOnly=yes -F /dev/null -o StrictHostKeyChecking=no",
|
1231 | 1235 | fake_deploy_key.portable_display()
|
@@ -1266,8 +1270,8 @@ fn requirements_txt_ssh_git_username() -> Result<()> {
|
1266 | 1270 | "#);
|
1267 | 1271 |
|
1268 | 1272 | let ssh_deploy_key = context.temp_dir.child("uv_test_key");
|
1269 |
| - ssh_deploy_key.write_str((decode_token(&[SSH_DEPLOY_KEY]) + "\n").as_str())?; |
1270 |
| - reduce_key_permissions(&ssh_deploy_key)?; |
| 1273 | + ssh_deploy_key.write_str((decode_token(&[READ_ONLY_GITHUB_SSH_DEPLOY_KEY]) + "\n").as_str())?; |
| 1274 | + reduce_ssh_key_file_permissions(&ssh_deploy_key)?; |
1271 | 1275 |
|
1272 | 1276 | // Use the specified SSH key, and only that key, ignore `~/.ssh/config`, disable host key
|
1273 | 1277 | // verification for Windows.
|
|
0 commit comments