Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"bytes"
"crypto/tls"
"encoding/base64"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net"
"net/url"
Expand Down Expand Up @@ -91,7 +93,10 @@ type FileConfig struct {
func ReadFromFile(filePath string) (*FileConfig, error) {
f, err := os.Open(filePath)
if err != nil {
return nil, trace.Wrap(err, fmt.Sprintf("failed to open file: %v", filePath))
if errors.Is(err, fs.ErrPermission) {
return nil, trace.Wrap(err, "failed to open file for Teleport configuration: %v. Ensure that you are running as a user with appropriate permissions.", filePath)
}
return nil, trace.Wrap(err, "failed to open file for Teleport configuration at %v", filePath)
}
defer f.Close()
return ReadConfig(f)
Expand Down
8 changes: 8 additions & 0 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/hex"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -623,6 +625,9 @@ func NewTeleport(cfg *Config) (*TeleportProcess, error) {
if os.IsNotExist(err) {
err := os.MkdirAll(cfg.DataDir, os.ModeDir|0700)
if err != nil {
if errors.Is(err, fs.ErrPermission) {
cfg.Log.Errorf("Teleport does not have permission to write to: %v. Ensure that you are running as a user with appropriate permissions.", cfg.DataDir)
}
return nil, trace.ConvertSystemError(err)
}
}
Expand Down Expand Up @@ -659,6 +664,9 @@ func NewTeleport(cfg *Config) (*TeleportProcess, error) {
cfg.Log.Infof("Generating new host UUID: %v.", cfg.HostUUID)
}
if err := utils.WriteHostUUID(cfg.DataDir, cfg.HostUUID); err != nil {
if errors.Is(err, fs.ErrPermission) {
cfg.Log.Errorf("Teleport does not have permission to write to: %v. Ensure that you are running as a user with appropriate permissions.", cfg.DataDir)
}
return nil, trace.Wrap(err)
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package utils

import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net"
"net/url"
Expand Down Expand Up @@ -437,8 +439,12 @@ func ReadHostUUID(dataDir string) (string, error) {

// WriteHostUUID writes host UUID into a file
func WriteHostUUID(dataDir string, id string) error {
err := ioutil.WriteFile(filepath.Join(dataDir, HostUUIDFile), []byte(id), os.ModeExclusive|0400)
err := os.WriteFile(filepath.Join(dataDir, HostUUIDFile), []byte(id), os.ModeExclusive|0400)
if err != nil {
if errors.Is(err, fs.ErrPermission) {
//do not convert to system error as this loses the ability to compare that it is a permission error
Comment thread
stevenGravy marked this conversation as resolved.
return err
}
return trace.ConvertSystemError(err)
}
return nil
Expand Down