Skip to content

Commit d91dce1

Browse files
authored
[Local Dev Environment] Remove Anonymous Auth in local dev environmen… (#738)
Remove Anonymous Auth in local dev environment grafana instance, update docs to reflect this change. Related to #737, as the anonymous role of `Admin` is being deprecated, and a `Viewer` anonymous role doesn't show the plugin, so for ease-of-use anonymous auth will be turned off. It can be re-enabled with the `Viewer` role via `local/config.yaml` by adding ``` grafanaWithAnonymousAuth: true ``` We could also have `grafanaAnonymousAuth` be a string key that allows for specifying a specific role, rather than an on/off switch, I have no strong opinions on that, and would love any opinions on it.
1 parent e01948c commit d91dce1

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

cmd/grafana-app-sdk/project_local.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type localEnvConfig struct {
4747
GenerateGrafanaDeployment bool `json:"generateGrafanaDeployment" yaml:"generateGrafanaDeployment"`
4848
GrafanaImage string `json:"grafanaImage" yaml:"grafanaImage"`
4949
GrafanaInstallPlugins string `json:"grafanaInstallPlugins" yaml:"grafanaInstallPlugins"`
50+
GrafanaWithAnonymousAuth bool `json:"grafanaWithAnonymousAuth" yaml:"grafanaWithAnonymousAuth"`
5051
}
5152

5253
type dataSourceConfig struct {
@@ -320,6 +321,7 @@ type yamlGenProperties struct {
320321
GenerateGrafanaDeployment bool
321322
GrafanaImage string
322323
GrafanaInstallPlugins string
324+
GrafanaAnonymousAuth string
323325
}
324326

325327
type yamlGenPropsCRD struct {
@@ -391,6 +393,9 @@ func generateKubernetesYAML(crdGenFunc func() (codejen.Files, error), pluginID s
391393
// Prefix with "localhost/" to ensure that our local build uses our locally-built image
392394
props.OperatorImage = fmt.Sprintf("localhost/%s", props.OperatorImage)
393395
}
396+
if config.GrafanaWithAnonymousAuth {
397+
props.GrafanaAnonymousAuth = "Viewer"
398+
}
394399

395400
if props.WebhookProperties.Enabled {
396401
if config.Webhooks.Port > 0 {

cmd/grafana-app-sdk/templates/local/generated/grafana.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ data:
6969
reporting_enabled = false
7070
[tracing.opentelemetry.otlp]
7171
address = tempo.default.svc:4317
72-
[auth.anonymous]
72+
[auth.anonymous]{{ if .GrafanaAnonymousAuth }}
7373
enabled = true
74-
org_role = Admin
74+
org_role = {{ .GrafanaAnonymousAuth }}{{ else }}
75+
enabled = false{{ end }}
7576
[log.frontend]
7677
enabled = true
7778
[plugins]

docs/local-development.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ With those extra two steps done, you should now have a working local deployment.
201201
202202
## Accessing Your Deployment
203203
204-
Once up, your local grafana can be accessed via [grafana.k3d.localhost:9999](http://grafana.k3d.localhost:9999) (if you used a `port` other than 9999 in your `local/config.yaml`, use that instead in the URL).
204+
Once up, your local grafana can be accessed via [grafana.k3d.localhost:9999](http://grafana.k3d.localhost:9999) (if you used a `port` other than 9999 in your `local/config.yaml`, use that instead in the URL).
205+
The default username and password for the local grafana is `admin`/`admin`.
206+
You can enable anonymous auth using a `Viewer` role by setting `grafanaWithAnonymousAuth: true` in `local/config.yaml`.
205207
206208
If you use kubectl, your kubeconfig should have its default context changed to the local cluster, so you can get any resources that way.
207209

docs/tutorials/issue-tracker/05-local-deployment.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,19 @@ Though not recommended, you can deploy without using tilt, if you desire. Not us
217217
### Interacting With Our Local Deployment
218218
219219
Our grafana is now available at [grafana.k3d.localhost:9999](http://grafana.k3d.localhost:9999).
220+
By default, the credentials to log in are `admin`/`admin`. You'll be prompted to change the password upon logging in.
221+
Note that if you do, you'll need to modify the cURL commands used later in this tutorial. You can also click `Skip` to avoid updating the password.
220222
Since our plugin is automatically installed, we can go to [grafana.k3d.localhost:9999/a/issuetrackerproject-app/](http://grafana.k3d.localhost:9999/a/issuetrackerproject-app/) and see the simple landing page that got generated for us, and we can interact with our backend APIs at [grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/resources/v1/issues](http://grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/resources/v1/issues).
221223
222224
Right now, if I do a curl to our list endpoint, we'll get back a response with an empty list:
223225
```shell
224-
$ curl http://grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/resources/v1/issues | jq .
226+
curl -u admin:admin http://grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/resources/v1/issues
227+
```
228+
> [!NOTE]
229+
> If you updated the password for your grafana instance, you'll need to change `-u admin:admin` to `-u admin:<your_new_password>`
230+
231+
```shell
232+
$ curl -u admin:admin http://grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/resources/v1/issues | jq .
225233
{
226234
"kind": "IssueList",
227235
"apiVersion": "issuetrackerproject.ext.grafana.com/v1",
@@ -235,7 +243,10 @@ $ curl http://grafana.k3d.localhost:9999/api/plugins/issuetrackerproject-app/res
235243
Our kinds are also available via the grafana API server, located at [http://grafana.k3d.localhost:9999/apis]. This is a kubernetes-compatible API server, and we can interact with it via cURL, or kubectl.
236244
Let's also list our issues that way:
237245
```shell
238-
curl http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
246+
curl -u admin:admin http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
247+
```
248+
```shell
249+
$ curl -u admin:admin http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
239250
{
240251
"apiVersion": "issuetrackerproject.ext.grafana.com/v1",
241252
"items": [],
@@ -249,7 +260,10 @@ curl http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/
249260
We can see the output is nearly identical, as the plugin backend is just a proxy to the API server. From this point, we could use the plugin backend or API server API,
250261
but seeing as the plugin backend will eventually be phased out of the default path, let's use the API server here, and create an Issue:
251262
```shell
252-
$ curl -X POST -H "content-type:application/json" -d '{"kind":"Issue","apiVersion":"issuetrackerproject.ext.grafana.com/v1","metadata":{"name":"test-issue","namespace":"default"},"spec":{"title":"Test","description":"A test issue","status":"open"}}' http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
263+
curl -u admin:admin -X POST -H "content-type:application/json" -d '{"kind":"Issue","apiVersion":"issuetrackerproject.ext.grafana.com/v1","metadata":{"name":"test-issue","namespace":"default"},"spec":{"title":"Test","description":"A test issue","status":"open"}}' http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
264+
```
265+
```shell
266+
$ curl -u admin:admin -X POST -H "content-type:application/json" -d '{"kind":"Issue","apiVersion":"issuetrackerproject.ext.grafana.com/v1","metadata":{"name":"test-issue","namespace":"default"},"spec":{"title":"Test","description":"A test issue","status":"open"}}' http://grafana.k3d.localhost:9999/apis/issuetrackerproject.ext.grafana.com/v1/namespaces/default/issues
253267
{
254268
"apiVersion": "issuetrackerproject.ext.grafana.com/v1",
255269
"kind": "Issue",
@@ -291,6 +305,9 @@ You can see that this includes metadata which we didn't define in our CUE, but w
291305
292306
For fun, we can also interact with our resources through kubectl:
293307
```shell
308+
kubectl get issue test-issue -o yaml
309+
```
310+
```shell
294311
$ kubectl get issue test-issue -o yaml
295312
apiVersion: issuetrackerproject.ext.grafana.com/v1
296313
kind: Issue

docs/tutorials/issue-tracker/06-frontend.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For this tutorial, we have one pre-written, that we'll discuss a few parts of. E
1212
mkdir -p plugin/src/api && curl -o plugin/src/api/issue_client.ts https://raw.githubusercontent.com/grafana/grafana-app-sdk/main/docs/tutorials/issue-tracker/frontend-files/issue-client.ts
1313
```
1414

15-
The client uses grafana libraries to make fetch requests to perform relevent actions, and uses the generated `Issue` type in `generated/issue/v1/issue_object_gen.ts` that mirrors our generated go `v1.Issue` type. We have methods for `get`, `list`, `create`, `update`, and `delete`. We'll use these methods in our update to the main page of the plugin.
15+
The client uses grafana libraries to make fetch requests to perform relevant actions, and uses the generated `Issue` type in `generated/issue/v1/issue_object_gen.ts` that mirrors our generated go `v1.Issue` type. We have methods for `get`, `list`, `create`, `update`, and `delete`. We'll use these methods in our update to the main page of the plugin.
1616

1717
## Main Page
1818

@@ -92,11 +92,11 @@ That we'll use in our display output to show the correct Issue status and displa
9292

9393
Now we want to redeploy our plugin front-end to see the changes. Since we don't need to rebuild the operator or the plugin's backend, we can just do
9494
```bash
95-
$ make build/plugin-frontend
95+
make build/plugin-frontend
9696
```
9797
After that completes, we can redploy to our active local environment with
9898
```bash
99-
$ make local/deploy_plugin
99+
make local/deploy_plugin
100100
```
101101
And just like that, we can refresh or go to [http://grafana.k3d.localhost:9999/a/issuetrackerproject-app/], and see our brand-new plugin UI.
102102
If we create a new issue, we can see that it shows up in the list, or via a `kubectl get issues`.

0 commit comments

Comments
 (0)