mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 01:25:25 +00:00
Add loadConfig S3 based on AWS_PROFILE ~/.aws/credentials
This commit is contained in:
parent
04a6c82730
commit
e35c6049bb
@ -235,6 +235,7 @@ func validateMissingS3Options(options *types.Options) []string {
|
|||||||
if options.AwsBucketName == "" {
|
if options.AwsBucketName == "" {
|
||||||
missing = append(missing, "AWS_TEMPLATE_BUCKET")
|
missing = append(missing, "AWS_TEMPLATE_BUCKET")
|
||||||
}
|
}
|
||||||
|
if options.AwsProfile == "" {
|
||||||
if options.AwsAccessKey == "" {
|
if options.AwsAccessKey == "" {
|
||||||
missing = append(missing, "AWS_ACCESS_KEY")
|
missing = append(missing, "AWS_ACCESS_KEY")
|
||||||
}
|
}
|
||||||
@ -244,6 +245,11 @@ func validateMissingS3Options(options *types.Options) []string {
|
|||||||
if options.AwsRegion == "" {
|
if options.AwsRegion == "" {
|
||||||
missing = append(missing, "AWS_REGION")
|
missing = append(missing, "AWS_REGION")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (options.AwsAccessKey == "" || options.AwsSecretKey == "" || options.AwsRegion == "") && options.AwsProfile == "" {
|
||||||
|
missing = append(missing, "AWS_PROFILE")
|
||||||
|
}
|
||||||
|
|
||||||
return missing
|
return missing
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,6 +455,7 @@ func readEnvInputVars(options *types.Options) {
|
|||||||
options.AwsSecretKey = os.Getenv("AWS_SECRET_KEY")
|
options.AwsSecretKey = os.Getenv("AWS_SECRET_KEY")
|
||||||
options.AwsBucketName = os.Getenv("AWS_TEMPLATE_BUCKET")
|
options.AwsBucketName = os.Getenv("AWS_TEMPLATE_BUCKET")
|
||||||
options.AwsRegion = os.Getenv("AWS_REGION")
|
options.AwsRegion = os.Getenv("AWS_REGION")
|
||||||
|
options.AwsProfile = os.Getenv("AWS_PROFILE")
|
||||||
|
|
||||||
// Azure options for downloading templates from an Azure Blob Storage container
|
// Azure options for downloading templates from an Azure Blob Storage container
|
||||||
options.AzureContainerName = os.Getenv("AZURE_CONTAINER_NAME")
|
options.AzureContainerName = os.Getenv("AZURE_CONTAINER_NAME")
|
||||||
|
|||||||
20
pkg/external/customtemplates/s3.go
vendored
20
pkg/external/customtemplates/s3.go
vendored
@ -62,7 +62,7 @@ func (bk *customTemplateS3Bucket) Update(ctx context.Context) {
|
|||||||
func NewS3Providers(options *types.Options) ([]*customTemplateS3Bucket, error) {
|
func NewS3Providers(options *types.Options) ([]*customTemplateS3Bucket, error) {
|
||||||
providers := []*customTemplateS3Bucket{}
|
providers := []*customTemplateS3Bucket{}
|
||||||
if options.AwsBucketName != "" && !options.AwsTemplateDisableDownload {
|
if options.AwsBucketName != "" && !options.AwsTemplateDisableDownload {
|
||||||
s3c, err := getS3Client(context.TODO(), options.AwsAccessKey, options.AwsSecretKey, options.AwsRegion)
|
s3c, err := getS3Client(context.TODO(), options.AwsAccessKey, options.AwsSecretKey, options.AwsRegion, options.AwsProfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorutil.NewWithErr(err).Msgf("error downloading s3 bucket %s", options.AwsBucketName)
|
return nil, errorutil.NewWithErr(err).Msgf("error downloading s3 bucket %s", options.AwsBucketName)
|
||||||
}
|
}
|
||||||
@ -104,10 +104,24 @@ func downloadToFile(downloader *manager.Downloader, targetDirectory, bucket, key
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getS3Client(ctx context.Context, accessKey string, secretKey string, region string) (*s3.Client, error) {
|
func getS3Client(ctx context.Context, accessKey string, secretKey string, region string, profile string) (*s3.Client, error) {
|
||||||
cfg, err := config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")), config.WithRegion(region))
|
var cfg aws.Config
|
||||||
|
var err error
|
||||||
|
if profile != "" {
|
||||||
|
cfg, err = config.LoadDefaultConfig(ctx, config.WithSharedConfigProfile(profile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
} else if accessKey != "" && secretKey != "" {
|
||||||
|
cfg, err = config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")), config.WithRegion(region))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cfg, err = config.LoadDefaultConfig(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
return s3.NewFromConfig(cfg), nil
|
return s3.NewFromConfig(cfg), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -345,6 +345,8 @@ type Options struct {
|
|||||||
GitLabTemplateRepositoryIDs []int
|
GitLabTemplateRepositoryIDs []int
|
||||||
// GitLabTemplateDisableDownload disables downloading templates from custom GitLab repositories
|
// GitLabTemplateDisableDownload disables downloading templates from custom GitLab repositories
|
||||||
GitLabTemplateDisableDownload bool
|
GitLabTemplateDisableDownload bool
|
||||||
|
// AWS access profile from ~/.aws/credentials file for downloading templates from S3 bucket
|
||||||
|
AwsProfile string
|
||||||
// AWS access key for downloading templates from S3 bucket
|
// AWS access key for downloading templates from S3 bucket
|
||||||
AwsAccessKey string
|
AwsAccessKey string
|
||||||
// AWS secret key for downloading templates from S3 bucket
|
// AWS secret key for downloading templates from S3 bucket
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user