Add autoprovision accounts flag

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer committed 2020-10-05 11:25:02 +02:00
1 parent 9a17287f73
commit 60c319faed
6 files changed
+44 -15

No files matched your search

@@ -0,0 +1,6 @@
Enhancement: Add autoprovision accounts flag
Added a new `PROXY_AUTOPROVISION_ACCOUNTS` environment variable. When enabled, the proxy will try to create a new account when it cannot match the username or email from the oidc userinfo to an existing user. Enable it to learn users from an external identity provider. Defaults to false.
https://github.com/owncloud/product/issues/219
https://github.com/owncloud/ocis/issues/629
+1
View File
@@ -265,6 +265,7 @@ func loadMiddlewares(ctx context.Context, l log.Logger, cfg *config.Config) alic
middleware.TokenManagerConfig(cfg.TokenManager), middleware.TokenManagerConfig(cfg.TokenManager),
middleware.AccountsClient(accounts), middleware.AccountsClient(accounts),
middleware.SettingsRoleService(roles), middleware.SettingsRoleService(roles),
middleware.AutoprovisionAccounts(cfg.AutoprovisionAccounts),
) )
// the connection will be established in a non blocking fashion // the connection will be established in a non blocking fashion
+14 -13
View File
@@ -85,19 +85,20 @@ type Reva struct {
// Config combines all available configuration parts. // Config combines all available configuration parts.
type Config struct { type Config struct {
File string File string
Log Log Log Log
Debug Debug Debug Debug
HTTP HTTP HTTP HTTP
Service Service Service Service
Tracing Tracing Tracing Tracing
Asset Asset Asset Asset
Policies []Policy Policies []Policy
OIDC OIDC OIDC OIDC
TokenManager TokenManager TokenManager TokenManager
PolicySelector *PolicySelector `mapstructure:"policy_selector"` PolicySelector *PolicySelector `mapstructure:"policy_selector"`
Reva Reva Reva Reva
PreSignedURL PreSignedURL PreSignedURL PreSignedURL
AutoprovisionAccounts bool
} }
// OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request
+11
View File
@@ -202,6 +202,17 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"PROXY_OIDC_INSECURE"}, EnvVars: []string{"PROXY_OIDC_INSECURE"},
Destination: &cfg.OIDC.Insecure, Destination: &cfg.OIDC.Insecure,
}, },
&cli.BoolFlag{
Name: "autoprovision-accounts",
Value: false,
Usage: "create accounts from OIDC access tokens to learn new users",
EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"},
Destination: &cfg.AutoprovisionAccounts,
},
// Presigned URLs
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "presignedurl-allow-method", Name: "presignedurl-allow-method",
Value: cli.NewStringSlice("GET"), Value: cli.NewStringSlice("GET"),
+1 -1
View File
@@ -104,7 +104,7 @@ func AccountUUID(opts ...Option) func(next http.Handler) http.Handler {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
} }
if status != 0 || account == nil { if status != 0 || account == nil {
if status == http.StatusNotFound { if opt.AutoprovisionAccounts && status == http.StatusNotFound {
account, status = createAccount(l, claims, opt.AccountsClient) account, status = createAccount(l, claims, opt.AccountsClient)
if status != 0 { if status != 0 {
w.WriteHeader(status) w.WriteHeader(status)
+11 -1
View File
@@ -1,9 +1,10 @@
package middleware package middleware
import ( import (
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
"net/http" "net/http"
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
acc "github.com/owncloud/ocis/accounts/pkg/proto/v0" acc "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/log"
@@ -36,6 +37,8 @@ type Options struct {
Store storepb.StoreService Store storepb.StoreService
// PreSignedURLConfig to configure the middleware // PreSignedURLConfig to configure the middleware
PreSignedURLConfig config.PreSignedURL PreSignedURLConfig config.PreSignedURL
// AutoprovisionAccounts when an account does not exist.
AutoprovisionAccounts bool
} }
// newOptions initializes the available default options. // newOptions initializes the available default options.
@@ -118,3 +121,10 @@ func PreSignedURLConfig(cfg config.PreSignedURL) Option {
o.PreSignedURLConfig = cfg o.PreSignedURLConfig = cfg
} }
} }
// AutoprovisionAccounts provides a function to set the AutoprovisionAccounts config
func AutoprovisionAccounts(val bool) Option {
return func(o *Options) {
o.AutoprovisionAccounts = val
}
}