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

[Build-deps]: Bump github.com/rs/zerolog from 1.21.0 to 1.22.0 #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions changelog/unreleased/use-uid-gid-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: use UidNumber and GidNumber fields in User objects

Update instances where CS3API's `User` objects are created and used to use `GidNumber`,
and `UidNumber` fields instead of storing them in `Opaque` map.

https://github.com/cs3org/reva/issues/1516
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/pkg/xattr v0.4.3
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.21.0
github.com/rs/zerolog v1.22.0
github.com/sciencemesh/meshdirectory-web v1.0.4
github.com/stretchr/testify v1.7.0
github.com/studio-b12/gowebdav v0.0.0-20200303150724-9380631c29a1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/rs/zerolog v1.21.0 h1:Q3vdXlfLNT+OftyBHsU0Y445MD+8m8axjKgf2si0QcM=
github.com/rs/zerolog v1.21.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
github.com/rs/zerolog v1.22.0 h1:XrVUjV4K+izZpKXZHlPrYQiDtmdGiCylnT4i43AAWxg=
github.com/rs/zerolog v1.22.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
github.com/rubenv/sql-migrate v0.0.0-20190212093014-1007f53448d7/go.mod h1:WS0rl9eEliYI8DPnr3TOwz4439pay+qNgzJoVya/DmY=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
4 changes: 4 additions & 0 deletions pkg/auth/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Credentials struct {
DisplayName string `mapstructure:"display_name" json:"display_name"`
Secret string `mapstructure:"secret" json:"secret"`
Groups []string `mapstructure:"groups" json:"groups"`
UIDNumber int64 `mapstructure:"uid_number" json:"uid_number"`
GIDNumber int64 `mapstructure:"gid_number" json:"gid_number"`
Opaque *typespb.Opaque `mapstructure:"opaque" json:"opaque"`
}

Expand Down Expand Up @@ -111,6 +113,8 @@ func (m *manager) Authenticate(ctx context.Context, username string, secret stri
MailVerified: c.MailVerified,
DisplayName: c.DisplayName,
Groups: c.Groups,
UidNumber: c.UIDNumber,
GidNumber: c.GIDNumber,
Opaque: c.Opaque,
// TODO add arbitrary keys as opaque data
}, nil
Expand Down
25 changes: 11 additions & 14 deletions pkg/auth/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"context"
"crypto/tls"
"fmt"
"strconv"
"strings"

user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/auth"
"github.com/cs3org/reva/pkg/auth/manager/registry"
Expand Down Expand Up @@ -182,7 +182,14 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
if getGroupsResp.Status.Code != rpc.Code_CODE_OK {
return nil, errors.Wrap(err, "ldap: grpc getting user groups failed")
}

gidNumber, err := strconv.ParseInt(sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.GIDNumber), 10, 64)
if err != nil {
return nil, err
}
uidNumber, err := strconv.ParseInt(sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.UIDNumber), 10, 64)
if err != nil {
return nil, err
}
u := &user.User{
Id: userID,
// TODO add more claims from the StandardClaims, eg EmailVerified
Expand All @@ -191,18 +198,8 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
Groups: getGroupsResp.Groups,
Mail: sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.Mail),
DisplayName: sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.DisplayName),
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": {
Decoder: "plain",
Value: []byte(sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.UIDNumber)),
},
"gid": {
Decoder: "plain",
Value: []byte(sr.Entries[0].GetEqualFoldAttributeValue(am.c.Schema.GIDNumber)),
},
},
},
UidNumber: uidNumber,
GidNumber: gidNumber,
}
log.Debug().Interface("entry", sr.Entries[0]).Interface("user", u).Msg("authenticated user")

Expand Down
24 changes: 5 additions & 19 deletions pkg/auth/manager/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
oidc "github.com/coreos/go-oidc"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/auth"
"github.com/cs3org/reva/pkg/auth/manager/registry"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -129,26 +128,12 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
return nil, fmt.Errorf("no \"preferred_username\" or \"name\" attribute found in userinfo: maybe the client did not request the oidc \"profile\"-scope")
}

