Skip to content

Add support for JSON format to '/webapi/auth/export' endpoint#50193

Merged
fheinecke merged 3 commits intomasterfrom
fred/webapi-support-accept-header-1
Feb 19, 2025
Merged

Add support for JSON format to '/webapi/auth/export' endpoint#50193
fheinecke merged 3 commits intomasterfrom
fred/webapi-support-accept-header-1

Conversation

@fheinecke
Copy link
Copy Markdown
Contributor

@fheinecke fheinecke commented Dec 13, 2024

This adds support for JSON-encoding responses from the /webapi/auth/export and /webapi/sites/:site/auth/export endpoints. Clients can set format=json, similarly to format=zip, to get a JSON-encoded version of the requested CA public certs.

My use case for this is pulling the Teleport Database Access client CA public cert into a k8s cluster via Kyverno. Kyverno only supports HTTP endpoints that return a properly-formatted JSON response.

This endpoint was originally added to make Teleport setup easier. The PR is intended to extend this.

changelog: Added JSON response support to the /webapi/auth/export public certificate API endpoint.

Comment thread lib/web/apiserver.go Outdated
Copy link
Copy Markdown
Contributor

@kopiczko kopiczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but the Marshal error should be handled properly as @marcoandredinis noted

Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver_test.go Outdated
@fheinecke fheinecke requested a review from zmb3 December 13, 2024 21:52
@fheinecke fheinecke force-pushed the fred/webapi-support-accept-header-1 branch from 5625ec3 to 18029ae Compare December 13, 2024 23:45
Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver.go Outdated
Comment thread lib/web/apiserver.go Outdated
mimeTypes = append(mimeTypes, "text/plain")

// Ignore duplicate MIME types
mimeTypes = slices.Compact(mimeTypes)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to apply slices.Sort first. slices.Compact only "replaces consecutive runs of equal elements with a single copy"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use utils.Deduplicate here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use utils.Deduplicate - order needs to be preserved, as this should pick the first valid MIME type

Comment thread lib/web/apiserver_test.go Outdated
Comment thread lib/web/apiserver.go Outdated
@fheinecke fheinecke requested a review from zmb3 December 17, 2024 17:59
Signed-off-by: Fred Heinecke <fred.heinecke@goteleport.com>
@fheinecke fheinecke force-pushed the fred/webapi-support-accept-header-1 branch from b1d3c93 to cf13052 Compare February 19, 2025 20:08
@fheinecke fheinecke changed the title Add support for HTTP 'Accept' header to '/webapi/auth/export' endpoint Add support for JSON format to '/webapi/auth/export' endpoint Feb 19, 2025
Comment thread lib/web/ca_export.go
@fheinecke fheinecke added this pull request to the merge queue Feb 19, 2025
Merged via the queue into master with commit e361511 Feb 19, 2025
@fheinecke fheinecke deleted the fred/webapi-support-accept-header-1 branch February 19, 2025 22:02
@public-teleport-github-review-bot
Copy link
Copy Markdown

@fheinecke See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants