Skip to content

Commit

Permalink
Merge pull request #1384 from srl-labs/fix-authkeys
Browse files Browse the repository at this point in the history
Fix pub keys population
  • Loading branch information
hellt committed May 16, 2023
2 parents 460deb4 + bbe9579 commit 8c91af2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions clab/authz_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const (
func (c *CLab) CreateAuthzKeysFile() error {
b := new(bytes.Buffer)

p := utils.ResolvePath(pubKeysGlob, c.TopoPaths.TopologyFileDir())
p := utils.ResolvePath(pubKeysGlob, "")

all, err := filepath.Glob(p)
if err != nil {
return fmt.Errorf("failed globbing the path %s", p)
}

f := utils.ResolvePath(authzKeysFPath, c.TopoPaths.TopologyFileDir())
f := utils.ResolvePath(authzKeysFPath, "")

if utils.FileExists(f) {
log.Debugf("%s found, adding the public keys it contains", f)
Expand All @@ -47,7 +47,15 @@ func (c *CLab) CreateAuthzKeysFile() error {
log.Debugf("found public key files %q", all)

for _, fn := range all {
rb, _ := os.ReadFile(fn)
rb, err := os.ReadFile(fn)
if err != nil {
return fmt.Errorf("failed reading the file %s: %v", fn, err)
}
// ensure the key ends with a newline
if !bytes.HasSuffix(rb, []byte("\n")) {
rb = append(rb, []byte("\n")...)
}

b.Write(rb)
}

Expand Down
1 change: 1 addition & 0 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func (c *CLab) scheduleNodes(ctx context.Context, maxWorkers int,
&nodes.PreDeployParams{
Cert: c.Cert,
TopologyName: c.Config.Name,
TopoPaths: c.TopoPaths,
},
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions nodes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func SetNonDefaultRuntimePerKind(kindnames []string, runtime string) error {
type PreDeployParams struct {
Cert *cert.Cert
TopologyName string
TopoPaths *types.TopoPaths
}

// DeployParams contains parameters for the Deploy function.
Expand Down
2 changes: 1 addition & 1 deletion nodes/srl/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (s *srl) PreDeploy(_ context.Context, params *nodes.PreDeployParams) error
}

// mount authorized_keys file to enable passwordless login
authzKeysPath := filepath.Join(filepath.Dir(s.Cfg.LabDir), "authorized_keys")
authzKeysPath := params.TopoPaths.AuthorizedKeysFilename()
if utils.FileExists(authzKeysPath) {
s.Cfg.Binds = append(s.Cfg.Binds,
fmt.Sprint(authzKeysPath, ":/root/.ssh/authorized_keys:ro"),
Expand Down

0 comments on commit 8c91af2

Please sign in to comment.