From 860dcb2fd87fa69edab0a46b86c68fb89ec448e7 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 1 Feb 2023 11:36:53 +0100 Subject: [PATCH] Read password from stdin Add warning to password prompt. --- .../provs/framework/core/cli/CliUtils.kt | 5 +++-- .../provs/framework/ubuntu/user/base/User.kt | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt index 7df1a52..76164fd 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt @@ -47,11 +47,12 @@ fun createProvInstance( } } - private fun createLocalProvInstance(): Prov { val prov = local() + prov.cmd("sudo -K") // revoke any temporary sudo privileges if (!prov.currentUserCanSudo()) { - val password = PromptSecretSource("Please enter password to configure sudo without password in the future.").secret() + val password = PromptSecretSource("Please enter password to configure sudo without password in the future." + + "\nWarning: This will permanently allow your user to use sudo privileges without a password.").secret() prov.makeUserSudoerWithNoSudoPasswordRequired(password) } return prov diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt index 7da1ec4..233f275 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt @@ -132,10 +132,9 @@ fun Prov.userIsInGroupSudo(userName: String): Boolean { */ @Suppress("unused") fun Prov.currentUserCanSudo(): Boolean { - return chk("timeout 1 sudo id") + return chk("timeout 1 sudo -S id") } - /** * Returns username of current user if it can be determined */