opaqueObj := &types.Opaque{
Map: map[string]*types.OpaqueEntry{},
}
var uid, gid int64
if am.c.UIDClaim != "" {
uid, ok := claims[am.c.UIDClaim]
if ok {
opaqueObj.Map["uid"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", uid)),
}
}
uid, _ = claims[am.c.UIDClaim].(int64)
}
if am.c.GIDClaim != "" {
gid, ok := claims[am.c.GIDClaim]
if ok {
opaqueObj.Map["gid"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", gid)),
}
}
gid, _ = claims[am.c.GIDClaim].(int64)
}

userID := &user.UserId{
Expand Down Expand Up @@ -180,7 +165,8 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
Mail: claims["email"].(string),
MailVerified: claims["email_verified"].(bool),
DisplayName: claims["name"].(string),
Opaque: opaqueObj,
UidNumber: uid,
GidNumber: gid,
}

return u, nil
Expand Down
43 changes: 11 additions & 32 deletions pkg/cbox/user/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
utils "github.com/cs3org/reva/pkg/cbox/utils"
"github.com/cs3org/reva/pkg/user"
Expand Down Expand Up @@ -169,6 +168,8 @@ func (m *manager) parseAndCacheUser(ctx context.Context, userData map[string]int
upn, _ := userData["upn"].(string)
mail, _ := userData["primaryAccountEmail"].(string)
name, _ := userData["displayName"].(string)
uidNumber, _ := userData["uid"].(int64)
gidNumber, _ := userData["gid"].(int64)

userID := &userpb.UserId{
OpaqueId: upn,
Expand All @@ -179,18 +180,8 @@ func (m *manager) parseAndCacheUser(ctx context.Context, userData map[string]int
Username: upn,
Mail: mail,
DisplayName: name,
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", userData["uid"])),
},
"gid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", userData["gid"])),
},
},
},
UidNumber: uidNumber,
GidNumber: gidNumber,
}

if err := m.cacheUserDetails(u); err != nil {
Expand Down Expand Up @@ -274,6 +265,8 @@ func (m *manager) findUsersByFilter(ctx context.Context, url string, users map[s
upn, _ := usrInfo["upn"].(string)
mail, _ := usrInfo["primaryAccountEmail"].(string)
name, _ := usrInfo["displayName"].(string)
uidNumber, _ := usrInfo["uid"].(int64)
gidNumber, _ := usrInfo["gid"].(int64)

uid := &userpb.UserId{
OpaqueId: upn,
Expand All @@ -284,18 +277,8 @@ func (m *manager) findUsersByFilter(ctx context.Context, url string, users map[s
Username: upn,
Mail: mail,
DisplayName: name,
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", usrInfo["uid"])),
},
"gid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(fmt.Sprintf("%0.f", usrInfo["gid"])),
},
},
},
UidNumber: uidNumber,
GidNumber: gidNumber,
}
}

Expand Down Expand Up @@ -386,12 +369,8 @@ func (m *manager) IsInGroup(ctx context.Context, uid *userpb.UserId, group strin
}

func extractUID(u *userpb.User) (string, error) {
if u.Opaque != nil && u.Opaque.Map != nil {
if uidObj, ok := u.Opaque.Map["uid"]; ok {
if uidObj.Decoder == "plain" {
return string(uidObj.Value), nil
}
}
if u.UidNumber == 0 {
return "", errors.New("rest: could not retrieve UID from user")
}
return "", errors.New("rest: could not retrieve UID from user")
return fmt.Sprintf("%v", u.UidNumber), nil
}
26 changes: 11 additions & 15 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ func getUser(ctx context.Context) (*userpb.User, error) {
err := errors.Wrap(errtypes.UserRequired(""), "eos: error getting user from ctx")
return nil, err
}
if u.UidNumber == 0 {
return nil, errors.New("eos: invalid user id")
}
if u.GidNumber == 0 {
return nil, errors.New("eos: invalid group id")
}
return u, nil
}

Expand Down Expand Up @@ -1459,23 +1465,13 @@ func getResourceType(isDir bool) provider.ResourceType {
}

func (fs *eosfs) extractUIDAndGID(u *userpb.User) (string, string, error) {
var uid, gid string
if u.Opaque != nil && u.Opaque.Map != nil {
if uidObj, ok := u.Opaque.Map["uid"]; ok {
if uidObj.Decoder == "plain" {
uid = string(uidObj.Value)
}
}
if gidObj, ok := u.Opaque.Map["gid"]; ok {
if gidObj.Decoder == "plain" {
gid = string(gidObj.Value)
}
}
if u.UidNumber == 0 {
return "", "", errors.New("eos: uid missing for user")
}
if uid == "" || gid == "" {
return "", "", errors.New("eos: uid or gid missing for user")
if u.GidNumber == 0 {
return "", "", errors.New("eos: gid missing for user")
}
return uid, gid, nil
return fmt.Sprintf("%v", u.UidNumber), fmt.Sprintf("%v", u.GidNumber), nil
}

func (fs *eosfs) getUIDGateway(ctx context.Context, u *userpb.UserId) (string, string, error) {
Expand Down
38 changes: 7 additions & 31 deletions pkg/user/manager/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ package demo
import (
"context"
"errors"
"fmt"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/pkg/user/manager/registry"
Expand Down Expand Up @@ -69,12 +69,8 @@ func extractClaim(u *userpb.User, claim string) (string, error) {
case "username":
return u.Username, nil
case "uid":
if u.Opaque != nil && u.Opaque.Map != nil {
if uidObj, ok := u.Opaque.Map["uid"]; ok {
if uidObj.Decoder == "plain" {
return string(uidObj.Value), nil
}
}
if u.UidNumber != 0 {
return fmt.Sprintf("%v", u.UidNumber), nil
}
}
return "", errors.New("demo: invalid field")
Expand Down Expand Up @@ -114,18 +110,8 @@ func getUsers() map[string]*userpb.User {
Groups: []string{"sailing-lovers", "violin-haters", "physics-lovers"},
Mail: "einstein@example.org",
DisplayName: "Albert Einstein",
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("123"),
},
"gid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("987"),
},
},
},
UidNumber: 123,
GidNumber: 987,
},
"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c": &userpb.User{
Id: &userpb.UserId{
Expand All @@ -136,18 +122,8 @@ func getUsers() map[string]*userpb.User {
Groups: []string{"radium-lovers", "polonium-lovers", "physics-lovers"},
Mail: "marie@example.org",
DisplayName: "Marie Curie",
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("456"),
},
"gid": &types.OpaqueEntry{
Decoder: "plain",
Value: []byte("987"),
},
},
},
UidNumber: 456,
GidNumber: 987,
},
"932b4540-8d16-481e-8ef4-588e4b6b151c": &userpb.User{
Id: &userpb.UserId{
Expand Down
9 changes: 2 additions & 7 deletions pkg/user/manager/demo/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
)

Expand All @@ -42,12 +41,8 @@ func TestUserManager(t *testing.T) {
Groups: []string{"sailing-lovers", "violin-haters", "physics-lovers"},
Mail: "einstein@example.org",
DisplayName: "Albert Einstein",
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"uid": &types.OpaqueEntry{Decoder: "plain", Value: []byte("123")},
"gid": &types.OpaqueEntry{Decoder: "plain", Value: []byte("987")},
},
},
UidNumber: 123,
GidNumber: 987,
}
uidFake := &userpb.UserId{Idp: "nonesense", OpaqueId: "fakeUser"}
groupsEinstein := []string{"sailing-lovers", "violin-haters", "physics-lovers"}
Expand Down
9 changes: 3 additions & 6 deletions pkg/user/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package json
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"strings"

Expand Down Expand Up @@ -111,12 +112,8 @@ func extractClaim(u *userpb.User, claim string) (string, error) {
case "username":
return u.Username, nil
case "uid":
if u.Opaque != nil && u.Opaque.Map != nil {
if uidObj, ok := u.Opaque.Map["uid"]; ok {
if uidObj.Decoder == "plain" {
return string(uidObj.Value), nil
}
}
if u.UidNumber != 0 {
return fmt.Sprintf("%v", u.UidNumber), nil
}
}
return "", errors.New("json: invalid field")
Expand Down
Loading