|
| 1 | +--- |
| 2 | +title: "Configuration" |
| 3 | +linkTitle: "Configuration" |
| 4 | +weight: 2 |
| 5 | +description: > |
| 6 | + Setting up and configuring Elekto for operation |
| 7 | +--- |
| 8 | + |
| 9 | +# Configuration and Setup |
| 10 | + |
| 11 | +Elekto's configuration is divided into three parts: |
| 12 | + |
| 13 | +1. Oauth and GitHub configuration |
| 14 | +2. Runtime environment |
| 15 | +3. Per-election configuration |
| 16 | + |
| 17 | +This document covers the first two, which consists of the items that need to be configured before Elekto will run. The third part is covered in the [Administrator Guide]. |
| 18 | + |
| 19 | +## Oauth and Repository Configuration |
| 20 | + |
| 21 | +Elekto relies on an external Oauth provider for user authentication, by design. This provider must be configured to accept authentication requests from Elekto. You may only have one Oauth provider per Elekto instance, as authentication happens before selecting an election. |
| 22 | + |
| 23 | +You must also configure the repository that contains the election metadata (hereafter "the repo") to push changes to Elekto. |
| 24 | + |
| 25 | +Currently, the only Oauth provider offered is GitHub. Contributions of additional providers are extremely welcome. |
| 26 | + |
| 27 | +### GitHub Setup |
| 28 | + |
| 29 | +#### GitHub Oauth |
| 30 | + |
| 31 | +You must set up an "Oauth Application" that Elekto can use. In GitHub, this is under Settings-->Developer Tools-->Oauth Applications. Note that Oauth Apps are belong to *accounts* rather than organizations, so you'll want to set up an account with shared access in your infra team. We also recommend setting up a separate Oauth App for Elekto rather than re-using one created for other purposes, and giving each Elekto instance its own secret key. |
| 32 | + |
| 33 | +The Oauth App must have the following settings: |
| 34 | + |
| 35 | +* |
| 36 | + |
| 37 | +Having configured this, you can populate GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET in Elekto's runtime environment. |
| 38 | + |
| 39 | +#### GitHub Repository Webhook |
| 40 | + |
| 41 | +In order to receive changes from the repo, you need to add a webhook that pushes changes whenever you merge. Webhooks are under "settings" for the individual repository (which also means you must be a repo onwer). |
| 42 | + |
| 43 | +The Webhook should have the following settings: |
| 44 | + |
| 45 | +* Push webhook |
| 46 | +* JSON data format |
| 47 | +* Use TLS |
| 48 | +* |
| 49 | +* Shared Secret set to the same as META_SECRET |
| 50 | + |
| 51 | +This last "secret" is an arbitrary string that authenticates the push to the Elekto server. It can be any string, such as one created by a password generator or a passphrase you like. This string then gets set in META_SECRET. |
| 52 | + |
| 53 | +## The Environment File |
| 54 | + |
| 55 | +Elekto is designed to accept its runtime configuration as ENV variables in its shell environment. A sample `.env.example` file can be found in the base directory of the Elekto source. These ENV configuration variables are not expected to change frequently, or at all, for any particular running Elekto instance. Changing them generally requires restarting Elekto. |
| 56 | + |
| 57 | +All of these env variables need to be set before starting Elekto as a uwsgi application, or even in developer mode; without them, Elekto will error out and refuse to start. You can set this up however you please: |
| 58 | + |
| 59 | +* as the `.bashrc` for the elekto application user |
| 60 | +* as ENV variables for a container running Elekto |
| 61 | +* preloaded in a systemd unit file |
| 62 | +* injected through a ConfigMap and a Secret into an Kubernetes pod |
| 63 | + |
| 64 | +Since we use ENV for Elekto configuration, this does mean that Elekto must be launched under a shell. |
| 65 | + |
| 66 | +### ENV Variables |
| 67 | + |
| 68 | +What follows are the ENV variables that must be set for Elekto to run. |
| 69 | + |
| 70 | +#### Application Information |
| 71 | + |
| 72 | +**APP_NAME** |
| 73 | + |
| 74 | +*Required* Name of the Elekto instance you are running. Displays in some parts of the UI. For user information only. |
| 75 | + |
| 76 | +Example: `k8s.elections` |
| 77 | + |
| 78 | +**APP_ENV** |
| 79 | + |
| 80 | +*Optional* Status of this Elekto instance, for CI/CD purposes. Not used internally by Elekto. |
| 81 | + |
| 82 | +Example: `production` or `development` |
| 83 | + |
| 84 | +**APP_KEY** |
| 85 | + |
| 86 | +*Optional* Seed string for Flask encryption if running Flask in standalone mode. Not required if fronting with an HTTPS webserver. |
| 87 | + |
| 88 | +Example: `` |
| 89 | + |
| 90 | +FIXME |
| 91 | + |
| 92 | +**APP_DEBUG** |
| 93 | + |
| 94 | +*Required* Whether to run in Debug mode for troubleshooting purposes. In Debug mode, will output stack traces for errors and reload templates. |
| 95 | + |
| 96 | +Example: `True` or `False` |
| 97 | + |
| 98 | +**APP_URL** |
| 99 | + |
| 100 | +*Optional* URL of the Elekto instance. Used by some uwsgi and/or Nginx configurations. Not used internally by Elekto. |
| 101 | + |
| 102 | +Example: `http://elections.knative.dev` |
| 103 | + |
| 104 | +**APP_PORT** |
| 105 | + |
| 106 | +*Optional* Used in some uwsgi start scripts, and when running Flask in standalone mode. Port on which to serve Elekto. |
| 107 | + |
| 108 | +Example: `5000` |
| 109 | + |
| 110 | +**APP_HOST** |
| 111 | + |
| 112 | +*Optional* Used in some webserver startup scripts, and by the Flask server in standalone mode. Name of the host served by this Elekto instance. |
| 113 | + |
| 114 | +Example: `localhost` |
| 115 | + |
| 116 | +**APP_CONNECT** |
| 117 | + |
| 118 | +*Optional* Whether to serve uwsgi over HTTP or via a local unix socket. Used by some startup scripts; see `entrypoint.sh` for an example. |
| 119 | + |
| 120 | +Example: `http` or `socket` |
| 121 | + |
| 122 | +#### Database Connection |
| 123 | + |
| 124 | +**DB_CONNECTION** |
| 125 | + |
| 126 | +*Required* Which database connection type to use. Currently only postgresql, mysql, and sqlite are supported. |
| 127 | + |
| 128 | +Example: `postgresql`, `mysql`, or `sqlite` |
| 129 | + |
| 130 | +**DB_HOST** |
| 131 | + |
| 132 | +*Required* The URL, IP, or hostname of the database server. Ignored if using SQLite (set to `N/A`). |
| 133 | + |
| 134 | +Example: `pgdb-1a.prod.elekto.dev` |
| 135 | + |
| 136 | +**DB_PORT** |
| 137 | + |
| 138 | +*Required* The network port for the database server. Ignored if using SQLite (set to `1001`). |
| 139 | + |
| 140 | +Example: `3306` |
| 141 | + |
| 142 | +**DB_PATH** |
| 143 | + |
| 144 | +*Optional* Used only for SQLite. Path to the database filesystem. |
| 145 | + |
| 146 | +Example: `/var/db/elekto-db` |
| 147 | + |
| 148 | +**DB_USERNAME** |
| 149 | + |
| 150 | +*Required* Login user for the Elekto database. Not used by SQLite. |
| 151 | + |
| 152 | +Example: `elekto` |
| 153 | + |
| 154 | +**DB_PASSWORD** |
| 155 | + |
| 156 | +*Required* Authentication password for the Elekto database. Not used by SQLite. |
| 157 | + |
| 158 | +Example: `1a6e4b3f55dc` |
| 159 | + |
| 160 | +#### Repository Configuration |
| 161 | + |
| 162 | +**META_REPO** |
| 163 | + |
| 164 | +*Required* GIT clone URL for the repository which contains the election configurations. Should be the `.git` link, not the `.html` one. |
| 165 | + |
| 166 | +Example: `https://github.com/kalkayan/k8s.elections.meta.git` |
| 167 | + |
| 168 | +**ELECTION_DIR** |
| 169 | + |
| 170 | +*Required* Directory, relative to the Git repository root, containing the set of election subdirectories. Can be an arbitrarily deep path. Do not use a leading or trailing `/`. |
| 171 | + |
| 172 | +Example: `elections`, `gov/steering/elections` |
| 173 | + |
| 174 | +**META_DEPLOYMENT** |
| 175 | + |
| 176 | +*Optional* Reserved for future advanced configuration use. |
| 177 | + |
| 178 | +Example: `local`, `sidecar` |
| 179 | + |
| 180 | +**META_PATH** |
| 181 | + |
| 182 | +*Required* Local file location at which to store a clone of the election data repository. This directory will be created by Elekto at sync time, so the application must have the ability to write to the parent directory. May be absolute or relative; if relative, will be under the eletko source directory. Defaults to `meta`. For containers, a directory under `/tmp` is recommended to make sure the location is writeable. |
| 183 | + |
| 184 | +Example: `meta`, `/tmp/meta` |
| 185 | + |
| 186 | +**META_BRANCH** |
| 187 | + |
| 188 | +*Required* Which git branch has the merged version of the election data. Defaults to `main`. |
| 189 | + |
| 190 | +Example: `main`, `master`, `prod` |
| 191 | + |
| 192 | +**META_SECRET** |
| 193 | + |
| 194 | +*Required* The shared secret string used in the Github webhook for updates of the election data repository. Can be set to anything you like; we recommend a random md5 string or generated password. |
| 195 | + |
| 196 | +Example: `92a488d11c0d27bbfea0a97e3332e08a` |
| 197 | + |
| 198 | +#### Oauth Settings |
| 199 | + |
| 200 | +At this time, there are only settings available for GitHub because other Oauth sources haven't been implemented. When other sources get added to Elekto, each will get their own configuration variables. |
| 201 | + |
| 202 | +**GITHUB_REDIRECT** |
| 203 | + |
| 204 | +*Required* Flask path for the GitHub authentication callback. Defaults to `/oauth/github/callback`, and there's no good reason to change it. |
| 205 | + |
| 206 | +Example: `/oauth/github/callback` |
| 207 | + |
| 208 | +**GITHUB_CLIENT_ID** |
| 209 | + |
| 210 | +*Required* The Client ID from the GitHub Oauth Application. |
| 211 | + |
| 212 | +Example: `0b9138c0b2ffeefd9fc1` |
| 213 | + |
| 214 | +**GITHUB_CLIENT_SECRET** |
| 215 | + |
| 216 | +*Required* The Client Secret from the GitHub Oauth Application. |
| 217 | + |
| 218 | +Example: `dd37278f8e9d57571590ad9288f0aae62228c2e8` |
0 commit comments