Clear password feature
This commit is contained in:
parent
9e82bfc2b5
commit
2077271306
@ -242,6 +242,23 @@ func (c *Container) SetPassword(password string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearPassword removes password for system user app in the container
|
||||||
|
func (c *Container) ClearPassword() error {
|
||||||
|
driver := c.getDriver()
|
||||||
|
|
||||||
|
_, err := driver.Exec(c.App.Name, []string{"passwd", "-d", "app"}, "", []string{}, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = driver.Exec(c.App.Name, []string{"rm", "-f", passwordFile}, "", []string{}, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Generate SSH keys and copies it into authorized keys
|
// Generate SSH keys and copies it into authorized keys
|
||||||
// Returns true if the key was generated in this call and error if there is any.
|
// Returns true if the key was generated in this call and error if there is any.
|
||||||
// The container has to run for this to work.
|
// The container has to run for this to work.
|
||||||
|
20
glue/main.go
20
glue/main.go
@ -591,6 +591,26 @@ func (p *Processor) SetPassword(password string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearPassword removes password from the SSH user
|
||||||
|
func (p *Processor) ClearPassword() error {
|
||||||
|
err := p.waitForApp()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
container, err := p.getContainer()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = container.ClearPassword()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Generate SSH key and adds it into authorized_keys
|
// Generate SSH key and adds it into authorized_keys
|
||||||
// These pair of keys is used for deployment.
|
// These pair of keys is used for deployment.
|
||||||
// Returns private key, pubkey and error.
|
// Returns private key, pubkey and error.
|
||||||
|
20
handlers.go
20
handlers.go
@ -212,6 +212,26 @@ func setPasswordHandler(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear password for the app user in the container
|
||||||
|
func clearPasswordHandler(c echo.Context) error {
|
||||||
|
name := c.Param("name")
|
||||||
|
|
||||||
|
processor := glue.Processor{
|
||||||
|
AppName: name,
|
||||||
|
DB: common.GetDBConnection(),
|
||||||
|
DockerSock: config.DockerSocket,
|
||||||
|
BindIPHTTP: config.AppsBindIPHTTP,
|
||||||
|
BindIPSSH: config.AppsBindIPSSH,
|
||||||
|
AppsPath: config.AppsPath,
|
||||||
|
}
|
||||||
|
err := processor.ClearPassword()
|
||||||
|
if err != nil {
|
||||||
|
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, Message{Message: "ok"})
|
||||||
|
}
|
||||||
|
|
||||||
// Copies body of the request into /srv/.ssh/authorized_keys
|
// Copies body of the request into /srv/.ssh/authorized_keys
|
||||||
func setKeysHandler(c echo.Context) error {
|
func setKeysHandler(c echo.Context) error {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
|
@ -57,6 +57,7 @@ func _messageHandler(m *nats.Msg) error {
|
|||||||
"get_active_tech": getActiveTechHandler,
|
"get_active_tech": getActiveTechHandler,
|
||||||
"update_keys": updateKeysEventHandler,
|
"update_keys": updateKeysEventHandler,
|
||||||
"set_password": setPasswordEventHandler,
|
"set_password": setPasswordEventHandler,
|
||||||
|
"clear_password": clearPasswordEventHandler,
|
||||||
"processes": processesEventHandler,
|
"processes": processesEventHandler,
|
||||||
"enable_tech": enableTechEventHandler,
|
"enable_tech": enableTechEventHandler,
|
||||||
"rebuild": rebuildEventHandler,
|
"rebuild": rebuildEventHandler,
|
||||||
@ -538,6 +539,30 @@ func setPasswordEventHandler(m *nats.Msg, message *RequestMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear password for the app user in the container
|
||||||
|
func clearPasswordEventHandler(m *nats.Msg, message *RequestMessage) error {
|
||||||
|
processor := glue.Processor{
|
||||||
|
AppName: message.AppName,
|
||||||
|
DB: common.GetDBConnection(),
|
||||||
|
SnapshotProcessor: &snapshotProcessor,
|
||||||
|
DockerSock: config.DockerSocket,
|
||||||
|
BindIPHTTP: config.AppsBindIPHTTP,
|
||||||
|
BindIPSSH: config.AppsBindIPSSH,
|
||||||
|
AppsPath: config.AppsPath,
|
||||||
|
}
|
||||||
|
err := processor.ClearPassword()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("ERROR password clearing problem: " + err.Error())
|
||||||
|
publish(message.AppName, "backend problem", true)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
publish(message.AppName, "password deleted", false)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Application processes
|
// Application processes
|
||||||
func processesEventHandler(m *nats.Msg, message *RequestMessage) error {
|
func processesEventHandler(m *nats.Msg, message *RequestMessage) error {
|
||||||
processor := glue.Processor{
|
processor := glue.Processor{
|
||||||
|
3
main.go
3
main.go
@ -174,6 +174,9 @@ func main() {
|
|||||||
// Set password for the app user in the container
|
// Set password for the app user in the container
|
||||||
e.PUT("/v1/apps/:name/password", setPasswordHandler)
|
e.PUT("/v1/apps/:name/password", setPasswordHandler)
|
||||||
|
|
||||||
|
// Clear password for the app user in the container
|
||||||
|
e.DELETE("/v1/apps/:name/password", clearPasswordHandler)
|
||||||
|
|
||||||
// Copies body of the request into /srv/.ssh/authorized_keys
|
// Copies body of the request into /srv/.ssh/authorized_keys
|
||||||
e.PUT("/v1/apps/:name/keys", setKeysHandler)
|
e.PUT("/v1/apps/:name/keys", setKeysHandler)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user