sdk/enter: unconditionally unset GNUGHOME
Always unset GNUPGHOME since if there is a ~/.gnupg we're bind mounting
then we're always binding it to the default for GNUPGHOME and if there's
not, we don't want to touch GPG at all, so we should not carry over the
environment variable.
@@ -182,17 +182,19 @@ func (e *enter) mountGnupg() error {
origHome = filepath.Join(e.User.HomeDir, ".gnupg")
}
+ // gpg misbehaves in the SDK with GNUPGHOME set to anything but
+ // ~/.gnupg. New SDKs don't encounter this problem because GNUPGHOME
+ // is no longer included in the sudo env_keep list. For old SDKs,
+ // unset GNUPGHOME so the default ~/.gnupg is used.
+ if err := os.Unsetenv("GNUPGHOME"); err != nil {
+ return err
+ }
+
if _, err := os.Stat(origHome); err != nil {
// Skip but do not bind mount anything
return nil
}
- // gpg misbehaves in the sdk with GNUPGHOME set to anything but ~/.gnupg
- // so always unset it so the default ~/.gnupg is used.
- if err := os.Unsetenv("GNUPGHOME"); err != nil {
- return err
- }
-
// now mount the agent socket directory through
newHome := filepath.Join(e.Chroot, e.User.HomeDir, ".gnupg")
if err := system.Bind(origHome, newHome); err != nil {
