Skip to content

Commit

Permalink
fix license base64 decode salt. (labring#4127)
Browse files Browse the repository at this point in the history
Signed-off-by: yy <[email protected]>
  • Loading branch information
lingdie committed Oct 20, 2023
1 parent 7aaad32 commit f6c35d9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion controllers/job/init/deploy/manifests/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
secretKeyRef:
name: desktop-frontend-secret
key: mongodb_uri
- name: PASSWORD_SALT_KEY
- name: PASSWORD_SALT
valueFrom:
secretKeyRef:
name: desktop-frontend-secret
Expand Down
11 changes: 3 additions & 8 deletions controllers/job/init/internal/util/database/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package database

import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"os"
)
Expand All @@ -11,12 +10,8 @@ var (
saltKey = os.Getenv("PASSWORD_SALT_KEY")
)

func hashPassword(password string) (string, error) {
func hashPassword(password string) string {
hash := sha256.New()
validSalt, err := base64.StdEncoding.DecodeString(saltKey)
if err != nil {
return "", err
}
hash.Write([]byte(password + string(validSalt)))
return hex.EncodeToString(hash.Sum(nil)), nil
hash.Write([]byte(password + saltKey))
return hex.EncodeToString(hash.Sum(nil))
}
6 changes: 1 addition & 5 deletions controllers/job/init/internal/util/database/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func PresetAdminUser(ctx context.Context) error {
}

func newAdminUser() (*User, error) {
hashedPassword, err := hashPassword(DefaultAdminPassword)
if err != nil {
return nil, err
}
return newUser(uuid.New().String(), DefaultAdminUserName, DefaultAdminUserName, hashedPassword, controller.DefaultAdminUserName), nil
return newUser(uuid.New().String(), DefaultAdminUserName, DefaultAdminUserName, hashPassword(DefaultAdminPassword), controller.DefaultAdminUserName), nil
}

func newUser(uid, name, passwordUser, hashedPassword, k8sUser string) *User {
Expand Down
2 changes: 1 addition & 1 deletion deploy/cloud/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function sealos_authorize {
# wait for admin user create
echo "Waiting for admin user create"

while [ -z "$(kubectl get ns -n ns-admin 2>/dev/null)" ]; do
while [ -z "$(kubectl get ns ns-admin 2>/dev/null)" ]; do
sleep 1
done

Expand Down

0 comments on commit f6c35d9

Please sign in to comment.