-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add webapi v2 endpoints for creating discovery token and enrolling eks with labels #50472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -446,8 +446,6 @@ func (h *APIHandler) Close() error { | |
|
|
||
| // NewHandler returns a new instance of web proxy handler | ||
| func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) { | ||
| const apiPrefix = "/" + teleport.WebAPIVersion | ||
|
|
||
| cfg.SetDefaults() | ||
|
|
||
| h := &Handler{ | ||
|
|
@@ -612,13 +610,31 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) { | |
| h.nodeWatcher = cfg.NodeWatcher | ||
| } | ||
|
|
||
| routingHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // ensure security headers are set for all responses | ||
| httplib.SetDefaultSecurityHeaders(w.Header()) | ||
|
|
||
| // request is going to the API? | ||
| if strings.HasPrefix(r.URL.Path, apiPrefix) { | ||
| http.StripPrefix(apiPrefix, h).ServeHTTP(w, r) | ||
| const v1Prefix = "/v1" | ||
| notFoundRoutingHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // Request is going to the API? | ||
| // If no routes were matched, it could be because it's a path with `v1` prefix | ||
| // (eg: the Teleport web app will call "most" endpoints with v1 prefixed). | ||
| // | ||
| // `v1` paths are not defined with `v1` prefix. If the path turns out to be prefixed | ||
| // with `v1`, it will be stripped and served again. Historically, that's how it started | ||
| // and should be kept that way to prevent breakage. | ||
| // | ||
| // v2+ prefixes will be expected by both caller and definition and will not be stripped. | ||
| if strings.HasPrefix(r.URL.Path, v1Prefix) { | ||
| pathParts := strings.Split(r.URL.Path, "/") | ||
| if len(pathParts) > 2 { | ||
| // check against known second part of path to ensure we | ||
| // aren't allowing paths like /v1/v2/webapi | ||
| // part[0] is empty space from leading slash "/" | ||
| // part[1] is the prefix "v1" | ||
| switch pathParts[2] { | ||
| case "webapi", "enterprise", "scripts", ".well-known", "workload-identity": | ||
| http.StripPrefix(v1Prefix, h).ServeHTTP(w, r) | ||
| return | ||
| } | ||
| } | ||
| httplib.RouteNotFoundResponse(r.Context(), w, teleport.Version) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -670,11 +686,12 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) { | |
| h.logger.ErrorContext(r.Context(), "Failed to execute index page template", "error", err) | ||
| } | ||
| } else { | ||
| http.NotFound(w, r) | ||
| httplib.RouteNotFoundResponse(r.Context(), w, teleport.Version) | ||
| return | ||
| } | ||
| }) | ||
|
|
||
| h.NotFound = routingHandler | ||
| h.NotFound = notFoundRoutingHandler | ||
|
|
||
| if cfg.PluginRegistry != nil { | ||
| if err := cfg.PluginRegistry.RegisterProxyWebHandlers(h); err != nil { | ||
|
|
@@ -867,8 +884,12 @@ func (h *Handler) bindDefaultEndpoints() { | |
| h.POST("/webapi/tokens", h.WithAuth(h.upsertTokenHandle)) | ||
| // used for updating a token | ||
| h.PUT("/webapi/tokens", h.WithAuth(h.upsertTokenHandle)) | ||
| // used for creating tokens used during guided discover flows | ||
| // TODO(kimlisa): DELETE IN 19.0 - Replaced by /v2/webapi/token endpoint | ||
| // MUST delete with related code found in web/packages/teleport/src/services/joinToken/joinToken.ts(fetchJoinToken) | ||
| h.POST("/webapi/token", h.WithAuth(h.createTokenForDiscoveryHandle)) | ||
| // used for creating tokens used during guided discover flows | ||
| // v2 endpoint processes "suggestedLabels" field | ||
| h.POST("/v2/webapi/token", h.WithAuth(h.createTokenForDiscoveryHandle)) | ||
| h.GET("/webapi/tokens", h.WithAuth(h.getTokens)) | ||
| h.DELETE("/webapi/tokens", h.WithAuth(h.deleteToken)) | ||
|
|
||
|
|
@@ -1000,7 +1021,11 @@ func (h *Handler) bindDefaultEndpoints() { | |
| h.GET("/webapi/scripts/integrations/configure/deployservice-iam.sh", h.WithLimiter(h.awsOIDCConfigureDeployServiceIAM)) | ||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/ec2", h.WithClusterAuth(h.awsOIDCListEC2)) | ||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/eksclusters", h.WithClusterAuth(h.awsOIDCListEKSClusters)) | ||
| // TODO(kimlisa): DELETE IN 19.0 - replaced by /v2/webapi/sites/:site/integrations/aws-oidc/:name/enrolleksclusters | ||
| // MUST delete with related code found in web/packages/teleport/src/services/integrations/integrations.ts(enrollEksClusters) | ||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/enrolleksclusters", h.WithClusterAuth(h.awsOIDCEnrollEKSClusters)) | ||
| // v2 endpoint introduces "extraLabels" field. | ||
| h.POST("/v2/webapi/sites/:site/integrations/aws-oidc/:name/enrolleksclusters", h.WithClusterAuth(h.awsOIDCEnrollEKSClusters)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: from endpoint organization perspective - Instead of mixing I do not have a strong preference either way but feel like separation will make it more cleaner as number of v2 grows.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll leave it as is, b/c we tend to group similar endpoints together and i think the binding method will separate them
flyinghermit marked this conversation as resolved.
|
||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/ec2ice", h.WithClusterAuth(h.awsOIDCListEC2ICE)) | ||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/deployec2ice", h.WithClusterAuth(h.awsOIDCDeployEC2ICE)) | ||
| h.POST("/webapi/sites/:site/integrations/aws-oidc/:name/securitygroups", h.WithClusterAuth(h.awsOIDCListSecurityGroups)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,10 +29,14 @@ import ( | |
| ) | ||
|
|
||
| // NewDebugFileSystem returns the HTTP file system implementation | ||
| func newDebugFileSystem() (http.FileSystem, error) { | ||
| func NewDebugFileSystem(isEnterprise bool) (http.FileSystem, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it need to be exported?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i forgot to push the branch that required this change in enterprise: https://github.com/gravitational/teleport.e/pull/5818, i added a enterprise not found handler test there (just in case...) |
||
| // If the location of the UI changes on disk then this will need to be updated. | ||
| assetsPath := "../../webassets/teleport" | ||
|
|
||
| if isEnterprise { | ||
| assetsPath = "../../../webassets/teleport" | ||
| } | ||
|
|
||
| // Ensure we have the built assets available before continuing. | ||
| for _, af := range []string{"index.html", "/app"} { | ||
| _, err := os.Stat(filepath.Join(assetsPath, af)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.