Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: userdata not executable due to umask #19987

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions pkg/hostman/guestfs/fsdriver/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *sLinuxRootFs) deployUserDataByCron(userData string) error {
if err != nil {
return errors.Wrap(err, "chmod user_data fail")
}
cron := fmt.Sprintf("@reboot %s\n", userDataPath)
cron := fmt.Sprintf("@reboot /bin/sh %s\n", userDataPath)
err = d.rootFs.FilePutContents(userDataCronPath, cron, false, false)
if err != nil {
return errors.Wrap(err, "save user_data cron fail")
Expand Down Expand Up @@ -89,7 +89,7 @@ func (d *sLinuxRootFs) deployUserDataBySystemd(userData string) error {
}
}
{
err := d.installInitScript(serviceName, scriptPath)
err := d.installInitScript(serviceName, "/bin/sh "+scriptPath)
if err != nil {
return errors.Wrap(err, "installInitScript")
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/hostman/guestfs/sshpart/sshclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sshpart

import "yunion.io/x/log"

type ISSHClient interface {
Run(cmds ...string) ([]string, error)
}

type sFakeSshClient struct {
}

func (c *sFakeSshClient) Run(cmds ...string) ([]string, error) {
log.Debugf("run cmds: %s", cmds)
return []string{}, nil
}
4 changes: 2 additions & 2 deletions pkg/hostman/guestfs/sshpart/sshpart.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ import (
)

type SSHPartition struct {
term *ssh.Client
term ISSHClient // *ssh.Client
partDev string
mountPath string
isLVM bool
}

var _ fsdriver.IDiskPartition = &SSHPartition{}

func NewSSHPartition(term *ssh.Client, partDev string, isLVM bool) *SSHPartition {
func NewSSHPartition(term ISSHClient, partDev string, isLVM bool) *SSHPartition {
p := new(SSHPartition)
p.term = term
p.partDev = partDev
Expand Down
29 changes: 9 additions & 20 deletions pkg/hostman/guestfs/sshpart/sshpart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,35 @@

package sshpart

// TODO: rewrite this test
/*
import (
//"syscall"
"testing"

"yunion.io/x/log"

"yunion.io/x/onecloud/pkg/cloudcommon/sshkeys"
"yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
"yunion.io/x/onecloud/pkg/util/ssh"
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
)

var defaultSSHClient *ssh.Client
var defaultSSHClient ISSHClient

func init() {
var err error
defaultSSHClient, err = ssh.NewClient("192.168.0.254", 22, "root", "oYA79tAcs4A1X4uT", "")
if err != nil {
log.Fatalf("Connect to ssh client error: %v", err)
}
defaultSSHClient = &sFakeSshClient{}
}

func TestNewSSHPartition(t *testing.T) {
dev := NewSSHPartition(defaultSSHClient, "/dev/sda2")
//err := dev.Mount()
//if err != nil {
//t.Errorf("Mount error: %v", err)
//return
//}
//defer func() { dev.Unmount() }()
dev := NewSSHPartition(defaultSSHClient, "/dev/sda2", false)
log.Infof("%v", dev.Exists("/", false))
log.Infof("%v", dev.Exists("/etc/", false))
log.Infof("%v", dev.ListDir("/", false))
dev.Mkdir("/tmp/test123", 0777, false)
dev.Chmod("/", 0777, false)
dev.FilePutContents("/tmp/test123/content", "test1234\nhhhh", true, false)
pubkeys := &sshkeys.SSHKeys{
pubkeys := &apis.SSHKeys{
PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz0BLJD+xXYd3AP26uFs42mQSoznPew6gC84P9eUEAJHdkT/8WqTJV0z9M8ZU+8UbuR3iTSbblatrZepPkU2KkvE9ZkFftCIGCWCgvRWFfrDdMF1jwGYtKDg1xVxCmxzTgR+NCuE7HIyDsNL/IKbIVH6QMCxwAIdxHrAT4WdVvkDrD5ihSmIMgnmbCSidok8N7l9zECN54EccV3LGaABumtO5Y7Um7HRm+gdc6esg3HTkIXW402w92zaeHaqm4EGek/FB24WhIcwSErMhXnnHPoAATNzWD+3RQZo2po+95FE/oZw7QO7hG9lWmCDYpJNim+Ix35ftYs1j1S4hray3z lzx@lzx-t470p",
}
err := fsdriver.DeployAuthorizedKeys(dev, "/home/cloudroot", pubkeys, true)
err := fsdriver.DeployAuthorizedKeys(dev, "/home/cloudroot", pubkeys, true, false)
if err != nil {
log.Errorf("Deploy keys error: %v", err)
}
}*/
}
Loading