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

iam/apiv1: allow GetIamPolicy and GetIamPolicy on Service Account resources #11320

Open
diogoteles08 opened this issue Dec 19, 2024 · 1 comment
Assignees
Labels
api: iam Issues related to the Identity and Access Management API. type: question Request for information or clarification. Not an issue.

Comments

@diogoteles08
Copy link

diogoteles08 commented Dec 19, 2024

Is your feature request related to a problem? Please describe.

I need to update the IAM policy of a ServiceAccount resource and currently I couldn't find any way to do it using the google-cloud-go.

I could find documentation on how to do it using gcloud client libraries in Python and Java, but not for Go.

Describe the solution you'd like

The solution I'd like is basically allow using https://pkg.go.dev/cloud.google.com/go/iam@v1.3.0/apiv1#example-IamPolicyClient.GetIamPolicy with a Service Account as a resource.

This is an example on how I tried to do so:

package main

import (
	"context"
	"log"

	iam "cloud.google.com/go/iam/apiv1"
	"cloud.google.com/go/iam/apiv1/iampb"
)
func main() {
	ctx := context.Background()
	iamClient, err := iam.NewIamPolicyClient(ctx)
        if err != nil {
	    log.Fatalf("failed to create IAM client: %s", err)
	}
	defer iamClient.Close()
	req := &iampb.GetIamPolicyRequest{
	    Resource: "projects/{PROJECT_ID}/serviceAccounts/{EMAIL_ADDRESS}", // I also tried the full resource as suggested in https://cloud.google.com/iam/docs/full-resource-names
            Options:  &iampb.GetPolicyOptions{RequestedPolicyVersion: 3}
	}

	res, err := c.GetIamPolicy(ctx, req)
	if err != nil {
            log.Fatalf("failed to get IAM policy: %s", err)
	}

	log.Printf("res: %v", res)
}

But I repeatedly get this error::

rpc error: code = Unimplemented desc = unexpected HTTP status code received from server: 404 (Not Found); transport: received unexpected content-type "text/html; charset=UTF-8"
exit status 1

I could observe this behavior on the version v1.1.13, that I usually work with, but also in latest (v1.3.0)

Describe alternatives you've considered

Weirdly enough, I could make it work using the library google.golang.org/api, but it's considered complete and it's only on maintenance mode. I followed the exemple here: https://cloud.google.com/iam/docs/reference/rest/v1/projects.serviceAccounts/getIamPolicy#go

Additional context

Similar issue: #8671

@diogoteles08 diogoteles08 added the triage me I really want to be triaged. label Dec 19, 2024
@product-auto-label product-auto-label bot added the api: iam Issues related to the Identity and Access Management API. label Dec 19, 2024
@quartzmo quartzmo added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Dec 30, 2024
@quartzmo
Copy link
Member

quartzmo commented Jan 8, 2025

Hi @diogoteles08,

The examples that you link for Python and Java show the following imports of IAM Admin V1 clients:

import com.google.cloud.iam.admin.v1.IAMClient;
from google.cloud import iam_admin_v1

Your own example above however uses the IAM V1 (cloud.google.com/go/iam/apiv1) client.

Can you change it to instead use the cloud.google.com/go/iam/admin/apiv1 client and report back the result? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: iam Issues related to the Identity and Access Management API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants