Skip to content
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

cta: narrow down docker API #209

Merged
merged 3 commits into from
Sep 6, 2023
Merged

cta: narrow down docker API #209

merged 3 commits into from
Sep 6, 2023

Conversation

royra
Copy link
Collaborator

@royra royra commented Aug 30, 2023

replace generic docker API proxy with specific endpoints

@royra royra requested a review from Yshayy August 30, 2023 09:00
docker: Dockerode
}) => {
const handler = tryHandler({ log }, async (req, res) => {
const { pathname: path } = url.parse(req.url || '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to take more careful look, but I think that since this api is know behaving very similar to a regular rest-api, it might worth using express/fastify or other package to reduce the noise and high-level implementations of routing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

converted to fastify

const handler = tryHandler({ log }, async (req, res) => {
const { pathname: path } = url.parse(req.url || '')

if (req.method === 'GET' && path === '/healthz') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not specifically for this PR, but teed to add support for CORS, so these apis can be fetched also from client.
@eliyabar currently add it locally for testing

Copy link
Contributor

Choose a reason for hiding this comment

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

CORS can work without the cookie and only by using Authorization header, so no need for access-control-allow-credentials. (Apparently WS doesn't respect CORS anyhow)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

if (!await dockerFilter.inspectContainer(containerId)) {
throw new NotFoundError()
}
const { obj: { tty: ttyQueryParam }, search } = parseQueryParams(req.url ?? '', { tty: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

It might worth splitting it to two ops in the future:
One for creating the exec/logs handler (return handle url), the other for reading in websocket based on the handle.
The handle can up-for-grabs and available in a limited time window. (can be saved even in CTA memory, or localfs)

It can be a bit safer as POST requests can work with authorization header and CORS.

@@ -70,6 +72,10 @@ export const addComposeTunnelAgentService = (
machineStatusCommand?: MachineStatusCommand
envMetadata: EnvMetadata
composeModelPath: string
composeProject: string
profileThumbprint?: string
privateMode: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

The privateMode can be derived from the defaultAccess paramter (or the opposite), it's a label with product semantics, while defaultAccess is a CTA env var, but they are basically the same. (The label is currently only read by the Docker extension AFAIK)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can the privateMode be read from the /env-metadata endpoint instead of the label?

Roy Razon added 3 commits September 5, 2023 11:19
replace generic docker API proxy with specific endpoints
@royra royra force-pushed the cta-narrow-docker-api branch from d58bd24 to e7a2fb1 Compare September 6, 2023 10:32
Comment on lines +26 to +31
app.get('/compose-model', async ({ log }, res) => {
log.debug('compose-model handler')
void res
.header('Content-Type', 'application/x-yaml')
.send(await fs.promises.readFile(composeModelPath, { encoding: 'utf-8' }))
})

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [a file system access](1), but is not rate-limited.
@royra royra merged commit fcd6601 into main Sep 6, 2023
@royra royra deleted the cta-narrow-docker-api branch September 6, 2023 10:39
@royra royra mentioned this pull request Sep 6, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants