-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(cli,webapp): allow deploys with environment API keys #4561
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
base: main
Are you sure you want to change the base?
Changes from all commits
1360422
e441a06
6a8a129
e4e134a
fd8bf06
b84c228
bb55c9d
4a0506f
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "trigger.dev": patch | ||
| --- | ||
|
|
||
| Allow `trigger deploy` to authenticate with an environment API key from `TRIGGER_ACCESS_TOKEN`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,9 @@ import { | |
| } from "~/services/apiAuth.server"; | ||
| import { logger } from "~/services/logger.server"; | ||
| import { | ||
| authenticateEnvironmentScopedApiRequest, | ||
| apiKeyForProjectEnvironmentBootstrap, | ||
| authenticateEnvironmentBootstrapRequest, | ||
| authorizePatEnvironmentAccess, | ||
| presentedApiKeyFromAuthentication, | ||
| } from "~/services/environmentVariableApiAccess.server"; | ||
|
|
||
| const ParamsSchema = z.object({ | ||
|
|
@@ -30,9 +30,9 @@ export async function loader({ request, params }: LoaderFunctionArgs) { | |
| const { projectRef, env } = parsedParams.data; | ||
|
|
||
| try { | ||
| // PAT/OAT authenticate on the legacy path; machine API keys go through | ||
| // the RBAC controller so additional keys (and their grants) are enforced. | ||
| const authResult = await authenticateEnvironmentScopedApiRequest(request, "read", "apiKeys"); | ||
| // PAT/OAT authenticate on the legacy path; machine API keys only need to | ||
| // prove they are valid because bootstrap echoes the same key back. | ||
| const authResult = await authenticateEnvironmentBootstrapRequest(request); | ||
| if (!authResult.ok) { | ||
| return json({ error: authResult.error }, { status: authResult.status }); | ||
| } | ||
|
|
@@ -46,29 +46,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) { | |
| ); | ||
|
|
||
| // User tokens bootstrap the environment's secret key, so gate them on | ||
| // env-tier read:apiKeys. Machine credentials are checked against the same | ||
| // permission before their presented key is returned below. | ||
| const denied = await authorizePatEnvironmentAccess({ | ||
| request, | ||
| authType: authenticationResult.type, | ||
| ability: | ||
| authenticationResult.type === "apiKey" && authenticationResult.result.ok | ||
| ? authenticationResult.result.ability | ||
| : undefined, | ||
| organizationId: environment.organizationId, | ||
| projectId: environment.project.id, | ||
| envType: environment.type, | ||
| resource: "apiKeys", | ||
| action: "read", | ||
| }); | ||
| if (denied) return denied; | ||
|
|
||
| // API-key callers already possess a valid environment credential. Reuse | ||
| // exactly what they presented instead of exchanging it for the root key. | ||
| const presentedApiKey = presentedApiKeyFromAuthentication(authenticationResult); | ||
| // env-tier read:apiKeys. A machine credential never receives that root key. | ||
| if (authenticationResult.type !== "apiKey") { | ||
| const denied = await authorizePatEnvironmentAccess({ | ||
| request, | ||
| authType: authenticationResult.type, | ||
| organizationId: environment.organizationId, | ||
| projectId: environment.project.id, | ||
| envType: environment.type, | ||
| resource: "apiKeys", | ||
| action: "read", | ||
| }); | ||
| if (denied) return denied; | ||
| } | ||
|
Comment on lines
48
to
+61
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. 🔍 Bootstrap endpoint now accepts any valid environment key, including restricted ones The scope check was dropped for machine credentials: previously Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| const result: GetProjectEnvResponse = { | ||
| apiKey: presentedApiKey ?? environment.apiKey, | ||
| apiKey: apiKeyForProjectEnvironmentBootstrap(authenticationResult, environment.apiKey), | ||
| name: environment.project.name, | ||
| apiUrl: processEnv.API_ORIGIN ?? processEnv.APP_ORIGIN, | ||
| projectId: environment.project.id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.