Flipt authorization is disabled (not required) by default.Head to the Configuration: Authorization section to learn how to enable it.
allowed == true
for the request to be allowed.
/api/v1/
Open Policy Agent (OPA)
Open Policy Agent (OPA) is a general-purpose policy engine that can be used to configure and enforce authorization policies. OPA provides a unified toolset and framework for policy across the cloud native stack. Open Policy Agent is a CNCF project and is used by many organizations to enforce policies across their cloud-native environments. Flipt embeds OPA to evaluate policies that determine whether a request should be allowed or denied. This means that no additional infrastructure or services are required to use OPA with Flipt.Check out our Role-Based Access Control with Keycloak
guide for an example on
how to configure and use role-based access control (RBAC) with Flipt and
Keycloak using OPA.
Policies
Flipt uses OPA to enforce authorization policies for the Management API. The policies are written in Rego, a powerful, declarative policy language. The path to this file is provided as described in the Configuration: Authorization section. Part of the power of OPA is that it’s extremely flexible as it allows you to define fine-grained policies tailored to your exact needs. Here’s an example of a simple policy that checks whether custom claims provided at authentication time include a keyroles
containing a value admin
:
policy.rego
OPA has a rich set of built-in functions that can be used to write complex
policies. They also provide a Rego
Playground where you can test your
policies before deploying them.
input.authentication
: The authentication information for the request. These are specific to each authentication provider/method and can include things like the user’s roles, email, etc.input.request
: The incoming request details, such as thenamespace
,resource
, andaction
.
Authentication Information
Flipt provides the raw authentication information to OPA for evaluation. This information is specific to the authentication method used to authenticate the request. For example, if you’re using the OIDC authentication method, theinput.authentication.metadata
field may contain the user’s name and email as well as custom claims assigned to the user.
Here is an example of the input.authentication.metadata
field for a request authenticated using an example OIDC provider:
The
io.flipt.auth.claims
field is a JSON object that contains custom claims
provided by the authentication provider. Each authentication provider may
provide different claims, so it’s up to you to map these claims as needed in
your policies.input.authentication
field:
metadata
: A map of authentication metadata provided by the authentication method. This can include the user’s email, name, roles, etc.io.flipt.auth.email
: The user’s email address.io.flipt.auth.name
: The user’s name.io.flipt.auth.claims
: A map of all claims provided by the authentication method. This can include the user’s roles, groups, etc. These claims are marshaled into a JSON string before being passed to OPA for evaluation.
method
: The authentication method used to authenticate the request.
Helper Functions
To make it easier to write policies, Flipt provides a set of helper functions that are available to be used for theinput
field.
flipt.is_auth_method(input, method)
The helper function flipt.is_auth_method(input, method)
can be used to check if the request was authenticated using the specified method.
The method
parameter is the authentication method name as it is registered in Flipt, e.g. oidc
, token
, kubernetes
, github
, jwt
.
Example:
policy.rego
Mapping Identity
Each authentication method configurable within Flipt will provide different information depending on the identity. It’s up to you to combine identity information (authentication
) with the requested resource (request
) to make an authorization decision whether or not the request should be allowed (allow
).
Some authentication methods provide user details such as roles directly, while others may provide a user ID or email that you can use to look up roles in your own system. Many authentication providers support adding custom claims to the JWT token, which can be used to provide additional information about the user.
For example, Okta allows you to add custom claims using their groups feature. An example JWT token with custom claims generated by Okta might look like this:
groups
claim is used to provide the user’s organizational groups. You can then write a policy that checks for the presence of specific groups to determine whether the user should be allowed to access a particular resource.
policy.rego
The Rego builtin
json.unmarshal
function is used to convert the groups
claim from a string to a JSON object that can be queried in the policy.Flipt encodes the raw authentication claims as a JSON string to pass them to OPA for evaluation.Flipt has no notion of users or roles internally, it simply passes the raw
authentication information along with other request metadata to OPA for
evaluation.
Request Information
Theinput.request
field contains information about the incoming request. This includes the namespace
, resource
, and action
of the request.
-
namespace
: The namespace in Flipt of the resource being accessed. If no namespace is provided, the default namespace is used, or it is not applicable as the resource is not namespace scoped (e.g. authentication) -
resource
: The resource being accessed. This can be one of:namespace
: Access to namespace resources (e.g., listing or creating namespaces).flag
: Access to flag resources and sub-resources (e.g., listing or creating flags, variants, rules or rollouts).segment
: Access to segment resources and sub-resources (e.g., listing or creating segments, constraints or distributions).authentication
: Access to authentication resources (e.g., listing or creating client tokens).
-
subject
: The (optional) nested subject of the request. This can be one of:namespace
: Access to namespace resources.flag
: Access to flag resources.segment
: Access to segment resources.constraint
: Access to segment constraint resources.distribution
: Access to segment distribution resources.
token
: Access to client token resources.
-
action
: The action being performed on the resource. This can be one of:create
: Access to create resources.read
: Access to list or read resources.update
: Access to update resources.delete
: Access to delete resources.
input.request
field for a request to list flags in the default namespace:
policy.rego
IT
group to delete flags in the default namespace:
policy.rego
External Data
OPA policies can also use external data sources to make decisions. This can be useful when you need to make decisions based on data that is not available in the request context. For example, if your authentication method does not provide user roles, you could use an external data source to map user IDs to roles. Here is an example policy that uses an external data source to check if the user has theadmin
role:
policy.rego
data.json
Authoring Policies
While the examples provided in this document are simple, you can write policies that are as complex as you need. OPA provides a rich set of built-in functions that can be used to write complex policies.Check out our Role-Based Access Control with Keycloak
guide for an example on
how to configure and use role-based access control (RBAC) with Flipt and
Keycloak using OPA.