Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: iam auth (#12975)

Danny Xuda1f0baefeac
diff --git a/backend/api/v1/acl.go b/backend/api/v1/acl.go
index f9d51716fd..2fa93d8cce 100644
--- a/backend/api/v1/acl.go
+++ b/backend/api/v1/acl.go
@@ -206,6 +206,30 @@ func (in *ACLInterceptor) doIAMPermissionCheck(ctx context.Context, fullMethod s
if authContext.AuthMethod == common.AuthMethodCustom {
return true, nil, nil
}
+ if authContext.AuthMethod == common.AuthMethodIAM {
+ // Handle GetProject() error status.
+ for _, resource := range authContext.Resources {
+ slog.Debug("IAM auth method", slog.String("method", fullMethod), slog.String("permission", authContext.Permission), slog.String("project", resource.ProjectID), slog.Bool("workspace", resource.Workspace))
+ if resource.Workspace {
+ ok, err := in.iamManager.CheckPermission(ctx, authContext.Permission, user)
+ if err != nil {
+ return false, nil, err
+ }
+ if !ok {
+ return false, nil, nil
+ }
+ } else {
+ ok, err := in.iamManager.CheckPermission(ctx, authContext.Permission, user, resource.ProjectID)
+ if err != nil {
+ return false, []string{resource.ProjectID}, err
+ }
+ if !ok {
+ return false, []string{resource.ProjectID}, nil
+ }
+ }
+ }
+ return true, nil, nil
+ }
p := authContext.Permission
switch fullMethod {
@@ -269,10 +293,15 @@ func (in *ACLInterceptor) populateRawResources(ctx context.Context, authContext
if resource != nil {
switch {
case strings.HasPrefix(resource.Name, "projects/"):
- match := projectRegex.FindString(resource.Name)
- if match != "" {
- resource.Project = match
+ project := projectRegex.FindString(resource.Name)
+ if project == "" {
+ return errors.Errorf("invalid project resource %q", resource.Name)
+ }
+ projectID, err := common.GetProjectID(project)
+ if err != nil {
+ return err
}
+ resource.ProjectID = projectID
case strings.HasPrefix(resource.Name, "instances/") && strings.Contains(resource.Name, "/databases/"):
match := databaseRegex.FindString(resource.Name)
if match != "" {
@@ -280,7 +309,7 @@ func (in *ACLInterceptor) populateRawResources(ctx context.Context, authContext
if err != nil {
return errors.Wrapf(err, "failed to get database %q", match)
}
- resource.Project = database.ProjectID
+ resource.ProjectID = database.ProjectID
}
}
authContext.Resources = append(authContext.Resources, resource)
diff --git a/backend/common/context.go b/backend/common/context.go
index 76ed3b9874..f5d93ae027 100644
--- a/backend/common/context.go
+++ b/backend/common/context.go
@@ -38,7 +38,7 @@ const (
type Resource struct {
Type string
Name string
- Project string
+ ProjectID string
Workspace bool
}