-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Support for Code Signing For AWS Lambda #16384
Merged
bflad
merged 9 commits into
hashicorp:master
from
santiagocardenas:aws-lambda-code-signing-support
Nov 23, 2020
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c5b3b1
Code Signing for AWS Lambda Support (Lambda Layers)
santiagocardenas 4ead7e7
Code Signing for AWS Lambda (Code Signing Config and Function)
santiagocardenas badb4b0
Code Signing for AWS Lambda (Code Signing Config and Function) Follow-up
santiagocardenas 5f02104
Update aws/data_source_aws_lambda_code_signing_config_test.go
santiagocardenas 6392f2b
Remove hardcoded ARNs.
santiagocardenas 8a27421
Fix markdown docs lint errors.
santiagocardenas 0365959
Fix import lint error.
santiagocardenas 03468d5
Update website/docs/d/lambda_code_signing_config.html.markdown
santiagocardenas 308652a
Apply suggestions from code review
bflad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/lambda" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAwsLambdaCodeSigningConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsLambdaCodeSigningConfigRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArn, | ||
}, | ||
"allowed_publishers": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"signing_profile_version_arns": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Set: schema.HashString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"policies": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"untrusted_artifact_on_deployment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"config_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_modified": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsLambdaCodeSigningConfigRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).lambdaconn | ||
|
||
arn := d.Get("arn").(string) | ||
|
||
configOutput, err := conn.GetCodeSigningConfig(&lambda.GetCodeSigningConfigInput{ | ||
CodeSigningConfigArn: aws.String(arn), | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Lambda code signing config (%s): %s", arn, err) | ||
} | ||
|
||
if configOutput == nil { | ||
return fmt.Errorf("error getting Lambda code signing config (%s): empty response", arn) | ||
} | ||
|
||
codeSigningConfig := configOutput.CodeSigningConfig | ||
if codeSigningConfig == nil { | ||
return fmt.Errorf("error getting Lambda code signing config (%s): empty CodeSigningConfig", arn) | ||
} | ||
|
||
if err := d.Set("config_id", codeSigningConfig.CodeSigningConfigId); err != nil { | ||
return fmt.Errorf("error setting lambda code signing config id: %s", err) | ||
} | ||
|
||
if err := d.Set("description", codeSigningConfig.Description); err != nil { | ||
return fmt.Errorf("error setting lambda code signing config description: %s", err) | ||
} | ||
|
||
if err := d.Set("last_modified", codeSigningConfig.LastModified); err != nil { | ||
return fmt.Errorf("error setting lambda code signing config last modified: %s", err) | ||
} | ||
|
||
if err := d.Set("allowed_publishers", flattenLambdaCodeSigningConfigAllowedPublishers(codeSigningConfig.AllowedPublishers)); err != nil { | ||
return fmt.Errorf("error setting lambda code signing config allowed publishers: %s", err) | ||
} | ||
|
||
if err := d.Set("policies", []interface{}{ | ||
map[string]interface{}{ | ||
"untrusted_artifact_on_deployment": codeSigningConfig.CodeSigningPolicies.UntrustedArtifactOnDeployment, | ||
}, | ||
}); err != nil { | ||
return fmt.Errorf("error setting lambda code signing config code signing policies: %s", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(codeSigningConfig.CodeSigningConfigArn)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAWSLambdaCodeSigningConfig_basic(t *testing.T) { | ||
dataSourceName := "data.aws_lambda_code_signing_config.test" | ||
resourceName := "aws_lambda_code_signing_config.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAWSLambdaCodeSigningConfigBasic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "allowed_publishers.0.signing_profile_version_arns.*", resourceName, "allowed_publishers.0.signing_profile_version_arns.*"), | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAWSLambdaCodeSigningConfig_PolicyConfigId(t *testing.T) { | ||
dataSourceName := "data.aws_lambda_code_signing_config.test" | ||
resourceName := "aws_lambda_code_signing_config.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAWSLambdaCodeSigningConfigConfigurePolicy, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "allowed_publishers.0.signing_profile_version_arns.*", resourceName, "allowed_publishers.0.signing_profile_version_arns.*"), | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resource.TestCheckResourceAttrPair(dataSourceName, "policies", resourceName, "policies"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "config_id", resourceName, "config_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAWSLambdaCodeSigningConfig_Description(t *testing.T) { | ||
dataSourceName := "data.aws_lambda_code_signing_config.test" | ||
resourceName := "aws_lambda_code_signing_config.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAWSLambdaCodeSigningConfigConfigureDescription, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "allowed_publishers.0.signing_profile_version_arns.*", resourceName, "allowed_publishers.0.signing_profile_version_arns.*"), | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourceAWSLambdaCodeSigningConfigBasic = ` | ||
resource "aws_signer_signing_profile" "test" { | ||
platform_id = "AWSLambda-SHA384-ECDSA" | ||
} | ||
|
||
resource "aws_lambda_code_signing_config" "test" { | ||
allowed_publishers { | ||
signing_profile_version_arns = [ | ||
aws_signer_signing_profile.test.version_arn | ||
] | ||
} | ||
} | ||
|
||
data "aws_lambda_code_signing_config" "test" { | ||
arn = aws_lambda_code_signing_config.test.arn | ||
} | ||
` | ||
|
||
const testAccDataSourceAWSLambdaCodeSigningConfigConfigurePolicy = ` | ||
resource "aws_signer_signing_profile" "test" { | ||
platform_id = "AWSLambda-SHA384-ECDSA" | ||
} | ||
|
||
resource "aws_lambda_code_signing_config" "test" { | ||
allowed_publishers { | ||
signing_profile_version_arns = [ | ||
aws_signer_signing_profile.test.version_arn | ||
] | ||
} | ||
|
||
policies { | ||
untrusted_artifact_on_deployment = "Warn" | ||
} | ||
} | ||
|
||
data "aws_lambda_code_signing_config" "test" { | ||
arn = aws_lambda_code_signing_config.test.arn | ||
} | ||
` | ||
|
||
const testAccDataSourceAWSLambdaCodeSigningConfigConfigureDescription = ` | ||
resource "aws_signer_signing_profile" "test" { | ||
platform_id = "AWSLambda-SHA384-ECDSA" | ||
} | ||
|
||
resource "aws_lambda_code_signing_config" "test" { | ||
allowed_publishers { | ||
signing_profile_version_arns = [ | ||
aws_signer_signing_profile.test.version_arn | ||
] | ||
} | ||
|
||
description = "Code Signing Config for app A" | ||
} | ||
|
||
data "aws_lambda_code_signing_config" "test" { | ||
arn = aws_lambda_code_signing_config.test.arn | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followup note: GovCloud (US) support is not present for initial release, will need to skip testing in that environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on gov cloud and am not using this data source however i am getting errors on all my pipelines after release. ref #16398