Skip to content

Add option to list (import) roles from provider #55

@rahmatrhd

Description

@rahmatrhd

Summary
Project-level (or org-level) access in GCP already comes with many predefined roles plus the custom role that the user can create themselves, and it would be tedious to list all of those manually in ResourceConfig.Roles

Roles []*Role `json:"roles" yaml:"roles" validate:"required"`

Would be easier if this can be automatically populated from the provider (similar way with resources being imported from provider)

Proposed solution

  1. Update provider config
// domain/provider.go
+ type ImportRoles struct {
+ 	Enable bool
+ 	Filter string // expression
+ }

  type ResourceConfig struct {
	Type        string        `json:"type"
	Filter      string        `json:"filter"
	Policy      *PolicyConfig `json:"policy"
	Roles       []*Role       `json:"roles"
+ 	ImportRoles ImportRoles   `json:"import_roles"
  }

A new option ImportRoles is introduced within the ResourceConfig to indicate that the roles listing will be coming from the provider instead of the old Roles list

  1. Handle new config during provider create and edit
    During create/edit, the following logic applies:

    1. Validation
      1. Roles is required if ImportRoles is empty/not specified vice versa
      2. Return error if both values exist (should only specify one)
    2. Imported roles won't be stored in the DB, after fetching from the provider the list will be stored in an in-memory cache to keep the roles up to date
  2. Provider roles listing
    The following logic will be updated to support retrieving the roles from the cached data instead of from ResourceConfig.Roles in the case of providers with ImportRoles option enabled

    func (p *Provider) GetRoles(pc *domain.ProviderConfig, resourceType string) ([]*domain.Role, error) {
    if resourceType != ResourceTypeProject && resourceType != ResourceTypeOrganization {
    return nil, ErrInvalidResourceType
    }
    return provider.GetRoles(pc, resourceType)
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions