Skip to content

ECOPROJECT-4271 | fix: implement permissions check for vsphere root level read#183

Draft
itroyano wants to merge 1 commit intokubev2v:mainfrom
itroyano:verifyReadPermissions
Draft

ECOPROJECT-4271 | fix: implement permissions check for vsphere root level read#183
itroyano wants to merge 1 commit intokubev2v:mainfrom
itroyano:verifyReadPermissions

Conversation

@itroyano
Copy link
Copy Markdown

@itroyano itroyano commented Mar 24, 2026

The issue in title happens because the user creds are correct AND have read permissions, but the read permissions do not extend to the vCenter root level.
What ends up happening is the parser func (called after verifyCreds) can get a null "cluster" column and throws the error in the ticket.
It could potentially throw other related errors we want to avoid getting.

Signed-off-by: Igor Troyanovsky itroyano@redhat.com
Assisted-by: claude
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED

@itroyano itroyano requested a review from a team as a code owner March 24, 2026 10:09
@itroyano itroyano requested review from amalimov and nirarg March 24, 2026 10:09
@itroyano itroyano marked this pull request as draft March 24, 2026 10:09
Comment thread pkg/collector/vsphere.go Outdated
return nil
}

func (c *VSphereCollector) checkReadOnlyPermissions(ctx context.Context, client *govmomi.Client, username string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the function actually check if the user has (amongst possible other priviliges) a read permission, right?

In that case the name is misleading, maybe a better name would be "hasReadPermissions"?

Comment thread pkg/collector/vsphere.go Outdated
return fmt.Errorf("failed to check read-only permissions on vCenter root level: %w", err)
}

if len(hasPrivileges) == 0 || !hasPrivileges[0] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a nitpick :-) feel free to ignore.

I'm not familiar with this library, so I don't know if this is the idiomatic way to test this - but assiging meaning to an index of a slice might be brittle. Should someone later try to expand the function by adding more "priviliges" to the authMgr.HasPrivilegeOnEntity call.

I would consider adding a comment above either the authMgr.HasPrivilegeOnEntity call, or asserting that the length of the result slice is no bigger than 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @amalimov
Apologies I haven't provided proper context here.
The issue in title happens because the user creds are correct AND have read permissions, but the read permissions do not extend to the vCenter root level.
What ends up happening is the parser func (called after verifyCreds) gets a null "cluster" column and throws the error in the ticket.

I'll add the necessary changes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

adding the description to the PR now

@amalimov
Copy link
Copy Markdown
Contributor

/lgtm

@amalimov
Copy link
Copy Markdown
Contributor

looks good, just added two minor suggestions (feel free to ignore)

@AvielSegev
Copy link
Copy Markdown
Collaborator

Just a thought here:
We are using forklift's collector during the collection process.
Isn’t that a bug in MTV?

Comment thread pkg/collector/vsphere.go Outdated
return nil
}

func (c *VSphereCollector) checkReadOnlyPermissions(ctx context.Context, client *govmomi.Client, username string) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Amended now. testing locally.

Comment thread pkg/collector/vsphere.go Outdated
}

func (c *VSphereCollector) checkReadOnlyPermissions(ctx context.Context, client *govmomi.Client, username string) error {
if client == nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How can this happen?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

removed

Comment thread pkg/collector/vsphere.go Outdated
authMgr := object.NewAuthorizationManager(client.Client)

// Check if user has basic read privileges on root folder
hasPrivileges, err := authMgr.HasPrivilegeOnEntity(ctx, rootFolder, username, []string{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nitpick: you could extract rootFolder directly here..

@itroyano itroyano force-pushed the verifyReadPermissions branch 2 times, most recently from 18d4b51 to aa7f318 Compare March 24, 2026 16:33
@itroyano
Copy link
Copy Markdown
Author

itroyano commented Mar 25, 2026

Code doesn't work... it reached logging "vCenter read-only permissions verified" with my known-bad user, and I got the bug error again
"schema validation failed: [{MISSING_CLUSTER vinfo Cluster 'Cluster' column is missing or empty in the vInfo sheet - cannot determine cluster membership}]" :(

Expected result was "user is missing required privileges"

@itroyano itroyano force-pushed the verifyReadPermissions branch 2 times, most recently from be0a3c2 to c76ad07 Compare March 30, 2026 07:20
@itroyano itroyano marked this pull request as ready for review March 30, 2026 07:22
@itroyano itroyano marked this pull request as draft March 30, 2026 07:32
Signed-off-by: Igor Troyanovsky <itroyano@redhat.com>

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
@itroyano itroyano force-pushed the verifyReadPermissions branch from c76ad07 to 767921b Compare March 30, 2026 07:55
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.

4 participants