Skip to content

feat: enable ai-services to run in non-root mode#682

Open
Shubhamag12 wants to merge 5 commits intoIBM:mainfrom
Shubhamag12:non_root
Open

feat: enable ai-services to run in non-root mode#682
Shubhamag12 wants to merge 5 commits intoIBM:mainfrom
Shubhamag12:non_root

Conversation

@Shubhamag12
Copy link
Copy Markdown
Contributor

@Shubhamag12 Shubhamag12 commented Apr 27, 2026

Non-root user implementation based on proposal: #683

Comment thread ai-services/internal/pkg/bootstrap/spyreconfig/spyre/repair.go Outdated
type: Directory
containers:
- name: instruct
securityContext:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need I believe, all the containers will have this label

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same comment applies for all the other places where you have these labels.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will verify this and remove if not required

}

// buildAndInstallSELinuxPolicy builds and installs the SELinux policy module.
func buildAndInstallSELinuxPolicy(tmpDir string) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we need to make this generic for other policy like podman socket, will do in a follow up PR

}

// updateSELinuxFileContext updates the SELinux file context database.
func updateSELinuxFileContext() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function explicitly labels the device file with but this needs to be run every time when new devices are created(hotplug etc.) to avoid this we can enhance the existing udev rule which will add the labels automatically when there is a new device onboard.

e.g:

# Example udev rule
SUBSYSTEM=="vfio", ACTION=="add", SECLABEL{selinux}="system_u:object_r:vfio_device_t:s0"

explore adding the content to the already existing udev rule

}

// applySELinuxLabels applies SELinux labels to existing VFIO devices.
func applySELinuxLabels() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even this is not required if we handle them via udev rule which I mentioned above.

Comment thread ai-services/internal/pkg/bootstrap/spyreconfig/utils/utils.go Outdated
Comment thread ai-services/internal/pkg/runtime/podman/podman.go Outdated
@@ -25,10 +25,18 @@ func (r *RootRule) Description() string {
func (r *RootRule) Verify() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this becomes info only check instead of a blocking one?! correct if I'm wrong!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right
That leaves us with one confusion, for bootstrap we require either sudo or root privileges. Also, this function is called while creating application as well (via validate), there this function will fail if user is non-root.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm little worried about the below modification you are making that is it! IMO we should just remove this root validator itself considering we don't need root anymore..

Signed-off-by: sagarwal-ibm <sagarwal@ibm.com>
Signed-off-by: sagarwal-ibm <sagarwal@ibm.com>
Signed-off-by: sagarwal-ibm <sagarwal@ibm.com>
Shubhamag12 and others added 2 commits April 29, 2026 15:12
Signed-off-by: Shubham Agarwal <49315586+Shubhamag12@users.noreply.github.com>
Signed-off-by: sagarwal-ibm <sagarwal@ibm.com>
@Shubhamag12 Shubhamag12 requested a review from mkumatag April 29, 2026 09:57
@Shubhamag12 Shubhamag12 marked this pull request as ready for review April 29, 2026 09:57
if euid != 0 && os.Getenv("XDG_RUNTIME_DIR") == "" {
uid := os.Getuid()
logger.Infoln("running command as %s", uid, logger.VerbosityLevelDebug)
if err := os.Setenv("XDG_RUNTIME_DIR", fmt.Sprintf("/run/user/%d", uid)); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set it here, it will only apply to that specific shell. I'm not sure why we're setting this environment variable here at all.

Copy link
Copy Markdown
Contributor Author

@Shubhamag12 Shubhamag12 Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move it to create cmd in that case?
because while creating application, I was facing this error

failed to pull image registry.redhat.io/rhaiis/vllm-spyre-rhel9:3.2.5: reading JSON file "/run/containers/1001/auth.json": open /run/containers/1001/auth.json: permission denied

Even though the above error says permission denied, it was because of the fact that podman was not able to access the runtime files.

So thought of exporting this var here since we call validate function everytime we create application

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this validator and fix this permission somewhere else

and fix this somewhere else wher


const (
// dirPermissions is the default permission for creating directories.
dirPermissions = 0755
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These permissions are for tow different things, let us keep this variable here as well for the local consumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants