From: Peter Amstutz Date: Wed, 12 Aug 2020 20:10:32 +0000 (-0400) Subject: 16683: Set and check ForwardedFor on federated list requests X-Git-Tag: 2.1.0~139^2~6 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/de89bbf6824a39990e1605e4bd041b5d1ed464ea 16683: Set and check ForwardedFor on federated list requests Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- diff --git a/lib/controller/federation/generated.go b/lib/controller/federation/generated.go index 20edd90b95..8745f3b973 100755 --- a/lib/controller/federation/generated.go +++ b/lib/controller/federation/generated.go @@ -23,6 +23,7 @@ func (conn *Conn) generated_ContainerList(ctx context.Context, options arvados.L var needSort atomic.Value needSort.Store(false) err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) { + options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor cl, err := backend.ContainerList(ctx, options) if err != nil { return nil, err @@ -63,6 +64,7 @@ func (conn *Conn) generated_SpecimenList(ctx context.Context, options arvados.Li var needSort atomic.Value needSort.Store(false) err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) { + options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor cl, err := backend.SpecimenList(ctx, options) if err != nil { return nil, err @@ -103,6 +105,7 @@ func (conn *Conn) generated_UserList(ctx context.Context, options arvados.ListOp var needSort atomic.Value needSort.Store(false) err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) { + options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor cl, err := backend.UserList(ctx, options) if err != nil { return nil, err diff --git a/lib/controller/federation/list.go b/lib/controller/federation/list.go index 0a596eb9cb..bc6d3e00a4 100644 --- a/lib/controller/federation/list.go +++ b/lib/controller/federation/list.go @@ -27,6 +27,7 @@ func (conn *Conn) generated_CollectionList(ctx context.Context, options arvados. var needSort atomic.Value needSort.Store(false) err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) { + options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor cl, err := backend.CollectionList(ctx, options) if err != nil { return nil, err @@ -107,7 +108,7 @@ func (conn *Conn) generated_CollectionList(ctx context.Context, options arvados. // backend. func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions, fn func(context.Context, string, arvados.API, arvados.ListOptions) ([]string, error)) error { - if opts.BypassFederation { + if opts.BypassFederation || opts.ForwardedFor != "" { // Client requested no federation. Pass through. _, err := fn(ctx, conn.cluster.ClusterID, conn.local, opts) return err @@ -249,7 +250,7 @@ func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions done, err := fn(ctx, clusterID, backend, remoteOpts) if err != nil { - errs <- httpErrorf(http.StatusBadGateway, err.Error()) + errs <- httpErrorf(http.StatusBadGateway, "%s", err.Error()) return } progress := false diff --git a/sdk/go/arvados/api.go b/sdk/go/arvados/api.go index c32f88864f..4e7e74c8ac 100644 --- a/sdk/go/arvados/api.go +++ b/sdk/go/arvados/api.go @@ -86,6 +86,7 @@ type ListOptions struct { IncludeTrash bool `json:"include_trash"` IncludeOldVersions bool `json:"include_old_versions"` BypassFederation bool `json:"bypass_federation"` + ForwardedFor string `json:"forwarded_for,omitempty"` } type CreateOptions struct {