keycloak logo
Keycloak v5.1.0, Mar 14 23

keycloak.openid.ClientPolicy

This resource can be used to create client policy.

Example Usage

In this example, we'll create a new OpenID client, then enabled permissions for the client. A client without permissions disabled cannot be assigned by a client policy. We'll use the

using System.Collections.Generic;
using Pulumi;
using Keycloak = Pulumi.Keycloak;

return await Deployment.RunAsync(() => 
{
    var realm = new Keycloak.Realm("realm", new()
    {
        RealmName = "my-realm",
        Enabled = true,
    });

    var openidClient = new Keycloak.OpenId.Client("openidClient", new()
    {
        ClientId = "openid_client",
        RealmId = realm.Id,
        AccessType = "CONFIDENTIAL",
        ServiceAccountsEnabled = true,
    });

    var myPermission = new Keycloak.OpenId.ClientPermissions("myPermission", new()
    {
        RealmId = realm.Id,
        ClientId = openidClient.Id,
    });

    var realmManagement = Keycloak.OpenId.GetClient.Invoke(new()
    {
        RealmId = "my-realm",
        ClientId = "realm-management",
    });

    var tokenExchange = new Keycloak.OpenId.ClientPolicy("tokenExchange", new()
    {
        ResourceServerId = realmManagement.Apply(getClientResult => getClientResult.Id),
        RealmId = realm.Id,
        Logic = "POSITIVE",
        DecisionStrategy = "UNANIMOUS",
        Clients = new[]
        {
            openidClient.Id,
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v5/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
		}
		openidClient, err := openid.NewClient(ctx, "openidClient", &openid.ClientArgs{
			ClientId:               pulumi.String("openid_client"),
			RealmId:                realm.ID(),
			AccessType:             pulumi.String("CONFIDENTIAL"),
			ServiceAccountsEnabled: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		_, err = openid.NewClientPermissions(ctx, "myPermission", &openid.ClientPermissionsArgs{
			RealmId:  realm.ID(),
			ClientId: openidClient.ID(),
		})
		if err != nil {
			return err
		}
		realmManagement, err := openid.LookupClient(ctx, &openid.LookupClientArgs{
			RealmId:  "my-realm",
			ClientId: "realm-management",
		}, nil)
		if err != nil {
			return err
		}
		_, err = openid.NewClientPolicy(ctx, "tokenExchange", &openid.ClientPolicyArgs{
			ResourceServerId: *pulumi.String(realmManagement.Id),
			RealmId:          realm.ID(),
			Logic:            pulumi.String("POSITIVE"),
			DecisionStrategy: pulumi.String("UNANIMOUS"),
			Clients: pulumi.StringArray{
				openidClient.ID(),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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.ClientPermissions;
import com.pulumi.keycloak.openid.ClientPermissionsArgs;
import com.pulumi.keycloak.openid.OpenidFunctions;
import com.pulumi.keycloak.openid.inputs.GetClientArgs;
import com.pulumi.keycloak.openid.ClientPolicy;
import com.pulumi.keycloak.openid.ClientPolicyArgs;
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 openidClient = new Client("openidClient", ClientArgs.builder()        
            .clientId("openid_client")
            .realmId(realm.id())
            .accessType("CONFIDENTIAL")
            .serviceAccountsEnabled(true)
            .build());

        var myPermission = new ClientPermissions("myPermission", ClientPermissionsArgs.builder()        
            .realmId(realm.id())
            .clientId(openidClient.id())
            .build());

        final var realmManagement = OpenidFunctions.getClient(GetClientArgs.builder()
            .realmId("my-realm")
            .clientId("realm-management")
            .build());

        var tokenExchange = new ClientPolicy("tokenExchange", ClientPolicyArgs.builder()        
            .resourceServerId(realmManagement.applyValue(getClientResult -> getClientResult.id()))
            .realmId(realm.id())
            .logic("POSITIVE")
            .decisionStrategy("UNANIMOUS")
            .clients(openidClient.id())
            .build());

    }
}
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
openid_client = keycloak.openid.Client("openidClient",
    client_id="openid_client",
    realm_id=realm.id,
    access_type="CONFIDENTIAL",
    service_accounts_enabled=True)
my_permission = keycloak.openid.ClientPermissions("myPermission",
    realm_id=realm.id,
    client_id=openid_client.id)
realm_management = keycloak.openid.get_client(realm_id="my-realm",
    client_id="realm-management")
token_exchange = keycloak.openid.ClientPolicy("tokenExchange",
    resource_server_id=realm_management.id,
    realm_id=realm.id,
    logic="POSITIVE",
    decision_strategy="UNANIMOUS",
    clients=[openid_client.id])
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
const openidClient = new keycloak.openid.Client("openidClient", {
    clientId: "openid_client",
    realmId: realm.id,
    accessType: "CONFIDENTIAL",
    serviceAccountsEnabled: true,
});
const myPermission = new keycloak.openid.ClientPermissions("myPermission", {
    realmId: realm.id,
    clientId: openidClient.id,
});
const realmManagement = keycloak.openid.getClient({
    realmId: "my-realm",
    clientId: "realm-management",
});
const tokenExchange = new keycloak.openid.ClientPolicy("tokenExchange", {
    resourceServerId: realmManagement.then(realmManagement => realmManagement.id),
    realmId: realm.id,
    logic: "POSITIVE",
    decisionStrategy: "UNANIMOUS",
    clients: [openidClient.id],
});
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  openidClient:
    type: keycloak:openid:Client
    properties:
      clientId: openid_client
      realmId: ${realm.id}
      accessType: CONFIDENTIAL
      serviceAccountsEnabled: true
  myPermission:
    type: keycloak:openid:ClientPermissions
    properties:
      realmId: ${realm.id}
      clientId: ${openidClient.id}
  tokenExchange:
    type: keycloak:openid:ClientPolicy
    properties:
      resourceServerId: ${realmManagement.id}
      realmId: ${realm.id}
      logic: POSITIVE
      decisionStrategy: UNANIMOUS
      clients:
        - ${openidClient.id}
variables:
  realmManagement:
    fn::invoke:
      Function: keycloak:openid:getClient
      Arguments:
        realmId: my-realm
        clientId: realm-management

Create ClientPolicy Resource

new ClientPolicy(name: string, args: ClientPolicyArgs, opts?: CustomResourceOptions);
@overload
def ClientPolicy(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 clients: Optional[Sequence[str]] = None,
                 decision_strategy: Optional[str] = None,
                 description: Optional[str] = None,
                 logic: Optional[str] = None,
                 name: Optional[str] = None,
                 realm_id: Optional[str] = None,
                 resource_server_id: Optional[str] = None)
@overload
def ClientPolicy(resource_name: str,
                 args: ClientPolicyArgs,
                 opts: Optional[ResourceOptions] = None)
func NewClientPolicy(ctx *Context, name string, args ClientPolicyArgs, opts ...ResourceOption) (*ClientPolicy, error)
public ClientPolicy(string name, ClientPolicyArgs args, CustomResourceOptions? opts = null)
public ClientPolicy(String name, ClientPolicyArgs args)
public ClientPolicy(String name, ClientPolicyArgs args, CustomResourceOptions options)
type: keycloak:openid:ClientPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args ClientPolicyArgs
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 ClientPolicyArgs
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 ClientPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ClientPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args ClientPolicyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

ClientPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The ClientPolicy resource accepts the following input properties:

Clients List<string>

The clients allowed by this client policy.

RealmId string

The realm this client policy exists within.

ResourceServerId string

The ID of the resource server this client policy is attached to.

DecisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

Description string

The description of this client policy.

Logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

Name string

The name of this client policy.

Clients []string

The clients allowed by this client policy.

RealmId string

The realm this client policy exists within.

ResourceServerId string

The ID of the resource server this client policy is attached to.

DecisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

Description string

The description of this client policy.

Logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

Name string

The name of this client policy.

clients List<String>

The clients allowed by this client policy.

realmId String

The realm this client policy exists within.

resourceServerId String

The ID of the resource server this client policy is attached to.

decisionStrategy String

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description String

The description of this client policy.

logic String

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name String

The name of this client policy.

clients string[]

The clients allowed by this client policy.

realmId string

The realm this client policy exists within.

resourceServerId string

The ID of the resource server this client policy is attached to.

decisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description string

The description of this client policy.

logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name string

The name of this client policy.

clients Sequence[str]

The clients allowed by this client policy.

realm_id str

The realm this client policy exists within.

resource_server_id str

The ID of the resource server this client policy is attached to.

decision_strategy str

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description str

The description of this client policy.

logic str

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name str

The name of this client policy.

clients List<String>

The clients allowed by this client policy.

realmId String

The realm this client policy exists within.

resourceServerId String

The ID of the resource server this client policy is attached to.

decisionStrategy String

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description String

The description of this client policy.

logic String

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name String

The name of this client policy.

Outputs

All input properties are implicitly available as output properties. Additionally, the ClientPolicy 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 ClientPolicy Resource

Get an existing ClientPolicy 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?: ClientPolicyState, opts?: CustomResourceOptions): ClientPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        clients: Optional[Sequence[str]] = None,
        decision_strategy: Optional[str] = None,
        description: Optional[str] = None,
        logic: Optional[str] = None,
        name: Optional[str] = None,
        realm_id: Optional[str] = None,
        resource_server_id: Optional[str] = None) -> ClientPolicy
func GetClientPolicy(ctx *Context, name string, id IDInput, state *ClientPolicyState, opts ...ResourceOption) (*ClientPolicy, error)
public static ClientPolicy Get(string name, Input<string> id, ClientPolicyState? state, CustomResourceOptions? opts = null)
public static ClientPolicy get(String name, Output<String> id, ClientPolicyState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
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.
The following state arguments are supported:
Clients List<string>

The clients allowed by this client policy.

DecisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

Description string

The description of this client policy.

Logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

Name string

The name of this client policy.

RealmId string

The realm this client policy exists within.

ResourceServerId string

The ID of the resource server this client policy is attached to.

Clients []string

The clients allowed by this client policy.

DecisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

Description string

The description of this client policy.

Logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

Name string

The name of this client policy.

RealmId string

The realm this client policy exists within.

ResourceServerId string

The ID of the resource server this client policy is attached to.

clients List<String>

The clients allowed by this client policy.

decisionStrategy String

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description String

The description of this client policy.

logic String

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name String

The name of this client policy.

realmId String

The realm this client policy exists within.

resourceServerId String

The ID of the resource server this client policy is attached to.

clients string[]

The clients allowed by this client policy.

decisionStrategy string

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description string

The description of this client policy.

logic string

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name string

The name of this client policy.

realmId string

The realm this client policy exists within.

resourceServerId string

The ID of the resource server this client policy is attached to.

clients Sequence[str]

The clients allowed by this client policy.

decision_strategy str

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description str

The description of this client policy.

logic str

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name str

The name of this client policy.

realm_id str

The realm this client policy exists within.

resource_server_id str

The ID of the resource server this client policy is attached to.

clients List<String>

The clients allowed by this client policy.

decisionStrategy String

(Computed) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of AFFIRMATIVE, CONSENSUS, or UNANIMOUS. Applies to permissions.

description String

The description of this client policy.

logic String

(Computed) Dictates how the policy decision should be made. Can be either POSITIVE or NEGATIVE. Applies to policies.

name String

The name of this client policy.

realmId String

The realm this client policy exists within.

resourceServerId String

The ID of the resource server this client policy is attached to.

Package Details

Repository
Keycloak pulumi/pulumi-keycloak
License
Apache-2.0
Notes

This Pulumi package is based on the keycloak Terraform Provider.