Update ssh.kt with all files
This commit is contained in:
parent
942b7ab3a9
commit
72ed2951ee
1 changed files with 24 additions and 2 deletions
|
@ -6,7 +6,9 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.check
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFileFromResource
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFileFromResource
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled
|
||||||
|
|
||||||
|
val pathSshConfig = "/etc/ssh/ssh_config"
|
||||||
val pathSshdConfig = "/etc/ssh/sshd_config"
|
val pathSshdConfig = "/etc/ssh/sshd_config"
|
||||||
|
val pathSshdHardeningConfig = "/etc/ssh/sshd_config.d/sshd_hardening.conf"
|
||||||
val packageNameSshServer = "openssh-server"
|
val packageNameSshServer = "openssh-server"
|
||||||
val resourcePathSsh = "org/domaindrivenarchitecture/provs/server/infrastructure/ssh/"
|
val resourcePathSsh = "org/domaindrivenarchitecture/provs/server/infrastructure/ssh/"
|
||||||
|
|
||||||
|
@ -14,14 +16,34 @@ fun Prov.isSshdConfigExisting(): Boolean {
|
||||||
return checkFile(pathSshdConfig)
|
return checkFile(pathSshdConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.configureSshd() = task {
|
fun Prov.isSshConfigExisting(): Boolean {
|
||||||
if(isSshdConfigExisting() && isPackageInstalled(packageNameSshServer)) {
|
return checkFile(pathSshConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Prov.isSshdHardeningConfigExisting(): Boolean {
|
||||||
|
return checkFile(pathSshdHardeningConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Prov.configureSsh() = task {
|
||||||
|
if(isSshdConfigExisting() && isSshConfigExisting() && isSshdHardeningConfigExisting() && isPackageInstalled(packageNameSshServer)) {
|
||||||
|
createFileFromResource(
|
||||||
|
pathSshConfig,
|
||||||
|
"ssh_config",
|
||||||
|
resourcePathSsh,
|
||||||
|
"644",
|
||||||
|
true)
|
||||||
createFileFromResource(
|
createFileFromResource(
|
||||||
pathSshdConfig,
|
pathSshdConfig,
|
||||||
"sshd_config",
|
"sshd_config",
|
||||||
resourcePathSsh,
|
resourcePathSsh,
|
||||||
"644",
|
"644",
|
||||||
true)
|
true)
|
||||||
|
createFileFromResource(
|
||||||
|
pathSshdHardeningConfig,
|
||||||
|
"sshd_hardening.conf",
|
||||||
|
resourcePathSsh,
|
||||||
|
"644",
|
||||||
|
true)
|
||||||
cmd("service ssh restart", sudo = true)
|
cmd("service ssh restart", sudo = true)
|
||||||
} else {
|
} else {
|
||||||
ProvResult(false)
|
ProvResult(false)
|
||||||
|
|
Loading…
Reference in a new issue