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
- 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
-
Handle new config during provider create and edit
During create/edit, the following logic applies:
- Validation
Roles is required if ImportRoles is empty/not specified vice versa
- Return error if both values exist (should only specify one)
- 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
-
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) |
|
} |
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.Rolesguardian/domain/provider.go
Line 59 in 7966278
Would be easier if this can be automatically populated from the provider (similar way with resources being imported from provider)
Proposed solution
A new option
ImportRolesis introduced within theResourceConfigto indicate that the roles listing will be coming from the provider instead of the oldRoleslistHandle new config during provider create and edit
During create/edit, the following logic applies:
Rolesis required ifImportRolesis empty/not specified vice versaProvider roles listing
The following logic will be updated to support retrieving the roles from the cached data instead of from
ResourceConfig.Rolesin the case of providers with ImportRoles option enabledguardian/plugins/providers/gcloudiam/provider.go
Lines 149 to 155 in 7966278