Skip to content

Commit

Permalink
Grant read permissions to group and others for the agent binary (#817)
Browse files Browse the repository at this point in the history
* Grant read permissions to group and others for the agent binary

* pwdir: don't forget to os.Chown() in case privelege dropping is used
  • Loading branch information
edigaryev authored Dec 2, 2024
1 parent 51d0322 commit 29e1bcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/executor/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func RetrieveBinary(

agentCacheDir := filepath.Join(cacheDir, "cirrus", "agent")

if err := os.MkdirAll(agentCacheDir, 0700); err != nil {
if err := os.MkdirAll(agentCacheDir, 0755); err != nil {
return "", err
}

Expand Down Expand Up @@ -78,7 +78,7 @@ func RetrieveBinary(
}

// Make the agent binary executable
if err := tmpAgentFile.Chmod(0500); err != nil {
if err := tmpAgentFile.Chmod(0544); err != nil {
return "", err
}

Expand Down
24 changes: 23 additions & 1 deletion internal/executor/instance/persistentworker/pwdir/pwdir.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pwdir

import (
"github.com/cirruslabs/cirrus-cli/pkg/privdrop"
"os"
"path/filepath"
)
Expand All @@ -12,5 +13,26 @@ func StaticTempDirWithDynamicFallback() (string, error) {
return staticTempDir, nil
}

return os.MkdirTemp("", "cirrus-build-")
// Make sure that the agent binary belongs to the privilege-dropped
// user and group, in case privilege dropping was requested
if chownTo := privdrop.ChownTo; chownTo != nil {
if err := os.Chown(staticTempDir, chownTo.UID, chownTo.GID); err != nil {
return "", err
}
}

tempDir, err := os.MkdirTemp("", "cirrus-build-")
if err != nil {
return "", err
}

// Make sure that the agent binary belongs to the privilege-dropped
// user and group, in case privilege dropping was requested
if chownTo := privdrop.ChownTo; chownTo != nil {
if err := os.Chown(tempDir, chownTo.UID, chownTo.GID); err != nil {
return "", err
}
}

return tempDir, nil
}

0 comments on commit 29e1bcd

Please sign in to comment.