required field to true on the authorization configuration object.
config.yaml
required, the API will ensure valid credentials are present on management API requests. Evaluation and OFREP endpoints are excluded by default. See Evaluation and OFREP Exclusions to opt in to enforcement.
Once authorization has been set to
required: true all management API routes will require a valid authentication session as well.The UI will require a session-compatible authentication method (e.g. OIDC) to be enabled.Evaluation and OFREP Exclusions
Evaluation (/evaluate/v1 and /client/v2 snapshot/stream) and OFREP (/ofrep) endpoints bypass authorization by default, even when authorization.required is true.
To enforce authorization on evaluation or OFREP, set the corresponding exclusion option to false:
Sections of the API excluded from authentication always skip authorization as
well, since there is no identity to evaluate policy against. To enforce
authorization on evaluation or OFREP, you must also require authentication for
those sections by setting
authentication.exclude.evaluation and
authentication.exclude.ofrep to false.evaluate action instead of read. This lets you grant evaluation without granting management reads, for example with namespace-scoped tokens:
Backends
Flipt uses Open Policy Agent (OPA) to enforce authorization policies. OPA is a general-purpose policy engine that can be used to enforce policies across the stack. Flipt supports sourcing policies and external data from various backends. Currently, Flipt supports the following backends:Local
Flipt supports loading policy and external data from the local filesystem.Policies
For configuring policies, the files must be valid Rego files. You can specify the path to the policy file in thepolicy object in the authorization configuration object.
policy.rego
Flipt v2 uses
package flipt.authz.v2 instead of v1’s package flipt.authz.v1. This is a breaking change that reflects the enhanced
authorization model.Polling Interval
Flipt will poll the policy file for changes at a regular interval. By default, Flipt will poll the policy file every 5 minutes. You can adjust this interval by setting thepoll_interval field in the policy object.
External Data
In addition to policies that can be used to enforce authorization rules, Flipt also provides a way to pass external data to the policy evaluation from the local filesystem. These data objects must be valid JSON objects. This can be done by setting thedata object in the authorization configuration object.
Polling Interval
Like policies, Flipt will poll data files for changes at a regular interval. By default, Flipt will poll the data file every 30 seconds. You can adjust this interval by setting thepoll_interval field in the data object.
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 (k8s is accepted as an alias for kubernetes).
Example:
policy.rego
Policy Input
For every request that requires authorization, Flipt evaluates the policy against aninput document with two fields: request describes what the caller is trying to do, and authentication describes who the caller is.
Request
input.request contains the following fields:
scope: The level at which the action is performed:environment: operations on environments and on namespaces themselves, such as listing environments, creating a branch, or reading, updating and deleting a namespace.namespace: operations on a namespace and the resources (flags, segments, etc.) within it.authentication: listing, reading or deleting other authentication sessions and tokens. Requests with this scope have noenvironmentornamespace.
action: One ofcreate,read,update,deleteorevaluate. See Evaluation and OFREP Exclusions for whenevaluateis used.environment: The key of the environment the request targets. Omitted when the request is not bound to an environment.namespace: The key of the namespace the request targets. Omitted when the request is not bound to a namespace.
The
authentication scope was added in v2.14.1. Because these requests have
no environment, rules that match on input.request.environment never allow
them. Only callers allowed by a rule that doesn’t check the environment, such
as a global admin rule, can manage other authentications.Authentication
input.authentication contains the following fields:
id: The unique ID of the authentication. For static tokens, this is the token’s name in the configuration. Requests authenticated with a JWT have no ID.method: The authentication method as a number (1=token,2=oidc,3=kubernetes,4=github,5=jwt). Use theflipt.is_auth_methodhelper instead of comparing numbers.metadata: A map of metadata set by the authentication method. All values are strings.created_at,updated_atandexpires_at: Timestamps withsecondsandnanosfields. Omitted when unset. For example, static tokens have noexpires_at, and requests authenticated with a JWT have no timestamps.
Metadata Keys
The metadata keys depend on the authentication method used for the request:
A key is only present when the authentication method has a value for it. For example,
io.flipt.auth.email is missing if the OIDC provider does not return an email address. Keep the following in mind when writing policies:
io.flipt.auth.claimsholds all claims of the OIDC ID token (including the UserInfo claims whenfetch_extra_user_infois enabled) or of the JWT, encoded as a JSON string. Usejson.unmarshalto read claims that Flipt does not map to their own key, such as groups, roles or scopes.io.flipt.auth.github.organizationsandio.flipt.auth.github.teamsare only set when theread:orgscope is configured. They are JSON strings: a list of organizations, and a map of organization to a list of teams, respectively.- The
io.flipt.auth.jwt.*attributes follow the JWT claims mapping. JWT claims whose names start withio.flipt.authare also copied into the metadata as is, so a JWT can set keys such asio.flipt.auth.emaildirectly. Useflipt.is_auth_methodwhen a rule should only apply to one authentication method.
flipt-admins in the groups claim of their ID token:
policy.rego
platform team in the my-org GitHub organization:
policy.rego
Key Differences from v1
Flipt v2 authorization introduces several important changes:1. Environment-Aware Authorization
Unlike v1, which operates at the namespace level, v2 introduces a hierarchical model with environments:- Global scope: Full access to all environments and namespaces
- Environment scope: Manage namespaces within specific environments
- Namespace scope: Manage resources (flags, segments, etc.) within specific namespaces
2. Optional Policy Queries for UI Filtering
v2 policies can optionally implement two special queries to enable UI filtering. When implemented, these queries allow the Flipt UI to show only the environments and namespaces that users have access to:These queries are optional. If not implemented, the UI will show all
environments and namespaces, but authorization will still be enforced when
users attempt to access them.Implementing these queries improves the user
experience by filtering out inaccessible resources in the UI.
3. Simplified Request Structure
v2 uses a simplified request structure withscope field:
evaluate action is used for evaluation, snapshot, and OFREP requests when those endpoints are not excluded from authorization. Use it to grant evaluation without granting management reads.
Example Policies
Basic RBAC Policy
Here’s a complete example of a v2 RBAC policy. It identifies users by their email address (io.flipt.auth.email) and groups by the groups claim of their ID token, which works for OIDC providers that include a groups claim. If you use a different authentication method, adjust subject_ids to the metadata keys your method sets.
policy.rego
Example Data Structure
The accompanyingdata.json file defines role bindings:
data.json
- Global admins: Full access to everything
- Platform team: Manage all namespaces in production, read/update in staging
- Developers: Full access to specific namespaces in development, read-only in staging
Migration from v1
When migrating from v1 to v2:- Update package declaration from
flipt.authz.v1toflipt.authz.v2 - Add environment context to your role bindings
- Optionally implement the UI filtering queries:
viewable_environmentsandviewable_namespaces(env)for better UX - Update request handling to use the new
scopefield instead ofresource/subject - Remove bundle configurations as they’re not supported in v2 (yet)