skills/dnanexus-integration/references/authentication.md
DNAnexus bearer tokens impersonate the user who created them. They inherit that
user's project access and can launch billable jobs. Treat
DX_SECURITY_CONTEXT as a secret:
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.
Install dxpy, then authenticate:
dx login
dx whoami
dx select
dx pwd
dx login stores CLI state under ~/.dnanexus_config/. Use dx whoami and
dx pwd to verify identity and project without exposing the token.
For SSO accounts, create an API token in My Profile → API Tokens if required by the organization. Keep the login prompt interactive; avoid putting token values in shell history or transcripts.
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:
DX_SECURITY_CONTEXT.dx whoami; do not use dx env.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.
Standard user API tokens inherit the creating user's project access; they are not independently project-scoped. Minimize the dedicated identity's project memberships and access levels before issuing its token. If an organization provides a more restricted credential mechanism, prefer the narrowest available scope.
Tokens created without an explicit expiration expire after one month according to current platform guidance. Choose a shorter expiration whenever practical.
dx and dxpy primarily consume the JSON DX_SECURITY_CONTEXT.DX_AUTH_TOKEN into
DX_SECURITY_CONTEXT only when DX_SECURITY_CONTEXT is absent.dx-download-agent) checks DX_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.
DNAnexus utilities resolve configuration in this order:
~/.dnanexus_config/environment.jsonThis 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.
Use only non-secret commands:
dx whoami
dx pwd
If the shell environment should be discarded in favor of the saved CLI state:
source "$HOME/.dnanexus_config/unsetenv"
dx whoami
dx pwd
If the saved CLI state should be discarded instead:
dx clearenv
Do not print either source to compare token values.
Select a project interactively:
dx select
dx pwd
For 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.
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:
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.
For normal external clients, DNAnexus uses official hosts such as:
api.dnanexus.com for API callsauth.dnanexus.com for authenticationplatform.dnanexus.com for the web interfaceInside 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.
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:
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:
For AuthError, PermissionDenied, or unexpected project visibility:
dx whoami.dx pwd.VIEW to readUPLOAD to add dataCONTRIBUTE to run and modify project contentADMINISTER for membership and administrative operationsDo not respond to authentication failures by broadening permissions automatically.