Fix owner issue
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
Adam Štrauch 2023-04-29 00:02:33 +02:00
parent 617f818df4
commit 4a4da2c080
Signed by: cx
GPG Key ID: 018304FFA8988F8D
2 changed files with 22 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import (
// username in the containers under which all containers run // username in the containers under which all containers run
const appUsername = "app" const appUsername = "app"
const owner = "app:app"
const passwordFile = "/srv/.rosti" const passwordFile = "/srv/.rosti"
const deployKeyType = "ed25519" const deployKeyType = "ed25519"
const deployKeyPrefix = "rosti_deploy" const deployKeyPrefix = "rosti_deploy"
@ -328,7 +329,14 @@ func (c *Container) GetHostKey() (string, error) {
func (c *Container) AppendFile(filename string, text string, mode string) error { func (c *Container) AppendFile(filename string, text string, mode string) error {
driver := c.getDriver() driver := c.getDriver()
_, err := driver.Exec(c.App.Name, []string{"tee", "-a", filename}, text, []string{}, false) directory := path.Dir(filename)
_, err := driver.Exec(c.App.Name, []string{"mkdir", "-p", directory}, "", []string{}, false)
if err != nil {
return err
}
_, err = driver.Exec(c.App.Name, []string{"tee", "-a", filename}, text, []string{}, false)
if err != nil { if err != nil {
return err return err
} }
@ -338,6 +346,16 @@ func (c *Container) AppendFile(filename string, text string, mode string) error
return err return err
} }
_, err = driver.Exec(c.App.Name, []string{"chown", owner, directory}, "", []string{}, false)
if err != nil {
return err
}
_, err = driver.Exec(c.App.Name, []string{"chown", owner, filename}, "", []string{}, false)
if err != nil {
return err
}
return nil return nil
} }
@ -381,12 +399,12 @@ func (c *Container) SetFileContent(filename string, text string, mode string) er
return err return err
} }
_, err = driver.Exec(c.App.Name, []string{"chown", "app:app", directory}, "", []string{}, false) _, err = driver.Exec(c.App.Name, []string{"chown", owner, directory}, "", []string{}, false)
if err != nil { if err != nil {
return err return err
} }
_, err = driver.Exec(c.App.Name, []string{"chown", "app:app", filename}, "", []string{}, false) _, err = driver.Exec(c.App.Name, []string{"chown", owner, filename}, "", []string{}, false)
if err != nil { if err != nil {
return err return err
} }

View File

@ -456,7 +456,7 @@ func (p *Processor) UpdateKeys(keys string) error {
return err return err
} }
err = container.SetFileContent(sshPubKeysLocation, keys+"\n", "0600") err = container.AppendFile(sshPubKeysLocation, keys+"\n", "0600")
if err != nil { if err != nil {
return err return err
} }