Skip to content

Support RKT in validating #12

Description

@zenlint

If we want to support rkt in validation tool, I find out that some of the container end test programms should be different from the runc.
For example, for vallidate specs.Process, we use command below,

cmdlineBytes, err := ioutil.ReadFile("/proc/1/cmdline")
    if err != nil {
        return err
    }

    args := strings.Split(string(bytes.Trim(cmdlineBytes, "\x00")), " ")
    if len(args) != len(spec.Process.Args) {
        return fmt.Errorf("Process arguments expected: %v, actual: %v")
    }
    for i, a := range args {
        if a != spec.Process.Args[i] {
            return fmt.Errorf("Process arguments expected: %v, actual: %v", a, spec.Process.Args[i])
        }
    }

However, the /proc/1/cmdline in rkt contains systemd args, so the code logic in validating specs.Process.Args should be different with runc.

List my suggestion as below,
First, split the validation programme into seperate samples, such as,

func main() {
    app := cli.NewApp()
    app.Name = "oci-runtimeValidate"
    app.Version = "0.0.1"
    app.Usage = "Utilities for OCI runtime validation"
    app.EnableBashCompletion = true

    app.Commands = []cli.Command{
        {
            Name:    "validateOverall",
            Aliases: []string{"va"},
            Usage:   "Validate overall specs",
            Action: func(c *cli.Context) {
                validations := []validation{
                    validateHooks,
                    validateSelinux,
                    validateSeccomp,
                                        ...
                }

                for _, v := range validations {
                    if err := v(spec, rspec); err != nil {
                        logrus.Fatalf("Validation failed: %q", err)
                    }
                }
            },
        },
        {
            Name:    "validateSeccomp",
            Aliases: []string{"vse"},
            Usage:   "Validate Seccomp with specs",
            Action: func(c *cli.Context) {
                if err := validateSeccomp(spec, rspec); err != nil {
                    logrus.Fatalf("Validation failed: %q", err)
                }
            },
        },
        {
            Name:    "validateHooks",
            Aliases: []string{"vho"},
            Usage:   "Validate Hooks with specs",
            Action: func(c *cli.Context) {
                if err := validateHooks(spec, rspec); err != nil {
                    logrus.Fatalf("Validation failed: %q", err)
                }
            },
        },
        {
            Name:    "validateSelinux",
            Aliases: []string{"vsel"},
            Usage:   "Validate selinuxlabel with specs",
            Action: func(c *cli.Context) {
                if err := validateSelinux(spec, rspec); err != nil {
                    logrus.Fatalf("Validation failed: %q", err)
                }
            },
        },
...

With this way, we will have benifits as below,

  1. To do less job in container end with each case, lead to the same effort.
  2. Cases which have different realization in container end have less impect to others.
  3. Because we use the standard default template of specs in validate, so we have no need to validate all of the items every time.

What is your opinion? Expect to your response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions