Skip to content

Commit

Permalink
Fix logs permissions with the kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinguidee committed Sep 28, 2023
1 parent b7b4d41 commit 3095545
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion adapter/docker_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DockerCliAdapter struct {
func NewDockerCliAdapter() DockerCliAdapter {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
log.WarnKernel("couldn't connect with the Docker cli.",
log.Warn("couldn't connect with the Docker cli.",
vlog.String("error", err.Error()),
)

Expand Down
8 changes: 8 additions & 0 deletions cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func main() {

parseArgs()

checkNotRoot()

err := setupDependencies()
if err != nil {
log.Error(fmt.Errorf("failed to setup dependencies: %v", err))
Expand Down Expand Up @@ -94,6 +96,12 @@ func parseArgs() {
config.Current.Port = *flagPort
}

func checkNotRoot() {
if os.Getuid() == 0 {
log.Warn("while vertex-kernel must be run as root, the vertex user should not be root")
}
}

func setupDependencies() error {
for _, dep := range services.Dependencies {
err := setupDependency(dep.Updater)
Expand Down
44 changes: 9 additions & 35 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,30 @@ import (
)

var Default vlog.Logger
var DefaultKernel vlog.Logger

func init() {
var p string
if strings.Contains(os.Args[0], "kernel") || strings.Contains(os.Args[0], "Kernel") {
p = "live_kernel/logs"
} else {
p = "live/logs"
}

if strings.HasSuffix(os.Args[0], ".test") {
Default = *vlog.New(
vlog.WithOutputStd(),
)
DefaultKernel = *vlog.New(
vlog.WithOutputStd(),
)
Default.Info("test logger initialized")
} else {
Default = *vlog.New(
vlog.WithOutputStd(),
vlog.WithOutputFile("live/logs", vlog.LogFormatText),
vlog.WithOutputFile("live/logs", vlog.LogFormatJson),
)
DefaultKernel = *vlog.New(
vlog.WithOutputStd(),
vlog.WithOutputFile("live_kernel/logs", vlog.LogFormatText),
vlog.WithOutputFile("live_kernel/logs", vlog.LogFormatJson),
vlog.WithOutputFile(p, vlog.LogFormatText),
vlog.WithOutputFile(p, vlog.LogFormatJson),
)
Default.Info("full logger initialized")
}
}

// Vertex

func Debug(msg string, fields ...vlog.KeyValue) {
Default.Debug(msg, fields...)
}
Expand All @@ -55,25 +51,3 @@ func Error(err error, fields ...vlog.KeyValue) {
func Request(msg string, fields ...vlog.KeyValue) {
Default.Request(msg, fields...)
}

// Kernel

func DebugKernel(msg string, fields ...vlog.KeyValue) {
Default.Debug(msg, fields...)
}

func InfoKernel(msg string, fields ...vlog.KeyValue) {
Default.Info(msg, fields...)
}

func WarnKernel(msg string, fields ...vlog.KeyValue) {
Default.Warn(msg, fields...)
}

func ErrorKernel(err error, fields ...vlog.KeyValue) {
Default.Error(err, fields...)
}

func RequestKernel(msg string, fields ...vlog.KeyValue) {
Default.Request(msg, fields...)
}
10 changes: 5 additions & 5 deletions router/docker_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func handleLogsStdoutDockerContainer(c *gin.Context) {

_, err := fmt.Fprintln(w, scanner.Text())
if err != nil {
log.ErrorKernel(err)
log.Error(err)
return false
}
return true
Expand Down Expand Up @@ -179,7 +179,7 @@ func handleLogsStderrDockerContainer(c *gin.Context) {

_, err := fmt.Fprintln(w, scanner.Text())
if err != nil {
log.ErrorKernel(err)
log.Error(err)
return false
}
return true
Expand Down Expand Up @@ -250,7 +250,7 @@ func handlePullDockerImage(c *gin.Context) {

_, err := fmt.Fprintln(w, scanner.Text())
if err != nil {
log.ErrorKernel(err)
log.Error(err)
return false
}
return true
Expand Down Expand Up @@ -282,7 +282,7 @@ func handleBuildDockerImage(c *gin.Context) {

c.Stream(func(w io.Writer) bool {
if scanner.Err() != nil {
log.ErrorKernel(scanner.Err())
log.Error(scanner.Err())
return false
}

Expand All @@ -292,7 +292,7 @@ func handleBuildDockerImage(c *gin.Context) {

_, err := io.WriteString(w, scanner.Text()+"\n")
if err != nil {
log.ErrorKernel(err)
log.Error(err)
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion router/router_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *KernelRouter) Start() error {
}

url := "http://localhost:6131"
log.InfoKernel("vertex-kernel started",
log.Info("vertex-kernel started",
vlog.String("url", url),
)

Expand Down
4 changes: 2 additions & 2 deletions services/ssk_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewSSHKernelService(params *SSHKernelServiceParams) SSHKernelService {
var err error
s.authorizedKeysPath, err = getAuthorizedKeysPath()
if err != nil {
log.ErrorKernel(err)
log.Error(err)
}
}

Expand All @@ -45,7 +45,7 @@ func NewSSHKernelService(params *SSHKernelServiceParams) SSHKernelService {
func (s *SSHKernelService) GetAll() ([]types.PublicKey, error) {
bytes, err := os.ReadFile(s.authorizedKeysPath)
if err != nil && errors.Is(err, os.ErrNotExist) {
log.InfoKernel("authorized_keys file does not exist")
log.Info("authorized_keys file does not exist")
return []types.PublicKey{}, nil
} else if err != nil {
return nil, err
Expand Down

0 comments on commit 3095545

Please sign in to comment.