-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jkoberg <jkoberg@owncloud.com>
- Loading branch information
Showing
5 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Service Accounts | ||
|
||
Makes reva ready for service accounts by introducing an serviceaccounts auth manager | ||
|
||
https://github.com/cs3org/reva/pull/3926 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package serviceaccounts | ||
|
||
import ( | ||
"context" | ||
|
||
authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" | ||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" | ||
|
||
"github.com/cs3org/reva/v2/pkg/auth" | ||
"github.com/cs3org/reva/v2/pkg/auth/manager/registry" | ||
"github.com/cs3org/reva/v2/pkg/auth/scope" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type conf struct { | ||
ServiceUsers []serviceuser `mapstructure:"service_accounts"` | ||
} | ||
|
||
type serviceuser struct { | ||
ID string `mapstructure:"id"` | ||
Secret string `mapstructure:"secret"` | ||
} | ||
|
||
type manager struct { | ||
authenticate func(userID, secret string) error | ||
} | ||
|
||
func init() { | ||
registry.Register("serviceaccounts", New) | ||
} | ||
|
||
// Configure parses the map conf | ||
func (m *manager) Configure(config map[string]interface{}) error { | ||
c := &conf{} | ||
if err := mapstructure.Decode(config, c); err != nil { | ||
return errors.Wrap(err, "error decoding conf") | ||
} | ||
// only inmem authenticator for now | ||
a := &inmemAuthenticator{make(map[string]string)} | ||
for _, s := range c.ServiceUsers { | ||
// TODO: hash secrets | ||
a.m[s.ID] = s.Secret | ||
} | ||
m.authenticate = a.Authenticate | ||
return nil | ||
} | ||
|
||
// New creates a new manager for the 'service' authentication | ||
func New(conf map[string]interface{}) (auth.Manager, error) { | ||
m := &manager{} | ||
err := m.Configure(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return m, nil | ||
} | ||
|
||
// Authenticate authenticates the service account | ||
func (m *manager) Authenticate(ctx context.Context, userID string, secret string) (*userpb.User, map[string]*authpb.Scope, error) { | ||
if err := m.authenticate(userID, secret); err != nil { | ||
return nil, nil, err | ||
} | ||
scope, err := scope.AddOwnerScope(nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
return &userpb.User{ | ||
// TODO: more details for service users? | ||
Id: &userpb.UserId{OpaqueId: userID}, | ||
}, scope, nil | ||
} | ||
|
||
type inmemAuthenticator struct { | ||
m map[string]string | ||
} | ||
|
||
func (a *inmemAuthenticator) Authenticate(userID string, secret string) error { | ||
// TODO: hash secrets | ||
if a.m[userID] == secret { | ||
return nil | ||
} | ||
return errors.New("secrets do not match") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters