16683: Set and check ForwardedFor on federated list requests
authorPeter Amstutz <peter.amstutz@curii.com>
Wed, 12 Aug 2020 20:10:32 +0000 (16:10 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Thu, 13 Aug 2020 17:42:19 +0000 (13:42 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

lib/controller/federation/generated.go
lib/controller/federation/list.go
sdk/go/arvados/api.go

index 20edd90b95dad70791b21cf4f19bfce6b496bff4..8745f3b9730b068faa2cc9e8a02d4c5638c7164a 100755 (executable)
@@ -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
index 0a596eb9cb6ac6aac690dc19a2e43ca3dc723340..bc6d3e00a493361b4d9897aeab77e3abf5cced27 100644 (file)
@@ -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
index c32f88864f88750c00fe896286e147ccd9d061ce..4e7e74c8ac22ba27c621d8b66097e9db820ddc13 100644 (file)
@@ -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 {