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

preconfigureCallback: Allow Env Vars for Credentials Validation #2148

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ The following configuration points are available:
`sessionName`: Session name to use when assuming the role.
`tags`: Map of assume role session tags.
- `aws:insecure` - (Optional) Explicitly allow the provider to perform "insecure" SSL requests. If omitted, the default value is `false`.
- `aws:skipCredentialsValidation` - (Optional) Skip the credentials validation via the STS API. Useful for AWS API implementations that do not have STS available or implemented. Default value is `false`.
- `aws:skipCredentialsValidation` - (Optional) Skip the credentials validation via the STS API. Useful for AWS API implementations that do not have STS available or implemented. Default value is `false`. Can be set via the environment variable `AWS_SKIP_CREDENTIALS_VALIDATION`.
- `aws:skipGetEc2Platforms` - (Optional) Skip getting the supported EC2 platforms. Used by users that don't have ec2:DescribeAccountAttributes permissions. Default value is `true`.
- `aws:skipRegionValidation` - (Optional) Skip validation of provided region name. Useful for AWS-like implementations that use their own region names or to bypass the validation for regions that aren't publicly available yet. Default value is `true`.
- `aws:skipRequestionAccountId` - (Optional) Skip requesting the account ID. Useful for AWS API implementations that do not have the IAM, STS API, or metadata API. Default value is `false`. When specified, the use of ARNs is compromised as there is no accountID available to construct the ARN.
- `aws:skipMetadataApiCheck` - (Optional) Skip the AWS Metadata API check. Useful for AWS API implementations that do not have a metadata API endpoint. This provider from authenticating via the Metadata API by default. You may need to use other authentication methods like static credentials, configuration variables, or environment variables. Default is `true`.
- `aws:skipMetadataApiCheck` - (Optional) Skip the AWS Metadata API check. Useful for AWS API implementations that do not have a metadata API endpoint. This provider from authenticating via the Metadata API by default. You may need to use other authentication methods like static credentials, configuration variables, or environment variables. Default is `true`. Can be set via the environment variable `AWS_SKIP_METADATA_API_CHECK`.
- `aws:s3ForcePathStyle` - (Optional) Set this to true to force the request to use path-style addressing, i.e., `http://s3.amazonaws.com/BUCKET/KEY`. By default, the S3 client will use virtual hosted bucket addressing, `http://BUCKET.s3.amazonaws.com/KEY`, when possible. Specific to the Amazon S3 service. Default is `false`.

### Authenticating pulumi-aws via EC2 Instance Metadata?
Expand Down
36 changes: 26 additions & 10 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"unicode"

Expand Down Expand Up @@ -273,6 +274,25 @@ func stringValue(vars resource.PropertyMap, prop resource.PropertyKey, envs []st
return ""
}

// boolValue gets a bool value from a property map if present, else false
func boolValue(vars resource.PropertyMap, prop resource.PropertyKey, envs []string) bool {
val, ok := vars[prop]
if ok && val.IsBool() {
return val.BoolValue()
}
for _, env := range envs {
val, ok := os.LookupEnv(env)
if ok {
boolValue, err := strconv.ParseBool(val)
if err != nil {
return false
}
return boolValue
}
}
return false
}

func arrayValue(vars resource.PropertyMap, prop resource.PropertyKey, envs []string) []string {
val, ok := vars[prop]
var vals []string
Expand Down Expand Up @@ -300,12 +320,8 @@ func stringRef(s string) *string {
// configuration subset of `github.com/terraform-providers/terraform-provider-aws/aws.providerConfigure`. We do this
// before passing control to the TF provider to ensure we can report actionable errors.
func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) error {
var skipCredentialsValidation bool
if val, ok := vars["skipCredentialsValidation"]; ok {
if val.IsBool() {
skipCredentialsValidation = val.BoolValue()
}
}
skipCredentialsValidation := boolValue(vars, "skipCredentialsValidation",
[]string{"AWS_SKIP_CREDENTIALS_VALIDATION"})

// if we skipCredentialsValidation then we don't need to do anything in
// preConfigureCallback as this is an explicit operation
Expand Down Expand Up @@ -337,10 +353,10 @@ func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) erro
// will specify that skipMetadataApiCheck: false
// therefore, if we have skipMetadataApiCheck false, then we are enabling the imds client
config.EC2MetadataServiceEnableState = imds.ClientDisabled
if val, ok := vars["skipMetadataApiCheck"]; ok {
if val.IsBool() && !val.BoolValue() {
config.EC2MetadataServiceEnableState = imds.ClientEnabled
}
skipMetadataApiCheck := boolValue(vars, "skipMetadataApiCheck",
[]string{"AWS_SKIP_METADATA_API_CHECK"})
if !skipMetadataApiCheck {
config.EC2MetadataServiceEnableState = imds.ClientEnabled
}

// lastly let's set the sharedCreds and sharedConfig file. If these are not found then let's default to the
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ The following configuration points are available:
`sessionName`: Session name to use when assuming the role.
`tags`: Map of assume role session tags.
- `aws:insecure` - (Optional) Explicitly allow the provider to perform "insecure" SSL requests. If omitted, the default value is `false`.
- `aws:skipCredentialsValidation` - (Optional) Skip the credentials validation via the STS API. Useful for AWS API implementations that do not have STS available or implemented. Default value is `false`.
- `aws:skipCredentialsValidation` - (Optional) Skip the credentials validation via the STS API. Useful for AWS API implementations that do not have STS available or implemented. Default value is `false`. Can be set via the environment variable `AWS_SKIP_CREDENTIALS_VALIDATION`.
- `aws:skipGetEc2Platforms` - (Optional) Skip getting the supported EC2 platforms. Used by users that don't have ec2:DescribeAccountAttributes permissions. Default value is `true`.
- `aws:skipRegionValidation` - (Optional) Skip validation of provided region name. Useful for AWS-like implementations that use their own region names or to bypass the validation for regions that aren't publicly available yet. Default value is `true`.
- `aws:skipRequestionAccountId` - (Optional) Skip requesting the account ID. Useful for AWS API implementations that do not have the IAM, STS API, or metadata API. Default value is `false`. When specified, the use of ARNs is compromised as there is no accountID available to construct the ARN.
- `aws:skipMetadataApiCheck` - (Optional) Skip the AWS Metadata API check. Useful for AWS API implementations that do not have a metadata API endpoint. This provider from authenticating via the Metadata API by default. You may need to use other authentication methods like static credentials, configuration variables, or environment variables. Default is `true`.
- `aws:skipMetadataApiCheck` - (Optional) Skip the AWS Metadata API check. Useful for AWS API implementations that do not have a metadata API endpoint. This provider from authenticating via the Metadata API by default. You may need to use other authentication methods like static credentials, configuration variables, or environment variables. Default is `true`. Can be set via the environment variable `AWS_SKIP_METADATA_API_CHECK`.
- `aws:s3ForcePathStyle` - (Optional) Set this to true to force the request to use path-style addressing, i.e., `http://s3.amazonaws.com/BUCKET/KEY`. By default, the S3 client will use virtual hosted bucket addressing, `http://BUCKET.s3.amazonaws.com/KEY`, when possible. Specific to the Amazon S3 service. Default is `false`.

### Authenticating pulumi-aws via EC2 Instance Metadata?
Expand Down