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

Code Signing via CloudFormation? #2424

Closed
jplock opened this issue Nov 30, 2020 · 10 comments
Closed

Code Signing via CloudFormation? #2424

jplock opened this issue Nov 30, 2020 · 10 comments
Labels
blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@jplock
Copy link

jplock commented Nov 30, 2020

Describe your idea/feature/enhancement

Related to #2407, is it possible to deploy a code signed Lambda function using CloudFormation or do you have to use sam deploy? We have CodePipeline's configured that run sam package from CodeBuild, but then use CodePipeline's CloudFormation integration to provisioned the packaged YAML file template (so we don't run sam deploy in our pipeline). CloudFormation returns an error message:

Lambda cannot deploy the function. The function or layer might be signed using a signature that the client is not configured to accept.

Reading https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/authoring-codesigning.html and https://aws.amazon.com/blogs/aws/new-code-signing-a-trust-and-integrity-control-for-aws-lambda/, it's not clear whether this is supported or not.

Thanks.

@mndeveci
Copy link
Contributor

mndeveci commented Dec 4, 2020

Hi @jplock ,

Code signing is supported with both deploy and package commands. You can use sam package --signing-profile MyFunctionName=MySigningProfile ... just for packaging and signing the artifact which is uploaded to s3 bucket. This will also update template with signed artifact locations.

Please let us know if this works for you.

Thanks

@mndeveci mndeveci added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. and removed type/question labels Dec 4, 2020
@jplock
Copy link
Author

jplock commented Dec 4, 2020

Right so that’s happening and I see the signed packages in S3 and the template is updated to point to them. But then if I upload the template directly into CloudFormation I get that “not configured to accept” message. Do I have to grant access to cloudformation.amazonaws.com to be able to read the signing profile somehow?

@jplock
Copy link
Author

jplock commented Dec 4, 2020

The error seems to be coming from the Lambda service based on the actual exception visible in the CloudFormation event when it starts rolling back the stack.

@mndeveci
Copy link
Contributor

mndeveci commented Dec 5, 2020

I talked with the Lambda team and they said this might be caused if you have signed code using a signing profile that is not included in the code signing config in your template. Can you confirm that you are using same signing profile in your template and when packaging your code?

They also sent this main documentation page for code signer; https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html

@jplock
Copy link
Author

jplock commented Dec 5, 2020

Oh interesting. So in this case, I created the code signing config outside of the template and just referenced the ARN in the CodeSigningConfigArn property so I could reuse the signing config across multiple stacks each creating separate Lambda functions (but I want them to all use the same signing config).

Is that supported or should each CloudFormation stack create it's own code signing configuration (which reference the same underlying signing profile)?

Thanks for looking into this.

@mndeveci
Copy link
Contributor

mndeveci commented Dec 7, 2020

Yes this should work fine. One thing I can suggest to look at is the property that you assigned in SigningProfileVersionArns in AWS::Lambda::CodeSigningConfig resource. They should be profileVersionArn of the signing profile, not the ARN of the signing profile.

I will create and test it by creating 2 stacks,

  • First one will only contain the signing profile and code signing config
  • Second one will use the code signing config and signing profile from the first one

And if you can provide us the example template that you used which re-produces the issue, I can test that one as well.

@jplock
Copy link
Author

jplock commented Dec 8, 2020

That was it! Is there a way to get the signing profile version ARN via CloudFormation? My template looks like this:

SigningProfile:
  Type: "AWS::Signer::SigningProfile"
  Properties:
    PlatformId: AWSLambda-SHA384-ECDSA
    SignatureValidityPeriod:
      Type: MONTHS
      Value: 135

CodeSigningConfig:
  Type: "AWS::Lambda::CodeSigningConfig"
  Properties:
    Description: "Code Signing"
    AllowedPublishers:
      SigningProfileVersionArns:
        - !Ref SigningProfile  <-- this just returns the signing profile ARN without the version
    CodeSigningPolicies:
      UntrustedArtifactOnDeployment: Enforce

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-signer-signingprofile.html doesn't mention any other return values.

@mndeveci
Copy link
Contributor

mndeveci commented Dec 8, 2020

Glad that it worked, I pinged Lambda team that they will mention this in their documentation. And for your last question, you can use !GetAtt SigningProfile.ProfileVersionArn to get the profileVersionArn from signing profile. This last one is not mentioned in the docs, they will update that as well.

Here is the template;

  SigningProfile:
    Type: "AWS::Signer::SigningProfile"
    Properties:
      PlatformId: AWSLambda-SHA384-ECDSA

  CodeSigningConfig:
    Type: "AWS::Lambda::CodeSigningConfig"
    Properties:
      Description: "Code Signing"
      AllowedPublishers:
        SigningProfileVersionArns:
          - !GetAtt SigningProfile.ProfileVersionArn
      CodeSigningPolicies:
        UntrustedArtifactOnDeployment: Enforce

Please let me know if you need more information by reopening this ticket.

@mndeveci mndeveci closed this as completed Dec 8, 2020
@jplock
Copy link
Author

jplock commented Dec 8, 2020

Thank you for the help!

jeromevdl added a commit to jeromevdl/aws-cloudformation-user-guide that referenced this issue Jul 16, 2021
Adding the Return values section as it was not available. I don't know the other available values, please complete this section.

Found this one thanks to @mndeveci on aws/aws-sam-cli#2424
@Manouchehri
Copy link

Hmm, is there a reason why forgetting to use ProfileVersionArn sometimes appears to work initially, but fails later?

Took me awhile to figure out my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

4 participants