|
| 1 | +# How to setup third party OAuth for Grafana |
| 2 | + |
| 3 | +## Contents |
| 4 | + |
| 5 | +* [Introduction](#introduction) |
| 6 | +* [Prerequisites](#prerequisites) |
| 7 | +* [Steps](#steps) |
| 8 | +* [What's next?](#whats-next) |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +This document explains how to enable any supported auth provider on Grafana deployed as a part of |
| 13 | +Prometheus Operator. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- On Packet: You have a DNS entry in any DNS provider for `grafana.mydomain.net` against the Packet |
| 18 | + EIP. |
| 19 | +- On AWS: You don't have to make any special DNS entries. Just make sure that the |
| 20 | + `grafana.ingress.host` value is `grafana.<CLUSTER NAME>.<AWS DNS ZONE>`. |
| 21 | + |
| 22 | +## Steps |
| 23 | + |
| 24 | +**NOTE**: This guide assumes that the underlying cloud platform is Packet and the OAuth provider is |
| 25 | +GitHub. For other OAuth providers the steps are the same but the secret parameters will change as |
| 26 | +mentioned in [Step 3](#step-3). |
| 27 | + |
| 28 | +#### Step 1 |
| 29 | + |
| 30 | +- Create a GitHub OAuth application as documented in the [Grafana |
| 31 | + docs](https://grafana.com/docs/grafana/latest/auth/github/). |
| 32 | +- Set **Homepage URL** to https://grafana.mydomain.net. This should be same as the |
| 33 | + `grafana.ingress.host` or `grafana.<CLUSTER NAME>.<AWS DNS ZONE>` as shown in [Step 2](#step-2). |
| 34 | +- Set **Authorization callback URL** to https://grafana.mydomain.net/login/github. |
| 35 | +- Make a note of `Client ID` and `Client Secret`, they will be needed in [Step 3](#step-3). |
| 36 | + |
| 37 | +#### Step 2 |
| 38 | + |
| 39 | +Create a file named `prometheus-operator.lokocfg` file with the following contents: |
| 40 | + |
| 41 | +```tf |
| 42 | +component "prometheus-operator" { |
| 43 | + namespace = "monitoring" |
| 44 | +
|
| 45 | + grafana { |
| 46 | + secret_env = var.grafana_secret_env |
| 47 | + ingress { |
| 48 | + host = "grafana.mydomain.net" |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +Observe the value of variable `secret_env` it should match the name of variable to be created in |
| 55 | +[Step 3](#step-3). |
| 56 | + |
| 57 | +#### Step 3 |
| 58 | + |
| 59 | +Create a `lokofg.vars` file or add the following to an existing file, setting the values of this |
| 60 | +secret as needed: |
| 61 | + |
| 62 | +```tf |
| 63 | +grafana_secret_env = { |
| 64 | + "GF_AUTH_GITHUB_ENABLED" = "'true'" |
| 65 | + "GF_AUTH_GITHUB_ALLOW_SIGN_UP" = "'true'" |
| 66 | + "GF_AUTH_GITHUB_CLIENT_ID" = "YOUR_GITHUB_APP_CLIENT_ID" |
| 67 | + "GF_AUTH_GITHUB_CLIENT_SECRET" = "YOUR_GITHUB_APP_CLIENT_SECRET" |
| 68 | + "GF_AUTH_GITHUB_SCOPES" = "user:email,read:org" |
| 69 | + "GF_AUTH_GITHUB_AUTH_URL" = "https://github.com/login/oauth/authorize" |
| 70 | + "GF_AUTH_GITHUB_TOKEN_URL" = "https://github.com/login/oauth/access_token" |
| 71 | + "GF_AUTH_GITHUB_API_URL" = "https://api.github.com/user" |
| 72 | + "GF_AUTH_GITHUB_ALLOWED_ORGANIZATIONS" = "YOUR_GITHUB_ALLOWED_ORGANIZATIONS" |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +**NOTE**: In the above configuration, boolean values are set to `"'true'"` instead of plain `"true"` |
| 77 | +because Kubernetes expects the key value pair to be of type string and not boolean. |
| 78 | + |
| 79 | +Replace `YOUR_GITHUB_APP_CLIENT_ID` with `Client ID` and `YOUR_GITHUB_APP_CLIENT_SECRET` with |
| 80 | +`Client Secret` collected in [Step 1](#step-1). And replace `YOUR_GITHUB_ALLOWED_ORGANIZATIONS` with |
| 81 | +Github organisation that your users belong to. |
| 82 | + |
| 83 | +Modify the values of the GitHub Auth configuration from |
| 84 | + |
| 85 | +```ini |
| 86 | +[auth.github] |
| 87 | +enabled = true |
| 88 | +client_id = YOUR_GITHUB_APP_CLIENT_ID |
| 89 | +... |
| 90 | +``` |
| 91 | + |
| 92 | +to look like following: |
| 93 | + |
| 94 | +```tf |
| 95 | +"GF_AUTH_GITHUB_ENABLED" = "'true'" |
| 96 | +"GF_AUTH_GITHUB_CLIENT_ID" = "YOUR_GITHUB_APP_CLIENT_ID" |
| 97 | +``` |
| 98 | + |
| 99 | +The section name `[auth.github]` should be prepended with `GF_` and the name should be capitalised |
| 100 | +and `.` be replaced with `_`. |
| 101 | + |
| 102 | +Deploy the prometheus operator using following command: |
| 103 | + |
| 104 | +```bash |
| 105 | +lokoctl component apply prometheus-operator |
| 106 | +``` |
| 107 | + |
| 108 | +#### Step 4 |
| 109 | + |
| 110 | +Go to https://grafana.mydomain.net and use the newly appreared **Sign in with GitHub** button, to |
| 111 | +sign in with Github. |
| 112 | + |
| 113 | +## What's next? |
| 114 | + |
| 115 | +- Other auth providers for Grafana: |
| 116 | + https://grafana.com/docs/grafana/latest/auth/overview/#user-authentication-overview |
0 commit comments