first draft for configuring user agent multiplex on ocis

This commit is contained in:
A.Unger
2020-12-02 12:04:09 +01:00
parent 28e8f75ebd
commit 752cd4f626
6 changed files with 34 additions and 6 deletions
+4
View File
@@ -21,6 +21,10 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
scfg := configureStorageFrontend(cfg) scfg := configureStorageFrontend(cfg)
if err := command.Frontend(scfg).Before(c); err != nil {
return err
}
return cli.HandleAction( return cli.HandleAction(
command.Frontend(scfg).Action, command.Frontend(scfg).Action,
c, c,
-1
View File
@@ -64,7 +64,6 @@ func Authentication(opts ...Option) func(next http.Handler) http.Handler {
if options.OIDCIss == "" && options.EnableBasicAuth { if options.OIDCIss == "" && options.EnableBasicAuth {
basic(next).ServeHTTP(w, r) basic(next).ServeHTTP(w, r)
} }
}) })
} }
} }
-2
View File
@@ -61,8 +61,6 @@ func BasicAuth(optionSetters ...Option) func(next http.Handler) http.Handler {
Iss: oidcIss, Iss: oidcIss,
} }
fmt.Printf("\n\nHGAHAHAHA\n\n")
next.ServeHTTP(w, req.WithContext(oidc.NewContext(req.Context(), claims))) next.ServeHTTP(w, req.WithContext(oidc.NewContext(req.Context(), claims)))
}, },
) )
+13 -3
View File
@@ -6,6 +6,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"strings"
"time" "time"
"github.com/cs3org/reva/cmd/revad/runtime" "github.com/cs3org/reva/cmd/revad/runtime"
@@ -26,6 +27,17 @@ func Frontend(cfg *config.Config) *cli.Command {
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {
cfg.Reva.Frontend.Services = c.StringSlice("service") cfg.Reva.Frontend.Services = c.StringSlice("service")
cfg.Reva.Frontend.Middleware.Auth.CredentialsByUserAgent = make(map[string]string, 0)
uaw := c.StringSlice("user-agent-whitelist")
for _, v := range uaw {
parts := strings.Split(v, ":")
if len(parts) != 2 {
return fmt.Errorf("unexpected config value for user-agent whitelist: %v, expected format is user-agent:challenge", v) // TODO wording + error wrapping?
}
cfg.Reva.Frontend.Middleware.Auth.CredentialsByUserAgent[parts[0]] = parts[1]
}
return nil return nil
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
@@ -116,9 +128,7 @@ func Frontend(cfg *config.Config) *cli.Command {
"allow_credentials": true, "allow_credentials": true,
}, },
"auth": map[string]interface{}{ "auth": map[string]interface{}{
"credentials_by_user_agent": map[string]string{ "credentials_by_user_agent": cfg.Reva.Frontend.Middleware.Auth.CredentialsByUserAgent,
"mirall": "basic",
},
}, },
}, },
// TODO build services dynamically // TODO build services dynamically
+9
View File
@@ -83,6 +83,15 @@ type FrontendPort struct {
OCDavPrefix string OCDavPrefix string
OCSPrefix string OCSPrefix string
PublicURL string PublicURL string
Middleware Middleware
}
type Middleware struct {
Auth Auth
}
type Auth struct {
CredentialsByUserAgent map[string]string
} }
// DataGatewayPort has a public url // DataGatewayPort has a public url
+8
View File
@@ -133,6 +133,14 @@ func FrontendWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_HTTP_METHOD_OVERRIDE"}, EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_HTTP_METHOD_OVERRIDE"},
Destination: &cfg.Reva.UploadHTTPMethodOverride, Destination: &cfg.Reva.UploadHTTPMethodOverride,
}, },
// Middlewares
&cli.StringSliceFlag{
Name: "user-agent-whitelist", // TODO naming?
Value: cli.NewStringSlice("test"),
Usage: "TODO",
EnvVars: []string{"STORAGE_FRONTEND_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"},
},
} }
flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, TracingWithConfig(cfg)...)