keycloak.openid.ClientPolicy
Explore with Pulumi AI
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 keycloak.openid.ClientPolicy
resource to create a new client policy, which could be applied to many clients, for a realm and a resource_server_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("openid_client", {
clientId: "openid_client",
name: "openid_client",
realmId: realm.id,
accessType: "CONFIDENTIAL",
serviceAccountsEnabled: true,
});
const myPermission = new keycloak.openid.ClientPermissions("my_permission", {
realmId: realm.id,
clientId: openidClient.id,
});
const realmManagement = keycloak.openid.getClient({
realmId: "my-realm",
clientId: "realm-management",
});
const tokenExchange = new keycloak.openid.ClientPolicy("token_exchange", {
resourceServerId: realmManagement.then(realmManagement => realmManagement.id),
realmId: realm.id,
name: "my-policy",
logic: "POSITIVE",
decisionStrategy: "UNANIMOUS",
clients: [openidClient.id],
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
openid_client = keycloak.openid.Client("openid_client",
client_id="openid_client",
name="openid_client",
realm_id=realm.id,
access_type="CONFIDENTIAL",
service_accounts_enabled=True)
my_permission = keycloak.openid.ClientPermissions("my_permission",
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("token_exchange",
resource_server_id=realm_management.id,
realm_id=realm.id,
name="my-policy",
logic="POSITIVE",
decision_strategy="UNANIMOUS",
clients=[openid_client.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, "openid_client", &openid.ClientArgs{
ClientId: pulumi.String("openid_client"),
Name: pulumi.String("openid_client"),
RealmId: realm.ID(),
AccessType: pulumi.String("CONFIDENTIAL"),
ServiceAccountsEnabled: pulumi.Bool(true),
})
if err != nil {
return err
}
_, err = openid.NewClientPermissions(ctx, "my_permission", &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, "token_exchange", &openid.ClientPolicyArgs{
ResourceServerId: pulumi.String(realmManagement.Id),
RealmId: realm.ID(),
Name: pulumi.String("my-policy"),
Logic: pulumi.String("POSITIVE"),
DecisionStrategy: pulumi.String("UNANIMOUS"),
Clients: pulumi.StringArray{
openidClient.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 openidClient = new Keycloak.OpenId.Client("openid_client", new()
{
ClientId = "openid_client",
Name = "openid_client",
RealmId = realm.Id,
AccessType = "CONFIDENTIAL",
ServiceAccountsEnabled = true,
});
var myPermission = new Keycloak.OpenId.ClientPermissions("my_permission", 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("token_exchange", new()
{
ResourceServerId = realmManagement.Apply(getClientResult => getClientResult.Id),
RealmId = realm.Id,
Name = "my-policy",
Logic = "POSITIVE",
DecisionStrategy = "UNANIMOUS",
Clients = new[]
{
openidClient.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.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")
.name("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())
.name("my-policy")
.logic("POSITIVE")
.decisionStrategy("UNANIMOUS")
.clients(openidClient.id())
.build());
}
}
resources:
realm:
type: keycloak:Realm
properties:
realm: my-realm
enabled: true
openidClient:
type: keycloak:openid:Client
name: openid_client
properties:
clientId: openid_client
name: openid_client
realmId: ${realm.id}
accessType: CONFIDENTIAL
serviceAccountsEnabled: true
myPermission:
type: keycloak:openid:ClientPermissions
name: my_permission
properties:
realmId: ${realm.id}
clientId: ${openidClient.id}
tokenExchange:
type: keycloak:openid:ClientPolicy
name: token_exchange
properties:
resourceServerId: ${realmManagement.id}
realmId: ${realm.id}
name: my-policy
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
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new ClientPolicy(name: string, args: ClientPolicyArgs, opts?: CustomResourceOptions);
@overload
def ClientPolicy(resource_name: str,
args: ClientPolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def ClientPolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
clients: Optional[Sequence[str]] = None,
realm_id: Optional[str] = None,
resource_server_id: Optional[str] = None,
decision_strategy: Optional[str] = None,
description: Optional[str] = None,
logic: Optional[str] = None,
name: Optional[str] = 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.
Parameters
- 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.
Constructor example
The following reference example uses placeholder values for all input properties.
var clientPolicyResource = new Keycloak.OpenId.ClientPolicy("clientPolicyResource", new()
{
Clients = new[]
{
"string",
},
RealmId = "string",
ResourceServerId = "string",
DecisionStrategy = "string",
Description = "string",
Logic = "string",
Name = "string",
});
example, err := openid.NewClientPolicy(ctx, "clientPolicyResource", &openid.ClientPolicyArgs{
Clients: pulumi.StringArray{
pulumi.String("string"),
},
RealmId: pulumi.String("string"),
ResourceServerId: pulumi.String("string"),
DecisionStrategy: pulumi.String("string"),
Description: pulumi.String("string"),
Logic: pulumi.String("string"),
Name: pulumi.String("string"),
})
var clientPolicyResource = new ClientPolicy("clientPolicyResource", ClientPolicyArgs.builder()
.clients("string")
.realmId("string")
.resourceServerId("string")
.decisionStrategy("string")
.description("string")
.logic("string")
.name("string")
.build());
client_policy_resource = keycloak.openid.ClientPolicy("clientPolicyResource",
clients=["string"],
realm_id="string",
resource_server_id="string",
decision_strategy="string",
description="string",
logic="string",
name="string")
const clientPolicyResource = new keycloak.openid.ClientPolicy("clientPolicyResource", {
clients: ["string"],
realmId: "string",
resourceServerId: "string",
decisionStrategy: "string",
description: "string",
logic: "string",
name: "string",
});
type: keycloak:openid:ClientPolicy
properties:
clients:
- string
decisionStrategy: string
description: string
logic: string
name: string
realmId: string
resourceServerId: string
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.
- Realm
Id string - The realm this client policy exists within.
- Resource
Server stringId - The ID of the resource server this client policy is attached to.
- Decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - Name string
- The name of this client policy.
- Clients []string
- The clients allowed by this client policy.
- Realm
Id string - The realm this client policy exists within.
- Resource
Server stringId - The ID of the resource server this client policy is attached to.
- Decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - Name string
- The name of this client policy.
- clients List<String>
- The clients allowed by this client policy.
- realm
Id String - The realm this client policy exists within.
- resource
Server StringId - The ID of the resource server this client policy is attached to.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name String
- The name of this client policy.
- clients string[]
- The clients allowed by this client policy.
- realm
Id string - The realm this client policy exists within.
- resource
Server stringId - The ID of the resource server this client policy is attached to.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. 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_ strid - 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name str
- The name of this client policy.
- clients List<String>
- The clients allowed by this client policy.
- realm
Id String - The realm this client policy exists within.
- resource
Server StringId - The ID of the resource server this client policy is attached to.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. 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.
- Clients List<string>
- The clients allowed by this client policy.
- Decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - Name string
- The name of this client policy.
- Realm
Id string - The realm this client policy exists within.
- Resource
Server stringId - The ID of the resource server this client policy is attached to.
- Clients []string
- The clients allowed by this client policy.
- Decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - Name string
- The name of this client policy.
- Realm
Id string - The realm this client policy exists within.
- Resource
Server stringId - The ID of the resource server this client policy is attached to.
- clients List<String>
- The clients allowed by this client policy.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name String
- The name of this client policy.
- realm
Id String - The realm this client policy exists within.
- resource
Server StringId - The ID of the resource server this client policy is attached to.
- clients string[]
- The clients allowed by this client policy.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name string
- The name of this client policy.
- realm
Id string - The realm this client policy exists within.
- resource
Server stringId - 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name str
- The name of this client policy.
- realm_
id str - The realm this client policy exists within.
- resource_
server_ strid - The ID of the resource server this client policy is attached to.
- clients List<String>
- The clients allowed by this client policy.
- decision
Strategy 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
, orUNANIMOUS
. 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
orNEGATIVE
. Applies to policies. - name String
- The name of this client policy.
- realm
Id String - The realm this client policy exists within.
- resource
Server StringId - 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.