ab98ef
From 44b6004ee17cd2ae5930c7d8fd3ecafd7485a4d6 Mon Sep 17 00:00:00 2001
ab98ef
From: Eduardo Otubo <otubo@redhat.com>
ab98ef
Date: Mon, 17 Aug 2020 11:14:47 +0200
ab98ef
Subject: [PATCH 2/2] ssh exit with non-zero status on disabled user (#472)
ab98ef
ab98ef
RH-Author: Eduardo Otubo <otubo@redhat.com>
ab98ef
Message-id: <20200729074459.16096-1-otubo@redhat.com>
ab98ef
Patchwork-id: 98071
ab98ef
O-Subject: [RHEL-8.3.0 cloud-init PATCH] ssh exit with non-zero status on disabled user (#472)
ab98ef
Bugzilla: 1833874
ab98ef
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
ab98ef
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
ab98ef
ab98ef
commit e161059a18173e2b61c54dba9eab774401fb5f1f
ab98ef
Author: Eduardo Otubo <otubo@redhat.com>
ab98ef
Date:   Wed Jul 15 20:21:02 2020 +0200
ab98ef
ab98ef
    ssh exit with non-zero status on disabled user (#472)
ab98ef
ab98ef
    It is confusing for scripts, where a disabled user has been specified,
ab98ef
    that ssh exits with a zero status by default without indication anything
ab98ef
    failed.
ab98ef
ab98ef
    I think exitting with a non-zero status would make more clear in scripts
ab98ef
    and automated setups where things failed, thus making noticing the issue
ab98ef
    and debugging easier.
ab98ef
ab98ef
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ab98ef
    Signed-off-by: Aleksandar Kostadinov <akostadi@redhat.com>
ab98ef
ab98ef
    LP: #1170059
ab98ef
ab98ef
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
ab98ef
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ab98ef
---
ab98ef
 cloudinit/ssh_util.py         | 4 +++-
ab98ef
 doc/examples/cloud-config.txt | 2 +-
ab98ef
 2 files changed, 4 insertions(+), 2 deletions(-)
ab98ef
ab98ef
diff --git a/cloudinit/ssh_util.py b/cloudinit/ssh_util.py
ab98ef
index bcb23a5..8ff61a2 100644
ab98ef
--- a/cloudinit/ssh_util.py
ab98ef
+++ b/cloudinit/ssh_util.py
ab98ef
@@ -40,11 +40,13 @@ VALID_KEY_TYPES = (
ab98ef
     "ssh-rsa-cert-v01@openssh.com",
ab98ef
 )
ab98ef
 
ab98ef
+_DISABLE_USER_SSH_EXIT = 142
ab98ef
 
ab98ef
 DISABLE_USER_OPTS = (
ab98ef
     "no-port-forwarding,no-agent-forwarding,"
ab98ef
     "no-X11-forwarding,command=\"echo \'Please login as the user \\\"$USER\\\""
ab98ef
-    " rather than the user \\\"$DISABLE_USER\\\".\';echo;sleep 10\"")
ab98ef
+    " rather than the user \\\"$DISABLE_USER\\\".\';echo;sleep 10;"
ab98ef
+    "exit " + str(_DISABLE_USER_SSH_EXIT) + "\"")
ab98ef
 
ab98ef
 
ab98ef
 class AuthKeyLine(object):
ab98ef
diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt
ab98ef
index 0e82b83..f00db68 100644
ab98ef
--- a/doc/examples/cloud-config.txt
ab98ef
+++ b/doc/examples/cloud-config.txt
ab98ef
@@ -235,7 +235,7 @@ disable_root: false
ab98ef
 # The string '$USER' will be replaced with the username of the default user.
ab98ef
 # The string '$DISABLE_USER' will be replaced with the username to disable.
ab98ef
 #
ab98ef
-# disable_root_opts: no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"$USER\" rather than the user \"$DISABLE_USER\".';echo;sleep 10"
ab98ef
+# disable_root_opts: no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"$USER\" rather than the user \"$DISABLE_USER\".';echo;sleep 10;exit 142"
ab98ef
 
ab98ef
 # disable ssh access for non-root-users
ab98ef
 # To disable ssh access for non-root users, ssh_redirect_user: true can be
ab98ef
-- 
ab98ef
1.8.3.1
ab98ef