Security aspects
This page explains how security is handled in FlexMeasures. This deals with encryption, authentication and authorization. For hosts, we also provide some best practices.
Data
A FlexMeasures server handles two types of data in its Postgres database - structural data (e.g. information about sites, assets, users) and time series data for energy consumption/generation, prices or weather. Read more on The FlexMeasures data model. There is also a Redis database with information about ongoing forecasting and scheduling jobs (stored in a queueing system).
How these Postgres and Redis databases are set up and protected is up to the host.
More crucial to this documentation is that each FlexMeasures server reads from and writes to the Postgres database according to strict authentication and authorization rules. Much of the remainder of this page describes how this is implemented.
Finally, data sent back and forth between clients (e.g. browsers) and the server should be encrypted with HTTPS, the Hypertext Transfer Protocol encrypted by Transport Layer Security.
FlexMeasures does not set up HTTPS itself: that is up to the host, for instance on a reverse proxy or load balancer in front of FlexMeasures.
To have FlexMeasures redirect requests made via http:// to https://, set FLEXMEASURES_FORCE_HTTPS to True (it is False by default).
Authentication
Authentication is the system by which users tell the FlexMeasures platform that they are who they claim they are. This involves a username/password combination (“credentials”) or an access token.
No user passwords are stored in clear text on any server - the FlexMeasures platform only stores the hashed passwords, hashed with the Argon2 algorithm (the default of Flask-Security, which FlexMeasures uses for authentication). If an attacker steals these password hashes, they cannot compute the passwords from them in a practical amount of time.
In the API, access tokens are used so that the sending of usernames and passwords is limited (even if they are encrypted via https, see above) when dealing with the part of the FlexMeasures platform which sees the most traffic: the API functionality. Tokens thus have use cases for some scenarios, where developers want to treat authentication information with a little less care than credentials should be treated with, e.g. sharing among computers. However, they also expire fast, which is a common industry practice (by making them short-lived and requiring refresh, FlexMeasures limits the time an attacker can abuse a stolen token). At the moment, the access tokens on FlexMeasures platform expire after six hours. Access tokens are signed (with the itsdangerous library) and carry the time they were issued, which is how they expire. To change their maximum age, set
SECURITY_TOKEN_MAX_AGEto the number of seconds after which tokens should expire, in the config file (it is not read from an environment variable).In the UI, FlexMeasures supports two-factor authentication (2FA), which is off by default. When it is on, the knowledge of the password to your FlexMeasures account is not sufficient to gain access ― you also need a second piece of knowledge, which requires you to also have access to an independent system or device (e.g. a token sent to your email address). We strongly advise turning it on in production with SECURITY_TWO_FACTOR (see Two-factor authentication).
Note
Authentication (and authorization, see below) affects the FlexMeasures API and UI. The CLI (command line interface) can only be used if the user is already on the server and can execute flexmeasures commands, thus we can safely assume they are admins.
Best security-practices for hosts
Use the
TRUSTED_HOSTSsetting (see the Flask docs on the configuration and on the topic of host header validation) to specify on which hosts the platform is actually being provided. As an example for why this is valuable: FlexMeasures constructs URLs, e.g. for password reset links. Client code could set its ownHostrequest header to make these URLs lead to a different server. If the client “poisons” the URLs for its own users this way, they are using the user’s trust in the FlexMeasures host platform to hack them. List your own domain in this setting, but also the IP of your load balancer, if you are using one.