1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 14:48:55 +00:00

Use the kernel cmdline elide patch to load config into RancherOS that isn't visible in /pro/cmdline

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2017-03-11 00:23:22 +10:00
parent 4981e76755
commit f6ce1f0685
7 changed files with 45 additions and 3 deletions

0
config/config_test.go Normal file → Executable file
View File

0
config/data_funcs.go Normal file → Executable file
View File

11
config/disk.go Normal file → Executable file
View File

@@ -69,6 +69,17 @@ func LoadConfigWithPrefix(dirPrefix string) *CloudConfig {
return cfg
}
func SaveInitCmdline(cmdLineArgs string) {
log.Infof("INITINIT: %s", cmdLineArgs)
elidedCfg := parseCmdline(cmdLineArgs)
log.Infof("SaveInitCmdline: %#v", elidedCfg)
if err := WriteToFile(elidedCfg, CloudConfigInitFile); err != nil {
log.Errorf("Failed to write init-cmdline config: %s", err)
}
}
func CloudConfigDirFiles(dirPrefix string) []string {
cloudConfigDir := path.Join(dirPrefix, CloudConfigDir)

View File

@@ -40,6 +40,7 @@ const (
OsConfigFile = "/usr/share/ros/os-config.yml"
VarRancherDir = "/var/lib/rancher"
CloudConfigDir = "/var/lib/rancher/conf/cloud-config.d"
CloudConfigInitFile = "/var/lib/rancher/conf/cloud-config.d/init.yml"
CloudConfigBootFile = "/var/lib/rancher/conf/cloud-config.d/boot.yml"
CloudConfigNetworkFile = "/var/lib/rancher/conf/cloud-config.d/network.yml"
CloudConfigScriptFile = "/var/lib/rancher/conf/cloud-config-script"
@@ -85,9 +86,9 @@ type Repository struct {
type Repositories map[string]Repository
type CloudConfig struct {
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
WriteFiles []File `yaml:"write_files"`
Hostname string `yaml:"hostname"`
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
WriteFiles []File `yaml:"write_files,omitempty"`
Hostname string `yaml:"hostname,omitempty"`
Mounts [][]string `yaml:"mounts,omitempty"`
Rancher RancherConfig `yaml:"rancher,omitempty"`
Runcmd []yaml.StringandSlice `yaml:"runcmd,omitempty"`

View File

@@ -227,6 +227,13 @@ func RunInit() error {
func(c *config.CloudConfig) (*config.CloudConfig, error) {
return c, dfs.PrepareFs(&mountConfig)
},
func(c *config.CloudConfig) (*config.CloudConfig, error) {
// will this be passed to cloud-init-save?
cmdLineArgs := strings.Join(os.Args, " ")
config.SaveInitCmdline(cmdLineArgs)
return c, nil
},
mountOem,
func(_ *config.CloudConfig) (*config.CloudConfig, error) {
cfg := config.LoadConfig()
@@ -303,6 +310,7 @@ func RunInit() error {
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
filesToCopy := []string{
config.CloudConfigInitFile,
config.CloudConfigBootFile,
config.CloudConfigNetworkFile,
config.MetaDataFile,

View File

@@ -29,6 +29,10 @@ while [ "$#" -gt 0 ]; do
shift 1
QEMU_APPEND="${QEMU_APPEND} $1"
;;
--append-init)
shift 1
APPEND_INIT="${APPEND_INIT} $1"
;;
--memory)
shift 1
MEMORY="$1"
@@ -125,6 +129,9 @@ fi
if [ "$RM_USR" == "1" ]; then
KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr"
fi
if [ "$APPEND_INIT" != "" ]; then
KERNEL_ARGS="${KERNEL_ARGS} -- ${APPEND_INIT}"
fi
if [ "$BOOT_PXE" == "1" ]; then
sudo pixiecore boot \

15
tests/cmdline_test.go Executable file
View File

@@ -0,0 +1,15 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestElideCmdLine(c *C) {
runArgs := []string{
"--fresh",
"--append-init",
"cc.hostname=nope rancher.debug=true",
}
s.RunQemuWith(c, runArgs...)
s.CheckOutput(c, "nope\n", Equals, "hostname")
s.CheckOutput(c, "printk.devkmsg=on rancher.debug=true rancher.password=rancher console=ttyS0 rancher.autologin=ttyS0 rancher.state.dev=LABEL=RANCHER_STATE rancher.state.autoformat=[/dev/sda,/dev/vda] rancher.rm_usr -- \n", Equals, "cat /proc/cmdline")
}