Skip to content

fix(apps): give the account api key only to workers that call resources - #628

Draft
justinwlin wants to merge 1 commit into
mainfrom
fix/scope-worker-api-key
Draft

justinwlin wants to merge 1 commit into
mainfrom
fix/scope-worker-api-key

Conversation

@justinwlin

Copy link
Copy Markdown
Contributor

rp flash deploy and rp flash dev copy the account API key into every endpoint's template env. Workers that never call another resource still hold full account credentials, and so does anyone who can read the template. runpod-flash injected the key only for endpoints that make remote calls.

Change

New runpod/apps/remote_calls.py. For each resource it parses the module source, walks the resource body (skipping decorators, so @runpod.post doesn't count) and the module-level helpers it reaches. It gives the key when that code:

  • references another resource, or calls .remote / .spawn
  • uses anything imported from runpod (for example runpod.Queue(...))
  • uses a project-local import it can't follow

Unreadable source and nested definitions also get the key. Every uncertain case gives the key, so a worker that needs it never goes without. Deploy and dev payloads both use the analysis. Redeploying rewrites the template env, which drops a key left by an earlier deploy.

Verification
  • Live deploy of a leaf queue plus a caller queue that runs leaf.remote(). The templates showed caller with RUNPOD_API_KEY and leaf without it. Calling caller returned {'has_key': True, 'nested': {'has_key': False, 'x': 42}}, so the nested call still works. The app was deleted afterward.
  • Unit tests classify a direct call, a call through a helper, a runpod.Queue client, an API class with only decorators, a local import, and a nested definition. They also check the deploy and dev payload env. pytest tests: 1484 passed, coverage 91.61%.

Deploy and dev copied the client's account API key into every
endpoint's template env, so any endpoint's workers (and anyone who
can read its template) held full account credentials, including
endpoints that never call another resource. runpod-flash injected the
key only for endpoints whose functions make remote calls.

Analyze each resource's module source: the resource body (not its
decorators) and the module-level helpers it reaches. The key is added
when that code references another resource, calls .remote or .spawn,
uses anything imported from runpod, or uses a project-local import the
analysis cannot follow. Unreadable source and nested definitions also
get the key, so a worker that needs it never goes without.

This branch has not been deployed

No deployments
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.

1 participant