PolicyValidationMode Class
Validation mode for Cedar policy definitions.
Example
ts
declare const policyEngine: agentcore.PolicyEngine;
declare const gateway: agentcore.Gateway;
// Allow access unless the user is suspended
const policyWithUnless = new agentcore.Policy(this, "UnlessPolicy", {
policyEngine: policyEngine,
policyName: "unless_suspended",
statement: new agentcore.PolicyStatement({
effect: agentcore.PolicyEffect.PERMIT,
principal: agentcore.PolicyPrincipal.entityType('AgentCore::OAuthUser'),
action: agentcore.PolicyAction.any(),
resource: agentcore.PolicyResource.instance('AgentCore::Gateway', gateway.gatewayArn),
unless: [
agentcore.PolicyCondition.booleanEquals(
agentcore.PolicyAttribute.principal('suspended'), true),
],
}),
description: "Allow all actions unless user is suspended",
validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS,
});
// Generated Cedar:
// permit(
// principal is AgentCore::OAuthUser,
// action,
// resource == AgentCore::Gateway::"arn:..."
// )
// unless {
// principal.suspended == true
// };
python
# policy_engine: agentcore.PolicyEngine
# gateway: agentcore.Gateway
# Allow access unless the user is suspended
policy_with_unless = agentcore.Policy(self, "UnlessPolicy",
policy_engine=policy_engine,
policy_name="unless_suspended",
statement=agentcore.PolicyStatement(
effect=agentcore.PolicyEffect.PERMIT,
principal=agentcore.PolicyPrincipal.entity_type("AgentCore::OAuthUser"),
action=agentcore.PolicyAction.any(),
resource=agentcore.PolicyResource.instance("AgentCore::Gateway", gateway.gateway_arn),
unless=[
agentcore.PolicyCondition.boolean_equals(
agentcore.PolicyAttribute.principal("suspended"), True)
]
),
description="Allow all actions unless user is suspended",
validation_mode=agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS
)
java
PolicyEngine policyEngine;
Gateway gateway;
// Allow access unless the user is suspended
Policy policyWithUnless = Policy.Builder.create(this, "UnlessPolicy")
.policyEngine(policyEngine)
.policyName("unless_suspended")
.statement(PolicyStatement.Builder.create()
.effect(PolicyEffect.PERMIT)
.principal(PolicyPrincipal.entityType("AgentCore::OAuthUser"))
.action(PolicyAction.any())
.resource(PolicyResource.instance("AgentCore::Gateway", gateway.getGatewayArn()))
.unless(List.of(PolicyCondition.booleanEquals(PolicyAttribute.principal("suspended"), true)))
.build())
.description("Allow all actions unless user is suspended")
.validationMode(PolicyValidationMode.FAIL_ON_ANY_FINDINGS)
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
PolicyEngine policyEngine;
Gateway gateway;
// Allow access unless the user is suspended
var policyWithUnless = new Policy(this, "UnlessPolicy", new PolicyProps {
PolicyEngine = policyEngine,
PolicyName = "unless_suspended",
Statement = new PolicyStatement(new PolicyStatementProps {
Effect = PolicyEffect.PERMIT,
Principal = PolicyPrincipal.EntityType("AgentCore::OAuthUser"),
Action = PolicyAction.Any(),
Resource = PolicyResource.Instance("AgentCore::Gateway", gateway.GatewayArn),
Unless = new [] { PolicyCondition.BooleanEquals(PolicyAttribute.Principal("suspended"), true) }
}),
Description = "Allow all actions unless user is suspended",
ValidationMode = PolicyValidationMode.FAIL_ON_ANY_FINDINGS
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var policyEngine PolicyEngine
var gateway Gateway
// Allow access unless the user is suspended
policyWithUnless := agentcore.NewPolicy(this, jsii.String("UnlessPolicy"), &PolicyProps{
PolicyEngine: policyEngine,
PolicyName: jsii.String("unless_suspended"),
Statement: agentcore.NewPolicyStatement(&PolicyStatementProps{
Effect: agentcore.PolicyEffect_PERMIT,
Principal: agentcore.PolicyPrincipal_EntityType(jsii.String("AgentCore::OAuthUser")),
Action: agentcore.PolicyAction_Any(),
Resource: agentcore.PolicyResource_Instance(jsii.String("AgentCore::Gateway"), gateway.GatewayArn),
Unless: []PolicyCondition{
agentcore.PolicyCondition_BooleanEquals(agentcore.PolicyAttribute_Principal(jsii.String("suspended")), jsii.Boolean(true)),
},
}),
Description: jsii.String("Allow all actions unless user is suspended"),
ValidationMode: agentcore.PolicyValidationMode_FAIL_ON_ANY_FINDINGS(),
})
Properties
FAIL_ON_ANY_FINDINGSPolicyValidationModefail_on_any_findingsPolicyValidationModeFAIL_ON_ANY_FINDINGSPolicyValidationModeFAIL_ON_ANY_FINDINGSPolicyValidationModeFAIL_ON_ANY_FINDINGSPolicyValidationModestatic#Fail policy creation if any validation findings are detected.
This is the safer default - catches policy errors early.
IGNORE_ALL_FINDINGSPolicyValidationModeignore_all_findingsPolicyValidationModeIGNORE_ALL_FINDINGSPolicyValidationModeIGNORE_ALL_FINDINGSPolicyValidationModeIGNORE_ALL_FINDINGSPolicyValidationModestatic#Ignore all validation findings and create the policy anyway.
Use with caution - may result in runtime authorization errors.
The string value of the validation mode.
Methods
of(value: string): PolicyValidationMode // chainable@staticmethod def of(value: str) -> PolicyValidationModepublic static PolicyValidationMode of(String value)public static PolicyValidationMode Of(string value)func Of(Value *string) PolicyValidationModestatic#A validation mode that this version of the CDK does not model.
notes · 1 parameter
Prefer the static members above. Use this when the service has added a mode that the CDK has no member for yet: the CloudFormation registry schemas that validate the synthesized template ship with aws-cdk-lib and refresh on release, while the members above are added by hand, so a released CDK can accept a mode before it models one.
Parameters
valuevaluevaluevalueValue— the raw validation mode value to pass to CloudFormation.