Commit Graph

37 Commits

Author SHA1 Message Date
Steven Masley 1f5788feff
chore: remove rbac psuedo resources, add custom verbs (#13276)
Removes our pseudo rbac resources like `WorkspaceApplicationConnect` in favor of additional verbs like `ssh`. This is to make more intuitive permissions for building custom roles.

The source of truth is now `policy.go`
2024-05-15 11:09:42 -05:00
Steven Masley cb6b5e8fbd
chore: push rbac actions to policy package (#13274)
Just moved `rbac.Action` -> `policy.Action`. This is for the stacked PR to not have circular dependencies when doing autogen. Without this, the autogen can produce broken golang code, which prevents the autogen from compiling.

So just avoiding circular dependencies. Doing this in it's own PR to reduce LoC diffs in the primary PR, since this has 0 functional changes.
2024-05-15 09:46:35 -05:00
Steven Masley eeb3d63be6
chore: merge authorization contexts (#12816)
* chore: merge authorization contexts

Instead of 2 auth contexts from apikey and dbauthz, merge them to
just use dbauthz. It is annoying to have two.

* fixup authorization reference
2024-03-29 10:14:27 -05:00
Cian Johnston 42e997d39e
fix(coderd/rbac): do not cache context cancellation errors (#11840)
#7439 added global caching of RBAC results.
Calls are cached based on hash(subject, object, action).
We often use dbauthz.AsSystemRestricted to handle "internal" authz calls, and these are often repeated with similar arguments and are likely to get cached.
So a transient error doing an authz check on a system function will be cached for up to a minute.
I'm just starting off with excluding context.Canceled but there's likely a whole suite of different errors we want to also exclude from the global cache.
2024-01-26 16:19:55 +00:00
Steven Masley d6ba0dfecb
feat: add "updated" search param to workspaces (#11714)
* feat: add "updated" search param to workspaces
* rego -> sql needs to specify which <table>.organization_id
2024-01-23 11:52:06 -06:00
Steven Masley 0f17d7c144
chore: return context.Canceled when in Prepare for rbac (#10763)
Was returning a custom rego canceled error. This conforms with
how Authorize handles this error.
2023-11-17 20:28:59 +00:00
Kyle Carberry 22e781eced
chore: add /v2 to import module path (#9072)
* chore: add /v2 to import module path

go mod requires semantic versioning with versions greater than 1.x

This was a mechanical update by running:
```
go install github.com/marwan-at-work/mod/cmd/mod@latest
mod upgrade
```

Migrate generated files to import /v2

* Fix gen
2023-08-18 18:55:43 +00:00
Ammar Bandukwala 8899dd89ca
chore: add global caching to rbac (#7439)
Co-authored-by: Steven Masley <stevenmasley@coder.com>
2023-05-08 08:59:01 -05:00
Steven Masley 3368b8b65f
chore: Minor rbac memory optimization (#7391)
* test: Add benchmark for static rbac roles
* static roles should only be allocated once
* A unit test that modifies the ast value should not mess with the globals
* Cache subject AST values to avoid reallocating slices
2023-05-03 14:42:24 -05:00
Steven Masley 2137db0445
test: Handle Filter flake with ctx errors (#7119)
* test: Handle Fitler flake with ctx errors
* Add unit test to check filter for proper error
* Correctly return category of errors
2023-04-14 12:30:35 -05:00
Steven Masley fab8da633b
chore: Merge more rbac files (#6927)
* chore: Merge more rbac files

- Remove cache.go -> authz.go
- Remove query.go -> authz.go
- Remove role.go -> roles.go

* Order imports

* fmt
2023-04-03 09:05:06 -05:00
Steven Masley ce51435507
chore: Merge some rbac files, move some functions around (#6916)
* chore: Merge some rbac files, move some functions around

* Fix imports
2023-03-31 09:46:38 -05:00
Steven Masley 4cbbd1376d
feat: Turn on rbac check caching (#6202)
* chore: Turn on rbac check caching.

Should not affect much unless authz_querier experiment is
enabled
2023-02-15 08:56:07 -06:00
Steven Masley 32fbd10a1f
chore: Optimize parial rego execution byte allocations (#6144)
* chore: Implement benchmark for authorizer.Prepare

Identify time + alloc cost before optimizing
2023-02-10 08:39:45 -06:00
Steven Masley af59e2bcfa
chore: Optimize rego policy input allocations (#6135)
* chore: Optimize rego policy evaluation allocations

Manually convert to ast.Value instead of using generic
json.Marshal conversion.

* Add a unit test that prevents regressions of rego input

The optimized input is always compared to the normal json
marshal parser.
2023-02-09 13:47:17 -06:00
Steven Masley b359dbbd8b
chore: Allow RecordingAuthorizer to record multiple rbac authz calls (#6024)
* chore: Allow RecordingAuthorizer to record multiple rbac authz calls

Prior iteration only recorded the last call. This is required for
more comprehensive testing
2023-02-03 19:03:46 +00:00
Steven Masley b0a16150a3
chore: Implement standard rbac.Subject to be reused everywhere (#5881)
* chore: Implement standard rbac.Subject to be reused everywhere

An rbac subject is created in multiple spots because of the way we
expand roles, scopes, etc. This difference in use creates a list
of arguments which is unwieldy.

Use of the expander interface lets us conform to a single subject
in every case
2023-01-26 14:42:54 -06:00
Steven Masley b678309fc9
chore: Authz should support non-named roles (#5855)
* chore: Authz should support non-named roles

Named roles are a construct for users to assign/interact with roles.
For authzlayer implementation, we need to create "system" users.
To enforce strict security, we are making specific roles with
the exact required permissions for the system action.
These new roles should not be available to the user. There is a
clear code divide with this implementation that allows a RoleNames
implemenation for users to user, and system users can create their
own implementation
2023-01-25 10:54:16 -06:00
Steven Masley 08cce81ac8
feat: Implement allow_list for scopes for resource specific permissions (#5769)
* feat: Implement allow_list for scopes for resource specific permissions

Feature that adds an allow_list for scopes to specify particular resources.
This enables workspace agent tokens to use the same RBAC system as users.

- Add ID to compileSQL matchers
* Plumb through WithID on rbac objects
* Rename Scope -> ScopeName
* Update input.json with scope allow_list

Co-authored-by: Cian Johnston <cian@coder.com>
2023-01-19 13:41:36 -06:00
Steven Masley eb48341696
chore: More complete tracing for RBAC functions (#5690)
* chore: More complete tracing for RBAC functions
* Add input.json as example rbac input for rego cli

The input.json is required to play with the rego cli and debug
the policy without golang. It is good to have an example to run
the commands in the readme.md

* Add span events to capture authorize and prepared results
* chore: Add prometheus metrics to rbac authorizer
2023-01-13 16:07:15 -06:00
Steven Masley ab9298f382
chore: Rewrite rbac rego -> SQL clause (#5138)
* chore: Rewrite rbac rego -> SQL clause

Previous code was challenging to read with edge cases
- bug: OrgAdmin could not make new groups
- Also refactor some function names
2022-11-28 12:12:34 -06:00
Jon Ayers 3120c94c22
feat: add template RBAC/groups (#4235) 2022-10-10 15:37:06 -05:00
Steven Masley cd4ab97efa
feat: Convert rego queries into SQL clauses (#4225)
* feat: Convert rego queries into SQL clauses

* Fix postgres quotes to single quotes

* Ensure all test cases can compile into SQL clauses

* Do not export extra types

* Add custom query with rbac filter

* First draft of a custom authorized db call

* Add comments + tests

* Support better regex style matching for variables

* Handle jsonb arrays

* Remove auth call on workspaces

* Fix PG endpoints test

* Match psql implementation

* Add some comments

* Remove unused argument

* Add query name for tracking

* Handle nested types

This solves it without proper types in our AST.
Might bite the bullet and implement some better types

* Add comment

* Renaming function call to GetAuthorizedWorkspaces
2022-10-04 11:35:33 -04:00
Steven Masley d8008de77a
chore: Optimize Filter() for small lists (#4282) 2022-09-30 15:55:08 -04:00
Colin Adler 15b9a59786
chore: only trace rbac.Filter (#4177) 2022-09-23 15:21:56 -05:00
Kyle Carberry 8738755ffc
chore: Compile rego once to save CPU cycles in testing (#4169)
Compiling rego isn't very fast, so this should speed up tests in CI!
2022-09-23 16:26:04 +00:00
Steven Masley 2e30d0512e
chore: Move scope into the same auth call (#4162)
Scopes now are enforced in the same Authorize call as the roles. 
Vs 2 `Authorize()` calls
2022-09-23 11:07:30 -04:00
Dean Sheather 29d804e692
feat: add API key scopes and application_connect scope (#4067) 2022-09-19 17:39:02 +00:00
Colin Adler b340634aaa
feat: add rbac tracing (#4093) 2022-09-16 18:32:15 +00:00
Kyle Carberry b0fe9bcdd1
chore: Upgrade to Go 1.19 (#3617)
This is required as part of #3505.
2022-08-21 22:32:53 +00:00
Steven Masley 3ae42f4de9
chore: Update rego to be partial execution friendly (#3449)
- Improves performance of batch authorization calls
- Enables possibility to convert rego auth calls into SQL WHERE clauses
2022-08-11 22:07:48 +00:00
Steven Masley eea8dc6c16
feat: Add rbac to templateversion+orgmember endpoints (#1713) 2022-05-25 11:00:59 -05:00
Steven Masley c7ca86d374
feat: Implement RBAC checks on /templates endpoints (#1678)
* feat: Generic Filter method for rbac objects
2022-05-24 08:43:34 -05:00
Steven Masley 4ad5ac2d4a
feat: Rbac more coderd endpoints, unit test to confirm (#1437)
* feat: Enforce authorize call on all endpoints
- Make 'request()' exported for running custom requests
* Rbac users endpoints
* 401 -> 403
2022-05-17 13:43:19 -05:00
Colin Adler 97a95f1377
chore: upgrade golangci-lint to v1.46.0 (#1373) 2022-05-10 16:04:23 -05:00
Steven Masley 35211e2190
feat: Add user roles, but do not yet enforce them (#1200)
* chore: Rework roles to be expandable by name alone
2022-04-29 09:04:19 -05:00
Steven Masley 770c567123
feat: Add RBAC package for managing user permissions (#929)
This PR adds an RBAC package for managing using permissions:
- The top-level `authz.Authorize` function is the main user-facing entrypoint to the package.
- Actual permission evaluation is handled in `policy.rego`.
- Unit tests for `authz.Authorize` are in `authz_test.go`
- Documentation for the package is in `README.md`.

Co-authored-by: Cian Johnston <cian@coder.com>
2022-04-13 08:35:35 -05:00