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

Updated to not save the service principal passwords as plaintext in the statefile #2402

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 18 additions & 4 deletions azurerm/resource_arm_azuread_service_principal_password.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package azurerm

import (
"crypto/sha256"
"encoding/base64"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -40,10 +42,11 @@ func resourceArmActiveDirectoryServicePrincipalPassword() *schema.Resource {
},

"value": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
DiffSuppressFunc: resourceArmActiveDirectoryServicePrincipalPasswordDiff,
},

"start_date": {
Expand Down Expand Up @@ -120,6 +123,8 @@ func resourceArmActiveDirectoryServicePrincipalPasswordCreate(d *schema.Resource
return fmt.Errorf("Error creating Password Credential %q for Service Principal %q: %+v", keyId, objectId, err)
}

d.Set("value", resourceArmActiveDirectoryServicePrincipalPasswordHash(value))

d.SetId(fmt.Sprintf("%s/%s", objectId, keyId))

return resourceArmActiveDirectoryServicePrincipalPasswordRead(d, meta)
Expand Down Expand Up @@ -239,3 +244,12 @@ func resourceArmActiveDirectoryServicePrincipalPasswordDelete(d *schema.Resource

return nil
}

func resourceArmActiveDirectoryServicePrincipalPasswordHash(password string) string {
hash := sha256.Sum256([]byte(password))
return base64.StdEncoding.EncodeToString(hash[:])
}

func resourceArmActiveDirectoryServicePrincipalPasswordDiff(k, old, new string, d *schema.ResourceData) bool {
return old == resourceArmActiveDirectoryServicePrincipalPasswordHash(new)
}