Skip to content

feat(coder): add authz_querier experiment #5858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ func New(options *Options) *API {
if options == nil {
options = &Options{}
}
experiments := initExperiments(options.Logger, options.DeploymentConfig.Experiments.Value, options.DeploymentConfig.Experimental.Value)
// TODO: remove this once we promote authz_querier out of experiments.
if experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
panic("Coming soon!")
// if _, ok := (options.Database).(*authzquery.AuthzQuerier); !ok {
// options.Database = authzquery.NewAuthzQuerier(options.Database, options.Authorizer)
// }
}
if options.AppHostname != "" && options.AppHostnameRegex == nil || options.AppHostname == "" && options.AppHostnameRegex != nil {
panic("coderd: both AppHostname and AppHostnameRegex must be set or unset")
}
Expand Down Expand Up @@ -222,7 +230,7 @@ func New(options *Options) *API {
},
metricsCache: metricsCache,
Auditor: atomic.Pointer[audit.Auditor]{},
Experiments: initExperiments(options.Logger, options.DeploymentConfig.Experiments.Value, options.DeploymentConfig.Experimental.Value),
Experiments: experiments,
}
if options.UpdateCheckOptions != nil {
api.updateChecker = updatecheck.New(
Expand Down
9 changes: 9 additions & 0 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -176,6 +177,14 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
if options.Database == nil {
options.Database, options.Pubsub = dbtestutil.NewDB(t)
}
// TODO: remove this once we're ready to enable authz querier by default.
if strings.Contains(os.Getenv("CODER_EXPERIMENTS_TEST"), "authz_querier") {
panic("Coming soon!")
// if options.Authorizer != nil {
// options.Authorizer = &RecordingAuthorizer{}
// }
// options.Database = authzquery.NewAuthzQuerier(options.Database, options.Authorizer)
}
if options.DeploymentConfig == nil {
options.DeploymentConfig = DeploymentConfig(t)
}
Expand Down
8 changes: 6 additions & 2 deletions codersdk/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import (
type Experiment string

const (
// Add new experiments here!
// ExperimentExample Experiment = "example"
// ExperimentAuthzQuerier is an internal experiment that enables the ExperimentAuthzQuerier
// interface for all RBAC operations. NOT READY FOR PRODUCTION USE.
ExperimentAuthzQuerier Experiment = "authz_querier"

// Add new experiments here!
// ExperimentExample Experiment = "example"
)

var (
Expand Down
14 changes: 10 additions & 4 deletions docs/api/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,17 +1072,23 @@ curl -X GET http://coder-server:8080/api/v2/experiments \
> 200 Response

```json
["string"]
["authz_querier"]
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | --------------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of string |
| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------------------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of [codersdk.Experiment](schemas.md#codersdkexperiment) |

<h3 id="get-experiments-responseschema">Response Schema</h3>

Status Code **200**

| Name | Type | Required | Restrictions | Description |
| -------------- | ----- | -------- | ------------ | ----------- |
| `[array item]` | array | false | | |

To perform this operation, you must be authenticated. [Learn more](authentication.md).

## Update check
Expand Down
14 changes: 14 additions & 0 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,20 @@ CreateParameterRequest is a structure used to create a new parameter value for a
| `trial` | boolean | false | | |
| `warnings` | array of string | false | | |

## codersdk.Experiment

```json
"authz_querier"
```

### Properties

#### Enumerated Values

| Value |
| --------------- |
| `authz_querier` |

Comment on lines +2442 to +2455
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool. Would be cool if there was a description too. A problem for another PR

## codersdk.Feature

```json
Expand Down
4 changes: 2 additions & 2 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ export const Entitlements: Entitlement[] = [
]

// From codersdk/experiments.go
export type Experiment = never
export const Experiments: Experiment[] = []
export type Experiment = "authz_querier"
export const Experiments: Experiment[] = ["authz_querier"]

// From codersdk/features.go
export type FeatureName =
Expand Down