Skip to content
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

Ensure configured token is fetched during perms check #147

Merged
merged 1 commit into from
Oct 27, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pids
*.seed
*.pid.lock
.bra.toml
*.db

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
9 changes: 4 additions & 5 deletions pkg/plugin/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ func (app *App) GetAuthZClient(req *http.Request) (authz.EnforcementClient, erro
return nil, err
}

// Bail we cannot get token provisioned by externalServiceAccount and no token
// has been manually configured. In this case we cannot check permissions and moreover
// we cannot make API requests to Grafana
saToken, err := grafanaConfig.PluginAppClientSecret()
if err != nil || (saToken == "" && app.conf.Token == "") {
if err == nil {
err = errors.New("neither service account token nor configured token found")
}

if err != nil && app.conf.Token == "" {
ctxLogger.Error("failed to fetch service account and configured token", "error", err)

return nil, err
Expand Down
37 changes: 35 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,47 @@ extra configuration to get an API token from Grafana.
Grafana to make API requests to Grafana. This can be done automatically by enabling
feature flag `externalServiceAccounts`, which will create a service account and
provision a service account token automatically for the plugin. Please consult
[Local Installation](#local-installation) on how to configure the feature flags on
[Installation](#installation) on how to configure the feature flags on
Grafana server.

> [!NOTE]
> If the operators do not wish or cannot use `externalServiceAccounts` feature flag on
their Grafana deployment, it is possible to manually create an API token and set it in
the [plugin configuration options](#authentication-settings).

### Multiple Orgs

Grafana does not support yet automatically provisioning the plugins with service tokens
using `externalServiceAccounts`. More details can be found in this [GH issue](https://github.com/grafana/grafana/issues/91844).
A workaround in this case is to turn off the feature flag `externalServiceAccounts` and
manually create service account token for each Org. and setting it in the plugin
configuration file. In this case, the provisioned config for the plugin will look like this:

```yaml
apps:
- type: mahendrapaipuri-dashboardreporter-app
org_id: 1
org_name: Main Org.
disabled: false
secureJsonData:
saToken: <ServiceAccountTokenForMainOrg>
jsonData:
appUrl: http://localhost:3000

- type: mahendrapaipuri-dashboardreporter-app
org_id: 2
org_name: Test Org.
disabled: false
secureJsonData:
saToken: <ServiceAccountTokenForTestOrg>
jsonData:
appUrl: http://localhost:3000
```

> [!IMPORTANT]
> It is compulsory to disable `externalServiceAccounts` feature flag in multiple Org. setting
as plugin wont work as expected with this feature flag.

## Using plugin

### Using Grafana web UI
Expand Down Expand Up @@ -403,7 +436,7 @@ any HTTP client of your favorite programming language.

## Security

All the feature flags listed in the [Local Installation](#local-installation) section
All the feature flags listed in the [Installation](#installation) section
must be enabled on Grafana server for secure operation of your Grafana instance.
These feature flags enables the plugin to verify
the if the user who is making the request to generate the report has
Expand Down