Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 2x 2x 5x 5x 5x 5x 5x 5x 5x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 1x 1x 5x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 1x 1x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import * as iam from 'aws-cdk-lib/aws-iam'; import { CfnPolicyStore } from 'aws-cdk-lib/aws-verifiedpermissions'; import { ArnFormat, IResource, Resource, Stack } from 'aws-cdk-lib/core'; import { Construct } from 'constructs'; import { Policy, PolicyDefinitionProperty } from './policy'; import { AUTH_ACTIONS, READ_ACTIONS, WRITE_ACTIONS, } from './private/permissions'; export interface ISchema { cedarJson: string; } export interface IValidationSettings { mode: ValidationSettingsMode; } /** * Validation Settings mode, according to the Cloudformation PolicyStore resource */ export enum ValidationSettingsMode { OFF = 'OFF', STRICT = 'STRICT', } export interface IPolicyStore extends IResource { /** * ARN of the Policy Store. * * @attribute */ readonly policyStoreArn: string; /** * ID of the Policy Store. * * @attribute */ readonly policyStoreId: string; /** * * Adds an IAM policy statement associated with this policy store to an IAM * principal's policy. * * @param grantee The principal (no-op if undefined) * @param actions The set of actions to allow (i.e. "verifiedpermissions:IsAuthorized", "verifiedpermissions:ListPolicies", ...) */ grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant; /** * Permits an IAM principal all read operations on the policy store: GetIdentitySource, * GetPolicy, GetPolicyStore, GetPolicyTemplate, * GetSchema, ListIdentitySources, ListPolicies, ListPolicyTemplates. * * @param grantee */ grantRead(grantee: iam.IGrantable): iam.Grant; /** * Permits an IAM principal all write & read operations on the policy store: CreateIdentitySource, * CreatePolicy,CreatePolicyTemplate, DeleteIdentitySource, DeletePolicy, * DeletePolicyTemplate, PutSchema, UpdateIdentitySource, UpdatePolicy, UpdatePolicyTemplate. * * @param grantee */ grantWrite(grantee: iam.IGrantable): iam.Grant; /** * Permits an IAM principal all auth operations on the policy store: * IsAuthorized, IsAuthorizedWithToken * @param grantee */ grantAuth(grantee: iam.IGrantable): iam.Grant; } export interface PolicyStoreProps { /** * This attribute is not required from an API point of view. * It represents the schema (in Cedar) to be applied to the PolicyStore. * * @default - The schema (in Cedar) to be applied to the PolicyStore. */ readonly schema?: ISchema; /** * The policy store's validation settings. * * @default - If not provided, the Policy store will be created with ValidationSettingsMode = "OFF" */ readonly validationSettings: IValidationSettings; } export interface AddPolicyOptions { /** * The id of the Policy. */ readonly policyId: string; /** * The configuration of the Policy. */ readonly policyConfiguration: PolicyDefinitionProperty; } export interface PolicyStoreAttributes { /** * The ARN of the Amazon Verified Permissions Policy Store. * One of this, or `policyStoreId`, is required. * * @default - no PolicyStore arn */ readonly policyStoreArn?: string; /** * The id of the Amazon Verified Permissions PolicyStore. * One of this, or `policyStoreArn`, is required. * * @default - no PolicyStore id */ readonly policyStoreId?: string; } abstract class PolicyStoreBase extends Resource implements IPolicyStore { abstract readonly policyStoreArn: string; abstract readonly policyStoreId: string; public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant { return iam.Grant.addToPrincipal({ grantee, actions, resourceArns: [this.policyStoreArn], scope: this, }); } public grantAuth(grantee: iam.IGrantable): iam.Grant { return this.grant(grantee, ...AUTH_ACTIONS); } public grantRead(grantee: iam.IGrantable): iam.Grant { return this.grant(grantee, ...READ_ACTIONS); } public grantWrite(grantee: iam.IGrantable): iam.Grant { return this.grant(grantee, ...WRITE_ACTIONS.concat(READ_ACTIONS)); } } export class PolicyStore extends PolicyStoreBase { /** * Create a PolicyStore construct that represents an external policy store via policy store id. * * @param scope The parent creating construct (usually `this`). * @param id The construct's name. * @param policyStoreId The PolicyStore's id. */ public static fromPolicyStoreId( scope: Construct, id: string, policyStoreId: string, ): IPolicyStore { return PolicyStore.fromPolicyStoreAttributes(scope, id, { policyStoreId }); } /** * Create a PolicyStore construct that represents an external PolicyStore via policy store arn. * * @param scope The parent creating construct (usually `this`). * @param id The construct's name. * @param policyStoreArn The PolicyStore's ARN. */ public static fromPolicyStoreArn( scope: Construct, id: string, policyStoreArn: string, ): IPolicyStore { return PolicyStore.fromPolicyStoreAttributes(scope, id, { policyStoreArn }); } /** * Creates a PolicyStore construct that represents an external Policy Store. * * @param scope The parent creating construct (usually `this`). * @param id The construct's name. * @param attrs A `PolicyStoreAttributes` object. */ public static fromPolicyStoreAttributes( scope: Construct, id: string, attrs: PolicyStoreAttributes, ): IPolicyStore { class Import extends PolicyStoreBase { readonly policyStoreArn: string; readonly policyStoreId: string; constructor(policyStoreArn: string, policyStoreId: string) { super(scope, id); this.policyStoreArn = policyStoreArn; this.policyStoreId = policyStoreId; } } let policyStoreId: string; let policyStoreArn: string; const stack = Stack.of(scope); if (!attrs.policyStoreId) { if (!attrs.policyStoreArn) { throw new Error('One of policyStoreId or policyStoreArn is required!'); } policyStoreArn = attrs.policyStoreArn; const maybeId = stack.splitArn( attrs.policyStoreArn, ArnFormat.SLASH_RESOURCE_NAME, ).resourceName; if (!maybeId) { throw new Error( `ARN for PolicyStore must be in the form: ${ArnFormat.SLASH_RESOURCE_NAME}`, ); } policyStoreId = maybeId; } else { if (attrs.policyStoreArn) { throw new Error( 'Only one of policyStoreArn or policyStoreId can be provided', ); } policyStoreId = attrs.policyStoreId; policyStoreArn = stack.formatArn({ resource: 'policy-store', resourceName: attrs.policyStoreId, service: 'verifiedpermissions', }); } return new Import(policyStoreArn, policyStoreId); } private readonly policyStore: CfnPolicyStore; /** * ARN of the Policy Store. * * @attribute */ readonly policyStoreArn: string; /** * ID of the Policy Store. * * @attribute */ readonly policyStoreId: string; /** * Name of the Policy Store. */ readonly policyStoreName: string; /** * Schema definition of the Policy Store. */ readonly schema?: ISchema; /** * Validation Settings of the Policy Store. */ readonly validationSettings: IValidationSettings; constructor( scope: Construct, id: string, props: PolicyStoreProps = { validationSettings: { mode: ValidationSettingsMode.OFF, }, }, ) { super(scope, id); this.policyStore = new CfnPolicyStore(this, id, { schema: props.schema ? { cedarJson: props.schema.cedarJson, } : undefined, validationSettings: props.validationSettings, }); this.policyStoreArn = this.getResourceArnAttribute( this.policyStore.attrArn, { resource: 'policy-store', resourceName: this.physicalName, service: 'verifiedpermissions', }, ); this.policyStoreName = this.getResourceNameAttribute(this.policyStore.ref); this.policyStoreId = this.policyStore.attrPolicyStoreId; this.schema = props.schema; this.validationSettings = props.validationSettings; } /** * Add multiple policies to the policy store * * @param policyDefinitions An array of policy options for the policy stores policies. * @returns An array of created policy constructs. */ public addPolicies(policyDefinitions: AddPolicyOptions[]): Policy[] { let policies = policyDefinitions.map((policyOption) => { return new Policy(this, policyOption.policyId, { policyStore: this, definition: policyOption.policyConfiguration, }); }); return policies; } } |