|
14 | 14 |
|
15 | 15 | package rbac
|
16 | 16 |
|
17 |
| -import "github.com/goharbor/harbor/src/pkg/permission/types" |
| 17 | +import ( |
| 18 | + "github.com/goharbor/harbor/src/pkg/permission/types" |
| 19 | +) |
18 | 20 |
|
19 | 21 | // const action variables
|
20 | 22 | const (
|
@@ -81,9 +83,88 @@ const (
|
81 | 83 | ResourceSecurityHub = Resource("security-hub")
|
82 | 84 | )
|
83 | 85 |
|
| 86 | +type scope string |
| 87 | + |
| 88 | +const ( |
| 89 | + ScopeSystem = scope("System") |
| 90 | + ScopeProject = scope("Project") |
| 91 | +) |
| 92 | + |
| 93 | +// RobotPermissionProvider defines the permission provider for robot account |
| 94 | +type RobotPermissionProvider interface { |
| 95 | + GetPermissions(s scope) []*types.Policy |
| 96 | +} |
| 97 | + |
| 98 | +// GetPermissionProvider gives the robot permission provider |
| 99 | +func GetPermissionProvider() RobotPermissionProvider { |
| 100 | + // TODO will determine by the ui configuration |
| 101 | + return &NolimitProvider{} |
| 102 | +} |
| 103 | + |
| 104 | +// BaseProvider ... |
| 105 | +type BaseProvider struct { |
| 106 | +} |
| 107 | + |
| 108 | +// GetPermissions ... |
| 109 | +func (d *BaseProvider) GetPermissions(s scope) []*types.Policy { |
| 110 | + return PoliciesMap[s] |
| 111 | +} |
| 112 | + |
| 113 | +// NolimitProvider ... |
| 114 | +type NolimitProvider struct { |
| 115 | + BaseProvider |
| 116 | +} |
| 117 | + |
| 118 | +// GetPermissions ... |
| 119 | +func (n *NolimitProvider) GetPermissions(s scope) []*types.Policy { |
| 120 | + if s == ScopeSystem { |
| 121 | + return append(n.BaseProvider.GetPermissions(ScopeSystem), |
| 122 | + &types.Policy{Resource: ResourceRobot, Action: ActionCreate}, |
| 123 | + &types.Policy{Resource: ResourceRobot, Action: ActionRead}, |
| 124 | + &types.Policy{Resource: ResourceRobot, Action: ActionUpdate}, |
| 125 | + &types.Policy{Resource: ResourceRobot, Action: ActionList}, |
| 126 | + &types.Policy{Resource: ResourceRobot, Action: ActionDelete}, |
| 127 | + |
| 128 | + &types.Policy{Resource: ResourceUser, Action: ActionCreate}, |
| 129 | + &types.Policy{Resource: ResourceUser, Action: ActionRead}, |
| 130 | + &types.Policy{Resource: ResourceUser, Action: ActionUpdate}, |
| 131 | + &types.Policy{Resource: ResourceUser, Action: ActionList}, |
| 132 | + &types.Policy{Resource: ResourceUser, Action: ActionDelete}, |
| 133 | + |
| 134 | + &types.Policy{Resource: ResourceLdapUser, Action: ActionCreate}, |
| 135 | + &types.Policy{Resource: ResourceLdapUser, Action: ActionList}, |
| 136 | + |
| 137 | + &types.Policy{Resource: ResourceExportCVE, Action: ActionCreate}, |
| 138 | + &types.Policy{Resource: ResourceExportCVE, Action: ActionRead}, |
| 139 | + |
| 140 | + &types.Policy{Resource: ResourceQuota, Action: ActionUpdate}, |
| 141 | + |
| 142 | + &types.Policy{Resource: ResourceUserGroup, Action: ActionCreate}, |
| 143 | + &types.Policy{Resource: ResourceUserGroup, Action: ActionRead}, |
| 144 | + &types.Policy{Resource: ResourceUserGroup, Action: ActionUpdate}, |
| 145 | + &types.Policy{Resource: ResourceUserGroup, Action: ActionList}, |
| 146 | + &types.Policy{Resource: ResourceUserGroup, Action: ActionDelete}) |
| 147 | + } |
| 148 | + if s == ScopeProject { |
| 149 | + return append(n.BaseProvider.GetPermissions(ScopeProject), |
| 150 | + &types.Policy{Resource: ResourceRobot, Action: ActionCreate}, |
| 151 | + &types.Policy{Resource: ResourceRobot, Action: ActionRead}, |
| 152 | + &types.Policy{Resource: ResourceRobot, Action: ActionUpdate}, |
| 153 | + &types.Policy{Resource: ResourceRobot, Action: ActionList}, |
| 154 | + &types.Policy{Resource: ResourceRobot, Action: ActionDelete}, |
| 155 | + |
| 156 | + &types.Policy{Resource: ResourceMember, Action: ActionCreate}, |
| 157 | + &types.Policy{Resource: ResourceMember, Action: ActionRead}, |
| 158 | + &types.Policy{Resource: ResourceMember, Action: ActionUpdate}, |
| 159 | + &types.Policy{Resource: ResourceMember, Action: ActionList}, |
| 160 | + &types.Policy{Resource: ResourceMember, Action: ActionDelete}) |
| 161 | + } |
| 162 | + return []*types.Policy{} |
| 163 | +} |
| 164 | + |
84 | 165 | var (
|
85 |
| - PoliciesMap = map[string][]*types.Policy{ |
86 |
| - "System": { |
| 166 | + PoliciesMap = map[scope][]*types.Policy{ |
| 167 | + ScopeSystem: { |
87 | 168 | {Resource: ResourceAuditLog, Action: ActionList},
|
88 | 169 |
|
89 | 170 | {Resource: ResourcePreatInstance, Action: ActionRead},
|
@@ -154,7 +235,7 @@ var (
|
154 | 235 | {Resource: ResourceQuota, Action: ActionRead},
|
155 | 236 | {Resource: ResourceQuota, Action: ActionList},
|
156 | 237 | },
|
157 |
| - "Project": { |
| 238 | + ScopeProject: { |
158 | 239 | {Resource: ResourceLog, Action: ActionList},
|
159 | 240 |
|
160 | 241 | {Resource: ResourceProject, Action: ActionRead},
|
|
0 commit comments