Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioalvap committed Mar 29, 2022
1 parent ae3b3fb commit 3939ad0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions heartbeat/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// TODO: Support other architectures (e.g. arm)
//go:build linux
// +build linux

Expand Down Expand Up @@ -58,7 +57,7 @@ func init() {
// Note that we discard any errors because they are not actionable.
// The beat should use `getcap` at a later point to examine available capabilities
// rather than relying on errors from `setcap`
setCapabilities()
setCapabilities() //nolint: errcheck // we discard any errors because they are not actionable

switch runtime.GOARCH {
case "amd64", "386":
Expand All @@ -74,36 +73,36 @@ func changeUser(localUserName string) error {
if err != nil {
return fmt.Errorf("could not lookup '%s': %w", localUser, err)
}
localUserUid, err := strconv.Atoi(localUser.Uid)
localUserUID, err := strconv.Atoi(localUser.Uid)
if err != nil {
return fmt.Errorf("could not parse UID '%s' as int: %w", localUser.Uid, err)
}
localUserGid, err := strconv.Atoi(localUser.Gid)
localUserGID, err := strconv.Atoi(localUser.Gid)
if err != nil {
return fmt.Errorf("could not parse GID '%s' as int: %w", localUser.Uid, err)
}
// We include the root group because the docker image contains many directories (data,logs)
// that are owned by root:root with 0775 perms. The heartbeat user is in both groups
// in the container, but we need to repeat that here.
err = syscall.Setgroups([]int{localUserGid, 0})
err = syscall.Setgroups([]int{localUserGID, 0})
if err != nil {
return fmt.Errorf("could not set groups: %w", err)
}

// Set the main group as localUserUid so new files created are owned by the user's group
err = syscall.Setgid(localUserGid)
err = syscall.Setgid(localUserGID)
if err != nil {
return fmt.Errorf("could not set gid to %d: %w", localUserGid, err)
return fmt.Errorf("could not set gid to %d: %w", localUserGID, err)
}

// Note this is not the regular SetUID! Look at the 'cap' package docs for it, it preserves
// capabilities post-SetUID, which we use to lock things down immediately
err = cap.SetUID(localUserUid)
err = cap.SetUID(localUserUID)
if err != nil {
return fmt.Errorf("could not setuid to %d: %w", localUserUid, err)
return fmt.Errorf("could not setuid to %d: %w", localUserUID, err)
}

// This may not be necessary, but is good hygeine, we do some shelling out to node/npm etc.
// This may not be necessary, but is good hygiene, we do some shelling out to node/npm etc.
// and $HOME should reflect the user's preferences
return os.Setenv("HOME", localUser.HomeDir)
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (paths *Path) InitPaths(cfg *Path) error {
// make sure the data path exists
err = os.MkdirAll(paths.Data, 0770)
if err != nil {
return fmt.Errorf("Failed to create data path %s: %v", paths.Data, err)
return fmt.Errorf("failed to create data path %s: %w", paths.Data, err)
}

return nil
Expand Down

0 comments on commit 3939ad0

Please sign in to comment.