@albertofaria I have limited time that I can dedicate to this so I will just dump my thoughts here and see where things go from there. Hope you don't mind :)
The subject kinda says it all, really. The fact that the first argument passed to podman exec
is interpreted as the ssh username is extremely weird and, in my opinion, should be changed.
I guess you've done it that way instead of introducing another custom command line option like --cloud-init
because you only get to hook those up for podman run
?
Anyway, I think a better way is needed. My idea is that crun-qemu could conditionally interpret the first few arguments as its own options if they are present, without requiring them to be there.
Extremely hacky POC (apologies for my Rust being terrible, haven't touched the language in months/years):
diff --git a/src/commands/exec.rs b/src/commands/exec.rs
index 7b19cfc..b9abf85 100644
--- a/src/commands/exec.rs
+++ b/src/commands/exec.rs
@@ -17,10 +17,16 @@ pub fn exec(global_args: &liboci_cli::GlobalOpts, args: &liboci_cli::Exec) -> Re
serde_json::from_reader(File::open(process_config_path).map(BufReader::new)?)?;
let command = process.args().as_ref().expect("command specified");
-
- let ssh_user = command
- .first()
- .expect("first command argument is user to ssh as into the vm");
+ let mut ssh_user = "abologna"; // TODO grab this from $USERNAME
+ let mut skip = 0;
+
+ let first_arg = command.first();
+ if first_arg.is_some() && first_arg.unwrap() == "-l" {
+ ssh_user = command
+ .get(1)
+ .expect("first command argument is user to ssh as into the vm");
+ skip = 2;
+ }
let mut new_command = vec![];
@@ -32,12 +38,12 @@ pub fn exec(global_args: &liboci_cli::GlobalOpts, args: &liboci_cli::Exec) -> Re
"-o".to_string(),
"StrictHostKeyChecking=no".to_string(),
"-l".to_string(),
- ssh_user.clone(),
+ ssh_user.to_string(),
"localhost".to_string(),
]);
}
- new_command.extend(command.iter().skip(1).cloned());
+ new_command.extend(command.iter().skip(skip).cloned());
if ssh_user == "-" && new_command.is_empty() {
new_command.push("/bin/bash".to_string());
With this patch applied and
#cloud-config
users:
- name: abologna
groups: sudo
shell: /bin/bash
sudo: 'ALL=(ALL) NOPASSWD:ALL'
ssh-authorized-keys:
- ssh-rsa AAAAB3Nza...
in examples/cloud-init/config/user-data
, I can just do
$ podman exec --latest whoami
abologna
which is much closer to the interactions I normally expect from podman. If I use the default cloud-init data, I can still do
$ podman exec --latest -- -l fedora
fedora
which is only slightly clunkier. The trade-off is IMO very much worth it.
Additionally, I think it would be very useful to adopt this model to allow for further expansion. For example:
$ podman exec --latest -- --ssh-options="-o whatever" actual-command
Let me know what you think!
enhancement good first issue