mirror of
https://github.com/owncloud/ocis.git
synced 2026-10-25 11:39:24 +03:00
* fix: the public share configuration and fixed graceful shutdown
* fix: [OCISDEV-1433] remove GRPC_MAX_CONNECTION_AGE
The setting closed healthy grpc connections on a timer so that clients would redo
their DNS lookup. It never helped against the failure it was reached for - a
connection whose peer stopped answering - because the age limit is enforced by
the server, the grace period was left at infinity so a request already in flight
was never ended, and any value without a unit suffix silently disabled it again.
Detecting a peer that stops answering is now the job of the grpc clients, which
ping the peer while a request is in flight. The servers here got the matching
enforcement policy so they accept those pings; the client side arrives with the
next reva bump.
* fix: Added the new variable OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION that disable the resolution of public link shares when answering PROPFIND requests.
* chore: bump reva
* fix: The keepalive added to grpc clinet
* chore: bump reva
* build(deps): bump go 1.26.8, grpc-go dependency
---------
(cherry picked from commit e86eb4d210)
For the 9.0 branch, the reva dependency was pointed at reva's main-branch
merge of PR #748 (commit 373f9509a, pseudo-version
v2.0.0-20261005091647-373f9509a363) instead of the 8.2-targeted
e0beaa380005, since the 8.2 merge predates the VaultMode/UploadSessionFilter.Orphaned
APIs already present on the 9.0 reva lineage.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts:
# changelog/unreleased/security-bump-grpc.md
# go.mod
# go.sum
# vendor/google.golang.org/grpc/server.go
# vendor/google.golang.org/grpc/stream.go
# vendor/google.golang.org/grpc/version.go
# vendor/modules.txt
161 lines
5.8 KiB
Go
161 lines
5.8 KiB
Go
package http
|
|
|
|
import (
|
|
"fmt"
|
|
stdhttp "net/http"
|
|
|
|
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
|
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
|
"github.com/owncloud/reva/v2/pkg/events/stream"
|
|
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
|
"github.com/pkg/errors"
|
|
"go-micro.dev/v4"
|
|
"go-micro.dev/v4/events"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/account"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/cors"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/generators"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/keycloak"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/service/http"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
|
ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0"
|
|
searchsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0"
|
|
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
|
graphMiddleware "github.com/owncloud/ocis/v2/services/graph/pkg/middleware"
|
|
svc "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
|
|
)
|
|
|
|
// Server initializes the http service and server.
|
|
func Server(opts ...Option) (http.Service, error) {
|
|
options := newOptions(opts...)
|
|
|
|
service, err := http.NewService(
|
|
http.TLSConfig(options.Config.HTTP.TLS),
|
|
http.Logger(options.Logger),
|
|
http.Namespace(options.Config.HTTP.Namespace),
|
|
http.Name(options.Config.Service.Name),
|
|
http.Version(version.GetString()),
|
|
http.Address(options.Config.HTTP.Addr),
|
|
http.Context(options.Context),
|
|
http.Flags(options.Flags...),
|
|
http.TraceProvider(options.TraceProvider),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Error().
|
|
Err(err).
|
|
Msg("Error initializing http service")
|
|
return http.Service{}, fmt.Errorf("could not initialize http service: %w", err)
|
|
}
|
|
|
|
var eventsStream events.Stream
|
|
|
|
if options.Config.Events.Endpoint != "" {
|
|
var err error
|
|
connName := generators.GenerateConnectionName(options.Config.Service.Name, generators.NTypeBus)
|
|
eventsStream, err = stream.NatsFromConfig(connName, false, stream.NatsConfig(options.Config.Events))
|
|
if err != nil {
|
|
options.Logger.Error().
|
|
Err(err).
|
|
Msg("Error initializing events publisher")
|
|
return http.Service{}, errors.Wrap(err, "could not initialize events publisher")
|
|
}
|
|
}
|
|
|
|
middlewares := []func(stdhttp.Handler) stdhttp.Handler{
|
|
middleware.GetOtelhttpMiddleware(options.Config.Service.Name, options.TraceProvider),
|
|
chimiddleware.RequestID,
|
|
middleware.Version(
|
|
options.Config.Service.Name,
|
|
version.GetString(),
|
|
),
|
|
middleware.Logger(
|
|
options.Logger,
|
|
),
|
|
middleware.Cors(
|
|
cors.Logger(options.Logger),
|
|
cors.AllowedOrigins(options.Config.HTTP.CORS.AllowedOrigins),
|
|
cors.AllowedMethods(options.Config.HTTP.CORS.AllowedMethods),
|
|
cors.AllowedHeaders(options.Config.HTTP.CORS.AllowedHeaders),
|
|
cors.AllowCredentials(options.Config.HTTP.CORS.AllowCredentials),
|
|
),
|
|
}
|
|
// how do we secure the api?
|
|
var requireAdminMiddleware func(stdhttp.Handler) stdhttp.Handler
|
|
var roleService svc.RoleService
|
|
var valueService settingssvc.ValueService
|
|
var gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
|
|
grpcClient, err := grpc.NewClient(append(grpc.GetClientOptions(options.Config.GRPCClientTLS), grpc.WithKeepaliveParams(options.Config.GRPCClientOptions), grpc.WithTraceProvider(options.TraceProvider))...)
|
|
if err != nil {
|
|
return http.Service{}, err
|
|
}
|
|
if options.Config.HTTP.APIToken == "" {
|
|
middlewares = append(middlewares,
|
|
graphMiddleware.Auth(
|
|
account.Logger(options.Logger),
|
|
account.JWTSecret(options.Config.TokenManager.JWTSecret),
|
|
))
|
|
roleService = settingssvc.NewRoleService("com.owncloud.api.settings", grpcClient)
|
|
valueService = settingssvc.NewValueService("com.owncloud.api.settings", grpcClient)
|
|
gatewaySelector, err = pool.GatewaySelector(
|
|
options.Config.Reva.Address,
|
|
append(
|
|
options.Config.Reva.GetRevaOptions(),
|
|
pool.WithRegistry(registry.GetRegistry()),
|
|
pool.WithTracerProvider(options.TraceProvider),
|
|
)...)
|
|
if err != nil {
|
|
return http.Service{}, errors.Wrap(err, "could not initialize gateway selector")
|
|
}
|
|
} else {
|
|
middlewares = append(middlewares, graphMiddleware.Token(options.Config.HTTP.APIToken))
|
|
// use a dummy admin middleware for the chi router
|
|
requireAdminMiddleware = func(next stdhttp.Handler) stdhttp.Handler {
|
|
return next
|
|
}
|
|
// no gateway client needed
|
|
}
|
|
|
|
// Keycloak client is optional, so if it stays nil, it's fine.
|
|
var keyCloakClient keycloak.Client
|
|
if options.Config.Keycloak.BasePath != "" {
|
|
kcc := options.Config.Keycloak
|
|
if kcc.ClientID == "" || kcc.ClientSecret == "" || kcc.ClientRealm == "" || kcc.UserRealm == "" {
|
|
return http.Service{}, errors.New("keycloak client id, secret, client realm and user realm must be set")
|
|
}
|
|
keyCloakClient = keycloak.New(kcc.BasePath, kcc.ClientID, kcc.ClientSecret, kcc.ClientRealm, kcc.InsecureSkipVerify)
|
|
}
|
|
|
|
hClient := ehsvc.NewEventHistoryService("com.owncloud.api.eventhistory", grpcClient)
|
|
|
|
var handle svc.Service
|
|
handle, err = svc.NewService(
|
|
svc.Context(options.Context),
|
|
svc.Logger(options.Logger),
|
|
svc.Config(options.Config),
|
|
svc.Middleware(middlewares...),
|
|
svc.EventsPublisher(eventsStream),
|
|
svc.EventsConsumer(eventsStream),
|
|
svc.WithRoleService(roleService),
|
|
svc.WithValueService(valueService),
|
|
svc.WithRequireAdminMiddleware(requireAdminMiddleware),
|
|
svc.WithGatewaySelector(gatewaySelector),
|
|
svc.WithSearchService(searchsvc.NewSearchProviderService("com.owncloud.api.search", grpcClient)),
|
|
svc.KeycloakClient(keyCloakClient),
|
|
svc.EventHistoryClient(hClient),
|
|
svc.TraceProvider(options.TraceProvider),
|
|
)
|
|
|
|
if err != nil {
|
|
return http.Service{}, errors.New("could not initialize graph service")
|
|
}
|
|
|
|
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
|
|
return http.Service{}, err
|
|
}
|
|
|
|
return service, nil
|
|
}
|