From 4a4da2c080dd2f7a7d899a074e378c0d66ce43f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Sat, 29 Apr 2023 00:02:33 +0200 Subject: [PATCH] Fix owner issue --- containers/types.go | 24 +++++++++++++++++++++--- glue/main.go | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/containers/types.go b/containers/types.go index a60442c..04859dc 100644 --- a/containers/types.go +++ b/containers/types.go @@ -15,6 +15,7 @@ import ( // username in the containers under which all containers run const appUsername = "app" +const owner = "app:app" const passwordFile = "/srv/.rosti" const deployKeyType = "ed25519" 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 { 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 { return err } @@ -338,6 +346,16 @@ func (c *Container) AppendFile(filename string, text string, mode string) error 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 } @@ -381,12 +399,12 @@ func (c *Container) SetFileContent(filename string, text string, mode string) er 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 { 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 { return err } diff --git a/glue/main.go b/glue/main.go index a4319e8..5595ec5 100644 --- a/glue/main.go +++ b/glue/main.go @@ -456,7 +456,7 @@ func (p *Processor) UpdateKeys(keys string) error { return err } - err = container.SetFileContent(sshPubKeysLocation, keys+"\n", "0600") + err = container.AppendFile(sshPubKeysLocation, keys+"\n", "0600") if err != nil { return err }