mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
Obfuscate enroll secret in error (#16684)
When attempting to set an enroll secret which already exists in DB, error message no longer contains the secret in cleartext. #16621 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
d402f72c81
commit
6aedcf97be
1
changes/16621-obfuscate-enroll-secret
Normal file
1
changes/16621-obfuscate-enroll-secret
Normal file
@ -0,0 +1 @@
|
||||
When attempting to set an enroll secret which already exists in DB, error message no longer contains the secret in cleartext.
|
@ -147,6 +147,10 @@ func applyEnrollSecretsDB(ctx context.Context, q sqlx.ExtContext, teamID *uint,
|
||||
args = append(args, s.Secret, teamID, secretCreatedAt)
|
||||
}
|
||||
if _, err := q.ExecContext(ctx, sql, args...); err != nil {
|
||||
if isDuplicate(err) {
|
||||
// Obfuscate the secret in the error message
|
||||
err = alreadyExists("secret", fleet.MaskedPassword)
|
||||
}
|
||||
return ctxerr.Wrap(ctx, err, "insert secrets")
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package mysql
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -319,8 +321,9 @@ func testAppConfigEnrollSecretUniqueness(t *testing.T, ds *Datastore) {
|
||||
team1, err := ds.NewTeam(context.Background(), &fleet.Team{Name: "team1"})
|
||||
require.NoError(t, err)
|
||||
|
||||
const secret = "one_secret"
|
||||
expectedSecrets := []*fleet.EnrollSecret{
|
||||
{Secret: "one_secret"},
|
||||
{Secret: secret},
|
||||
}
|
||||
err = ds.ApplyEnrollSecrets(context.Background(), &team1.ID, expectedSecrets)
|
||||
require.NoError(t, err)
|
||||
@ -328,6 +331,7 @@ func testAppConfigEnrollSecretUniqueness(t *testing.T, ds *Datastore) {
|
||||
// Same secret at global level should not be allowed
|
||||
err = ds.ApplyEnrollSecrets(context.Background(), nil, expectedSecrets)
|
||||
require.Error(t, err)
|
||||
assert.False(t, strings.Contains(err.Error(), secret), fmt.Sprintf("error should not contain secret in plaintext: %s", err.Error()))
|
||||
}
|
||||
|
||||
func testAppConfigDefaults(t *testing.T, ds *Datastore) {
|
||||
|
Loading…
Reference in New Issue
Block a user