@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
330 lines (329 loc) • 18.7 kB
TypeScript
import * as pulumi from "@pulumi/pulumi";
import * as inputs from "../types/input";
import * as outputs from "../types/output";
/**
* Runs a simulation of the IAM policies of a particular principal against a given hypothetical request.
*
* You can use this data source in conjunction with
* Preconditions and Postconditions so that your configuration can test either whether it should have sufficient access to do its own work, or whether policies your configuration declares itself are sufficient for their intended use elsewhere.
*
* > **Note:** Correctly using this data source requires familiarity with various details of AWS Identity and Access Management, and how various AWS services integrate with it. For general information on the AWS IAM policy simulator, see [Testing IAM policies with the IAM policy simulator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html). This data source wraps the `iam:SimulatePrincipalPolicy` API action described on that page.
*
* ## Example Usage
*
* ### Self Access-checking Example
*
* The following example raises an error if the credentials passed to the AWS provider do not have access to perform the three actions `s3:GetObject`, `s3:PutObject`, and `s3:DeleteObject` on the S3 bucket with the given ARN.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const current = aws.getCallerIdentity({});
* const s3ObjectAccess = current.then(current => aws.iam.getPrincipalPolicySimulation({
* actionNames: [
* "s3:GetObject",
* "s3:PutObject",
* "s3:DeleteObject",
* ],
* policySourceArn: current.arn,
* resourceArns: ["arn:aws:s3:::my-test-bucket"],
* }));
* ```
*
* If you intend to use this data source to quickly raise an error when the given credentials are insufficient then you must use `dependsOn` inside any resource which would require those credentials, to ensure that the policy check will run first:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.s3.BucketObjectv2("example", {bucket: "my-test-bucket"}, {
* dependsOn: [s3ObjectAccess],
* });
* ```
*
* ### Testing the Effect of a Declared Policy
*
* The following example declares an S3 bucket and a user that should have access to the bucket, and then uses `aws.iam.getPrincipalPolicySimulation` to verify that the user does indeed have access to perform needed operations against the bucket.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const current = aws.getCallerIdentity({});
* const example = new aws.iam.User("example", {name: "example"});
* const exampleBucket = new aws.s3.Bucket("example", {bucket: "my-test-bucket"});
* const s3Access = new aws.iam.UserPolicy("s3_access", {
* name: "example_s3_access",
* user: example.name,
* policy: pulumi.jsonStringify({
* Version: "2012-10-17",
* Statement: [{
* Action: "s3:GetObject",
* Effect: "Allow",
* Resource: exampleBucket.arn,
* }],
* }),
* });
* const accountAccess = new aws.s3.BucketPolicy("account_access", {
* bucket: exampleBucket.bucket,
* policy: pulumi.jsonStringify({
* Version: "2012-10-17",
* Statement: [{
* Action: "s3:*",
* Effect: "Allow",
* Principal: {
* AWS: current.then(current => current.accountId),
* },
* Resource: [
* exampleBucket.arn,
* pulumi.interpolate`${exampleBucket.arn}/*`,
* ],
* }],
* }),
* });
* const s3ObjectAccess = aws.iam.getPrincipalPolicySimulationOutput({
* actionNames: ["s3:GetObject"],
* policySourceArn: example.arn,
* resourceArns: [exampleBucket.arn],
* resourcePolicyJson: accountAccess.policy,
* });
* ```
*
* When using `aws.iam.getPrincipalPolicySimulation` to test the effect of a policy declared elsewhere in the same configuration, it's important to use `dependsOn` to make sure that the needed policy has been fully created or updated before running the simulation.
*/
export declare function getPrincipalPolicySimulation(args: GetPrincipalPolicySimulationArgs, opts?: pulumi.InvokeOptions): Promise<GetPrincipalPolicySimulationResult>;
/**
* A collection of arguments for invoking getPrincipalPolicySimulation.
*/
export interface GetPrincipalPolicySimulationArgs {
/**
* A set of IAM action names to run simulations for. Each entry in this set adds an additional hypothetical request to the simulation.
*
* Action names consist of a service prefix and an action verb separated by a colon, such as `s3:GetObject`. Refer to [Actions, resources, and condition keys for AWS services](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html) to see the full set of possible IAM action names across all AWS services.
*/
actionNames: string[];
/**
* A set of additional principal policy documents to include in the simulation. The simulator will behave as if each of these policies were associated with the object specified in `policySourceArn`, allowing you to test the effect of hypothetical policies not yet created.
*/
additionalPoliciesJsons?: string[];
/**
* The ARN of an user that will appear as the "caller" of the simulated requests. If you do not specify `callerArn` then the simulation will use the `policySourceArn` instead, if it contains a user ARN.
*/
callerArn?: string;
/**
* Each `context` block defines an entry in the table of additional context keys in the simulated request.
*
* IAM uses context keys for both custom conditions and for interpolating dynamic request-specific values into policy values. If you use policies that include those features then you will need to provide suitable example values for those keys to achieve a realistic simulation.
*/
contexts?: inputs.iam.GetPrincipalPolicySimulationContext[];
/**
* A set of [permissions boundary policy documents](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html) to include in the simulation.
*/
permissionsBoundaryPoliciesJsons?: string[];
/**
* The [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the IAM user, group, or role whose policies will be included in the simulation.
*
* You must closely match the form of the real service request you are simulating in order to achieve a realistic result. You can use the following additional arguments to specify other characteristics of the simulated requests:
*/
policySourceArn: string;
/**
* A set of ARNs of resources to include in the simulation.
*
* This argument is important for actions that have either required or optional resource types listed in [Actions, resources, and condition keys for AWS services](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html), and you must provide ARNs that identify AWS objects of the appropriate types for the chosen actions.
*
* The policy simulator only automatically loads policies associated with the `policySourceArn`, so if your given resources have their own resource-level policy then you'll also need to provide that explicitly using the `resourcePolicyJson` argument to achieve a realistic simulation.
*/
resourceArns?: string[];
/**
* Specifies a special simulation type to run. Some EC2 actions require special simulation behaviors and a particular set of resource ARNs to achieve a realistic result.
*
* For more details, see the `ResourceHandlingOption` request parameter for [the underlying `iam:SimulatePrincipalPolicy` action](https://docs.aws.amazon.com/IAM/latest/APIReference/API_SimulatePrincipalPolicy.html).
*/
resourceHandlingOption?: string;
/**
* An AWS account ID to use for any resource ARN in `resourceArns` that doesn't include its own AWS account ID. If unspecified, the simulator will use the account ID from the `callerArn` argument as a placeholder.
*/
resourceOwnerAccountId?: string;
/**
* An IAM policy document representing the resource-level policy of all of the resources specified in `resourceArns`.
*
* The policy simulator cannot automatically load policies that are associated with individual resources, as described in the documentation for `resourceArns` above.
*/
resourcePolicyJson?: string;
}
/**
* A collection of values returned by getPrincipalPolicySimulation.
*/
export interface GetPrincipalPolicySimulationResult {
readonly actionNames: string[];
readonly additionalPoliciesJsons?: string[];
/**
* `true` if all of the simulation results have decision "allowed", or `false` otherwise.
*/
readonly allAllowed: boolean;
readonly callerArn?: string;
readonly contexts?: outputs.iam.GetPrincipalPolicySimulationContext[];
readonly id: string;
readonly permissionsBoundaryPoliciesJsons?: string[];
readonly policySourceArn: string;
readonly resourceArns?: string[];
readonly resourceHandlingOption?: string;
readonly resourceOwnerAccountId?: string;
readonly resourcePolicyJson?: string;
/**
* A set of result objects, one for each of the simulated requests, with the following nested attributes:
*/
readonly results: outputs.iam.GetPrincipalPolicySimulationResult[];
}
/**
* Runs a simulation of the IAM policies of a particular principal against a given hypothetical request.
*
* You can use this data source in conjunction with
* Preconditions and Postconditions so that your configuration can test either whether it should have sufficient access to do its own work, or whether policies your configuration declares itself are sufficient for their intended use elsewhere.
*
* > **Note:** Correctly using this data source requires familiarity with various details of AWS Identity and Access Management, and how various AWS services integrate with it. For general information on the AWS IAM policy simulator, see [Testing IAM policies with the IAM policy simulator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html). This data source wraps the `iam:SimulatePrincipalPolicy` API action described on that page.
*
* ## Example Usage
*
* ### Self Access-checking Example
*
* The following example raises an error if the credentials passed to the AWS provider do not have access to perform the three actions `s3:GetObject`, `s3:PutObject`, and `s3:DeleteObject` on the S3 bucket with the given ARN.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const current = aws.getCallerIdentity({});
* const s3ObjectAccess = current.then(current => aws.iam.getPrincipalPolicySimulation({
* actionNames: [
* "s3:GetObject",
* "s3:PutObject",
* "s3:DeleteObject",
* ],
* policySourceArn: current.arn,
* resourceArns: ["arn:aws:s3:::my-test-bucket"],
* }));
* ```
*
* If you intend to use this data source to quickly raise an error when the given credentials are insufficient then you must use `dependsOn` inside any resource which would require those credentials, to ensure that the policy check will run first:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.s3.BucketObjectv2("example", {bucket: "my-test-bucket"}, {
* dependsOn: [s3ObjectAccess],
* });
* ```
*
* ### Testing the Effect of a Declared Policy
*
* The following example declares an S3 bucket and a user that should have access to the bucket, and then uses `aws.iam.getPrincipalPolicySimulation` to verify that the user does indeed have access to perform needed operations against the bucket.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const current = aws.getCallerIdentity({});
* const example = new aws.iam.User("example", {name: "example"});
* const exampleBucket = new aws.s3.Bucket("example", {bucket: "my-test-bucket"});
* const s3Access = new aws.iam.UserPolicy("s3_access", {
* name: "example_s3_access",
* user: example.name,
* policy: pulumi.jsonStringify({
* Version: "2012-10-17",
* Statement: [{
* Action: "s3:GetObject",
* Effect: "Allow",
* Resource: exampleBucket.arn,
* }],
* }),
* });
* const accountAccess = new aws.s3.BucketPolicy("account_access", {
* bucket: exampleBucket.bucket,
* policy: pulumi.jsonStringify({
* Version: "2012-10-17",
* Statement: [{
* Action: "s3:*",
* Effect: "Allow",
* Principal: {
* AWS: current.then(current => current.accountId),
* },
* Resource: [
* exampleBucket.arn,
* pulumi.interpolate`${exampleBucket.arn}/*`,
* ],
* }],
* }),
* });
* const s3ObjectAccess = aws.iam.getPrincipalPolicySimulationOutput({
* actionNames: ["s3:GetObject"],
* policySourceArn: example.arn,
* resourceArns: [exampleBucket.arn],
* resourcePolicyJson: accountAccess.policy,
* });
* ```
*
* When using `aws.iam.getPrincipalPolicySimulation` to test the effect of a policy declared elsewhere in the same configuration, it's important to use `dependsOn` to make sure that the needed policy has been fully created or updated before running the simulation.
*/
export declare function getPrincipalPolicySimulationOutput(args: GetPrincipalPolicySimulationOutputArgs, opts?: pulumi.InvokeOutputOptions): pulumi.Output<GetPrincipalPolicySimulationResult>;
/**
* A collection of arguments for invoking getPrincipalPolicySimulation.
*/
export interface GetPrincipalPolicySimulationOutputArgs {
/**
* A set of IAM action names to run simulations for. Each entry in this set adds an additional hypothetical request to the simulation.
*
* Action names consist of a service prefix and an action verb separated by a colon, such as `s3:GetObject`. Refer to [Actions, resources, and condition keys for AWS services](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html) to see the full set of possible IAM action names across all AWS services.
*/
actionNames: pulumi.Input<pulumi.Input<string>[]>;
/**
* A set of additional principal policy documents to include in the simulation. The simulator will behave as if each of these policies were associated with the object specified in `policySourceArn`, allowing you to test the effect of hypothetical policies not yet created.
*/
additionalPoliciesJsons?: pulumi.Input<pulumi.Input<string>[]>;
/**
* The ARN of an user that will appear as the "caller" of the simulated requests. If you do not specify `callerArn` then the simulation will use the `policySourceArn` instead, if it contains a user ARN.
*/
callerArn?: pulumi.Input<string>;
/**
* Each `context` block defines an entry in the table of additional context keys in the simulated request.
*
* IAM uses context keys for both custom conditions and for interpolating dynamic request-specific values into policy values. If you use policies that include those features then you will need to provide suitable example values for those keys to achieve a realistic simulation.
*/
contexts?: pulumi.Input<pulumi.Input<inputs.iam.GetPrincipalPolicySimulationContextArgs>[]>;
/**
* A set of [permissions boundary policy documents](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html) to include in the simulation.
*/
permissionsBoundaryPoliciesJsons?: pulumi.Input<pulumi.Input<string>[]>;
/**
* The [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of the IAM user, group, or role whose policies will be included in the simulation.
*
* You must closely match the form of the real service request you are simulating in order to achieve a realistic result. You can use the following additional arguments to specify other characteristics of the simulated requests:
*/
policySourceArn: pulumi.Input<string>;
/**
* A set of ARNs of resources to include in the simulation.
*
* This argument is important for actions that have either required or optional resource types listed in [Actions, resources, and condition keys for AWS services](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html), and you must provide ARNs that identify AWS objects of the appropriate types for the chosen actions.
*
* The policy simulator only automatically loads policies associated with the `policySourceArn`, so if your given resources have their own resource-level policy then you'll also need to provide that explicitly using the `resourcePolicyJson` argument to achieve a realistic simulation.
*/
resourceArns?: pulumi.Input<pulumi.Input<string>[]>;
/**
* Specifies a special simulation type to run. Some EC2 actions require special simulation behaviors and a particular set of resource ARNs to achieve a realistic result.
*
* For more details, see the `ResourceHandlingOption` request parameter for [the underlying `iam:SimulatePrincipalPolicy` action](https://docs.aws.amazon.com/IAM/latest/APIReference/API_SimulatePrincipalPolicy.html).
*/
resourceHandlingOption?: pulumi.Input<string>;
/**
* An AWS account ID to use for any resource ARN in `resourceArns` that doesn't include its own AWS account ID. If unspecified, the simulator will use the account ID from the `callerArn` argument as a placeholder.
*/
resourceOwnerAccountId?: pulumi.Input<string>;
/**
* An IAM policy document representing the resource-level policy of all of the resources specified in `resourceArns`.
*
* The policy simulator cannot automatically load policies that are associated with individual resources, as described in the documentation for `resourceArns` above.
*/
resourcePolicyJson?: pulumi.Input<string>;
}