Skip to content
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

CodePipeline lambda action does not have access to artifact bucket #3274

Closed
1 of 5 tasks
jellevandenhooff opened this issue Jul 10, 2019 · 6 comments · Fixed by #3303
Closed
1 of 5 tasks

CodePipeline lambda action does not have access to artifact bucket #3274

jellevandenhooff opened this issue Jul 10, 2019 · 6 comments · Fixed by #3303
Labels
needs-triage This issue or PR still needs to be triaged.

Comments

@jellevandenhooff
Copy link

jellevandenhooff commented Jul 10, 2019

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce
    Create a codepipeline pipeline and action that invokes lambda. Use the codepipeline artifact credentials in the lambda function to access the input artifact. This fails with a permission error.

Some related code:

    const sourceOutput = new codepipeline.Artifact();
    const sourceAction = new codepipeline_actions.S3SourceAction({
      actionName: "GetSource",
      bucket: sourceBucket,
      output: sourceOutput,
      bucketKey: "Pipeline",
    });
    pipeline.addStage({
      stageName: "Start",
      actions: [sourceAction],
    });

    const fn = new lambda.Function(this, "TestLambda", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "main",
      code: lambda.Code.asset("./lambda-handler/main.zip"),
    });

    const deploy = new codepipeline_actions.LambdaInvokeAction({
      actionName: "Deploy",
      lambda: fn,
      inputs: [sourceOutput],
    });
  • What is the expected behavior (or behavior of feature suggested)?
    It works. Changing the role on the action to be pipeline.role fixes it.

  • What is the motivation / use case for changing the behavior or adding this feature?

  • Please tell us about your environment:

    "devDependencies": {
    "@types/node": "8.10.45",
    "typescript": "^3.3.3333",
    "ts-node": "^8.1.0",
    "aws-cdk": "^0.39.0"
  },
  "dependencies": {
    "@aws-cdk/aws-codepipeline": "^0.39.0",
    "@aws-cdk/aws-codepipeline-actions": "^0.39.0",
    "@aws-cdk/aws-lambda": "^0.39.0",
    "@aws-cdk/aws-s3": "^0.39.0",
    "@aws-cdk/core": "^0.39.0",
    "prettier": "^1.18.2",
    "source-map-support": "^0.5.9"
  }
}
  • CDK CLI Version: xx.xx.xx
  • Module Version: xx.xx.xx
  • OS: [all | Windows 10 | OSX Mojave | Ubuntu | etc... ]
  • Language: [all | TypeScript | Java | Python ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
@jellevandenhooff jellevandenhooff added the needs-triage This issue or PR still needs to be triaged. label Jul 10, 2019
@skinny85
Copy link
Contributor

Thanks for opening the issue @jellevandenhooff . The reason a Lambda function invoked in a CodePipeline does not need permissions to the artifact Bucket is that it gets a signed URL to the artifacts in the body of the event it receives. That link should be used to read and write the artifacts, not the Lambda Role permissions.

Hope this helps!

Thanks,
Adam

@jellevandenhooff
Copy link
Author

jellevandenhooff commented Jul 11, 2019 via email

@skinny85
Copy link
Contributor

I meant these: https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html#actions-invoke-lambda-function-json-event-example

{
    "CodePipeline.job": {
        "id": "11111111-abcd-1111-abcd-111111abcdef",
        "accountId": "111111111111",
        "data": {
            "actionConfiguration": {
                "configuration": {
                    "FunctionName": "MyLambdaFunctionForAWSCodePipeline",
                    "UserParameters": "some-input-such-as-a-URL"
                }
            },
            "inputArtifacts": [
                {
                    "location": {
                        "s3Location": {
                            "bucketName": "the name of the bucket configured as the pipeline artifact store in Amazon S3, for example codepipeline-us-east-2-1234567890",
                            "objectKey": "the name of the application, for example CodePipelineDemoApplication.zip"
                        },
                        "type": "S3"
                    },
                    "revision": null,
                    "name": "ArtifactName"
                }
            ],
            "outputArtifacts": [],
            "artifactCredentials": {
                "secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
                "sessionToken": "sessionToken",
                "accessKeyId": "AKIAIOSFODNN7EXAMPLE"
            },
            "continuationToken": "A continuation token if continuing job",
            "encryptionKey": { 
              "id": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
              "type": "KMS"
            }
        }
    }
}

The artifactCredentials field above.

@jellevandenhooff
Copy link
Author

jellevandenhooff commented Jul 11, 2019 via email

@skinny85
Copy link
Contributor

Let me try to reproduce this locally @jellevandenhooff . I'll report back.

@skinny85
Copy link
Contributor

You were correct @jellevandenhooff . Apologies you ran into this. I'll have a PR out with a fix today.

skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 12, 2019
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 12, 2019
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 12, 2019
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 13, 2019
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jul 15, 2019
…cket

The Lambda invoke action was missing granting permissions to the artifact bucket,
which meant attempts to use the credentials passed to it in the event resulted in an "access denied"
when attempting to read and/or write the action pipeline artifacts.
The fix is to grant the action role permissions to the artifact bucket
(read-write if the action has any outputs, just read if the action has only inputs).

Fixes aws#3274
skinny85 added a commit that referenced this issue Jul 16, 2019
…eline bucket (#3303)

The Lambda invoke action was missing granting permissions to the artifact bucket,
which meant attempts to use the credentials passed to it in the event resulted in an "access denied"
when trying to read and/or write the action pipeline artifacts.
The fix is to grant the action role permissions to the artifact bucket
(write if the action has any outputs, read if the action has any inputs).

Fixes #3274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants