Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: KubernetesClient.GetAsync() needs list permission instead of get #647

Closed
PSanetra opened this issue Oct 25, 2023 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@PSanetra
Copy link

Describe the bug

Using KubernetesClient.GetAsync() requires the calling client having list permissions on the target resource type.

To reproduce

  1. Create a KubernetesClient instance with a service account that has execlusively get permission on pod resources
  2. Execute KubernetesClient.GetAsync()
  3. The following exception occurs:
k8s.Autorest.HttpOperationException: Operation returned an invalid status code 'Forbidden', response body {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods \"my-pod\" is forbidden: User \"system:serviceaccount:my-namespace:my-service-account\" cannot list resource \"pods\" in API group \"\" in the namespace \"my-namespace\"","reason":"Forbidden","details":{"name":"my-pod","kind":"pods"},"code":403}

Expected behavior

KubernetesClient.GetAsync() should work if the client has get permissions on the target resource type.

Screenshots

No response

Additional Context

Related code:

public async Task<TEntity?> GetAsync<TEntity>(string name, string? @namespace = null)
where TEntity : IKubernetesObject<V1ObjectMeta>
{
var metadata = GetMetadata<TEntity>();
var list = @namespace switch
{
null => await _client.CustomObjects.ListClusterCustomObjectAsync<EntityList<TEntity>>(
metadata.Group ?? string.Empty,
metadata.Version,
metadata.PluralName,
fieldSelector: $"metadata.name={name}"),
_ => await _client.CustomObjects.ListNamespacedCustomObjectAsync<EntityList<TEntity>>(
metadata.Group ?? string.Empty,
metadata.Version,
@namespace,
metadata.PluralName,
fieldSelector: $"metadata.name={name}"),
};

@PSanetra PSanetra added the bug Something isn't working label Oct 25, 2023
buehler added a commit that referenced this issue Jan 17, 2024
buehler added a commit that referenced this issue Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant