Expose JWT permission error
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
c7ffaad763
commit
49167cc55f
@ -3,10 +3,12 @@ package modules
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"github.com/filecoin-project/lotus/api/apistruct"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api/apistruct"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/lib/addrutil"
|
"github.com/filecoin-project/lotus/lib/addrutil"
|
||||||
@ -38,7 +40,8 @@ type jwtPayload struct {
|
|||||||
|
|
||||||
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, error) {
|
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, error) {
|
||||||
key, err := keystore.Get(JWTSecretName)
|
key, err := keystore.Get(JWTSecretName)
|
||||||
if err != nil {
|
|
||||||
|
if errors.Is(err, types.ErrKeyInfoNotFound) {
|
||||||
log.Warn("Generating new API secret")
|
log.Warn("Generating new API secret")
|
||||||
|
|
||||||
sk, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32))
|
sk, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32))
|
||||||
@ -68,6 +71,8 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
|
|||||||
if err := lr.SetAPIToken(cliToken); err != nil {
|
if err := lr.SetAPIToken(cliToken); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, xerrors.Errorf("could not get JWT Token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
||||||
|
@ -346,7 +346,7 @@ func (fsr *fsLockedRepo) Get(name string) (types.KeyInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fstat.Mode()&0077 != 0 {
|
if fstat.Mode()&0077 != 0 {
|
||||||
return types.KeyInfo{}, xerrors.Errorf(kstrPermissionMsg, name, err)
|
return types.KeyInfo{}, xerrors.Errorf(kstrPermissionMsg, name, fstat.Mode())
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Open(keyPath)
|
file, err := os.Open(keyPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user