mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* feat: HA tailnet coordinator * fixup! feat: HA tailnet coordinator * fixup! feat: HA tailnet coordinator * remove printlns * close all connections on coordinator * impelement high availability feature * fixup! impelement high availability feature * fixup! impelement high availability feature * fixup! impelement high availability feature * fixup! impelement high availability feature * Add replicas * Add DERP meshing to arbitrary addresses * Move packages to highavailability folder * Move coordinator to high availability package * Add flags for HA * Rename to replicasync * Denest packages for replicas * Add test for multiple replicas * Fix coordination test * Add HA to the helm chart * Rename function pointer * Add warnings for HA * Add the ability to block endpoints * Add flag to disable P2P connections * Wow, I made the tests pass * Add replicas endpoint * Ensure close kills replica * Update sql * Add database latency to high availability * Pipe TLS to DERP mesh * Fix DERP mesh with TLS * Add tests for TLS * Fix replica sync TLS * Fix RootCA for replica meshing * Remove ID from replicasync * Fix getting certificates for meshing * Remove excessive locking * Fix linting * Store mesh key in the database * Fix replica key for tests * Fix types gen * Fix unlocking unlocked * Fix race in tests * Update enterprise/derpmesh/derpmesh.go Co-authored-by: Colin Adler <colin1adler@gmail.com> * Rename to syncReplicas * Reuse http client * Delete old replicas on a CRON * Fix race condition in connection tests * Fix linting * Fix nil type * Move pubsub to in-memory for twenty test * Add comment for configuration tweaking * Fix leak with transport * Fix close leak in derpmesh * Fix race when creating server * Remove handler update * Skip test on Windows * Fix DERP mesh test * Wrap HTTP handler replacement in mutex * Fix error message for relay * Fix API handler for normal tests * Fix speedtest * Fix replica resend * Fix derpmesh send * Ping async * Increase wait time of template version jobd * Fix race when closing replica sync * Add name to client * Log the derpmap being used * Don't connect if DERP is empty * Improve agent coordinator logging * Fix lock in coordinator * Fix relay addr * Fix race when updating durations * Fix client publish race * Run pubsub loop in a queue * Store agent nodes in order * Fix coordinator locking * Check for closed pipe Co-authored-by: Colin Adler <colin1adler@gmail.com>
229 lines
5.9 KiB
Go
229 lines
5.9 KiB
Go
package rbac
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const WildcardSymbol = "*"
|
|
|
|
// Objecter returns the RBAC object for itself.
|
|
type Objecter interface {
|
|
RBACObject() Object
|
|
}
|
|
|
|
// Resources are just typed objects. Making resources this way allows directly
|
|
// passing them into an Authorize function and use the chaining api.
|
|
var (
|
|
// ResourceWorkspace CRUD. Org + User owner
|
|
// create/delete = make or delete workspaces
|
|
// read = access workspace
|
|
// update = edit workspace variables
|
|
ResourceWorkspace = Object{
|
|
Type: "workspace",
|
|
}
|
|
|
|
// ResourceWorkspaceExecution CRUD. Org + User owner
|
|
// create = workspace remote execution
|
|
// read = ?
|
|
// update = ?
|
|
// delete = ?
|
|
ResourceWorkspaceExecution = Object{
|
|
Type: "workspace_execution",
|
|
}
|
|
|
|
// ResourceWorkspaceApplicationConnect CRUD. Org + User owner
|
|
// create = connect to an application
|
|
// read = ?
|
|
// update = ?
|
|
// delete = ?
|
|
ResourceWorkspaceApplicationConnect = Object{
|
|
Type: "application_connect",
|
|
}
|
|
|
|
// ResourceAuditLog
|
|
// read = access audit log
|
|
ResourceAuditLog = Object{
|
|
Type: "audit_log",
|
|
}
|
|
|
|
// ResourceTemplate CRUD. Org owner only.
|
|
// create/delete = Make or delete a new template
|
|
// update = Update the template, make new template versions
|
|
// read = read the template and all versions associated
|
|
ResourceTemplate = Object{
|
|
Type: "template",
|
|
}
|
|
|
|
// ResourceGroup CRUD. Org admins only.
|
|
// create/delete = Make or delete a new group.
|
|
// update = Update the name or members of a group.
|
|
// read = Read groups and their members.
|
|
ResourceGroup = Object{
|
|
Type: "group",
|
|
}
|
|
|
|
ResourceFile = Object{
|
|
Type: "file",
|
|
}
|
|
|
|
ResourceProvisionerDaemon = Object{
|
|
Type: "provisioner_daemon",
|
|
}
|
|
|
|
// ResourceOrganization CRUD. Has an org owner on all but 'create'.
|
|
// create/delete = make or delete organizations
|
|
// read = view org information (Can add user owner for read)
|
|
// update = ??
|
|
ResourceOrganization = Object{
|
|
Type: "organization",
|
|
}
|
|
|
|
// ResourceRoleAssignment might be expanded later to allow more granular permissions
|
|
// to modifying roles. For now, this covers all possible roles, so having this permission
|
|
// allows granting/deleting **ALL** roles.
|
|
// Never has an owner or org.
|
|
// create = Assign roles
|
|
// update = ??
|
|
// read = View available roles to assign
|
|
// delete = Remove role
|
|
ResourceRoleAssignment = Object{
|
|
Type: "assign_role",
|
|
}
|
|
|
|
// ResourceOrgRoleAssignment is just like ResourceRoleAssignment but for organization roles.
|
|
ResourceOrgRoleAssignment = Object{
|
|
Type: "assign_org_role",
|
|
}
|
|
|
|
// ResourceAPIKey is owned by a user.
|
|
// create = Create a new api key for user
|
|
// update = ??
|
|
// read = View api key
|
|
// delete = Delete api key
|
|
ResourceAPIKey = Object{
|
|
Type: "api_key",
|
|
}
|
|
|
|
// ResourceUser is the user in the 'users' table.
|
|
// ResourceUser never has any owners or in an org, as it's site wide.
|
|
// create/delete = make or delete a new user.
|
|
// read = view all 'user' table data
|
|
// update = update all 'user' table data
|
|
ResourceUser = Object{
|
|
Type: "user",
|
|
}
|
|
|
|
// ResourceUserData is any data associated with a user. A user has control
|
|
// over their data (profile, password, etc). So this resource has an owner.
|
|
ResourceUserData = Object{
|
|
Type: "user_data",
|
|
}
|
|
|
|
// ResourceOrganizationMember is a user's membership in an organization.
|
|
// Has ONLY an organization owner.
|
|
// create/delete = Create/delete member from org.
|
|
// update = Update organization member
|
|
// read = View member
|
|
ResourceOrganizationMember = Object{
|
|
Type: "organization_member",
|
|
}
|
|
|
|
// ResourceWildcard represents all resource types
|
|
ResourceWildcard = Object{
|
|
Type: WildcardSymbol,
|
|
}
|
|
|
|
// ResourceLicense is the license in the 'licenses' table.
|
|
// ResourceLicense is site wide.
|
|
// create/delete = add or remove license from site.
|
|
// read = view license claims
|
|
// update = not applicable; licenses are immutable
|
|
ResourceLicense = Object{
|
|
Type: "license",
|
|
}
|
|
|
|
// ResourceDeploymentFlags
|
|
ResourceDeploymentFlags = Object{
|
|
Type: "deployment_flags",
|
|
}
|
|
|
|
ResourceReplicas = Object{
|
|
Type: "replicas",
|
|
}
|
|
)
|
|
|
|
// Object is used to create objects for authz checks when you have none in
|
|
// hand to run the check on.
|
|
// An example is if you want to list all workspaces, you can create a Object
|
|
// that represents the set of workspaces you are trying to get access too.
|
|
// Do not export this type, as it can be created from a resource type constant.
|
|
type Object struct {
|
|
Owner string `json:"owner"`
|
|
// OrgID specifies which org the object is a part of.
|
|
OrgID string `json:"org_owner"`
|
|
|
|
// Type is "workspace", "project", "app", etc
|
|
Type string `json:"type"`
|
|
|
|
ACLUserList map[string][]Action ` json:"acl_user_list"`
|
|
ACLGroupList map[string][]Action ` json:"acl_group_list"`
|
|
}
|
|
|
|
func (z Object) RBACObject() Object {
|
|
return z
|
|
}
|
|
|
|
// All returns an object matching all resources of the same type.
|
|
func (z Object) All() Object {
|
|
return Object{
|
|
Owner: "",
|
|
OrgID: "",
|
|
Type: z.Type,
|
|
ACLUserList: map[string][]Action{},
|
|
ACLGroupList: map[string][]Action{},
|
|
}
|
|
}
|
|
|
|
// InOrg adds an org OwnerID to the resource
|
|
func (z Object) InOrg(orgID uuid.UUID) Object {
|
|
return Object{
|
|
Owner: z.Owner,
|
|
OrgID: orgID.String(),
|
|
Type: z.Type,
|
|
ACLUserList: z.ACLUserList,
|
|
ACLGroupList: z.ACLGroupList,
|
|
}
|
|
}
|
|
|
|
// WithOwner adds an OwnerID to the resource
|
|
func (z Object) WithOwner(ownerID string) Object {
|
|
return Object{
|
|
Owner: ownerID,
|
|
OrgID: z.OrgID,
|
|
Type: z.Type,
|
|
ACLUserList: z.ACLUserList,
|
|
ACLGroupList: z.ACLGroupList,
|
|
}
|
|
}
|
|
|
|
// WithACLUserList adds an ACL list to a given object
|
|
func (z Object) WithACLUserList(acl map[string][]Action) Object {
|
|
return Object{
|
|
Owner: z.Owner,
|
|
OrgID: z.OrgID,
|
|
Type: z.Type,
|
|
ACLUserList: acl,
|
|
ACLGroupList: z.ACLGroupList,
|
|
}
|
|
}
|
|
|
|
func (z Object) WithGroupACL(groups map[string][]Action) Object {
|
|
return Object{
|
|
Owner: z.Owner,
|
|
OrgID: z.OrgID,
|
|
Type: z.Type,
|
|
ACLUserList: z.ACLUserList,
|
|
ACLGroupList: groups,
|
|
}
|
|
}
|