authentication.md
238 lines · skills/dnanexus-integration/references/authentication.md at 5f2bc03
Authentication and Context
Raw lines 1 to 2Principles
DNAnexus bearer tokens act as the creating user within the token's scope. They can launch billable jobs where both user and token permissions allow it. Treat DX_SECURITY_CONTEXT as a secret:
- Never print, log, serialize, return, or commit it.
- Never place a token directly in source code, notebooks, input JSON, job properties, tags, or command output.
- Never read or export the entire environment to locate the token.
- Use only the named DNAnexus credential supplied by the user or secret manager.
- Do not send it to any non-DNAnexus endpoint.
dx env and dx env --bash display the active token. Do not run either command in captured terminals, CI logs, support bundles, or agent output.
Interactive Login
Install dxpy, then authenticate:
dx login
dx whoami
dx select
dx pwddx login stores CLI state under ~/.dnanexus_config/. Use dx whoami and dx pwd to verify identity and project without exposing the token.
New login sessions under the normal security policy expire after two hours of inactivity and no later than 18 hours after issuance. Organization policies can shorten these limits. This includes UI, username/password CLI, and SSO sessions; API tokens and job tokens have separate lifetimes.
For SSO accounts, follow the organization's login/token workflow. User-generated API tokens cannot access resources in the UKB RAP region, including tokens issued before this restriction. Use the supported interactive session workflow there. Keep login interactive; avoid token values in shell history or transcripts.
Raw lines 20 to 43Token Login and Automation
The CLI supports dx login --token TOKEN, but placing the literal token on a command line can expose it through shell history or process inspection. Preferred automation:
- Where API tokens are supported, create a short-lived token in the DNAnexus UI under My Profile → API Tokens → New Token. Choose Selected projects and the minimum required access level for each project.
- Use a dedicated user/service identity with only the required project access.
- Store the complete security context in the CI or orchestration secret manager under the exact key
DX_SECURITY_CONTEXT. - Inject that single key directly into the process environment.
- Mask the key in logs and never enable shell tracing around authentication.
- Verify with
dx whoami; do not usedx env. - Remove the secret from the process environment when the operation ends.
DX_SECURITY_CONTEXT must contain JSON text, not a bare UI token. Its secret value has this shape:
{
"auth_token_type": "Bearer",
"auth_token": "<secret-token>"
}Have the secret manager inject the complete serialized object. Do not build or echo it in a traced shell command.
Tokens with All projects have the account's access across projects, including PHI data. Selected projects tokens limit access to the selected projects and levels; they cannot exceed the creating user's permissions. Some administrative APIs require a full-scope token even when the user has the relevant project access. A permission failure can therefore reflect token scope as well as project membership. Minimize both, and never broaden scope automatically to make a failing command work.
Tokens created without an explicit expiration expire after one month according to current platform guidance. Choose a shorter expiration whenever practical.
Raw lines 44 to 84Tool-specific variable names
dxanddxpyprimarily consume the JSONDX_SECURITY_CONTEXT.- The dx-toolkit shell bootstrap maps
DX_AUTH_TOKENintoDX_SECURITY_CONTEXTonly whenDX_SECURITY_CONTEXTis absent. - Download Agent (
dx-download-agent) checksDX_API_TOKEN; when absent, it falls back to~/.dnanexus_config/environment.json.
These names are all sensitive but are not generic substitutes in every tool. Inject only the variable required by the selected client, and never mirror one secret into multiple variables without a concrete compatibility need.
Raw lines 85 to 96Configuration Precedence
DNAnexus utilities resolve configuration in this order:
- Command-line overrides
- Environment variables already set in the shell
~/.dnanexus_config/environment.json- Built-in defaults
This means a stale DX_SECURITY_CONTEXT in the shell overrides a later interactive dx login. A login can appear successful while subsequent commands still use the older shell credential.
Diagnose a context mismatch safely
Use only non-secret commands:
dx whoami
dx pwdIf the shell environment should be discarded in favor of the saved CLI state:
source "$HOME/.dnanexus_config/unsetenv"
dx whoami
dx pwdIf the saved CLI state should be discarded instead:
dx clearenvDo not print either source to compare token values.
Raw lines 110 to 134Project Context
Select a project interactively:
dx select
dx pwdFor scripts, prefer explicit project IDs and full paths instead of relying on ambient context:
dx ls "project-xxxx:/input"
dx download "project-xxxx:/input/sample.bam" --output "sample.bam"In Python, pass project="project-xxxx" to searches, uploads, downloads when needed for billing context, and executable runs. Explicit context prevents a script from silently operating on the project selected in another terminal.
Execution-Environment Credentials
Jobs receive a job-scoped security context from the platform. dxpy and dx consume it automatically. App code normally should not parse DX_SECURITY_CONTEXT.
Within an Application Execution Environment:
- Use the system-provided API host and security context unchanged.
- Do not forward the job environment to child processes that do not require it.
- If a subprocess needs only local computation, pass a minimal allowlisted environment.
- Never upload environment dumps, crash reports containing environment values, or shell traces.
- Do not override the internal API host with a user-controlled hostname.
Job authorization is inherited from the root execution and can expire. Current documentation limits job authentication tokens to 30 days, which aligns with the normal maximum job runtime.
Raw lines 156 to 175Endpoint Safety
For normal external clients, DNAnexus uses official hosts such as:
api.dnanexus.comfor API callsauth.dnanexus.comfor authenticationplatform.dnanexus.comfor the web interface
Inside jobs, the platform may supply a private API address. Accept only the system-provided value. Do not build code that combines the token with an arbitrary URL.
Custom API server overrides are advanced administrative features. Use them only when the user identifies an approved DNAnexus deployment and explicitly asks for the override.
Raw lines 176 to 191Rotation, Logout, and Revocation
dx logout ends the CLI session. If the session used an API token, current documentation states that logout invalidates that token.
Revoke a token when:
- It may have been exposed.
- Its user or automation no longer needs access.
- The associated script or service has been retired.
- The underlying account permissions changed materially.
Revocation is disruptive: running jobs and active uploads/downloads authenticated by the token terminate immediately with AuthError; charges already incurred remain billable. Confirm affected executions and transfers before revoking unless emergency containment is required.
After suspected compromise:
- Stop exposing the credential.
- Identify active executions and transfers without printing the token.
- Rotate or revoke the token.
- Review project membership and recent executions.
- Reissue only a short-lived replacement.
Authentication Failure Checklist
For AuthError, PermissionDenied, or unexpected project visibility:
- Run
dx whoami. - Run
dx pwd. - Check whether a shell environment overrides saved CLI state.
- Confirm the object exists in the stated project and region.
- Confirm the account has the needed project level:
VIEWto readUPLOADto add dataCONTRIBUTEto run and modify project contentADMINISTERfor membership and administrative operations- Check token expiration or revocation. For scoped tokens, also check that the target project and operation are in scope; user-generated API tokens do not support UKB RAP access.
- Check organization/TRE policies and download restrictions.
- Reauthenticate only after preserving evidence needed to understand affected jobs or transfers.
Do not respond to authentication failures by broadening permissions automatically.
Raw lines 217 to 238