Allows you to manage aggregate policies.
Aggregate policies combine multiple policies into a single policy, allowing you to reuse existing policies to build more complex authorization logic.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
realm: "my-realm",
enabled: true,
});
const test = new keycloak.openid.Client("test", {
clientId: "client_id",
realmId: realm.id,
accessType: "CONFIDENTIAL",
serviceAccountsEnabled: true,
authorization: {
policyEnforcementMode: "ENFORCING",
},
});
const rolePolicy = new keycloak.openid.ClientRolePolicy("role_policy", {
resourceServerId: test.resourceServerId,
realmId: realm.id,
name: "role_policy",
decisionStrategy: "UNANIMOUS",
logic: "POSITIVE",
roles: [{
id: testKeycloakRole.id,
required: true,
}],
});
const userPolicy = new keycloak.openid.ClientUserPolicy("user_policy", {
resourceServerId: test.resourceServerId,
realmId: realm.id,
name: "user_policy",
decisionStrategy: "UNANIMOUS",
logic: "POSITIVE",
users: [testKeycloakUser.id],
});
const testClientAggregatePolicy = new keycloak.openid.ClientAggregatePolicy("test", {
resourceServerId: test.resourceServerId,
realmId: realm.id,
name: "aggregate_policy",
decisionStrategy: "AFFIRMATIVE",
logic: "POSITIVE",
policies: [
rolePolicy.id,
userPolicy.id,
],
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
test = keycloak.openid.Client("test",
client_id="client_id",
realm_id=realm.id,
access_type="CONFIDENTIAL",
service_accounts_enabled=True,
authorization={
"policy_enforcement_mode": "ENFORCING",
})
role_policy = keycloak.openid.ClientRolePolicy("role_policy",
resource_server_id=test.resource_server_id,
realm_id=realm.id,
name="role_policy",
decision_strategy="UNANIMOUS",
logic="POSITIVE",
roles=[{
"id": test_keycloak_role["id"],
"required": True,
}])
user_policy = keycloak.openid.ClientUserPolicy("user_policy",
resource_server_id=test.resource_server_id,
realm_id=realm.id,
name="user_policy",
decision_strategy="UNANIMOUS",
logic="POSITIVE",
users=[test_keycloak_user["id"]])
test_client_aggregate_policy = keycloak.openid.ClientAggregatePolicy("test",
resource_server_id=test.resource_server_id,
realm_id=realm.id,
name="aggregate_policy",
decision_strategy="AFFIRMATIVE",
logic="POSITIVE",
policies=[
role_policy.id,
user_policy.id,
])
package main
import (
"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak"
"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak/openid"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
Realm: pulumi.String("my-realm"),
Enabled: pulumi.Bool(true),
})
if err != nil {
return err
}
test, err := openid.NewClient(ctx, "test", &openid.ClientArgs{
ClientId: pulumi.String("client_id"),
RealmId: realm.ID(),
AccessType: pulumi.String("CONFIDENTIAL"),
ServiceAccountsEnabled: pulumi.Bool(true),
Authorization: &openid.ClientAuthorizationArgs{
PolicyEnforcementMode: pulumi.String("ENFORCING"),
},
})
if err != nil {
return err
}
rolePolicy, err := openid.NewClientRolePolicy(ctx, "role_policy", &openid.ClientRolePolicyArgs{
ResourceServerId: test.ResourceServerId,
RealmId: realm.ID(),
Name: pulumi.String("role_policy"),
DecisionStrategy: pulumi.String("UNANIMOUS"),
Logic: pulumi.String("POSITIVE"),
Roles: openid.ClientRolePolicyRoleArray{
&openid.ClientRolePolicyRoleArgs{
Id: pulumi.Any(testKeycloakRole.Id),
Required: pulumi.Bool(true),
},
},
})
if err != nil {
return err
}
userPolicy, err := openid.NewClientUserPolicy(ctx, "user_policy", &openid.ClientUserPolicyArgs{
ResourceServerId: test.ResourceServerId,
RealmId: realm.ID(),
Name: pulumi.String("user_policy"),
DecisionStrategy: pulumi.String("UNANIMOUS"),
Logic: pulumi.String("POSITIVE"),
Users: pulumi.StringArray{
testKeycloakUser.Id,
},
})
if err != nil {
return err
}
_, err = openid.NewClientAggregatePolicy(ctx, "test", &openid.ClientAggregatePolicyArgs{
ResourceServerId: test.ResourceServerId,
RealmId: realm.ID(),
Name: pulumi.String("aggregate_policy"),
DecisionStrategy: pulumi.String("AFFIRMATIVE"),
Logic: pulumi.String("POSITIVE"),
Policies: pulumi.StringArray{
rolePolicy.ID(),
userPolicy.ID(),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Keycloak = Pulumi.Keycloak;
return await Deployment.RunAsync(() =>
{
var realm = new Keycloak.Realm("realm", new()
{
RealmName = "my-realm",
Enabled = true,
});
var test = new Keycloak.OpenId.Client("test", new()
{
ClientId = "client_id",
RealmId = realm.Id,
AccessType = "CONFIDENTIAL",
ServiceAccountsEnabled = true,
Authorization = new Keycloak.OpenId.Inputs.ClientAuthorizationArgs
{
PolicyEnforcementMode = "ENFORCING",
},
});
var rolePolicy = new Keycloak.OpenId.ClientRolePolicy("role_policy", new()
{
ResourceServerId = test.ResourceServerId,
RealmId = realm.Id,
Name = "role_policy",
DecisionStrategy = "UNANIMOUS",
Logic = "POSITIVE",
Roles = new[]
{
new Keycloak.OpenId.Inputs.ClientRolePolicyRoleArgs
{
Id = testKeycloakRole.Id,
Required = true,
},
},
});
var userPolicy = new Keycloak.OpenId.ClientUserPolicy("user_policy", new()
{
ResourceServerId = test.ResourceServerId,
RealmId = realm.Id,
Name = "user_policy",
DecisionStrategy = "UNANIMOUS",
Logic = "POSITIVE",
Users = new[]
{
testKeycloakUser.Id,
},
});
var testClientAggregatePolicy = new Keycloak.OpenId.ClientAggregatePolicy("test", new()
{
ResourceServerId = test.ResourceServerId,
RealmId = realm.Id,
Name = "aggregate_policy",
DecisionStrategy = "AFFIRMATIVE",
Logic = "POSITIVE",
Policies = new[]
{
rolePolicy.Id,
userPolicy.Id,
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.keycloak.Realm;
import com.pulumi.keycloak.RealmArgs;
import com.pulumi.keycloak.openid.Client;
import com.pulumi.keycloak.openid.ClientArgs;
import com.pulumi.keycloak.openid.inputs.ClientAuthorizationArgs;
import com.pulumi.keycloak.openid.ClientRolePolicy;
import com.pulumi.keycloak.openid.ClientRolePolicyArgs;
import com.pulumi.keycloak.openid.inputs.ClientRolePolicyRoleArgs;
import com.pulumi.keycloak.openid.ClientUserPolicy;
import com.pulumi.keycloak.openid.ClientUserPolicyArgs;
import com.pulumi.keycloak.openid.ClientAggregatePolicy;
import com.pulumi.keycloak.openid.ClientAggregatePolicyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var realm = new Realm("realm", RealmArgs.builder()
.realm("my-realm")
.enabled(true)
.build());
var test = new Client("test", ClientArgs.builder()
.clientId("client_id")
.realmId(realm.id())
.accessType("CONFIDENTIAL")
.serviceAccountsEnabled(true)
.authorization(ClientAuthorizationArgs.builder()
.policyEnforcementMode("ENFORCING")
.build())
.build());
var rolePolicy = new ClientRolePolicy("rolePolicy", ClientRolePolicyArgs.builder()
.resourceServerId(test.resourceServerId())
.realmId(realm.id())
.name("role_policy")
.decisionStrategy("UNANIMOUS")
.logic("POSITIVE")
.roles(ClientRolePolicyRoleArgs.builder()
.id(testKeycloakRole.id())
.required(true)
.build())
.build());
var userPolicy = new ClientUserPolicy("userPolicy", ClientUserPolicyArgs.builder()
.resourceServerId(test.resourceServerId())
.realmId(realm.id())
.name("user_policy")
.decisionStrategy("UNANIMOUS")
.logic("POSITIVE")
.users(testKeycloakUser.id())
.build());
var testClientAggregatePolicy = new ClientAggregatePolicy("testClientAggregatePolicy", ClientAggregatePolicyArgs.builder()
.resourceServerId(test.resourceServerId())
.realmId(realm.id())
.name("aggregate_policy")
.decisionStrategy("AFFIRMATIVE")
.logic("POSITIVE")
.policies(
rolePolicy.id(),
userPolicy.id())
.build());
}
}
resources:
realm:
type: keycloak:Realm
properties:
realm: my-realm
enabled: true
test:
type: keycloak:openid:Client
properties:
clientId: client_id
realmId: ${realm.id}
accessType: CONFIDENTIAL
serviceAccountsEnabled: true
authorization:
policyEnforcementMode: ENFORCING
rolePolicy:
type: keycloak:openid:ClientRolePolicy
name: role_policy
properties:
resourceServerId: ${test.resourceServerId}
realmId: ${realm.id}
name: role_policy
decisionStrategy: UNANIMOUS
logic: POSITIVE
roles:
- id: ${testKeycloakRole.id}
required: true
userPolicy:
type: keycloak:openid:ClientUserPolicy
name: user_policy
properties:
resourceServerId: ${test.resourceServerId}
realmId: ${realm.id}
name: user_policy
decisionStrategy: UNANIMOUS
logic: POSITIVE
users:
- ${testKeycloakUser.id}
testClientAggregatePolicy:
type: keycloak:openid:ClientAggregatePolicy
name: test
properties:
resourceServerId: ${test.resourceServerId}
realmId: ${realm.id}
name: aggregate_policy
decisionStrategy: AFFIRMATIVE
logic: POSITIVE
policies:
- ${rolePolicy.id}
- ${userPolicy.id}
Argument Reference
The following arguments are supported:
realm_id- (Required) The realm this policy exists in.resource_server_id- (Required) The ID of the resource server.name- (Required) The name of the policy.decision_strategy- (Required) The decision strategy, can be one ofUNANIMOUS,AFFIRMATIVE, orCONSENSUS.logic- (Optional) The logic, can be one ofPOSITIVEorNEGATIVE. Defaults toPOSITIVE.policies- (Required) A list of policy IDs to aggregate.description- (Optional) A description for the authorization policy.
Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
id- Policy ID representing the aggregate policy.
Create ClientAggregatePolicy Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new ClientAggregatePolicy(name: string, args: ClientAggregatePolicyArgs, opts?: CustomResourceOptions);@overload
def ClientAggregatePolicy(resource_name: str,
args: ClientAggregatePolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def ClientAggregatePolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
decision_strategy: Optional[str] = None,
policies: Optional[Sequence[str]] = None,
realm_id: Optional[str] = None,
resource_server_id: Optional[str] = None,
description: Optional[str] = None,
logic: Optional[str] = None,
name: Optional[str] = None)func NewClientAggregatePolicy(ctx *Context, name string, args ClientAggregatePolicyArgs, opts ...ResourceOption) (*ClientAggregatePolicy, error)public ClientAggregatePolicy(string name, ClientAggregatePolicyArgs args, CustomResourceOptions? opts = null)
public ClientAggregatePolicy(String name, ClientAggregatePolicyArgs args)
public ClientAggregatePolicy(String name, ClientAggregatePolicyArgs args, CustomResourceOptions options)
type: keycloak:openid:ClientAggregatePolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args ClientAggregatePolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args ClientAggregatePolicyArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args ClientAggregatePolicyArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args ClientAggregatePolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args ClientAggregatePolicyArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var clientAggregatePolicyResource = new Keycloak.OpenId.ClientAggregatePolicy("clientAggregatePolicyResource", new()
{
DecisionStrategy = "string",
Policies = new[]
{
"string",
},
RealmId = "string",
ResourceServerId = "string",
Description = "string",
Logic = "string",
Name = "string",
});
example, err := openid.NewClientAggregatePolicy(ctx, "clientAggregatePolicyResource", &openid.ClientAggregatePolicyArgs{
DecisionStrategy: pulumi.String("string"),
Policies: pulumi.StringArray{
pulumi.String("string"),
},
RealmId: pulumi.String("string"),
ResourceServerId: pulumi.String("string"),
Description: pulumi.String("string"),
Logic: pulumi.String("string"),
Name: pulumi.String("string"),
})
var clientAggregatePolicyResource = new ClientAggregatePolicy("clientAggregatePolicyResource", ClientAggregatePolicyArgs.builder()
.decisionStrategy("string")
.policies("string")
.realmId("string")
.resourceServerId("string")
.description("string")
.logic("string")
.name("string")
.build());
client_aggregate_policy_resource = keycloak.openid.ClientAggregatePolicy("clientAggregatePolicyResource",
decision_strategy="string",
policies=["string"],
realm_id="string",
resource_server_id="string",
description="string",
logic="string",
name="string")
const clientAggregatePolicyResource = new keycloak.openid.ClientAggregatePolicy("clientAggregatePolicyResource", {
decisionStrategy: "string",
policies: ["string"],
realmId: "string",
resourceServerId: "string",
description: "string",
logic: "string",
name: "string",
});
type: keycloak:openid:ClientAggregatePolicy
properties:
decisionStrategy: string
description: string
logic: string
name: string
policies:
- string
realmId: string
resourceServerId: string
ClientAggregatePolicy Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The ClientAggregatePolicy resource accepts the following input properties:
- Decision
Strategy string - Policies List<string>
- Realm
Id string - Resource
Server stringId - Description string
- Logic string
- Name string
- Decision
Strategy string - Policies []string
- Realm
Id string - Resource
Server stringId - Description string
- Logic string
- Name string
- decision
Strategy String - policies List<String>
- realm
Id String - resource
Server StringId - description String
- logic String
- name String
- decision
Strategy string - policies string[]
- realm
Id string - resource
Server stringId - description string
- logic string
- name string
- decision_
strategy str - policies Sequence[str]
- realm_
id str - resource_
server_ strid - description str
- logic str
- name str
- decision
Strategy String - policies List<String>
- realm
Id String - resource
Server StringId - description String
- logic String
- name String
Outputs
All input properties are implicitly available as output properties. Additionally, the ClientAggregatePolicy resource produces the following output properties:
- Id string
- The provider-assigned unique ID for this managed resource.
- Id string
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
- id string
- The provider-assigned unique ID for this managed resource.
- id str
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
Look up Existing ClientAggregatePolicy Resource
Get an existing ClientAggregatePolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: ClientAggregatePolicyState, opts?: CustomResourceOptions): ClientAggregatePolicy@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
decision_strategy: Optional[str] = None,
description: Optional[str] = None,
logic: Optional[str] = None,
name: Optional[str] = None,
policies: Optional[Sequence[str]] = None,
realm_id: Optional[str] = None,
resource_server_id: Optional[str] = None) -> ClientAggregatePolicyfunc GetClientAggregatePolicy(ctx *Context, name string, id IDInput, state *ClientAggregatePolicyState, opts ...ResourceOption) (*ClientAggregatePolicy, error)public static ClientAggregatePolicy Get(string name, Input<string> id, ClientAggregatePolicyState? state, CustomResourceOptions? opts = null)public static ClientAggregatePolicy get(String name, Output<String> id, ClientAggregatePolicyState state, CustomResourceOptions options)resources: _: type: keycloak:openid:ClientAggregatePolicy get: id: ${id}- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Decision
Strategy string - Description string
- Logic string
- Name string
- Policies List<string>
- Realm
Id string - Resource
Server stringId
- Decision
Strategy string - Description string
- Logic string
- Name string
- Policies []string
- Realm
Id string - Resource
Server stringId
- decision
Strategy String - description String
- logic String
- name String
- policies List<String>
- realm
Id String - resource
Server StringId
- decision
Strategy string - description string
- logic string
- name string
- policies string[]
- realm
Id string - resource
Server stringId
- decision_
strategy str - description str
- logic str
- name str
- policies Sequence[str]
- realm_
id str - resource_
server_ strid
- decision
Strategy String - description String
- logic String
- name String
- policies List<String>
- realm
Id String - resource
Server StringId
Import
Aggregate policies can be imported using the format: {{realmId}}/{{resourceServerId}}/{{policyId}}.
Example:
$ terraform import keycloak_openid_client_aggregate_policy.test my-realm/3bd4a686-1062-4b59-97b8-e4e3f10b99da/63b3cde8-987d-4cd9-9306-1955579281d9
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- Keycloak pulumi/pulumi-keycloak
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
keycloakTerraform Provider.
