21585: Updates installer's Terraform code to require IMDSv2 on service nodes.
[arvados.git] / lib / controller / router / router.go
index f2d1e1f0a7bcd7284f304832d9b219701fc0760d..d39f493a956b21d66b38182addb36f9462d57736 100644 (file)
@@ -86,6 +86,41 @@ func (rtr *router) addRoutes() {
                                return rtr.backend.Logout(ctx, *opts.(*arvados.LogoutOptions))
                        },
                },
+               {
+                       arvados.EndpointAuthorizedKeyCreate,
+                       func() interface{} { return &arvados.CreateOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.AuthorizedKeyCreate(ctx, *opts.(*arvados.CreateOptions))
+                       },
+               },
+               {
+                       arvados.EndpointAuthorizedKeyUpdate,
+                       func() interface{} { return &arvados.UpdateOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.AuthorizedKeyUpdate(ctx, *opts.(*arvados.UpdateOptions))
+                       },
+               },
+               {
+                       arvados.EndpointAuthorizedKeyGet,
+                       func() interface{} { return &arvados.GetOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.AuthorizedKeyGet(ctx, *opts.(*arvados.GetOptions))
+                       },
+               },
+               {
+                       arvados.EndpointAuthorizedKeyList,
+                       func() interface{} { return &arvados.ListOptions{Limit: -1} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.AuthorizedKeyList(ctx, *opts.(*arvados.ListOptions))
+                       },
+               },
+               {
+                       arvados.EndpointAuthorizedKeyDelete,
+                       func() interface{} { return &arvados.DeleteOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.AuthorizedKeyDelete(ctx, *opts.(*arvados.DeleteOptions))
+                       },
+               },
                {
                        arvados.EndpointCollectionCreate,
                        func() interface{} { return &arvados.CreateOptions{} },
@@ -210,14 +245,14 @@ func (rtr *router) addRoutes() {
                        },
                },
                {
-                       arvados.EndpointContainerLog,
-                       func() interface{} { return &arvados.ContainerLogOptions{} },
+                       arvados.EndpointContainerSSH,
+                       func() interface{} { return &arvados.ContainerSSHOptions{} },
                        func(ctx context.Context, opts interface{}) (interface{}, error) {
-                               return rtr.backend.ContainerLog(ctx, *opts.(*arvados.ContainerLogOptions))
+                               return rtr.backend.ContainerSSH(ctx, *opts.(*arvados.ContainerSSHOptions))
                        },
                },
                {
-                       arvados.EndpointContainerSSH,
+                       arvados.EndpointContainerSSHCompat,
                        func() interface{} { return &arvados.ContainerSSHOptions{} },
                        func(ctx context.Context, opts interface{}) (interface{}, error) {
                                return rtr.backend.ContainerSSH(ctx, *opts.(*arvados.ContainerSSHOptions))
@@ -241,6 +276,13 @@ func (rtr *router) addRoutes() {
                                return rtr.backend.ContainerGatewayTunnel(ctx, *opts.(*arvados.ContainerGatewayTunnelOptions))
                        },
                },
+               {
+                       arvados.EndpointContainerGatewayTunnelCompat,
+                       func() interface{} { return &arvados.ContainerGatewayTunnelOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.ContainerGatewayTunnel(ctx, *opts.(*arvados.ContainerGatewayTunnelOptions))
+                       },
+               },
                {
                        arvados.EndpointContainerRequestCreate,
                        func() interface{} { return &arvados.CreateOptions{} },
@@ -276,6 +318,13 @@ func (rtr *router) addRoutes() {
                                return rtr.backend.ContainerRequestDelete(ctx, *opts.(*arvados.DeleteOptions))
                        },
                },
+               {
+                       arvados.EndpointContainerRequestLog,
+                       func() interface{} { return &arvados.ContainerLogOptions{} },
+                       func(ctx context.Context, opts interface{}) (interface{}, error) {
+                               return rtr.backend.ContainerRequestLog(ctx, *opts.(*arvados.ContainerLogOptions))
+                       },
+               },
                {
                        arvados.EndpointGroupCreate,
                        func() interface{} { return &arvados.CreateOptions{} },
@@ -623,7 +672,7 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int
        if alt, ok := altMethod[endpoint.Method]; ok {
                methods = append(methods, alt)
        }
-       if strings.HasPrefix(endpoint.Path, strings.TrimSuffix(arvados.EndpointContainerLog.Path, "/{path:.*}")) {
+       if strings.HasSuffix(endpoint.Path, ".*}") {
                // webdav methods
                methods = append(methods, "OPTIONS", "PROPFIND")
        }
@@ -662,11 +711,8 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int
                }
                ctx := auth.NewContext(req.Context(), creds)
                ctx = arvados.ContextWithRequestID(ctx, req.Header.Get("X-Request-Id"))
-               logger.WithFields(logrus.Fields{
-                       "apiEndpoint": endpoint,
-                       "apiOptsType": fmt.Sprintf("%T", opts),
-                       "apiOpts":     opts,
-               }).Debug("exec")
+               req = req.WithContext(ctx)
+
                // Extract the token UUIDs (or a placeholder for v1 tokens)
                var tokenUUIDs []string
                for _, t := range creds.Tokens {
@@ -683,7 +729,13 @@ func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() int
                                tokenUUIDs = append(tokenUUIDs, "v1 token ending in "+end)
                        }
                }
-               httpserver.SetResponseLogFields(req.Context(), logrus.Fields{"tokenUUIDs": tokenUUIDs})
+               httpserver.SetResponseLogFields(ctx, logrus.Fields{"tokenUUIDs": tokenUUIDs})
+
+               logger.WithFields(logrus.Fields{
+                       "apiEndpoint": endpoint,
+                       "apiOptsType": fmt.Sprintf("%T", opts),
+                       "apiOpts":     opts,
+               }).Debug("exec")
                resp, err := exec(ctx, opts)
                if err != nil {
                        logger.WithError(err).Debugf("returning error type %T", err)