nokia / nokia/corteca-cli

Entrypoint validation fails if the entrypoint is a symlink

Open
#12 0 comments 0 reactions 1 assignee View on GitHub

@aegagros is already working on this.

Since May 22, 2025.

bug
Dominant language
Go
Stars
29
Forks
12
Avg merge
19h 37m
Merged PRs (30d)
2

Description

When the first item in the entrypoint array is a symbolic link (to /bin/busybox, for example), the entrypoint validation resolves this link relative to the build machine, rather than relative to the target rootfs. So, for example, the architecture validation would check /bin/busybox for compatibility, rather than /tmp/corteca-<id>/rootfs/bin/busybox, which would cause the validation to fail unless the build and target machines are the same architecture.

A full resolution is tricky, since we can't rely on standard lib functions (filepath.EvalSymlinks() exhibits the same behaviour). A partial fix is implemented below, but it currently only handles a single level of indirection:

func ValidateRootFS(rootfsPath string, targetArch string, appSettings configuration.AppSettings) error {
	entrypointPath := filepath.Join(rootfsPath, appSettings.Entrypoint[0])

	// TODO: handle more than a single symlink degree
	entrypointInfo, err := os.Lstat(entrypointPath)
	if err != nil {
		return err
	}
	if entrypointInfo.Mode()&os.ModeSymlink != 0 {
		// construct a rootfs-based path to the symlink target
		symPath, err := os.Readlink(entrypointPath)
		if err != nil {
			return err
		}
		entrypointPath = filepath.Join(rootfsPath, symPath)
	}
	if err := validateEntrypoint(entrypointPath, targetArch); err != nil {
		return err
	}

	if err := validateMounts(rootfsPath, appSettings.Runtime.Mounts); err != nil {
		return fmt.Errorf("runtime configuration error: %w", err)
	}

	return nil
}

This issue can be worked around by specifying the actual symlink targets in the entrypoint array. For example, if we wanted the container entry point to be a shell script, instead of specifying the entrypoint as ["/bin/sh", "/path/to/start.sh"], we could specify it as follows:

entrypoint:
  - /bin/busybox
  - sh
  - /path/to/start.sh

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.