-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide more grant APIs for the StateMachine construct #5933
Comments
I would re-shape these APIs to be -
|
Oh yeah! Good call Niranjan. Points 1. and 2. makes all more sense. The only thing to consider when implementing the 3rd point is that, some IAM actions goes over the
|
Maybe off-topic but I'm not finding much information out there, how can one achieve this right now? manually creating an IAM role and attaching the permissions? |
Hi @ospfranco , class StateMachine(stepfunctions.StateMachine):
def __init__(
self,
scope: core.Construct,
id_: str,
definition: IChainable,
role: Optional[iam.IRole] = None,
state_machine_name: Optional[str] = None,
state_machine_type: Optional[StateMachineType] = None,
timeout: Optional[core.Duration] = None) -> None:
super().__init__(
scope=scope,
id=id_,
definition=definition,
timeout=timeout,
role=role,
state_machine_name=state_machine_name,
state_machine_type=state_machine_type
)
self.execution_arn = core.Arn.format(
components=core.ArnComponents(
resource="execution",
service="states",
account=self.stack.account,
partition=self.stack.partition,
region=self.stack.region,
resource_name=self.state_machine_name,
sep=":"
),
stack=self.stack)
def grant_describe_execution(
self,
identity: iam.IGrantable) -> iam.Grant:
return iam.Grant.add_to_principal(
grantee=identity,
actions=[Action.DESCRIBE_EXECUTION.value],
resource_arns=[f"{self.execution_arn}:*"]
)
def grant_send_task_success_token(
self,
identity: iam.IGrantable) -> iam.Grant:
return iam.Grant.add_to_principal(
grantee=identity,
actions=[Action.SEND_TASK_SUCCESS.value],
resource_arns=[self.state_machine_arn]
)
def grant_send_task_failure_token(
self,
identity: iam.IGrantable) -> iam.Grant:
return iam.Grant.add_to_principal(
grantee=identity,
actions=[Action.SEND_TASK_FAILURE.value],
resource_arns=[self.state_machine_arn]
) And we use it like this: class ExampleStateMachine(StateMachine):
ARN_ENV_VAR = "EXAMPLE_STEP_FUNCTION"
def __init__(self,
scope: core.Construct,
example_lambda: ExampleLambda) -> None:
example_state = LambdaTask( # this is also our extension of a Task
scope=scope,
task_id="ExampleState",
lambda_function=example_state,
timeout=core.Duration.minutes(5))
definition = example_state
super().__init__(
scope=scope,
id_="ExampleStateMachine",
definition=definition,
timeout=core.Duration.minutes(5)) Then to instance the state machine: example_state_machine = ExampleStateMachine(
scope=self,
example_lambda=example_lambda) And to grant the permission: example_state_machine.grant_start_execution(
identity=lambda_who_call_the_state_machine.grant_principal)
example_state_machine.grant_describe_execution(
identity=lambda_who_call_the_state_machine.grant_principal) You can also do it as @nija-at suggest, that I think is more elegant |
This PR closes #5933. It adds additional grant APIs to supplement `grantStartExecution()`. API additions to `state-machine.ts`: - `grantRead()` method that grants read access to a role. - `grantTaskResponse()` method that grants task response access to a role. - `grantExecution()` method that allows user to specify what action to map onto all executions. - `grant()` method that allows user to specify what action to map onto the state machine. API additions to `activity.ts`: - `grant()` method that allows user to specify what action to map onto the activity. The idea behind these API methods is to mimic the convention of other `grant()` APIs in other modules. This is slightly more difficult with Step Functions because of the multiple resources that IAM actions can map onto. The rationale is that `grant()` in `state-machine.ts` will handle all custom permissions for the state machine, `grantExecution()` in `state-machine.ts` will handle all custom permissions for the executions, and `grant()` in `activity.ts` will handle all custom permissions for activities. `grantRead()` and `grantTaskResponse()` are convenience APIs that were specified in the original issue for this feature. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Perhaps I'm missing something here, but the Upon deploying CDK project, I am met with the warning message:
Of course, if I add the permission directly on the Lambda's role as a policy statement, everything works fine:
Is the intent of these APIs to allow to use as such for a Lambda function?
For further context, this Lambda lives outside of StepFunctions and is used for manual task response via API Gateway. |
Like
StateMachine#grantStartExecution
, be able to have aStateMachine#grantDescribeExecution
Use Case
In order to improve readability and have a standard way of give permissions over a StateMachine
As a devops
I'll want to give permission to describe an execution to an aws resource
Proposed Solution
First create an
executionArn
, like thestateMachineArn
, this because the arn are different when giving permissions.for example:
arn:aws:states:us-east-1:1234567890:stateMachine:StateMachineExample
arn:aws:states:us-east-1:1234567890:execution:StateMachineExample
Then create a method
grantDescribeExecution
and use theexecutionArn
.something like this:
and
On the other hand and not totally related, this could be done also:
Other
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: