* feat: Implemet the vault-storage feat: Separate the storage-users and graph to handle feat: move the space create cache configurate the vault srorage Postprocessing hide the assignment of the MountID to VaultStorageProviderID behind a flag to avoid the ID mismatch configurate the proxy to create the vault home space update the filter Make the graph able to handle vault prefix. no extra service needed apply the vault filter to sharedbyme and sharedwithme added vault-storage docker use squashed reva fix the finishUpload event restict webdav copy/move from the vault feat: provide the mfa to webdav and grpc feat: refactoring: provide the mfa to webdav and grpc mfa collaboration fix GetRootDriveChildren and more fix: send the MFA header in HTTP clients from the collaboration service provide the default storage user vault configuration update create_home middleware Update deployments/examples/ocis_full/vault-storage.yml Co-authored-by: Martin <github@diemattels.at> Update services/gateway/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/graph/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/graph/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/storage-users/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/proxy/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update services/storage-users/pkg/config/config.go Co-authored-by: Martin <github@diemattels.at> Update deployments/examples/ocis_full/vault-storage.yml Co-authored-by: Martin <github@diemattels.at> bump reva deduplicate the requireMFA middeware on vault routes. fix AppendPlainToOpaque. added the changlog and comments * feat: add the vault mode search * Update changelog/unreleased/enhancement-vault-storage.md Co-authored-by: Martin <github@diemattels.at> * update the readme. the reva vault storage provider configuration disabled by default * feat: [OCISDEV-531] add vault capabilities to the OCS capabilities endpoint * the port range allocated. the configuration updated. --------- Co-authored-by: Martin <github@diemattels.at>
104 lines
3.5 KiB
Go
104 lines
3.5 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
gmmetadata "go-micro.dev/v4/metadata"
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/account"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/mfa"
|
|
opkgm "github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
|
"github.com/owncloud/ocis/v2/services/graph/pkg/errorcode"
|
|
"github.com/owncloud/reva/v2/pkg/auth/scope"
|
|
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
|
|
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
|
"github.com/owncloud/reva/v2/pkg/token/manager/jwt"
|
|
)
|
|
|
|
// authOptions initializes the available default options.
|
|
func authOptions(opts ...account.Option) account.Options {
|
|
opt := account.Options{}
|
|
|
|
for _, o := range opts {
|
|
o(&opt)
|
|
}
|
|
|
|
return opt
|
|
}
|
|
|
|
// Auth provides a middleware to authenticate requests using the x-access-token header value
|
|
// and write it to the context. If there is no x-access-token the middleware prevents access and renders a json document.
|
|
func Auth(opts ...account.Option) func(http.Handler) http.Handler {
|
|
// Note: This largely duplicates what ocis-pkg/middleware/account.go already does (apart from a slightly different error
|
|
// handling). Ideally we should merge both middlewares.
|
|
opt := authOptions(opts...)
|
|
tokenManager, err := jwt.New(map[string]interface{}{
|
|
"secret": opt.JWTSecret,
|
|
"expires": int64(24 * 60 * 60),
|
|
})
|
|
if err != nil {
|
|
opt.Logger.Fatal().Err(err).Msgf("Could not initialize token-manager")
|
|
}
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r = mfa.EnhanceRequest(r)
|
|
|
|
ctx := r.Context()
|
|
t := r.Header.Get("x-access-token")
|
|
if t == "" {
|
|
errorcode.InvalidAuthenticationToken.Render(w, r, http.StatusUnauthorized, "Access token is empty.")
|
|
/* msgraph error for GET https://graph.microsoft.com/v1.0/me
|
|
{
|
|
"error":
|
|
{
|
|
"code":"InvalidAuthenticationToken",
|
|
"message":"Access token is empty.",
|
|
"innerError":{
|
|
"date":"2021-07-09T14:40:51",
|
|
"request-id":"bb12f7db-b4c4-43a9-ba4b-31676aeed019",
|
|
"client-request-id":"bb12f7db-b4c4-43a9-ba4b-31676aeed019"
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
return
|
|
}
|
|
|
|
u, tokenScope, err := tokenManager.DismantleToken(r.Context(), t)
|
|
if err != nil {
|
|
errorcode.InvalidAuthenticationToken.Render(w, r, http.StatusUnauthorized, "invalid token")
|
|
return
|
|
}
|
|
if ok, err := scope.VerifyScope(ctx, tokenScope, r); err != nil || !ok {
|
|
opt.Logger.Error().Str(log.RequestIDString, r.Header.Get("X-Request-ID")).Err(err).Msg("verifying scope failed")
|
|
errorcode.InvalidAuthenticationToken.Render(w, r, http.StatusUnauthorized, "verifying scope failed")
|
|
return
|
|
}
|
|
|
|
ctx = revactx.ContextSetToken(ctx, t)
|
|
ctx = revactx.ContextSetUser(ctx, u)
|
|
ctx = gmmetadata.Set(ctx, opkgm.AccountID, u.GetId().GetOpaqueId())
|
|
if m := u.GetOpaque().GetMap(); m != nil {
|
|
if roles, ok := m["roles"]; ok {
|
|
ctx = gmmetadata.Set(ctx, opkgm.RoleIDs, string(roles.GetValue()))
|
|
}
|
|
}
|
|
ctx = metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
|
|
|
|
initiatorID := r.Header.Get(ctxpkg.InitiatorHeader)
|
|
if initiatorID != "" {
|
|
ctx = ctxpkg.ContextSetInitiator(ctx, initiatorID)
|
|
ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.InitiatorHeader, initiatorID)
|
|
}
|
|
|
|
// Propagate MFA status to outgoing gRPC metadata so that services protected
|
|
// by the mfa interceptor (e.g. storage-users-vault) can enforce MFA at the gRPC layer.
|
|
ctx = ctxpkg.AppendMFAToOutgoingContext(ctx, mfa.Has(ctx))
|
|
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|
|
}
|