Running a script on user logs in

Continuing the discussion from Callback or hook to run a script when a user logs in. I’m trying to solve this scenario :

  • create the user’s home directory if it doesn’t exists
  • generate SSH keys if not present

I’m using AD auth and SSSD have been configured with a fallback home directory. In addition I’ve added a script in profile.d to generate SSH keys.

That works perfectly when I logon in a shell session and running “su foo” from root.
However when accessing OOD, I’m getting an Home Directory not found error, and even if I create it the script in profile.d is not run.

What would be the best way of implementing this ? How can I get the username if I implement the solution suggested in the link above which is replacing /opt/ood/ondemand/root/usr/sbin/nginx by a bootstrap script ?

Thanks,
Xavier

You can try the pun_pre_hook_root_cmd. This will run in a root context, so you’ll have to su to the user. It’s what we use to set up kubernetes credentials before the pun boots up.

https://osc.github.io/ood-documentation/latest/reference/files/ood-portal-yml.html?highlight=pre_hook

1 Like

So I confirm that adding a pun_pre_hook_roo_cmd calling a script works.
This script simply contains these lines :

#!/bin/bash
su - $2

$2 may change at some point in the future. I mean I see how easy that is for you, and I don’t anticipate it changing, but there interface there is named parameters (i.e., --user <someuser>).

Just something to be aware of - again, I don’t anticipate it changing, but I chose to use named parameters for this reason, so we could change the order if required (and believe documentation reflects that).

Make sense, will do the update accordingly