-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARGO-215: Add description for S6418 for Go
- Loading branch information
1 parent
56f509e
commit db29e7e
Showing
1 changed file
with
72 additions
and
25 deletions.
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 |
---|---|---|
@@ -1,44 +1,91 @@ | ||
FIXME: add a description | ||
:detections: variables/fields | ||
:defaultsensibility: 5 | ||
|
||
// If you want to factorize the description uncomment the following line and create the file. | ||
//include::../description.adoc[] | ||
include::../description.adoc[] | ||
|
||
== Why is this an issue? | ||
include::../ask-yourself.adoc[] | ||
|
||
FIXME: remove the unused optional headers (that are commented out) | ||
include::../recommended.adoc[] | ||
|
||
//=== What is the potential impact? | ||
== Sensitive Code Example | ||
|
||
== How to fix it | ||
//== How to fix it in FRAMEWORK NAME | ||
[source,go] | ||
---- | ||
var secret = "47828a8dd77ee1eb9dde2d5e93cb221ce8c32b37" | ||
func main() { | ||
callMyService(secret) | ||
} | ||
---- | ||
|
||
=== Code examples | ||
== Compliant Solution | ||
|
||
==== Noncompliant code example | ||
Using https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/[AWS Secrets Manager]: | ||
|
||
[source,go,diff-id=1,diff-type=noncompliant] | ||
[source,go] | ||
---- | ||
FIXME | ||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/secretsmanager" | ||
) | ||
func main() { | ||
secretsManager := ... | ||
secretName := "MY_SERVICE_SECRET" | ||
input := &secretsmanager.GetSecretValueInput{ | ||
SecretId: aws.String(secretName), | ||
} | ||
result, _ := secretsManager.GetSecretValue(input) | ||
secret := *result.SecretString | ||
// do something with the secret | ||
callMyService(secret) | ||
} | ||
---- | ||
|
||
==== Compliant solution | ||
Using https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-go?tabs=azure-cli[Azure Key Vault Secret]: | ||
|
||
[source,go,diff-id=1,diff-type=compliant] | ||
[source,go] | ||
---- | ||
FIXME | ||
import ( | ||
"context" | ||
"os" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets" | ||
) | ||
func main() { | ||
vaultUri := fmt.Sprintf("https://%s.vault.azure.net/", os.Getenv("KEY_VAULT_NAME")) | ||
credential, _ := azidentity.NewDefaultAzureCredential(nil) | ||
client, _ := azsecrets.NewClient(vaultUri, credential, nil) | ||
secretName := "MY_SERVICE_SECRET" | ||
version := "" | ||
resp, _ := client.GetSecret(context.TODO(), secretName, version, nil) | ||
secret := *resp.Value | ||
// do something with the secret | ||
callMyService(secret) | ||
} | ||
---- | ||
|
||
//=== How does this work? | ||
|
||
//=== Pitfalls | ||
include::../see.adoc[] | ||
|
||
* MSC - https://wiki.sei.cmu.edu/confluence/x/OjdGBQ[MSC03-J - Never hard code sensitive information] | ||
|
||
|
||
ifdef::env-github,rspecator-view[] | ||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
|
||
//=== Going the extra mile | ||
|
||
include::../parameters.adoc[] | ||
|
||
//== Resources | ||
//=== Documentation | ||
//=== Articles & blog posts | ||
//=== Conference presentations | ||
//=== Standards | ||
//=== External coding guidelines | ||
//=== Benchmarks | ||
''' | ||
endif::env-github,rspecator-view[] |