For the complete documentation index, see llms.txt. This page is also available as Markdown.
BETA

Policy as Code for users and user groups

Use OPA policies to enforce identity governance rules on user invitations, scope assignments, and user group membership changes.

This feature is in Beta and requires enablement. View all early access features.

Harness uses Open Policy Agent (OPA) as its policy engine. You can write governance rules in Rego that are evaluated whenever a user is invited or assigned to a scope, or whenever a user group is created, updated, or its membership changes.

Use these policies to enforce a wide range of identity governance rules.


What you will learn in this topic

By the end of this topic, you will be able to:

  • Create OPA policies for user invitation and scope-assignment events.

  • Create OPA policies for user group create, update, and membership-change events.

  • Understand the input payloads available for each event type.

  • Describe policies for common identity governance use cases.


Before you begin

Before you configure OPA for user and user groups, ensure you have the following:


Policy evaluation behavior

When a user is added to multiple groups in a single operation, Harness evaluates the policy for each group independently. If any group's policy denies the operation, the entire operation fails, and no group memberships are updated. If a policy issues a warning, Harness allows the operation to proceed and displays the warning, provided no policy denies the operation.

Configure a policy and policy set

The steps below describe how to create a policy and a polciy set for users and user groups, along with Rego samples.

Step 1: Create a policy

  1. In Harness, go to Account Settings → Policies → New Policy.

  2. Enter a Name and click Apply.

  3. Write your Rego policy. Described below are policies for user and user groups.

  • User policy example

    • Restrict invitations to allowed email domains:

  • User group policy example

    • Enforce a naming convention on identifiers:

    • Require at least one member before a group can be saved:

Go to Input payloads to view the available fields for each entity type.

  1. Click Save.

Step 2: Create a policy set

  1. Go to Policy Sets → New Policy Set.

  2. Enter a Name and optional Description.

  3. In Entity Type that this policy set applies to, select User or User Group.

  4. In On what event should the policy set be evaluated, select On Save.

  5. Click Continue.

  6. Click + Add Policy and select the policy you created.

  7. In What should happen if a policy fails?, select:

    • Warn & continue - the entity is saved and a warning is surfaced.

    • Error and exit - the save is blocked and an error is returned.

  8. Click Finish.


Input payloads

User

The following fields are available (inexhaustive) when a User On Save policy is evaluated:

Path
Contents

input.user.email

Email address being added or invited

input.user.orgIdentifier

Target org scope of the operation

input.user.existingMemberships

Existing org/project memberships, populated only for users already in the account; empty for first-time invitees

input.user.roleAssignments

Role bindings included in the request

input.user.userGroups

User groups included in the request

input.metadata.roleAssignmentMetadata

The invitor's current role assignments; use this for privilege checks

Use case: Policy to prevent non-admins from granting the account admin role:

Use case: To block org-scoped operations that would add a user who already belongs to a different org (the existingMemberships field is empty for first-time invitees, so this rule applies only to existing account members):

User group

The following fields are available (inexhaustive) when a User Group On Save policy is evaluated:

Path
Contents

input.userGroup.identifier

The group's unique identifier

input.userGroup.orgIdentifier

The org the group belongs to (empty string at account scope)

input.userGroup.users

Array of user IDs in the group

input.userGroup.userMemberships

Map of userId → array of scope objects, each with scopeLevel ("ORGANIZATION", "PROJECT", "ACCOUNT") and scope.orgIdentifier / scope.projectIdentifier

Role-assignment operations are not yet evaluated by OPA policies The user group payload contains scope-membership data (which orgs and projects users belong to) but not role assignments. Operations such as inheriting role assignments from a parent scope cannot be blocked with a policy. To write policies based on explicit role assignments at invite time, use the User entity type and input.metadata.roleAssignmentMetadata.


Last updated

Was this helpful?