Enforce authorized_keys from restrictions
This commit is contained in:
@@ -223,6 +223,14 @@ fn start_echo_server() -> u16 {
|
||||
}
|
||||
|
||||
fn write_native_client_auth(dir: &tempfile::TempDir, config_path: &std::path::Path) {
|
||||
write_native_client_auth_with_options(dir, config_path, "");
|
||||
}
|
||||
|
||||
fn write_native_client_auth_with_options(
|
||||
dir: &tempfile::TempDir,
|
||||
config_path: &std::path::Path,
|
||||
options: &str,
|
||||
) {
|
||||
let ssh_dir = dir.path().join(".ssh");
|
||||
fs::create_dir_all(&ssh_dir).unwrap();
|
||||
let signing = ed25519_dalek::SigningKey::from_bytes(&[42u8; 32]);
|
||||
@@ -232,11 +240,13 @@ fn write_native_client_auth(dir: &tempfile::TempDir, config_path: &std::path::Pa
|
||||
private
|
||||
.write_openssh_file(&ssh_dir.join("id_ed25519"), ssh_key::LineEnding::LF)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
dir.path().join("authorized_keys"),
|
||||
format!("{}\n", private.public_key().to_openssh().unwrap()),
|
||||
)
|
||||
.unwrap();
|
||||
let public = private.public_key().to_openssh().unwrap();
|
||||
let line = if options.is_empty() {
|
||||
public
|
||||
} else {
|
||||
format!("{options} {public}")
|
||||
};
|
||||
fs::write(dir.path().join("authorized_keys"), format!("{line}\n")).unwrap();
|
||||
|
||||
let config = load_server_config(Some(config_path.to_path_buf())).unwrap();
|
||||
let host_signing = load_or_create_host_key(&config).unwrap();
|
||||
@@ -556,6 +566,21 @@ fn native_attach_only_smoke() {
|
||||
assert!(stderr.contains("terminal_ready"), "stderr={stderr}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_attach_enforces_authorized_keys_from_option() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let port = free_udp_port();
|
||||
let config = write_server_config(&dir, port);
|
||||
write_native_client_auth_with_options(&dir, &config, "from=\"10.99.0.0/16\"");
|
||||
let mut server = start_server(&dir, &config);
|
||||
let output = native_attach_once(&dir, port);
|
||||
let _ = server.kill();
|
||||
let _ = server.wait();
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(!output.status.success(), "stderr={stderr}");
|
||||
assert!(stderr.contains("from="), "stderr={stderr}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_attach_only_smoke_uses_ssh_agent() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user