A Nexus Repository instance holds the packages every build trusts and the credentials every pipeline uses to publish them, so the way users, tokens and roles are set up decides who can change what ships to production. Most access to a repository manager is non-human: CI jobs, build tools and container runtimes pulling and pushing components with stored credentials. This guide covers how authentication realms, user tokens, service account tokens, roles and privileges work in Sonatype Nexus Repository 3, how to lock down administration, which settings to change after installation, and what to log. It is for platform engineers, DevOps teams and the security teams who review them. For the wider supply chain view, see the Software Supply Chain Security Guide.
This is an independent guide from NHI Mgmt Group, based on Sonatype's public documentation as of November 2026. It is not sponsored or reviewed by Sonatype. Product features change, so confirm settings against Sonatype's current documentation.
Key takeaways
- Close the post-install defaults first. Change the initial
adminpassword from theadmin.passwordfile, decide on anonymous access in the setup wizard, and replace the default admin email. - Give pipelines tokens, not passwords. Service account tokens (from 3.97.0) and user tokens keep directory passwords out of
settings.xml,.npmrcand CI variables, and both can expire and be revoked. - Turn off anonymous read for production. Sonatype's own best practice is to disable it, or attach a custom role that names only the repositories that must be public.
- Build roles from repository-view privileges. Grant
addandeditonly on the hosted repositories a team publishes to, and treatnx-allandnexus:users:updateas administrator rights. - Keep the audit log and scripting defaults. The Audit capability is on by default and Groovy scripting is off by default; keep both that way and forward
audit.logto your SIEM.
How identity and access work in Sonatype Nexus Repository
Nexus Repository 3 separates authentication, handled by realms, from authorisation, handled by roles made of privileges. Every request, from the web UI, the REST API or a build tool, is authenticated by one of the active realms and then checked against the roles mapped to that user.
Realms
Realms are activated and ordered under Security then Realms. Order decides which realm wins when the same user name exists in more than one. Sonatype advises keeping the Local Authenticating Realm at the top of the active list, so the local administrator can always sign in, and never removing every realm, which locks everyone out.
| Realm | What it authenticates | When to activate |
|---|---|---|
| Local Authenticating Realm | Users stored in Nexus | Always, at the top, for the administrator and break-glass access |
| LDAP Realm | Directory users over ldap (389) or ldaps (636) | Where users come from a directory; use ldaps |
| SAML Realm | Browser single sign-on through an identity provider | For interactive users, together with user tokens for build tools |
| Crowd Realm, OAuth2 Realm | Users from Atlassian Crowd or an OAuth2 provider | Only where that is the organisation's identity source |
| User Token Realm | Per-user token name and pass code | For build tools used by people, especially with SAML |
Service Account Realm (ServiceAccountRealm) | Service account tokens | For CI/CD and other applications |
Docker Bearer Token Realm (DockerToken) | Docker client logins | When Docker repositories are used; also needed for anonymous Docker pull |
npm Bearer Token Realm (NpmToken) | npm login and npm publishing tokens | When npm repositories are used |
NuGet API-Key Realm (NuGetApiKey) | NuGet API keys for deployment | When publishing to NuGet repositories |
Availability: Sonatype marks the SAML, Crowd, OAuth2 and User Token realms as Pro features, and lists service account tokens for Nexus Repository Pro, Pro+ and Sonatype Cloud. Activate only the realms that match your licence and the formats you host.
Roles and privileges
- Repository View privileges: created automatically for each format and repository, named
nx-repository-view-{format}-{repository}-{action}. Actions arebrowse(see in UI and search),read(download),edit,add(upload) anddelete. - Repository Admin privileges: control the configuration of repositories, separate from their content.
- Repository Content Selector privileges: limit access to content matching a selector expression, such as one team's namespace in a shared repository.
- Application privileges: control UI and API features such as users, roles, realms and settings.
- Wildcard and script privileges:
nx-allgrantsnexus:*, and script privileges control the Groovy script APIs. - Admin-equivalent rights: Sonatype warns that
nexus:users:updatelets a user change roles, including their own, so it is as powerful asnx-admin.
Admin roles and privileged access
- Secure the initial administrator: the first
adminpassword is written toadmin.passwordin the data directory and must be changed before the setup wizard or REST API can be used. Set a long unique password, store it in a vault and replace the default admin email address. - Use a central identity source for people: Nexus supports LDAP, SAML and Crowd realms; we recommend one of them over local user management. For LDAP, use
ldaps; Sonatype advises against simple authentication without it in production because passwords travel in clear text. Use a bind user with read access only to the users and groups Nexus needs. See the LDAP Security Deep Dive Guide or the SAML Security Guide. - Map groups to roles: when an LDAP or SAML group matches a Nexus role ID, members receive that role. Keep administrator membership in one small directory group and review it each quarter.
- Keep administration local and rare: keep the Local Authenticating Realm above SAML so administrators can sign in if the identity provider is down, but treat the local
adminaccount as break-glass. See the Break-Glass Account Guide. - Separate operational duties: create roles for repository administration, security administration (users, roles, realms, tokens) and read-only support, rather than giving
nx-adminto everyone who manages repositories. Keepnx-usertoken-users(reset other users' tokens) andnx-sa-adminwith the security role. - Enforce local password rules: set
nexus.password.validator(a regular expression) andnexus.password.validator.messageinnexus.propertiesfor any remaining local users. - Keep login rate limiting on: authentication attempt rate limiting is enabled by default, starting after 3 consecutive failures with a 30 second base delay rising to 900 seconds, set by the
nexus.auth.ratelimit.*properties. - Design for granting, not restricting: Sonatype advises against negative content selectors, which are slow and easily overridden by other permissions. Use team-specific hosted repositories where read access must be restricted.
Integrations, API tokens and service accounts
Pipelines, build agents and deployment tools are the heaviest users of a repository manager. Each is a non-human identity that can publish components everyone else then trusts. See the CI/CD Pipeline Identity Security Guide.
Choosing a credential type
| Credential | Best fit | Lifetime and control |
|---|---|---|
| Service account token | CI/CD jobs and applications | Tied to one role; expiry of 30, 60 or 90 days, 1 year or Never; shown once; revocation takes effect immediately |
| User token | A person's Maven, npm, Docker or curl client, especially with SAML | Optional expiry from 3.69.0 (default 30 days when turned on, 1 to 999 days); reset per user or for all users |
| Local or directory password | Interactive UI sign-in only | Governed by the directory or the local password rules |
| npm bearer token, NuGet API key | Format-specific publishing | Issued through the matching realm; rotate with the publishing account |
- Service account tokens for pipelines: create them under Settings, Security, Service Account Tokens, after activating
ServiceAccountRealm. Clients authenticate with the service account name and the passwordsat.{token}, or a bearer header for some formats. Sonatype's guidance: store tokens in a secrets manager, never commit them, prefer time-limited tokens, use Never sparingly, give the least-privileged role, and revoke unused tokens. - One token per pipeline and purpose: separate tokens for read-only dependency resolution and for publishing to a hosted repository, each with its own role, so a leaked read token cannot publish.
- User tokens for people: enable them under Settings, User Token (needs
nx-usertoken-settings), and turn on Require user tokens for repository authentication so repository URLs accept only tokens. Sonatype notes this option does not work for Docker when anonymous Docker pull is enabled. - Plan expiry before turning it on: user token expiry is measured from each token's creation date, so existing tokens older than the limit expire immediately. Warn teams and update CI settings first.
- Keep tokens out of files in repositories: Maven reads the token from the
serversection ofsettings.xmland npm from.npmrc. Inject these at build time from a secrets store. See the Secrets Management Guide. - Scripts and the REST API: Groovy scripting has been off by default since 3.21.2,
nexus.scripts.allowCreationdefaults tofalse, and Sonatype has announced Groovy scripting end of life for December 2026. Automate with the REST API and a service account token instead.
Logging and detection
The Audit capability is created and enabled by default and writes one JSON object per line to $data-dir/log/audit/audit.log, rotated daily with up to 90 days kept. Each entry records the initiator, domain, type and context. Forward it to a SIEM so the record survives a compromise of the server.
| Event to watch | Where it shows | Why it matters |
|---|---|---|
| New users, role changes, realm changes | audit.log security domain entries | Persistence or privilege escalation inside Nexus |
| Service account token creation, especially with expiry Never | audit.log | Long-lived pipeline credentials outside the standard |
| Anonymous access or SSL truststore changes | audit.log | Exposure of private content or trust of an unexpected upstream |
| Components added to or removed from release repositories | audit.log component and asset entries | Unexpected publishing, overwrites or deletions |
| Routing rule or proxy remote URL changes | audit.log | Upstream redirection that could pull untrusted packages |
| Repeated failed logins and rate limiting | Application and reverse proxy logs | Password guessing or a broken pipeline credential |
Metrics that show it is working
- Percentage of pipeline access using service account or user tokens rather than passwords.
- Number of service account tokens with expiry Never (target near zero, each with an exception).
- Number of users holding
nx-admin,nx-allornexus:users:update. - Percentage of proxy repositories with HTTPS remotes and an assigned routing rule.
- Days since the last review of roles and of the anonymous role.
Hardening baseline
| Area | Setting | Baseline |
|---|---|---|
| Initial admin | admin.password | Changed at first login, vaulted, default email replaced |
| Anonymous access | Allow anonymous users to access the server | Off for production; otherwise a custom role limited to named repositories |
| Default role | Role granted to all authenticated users | No more than read on shared repositories |
| Inbound TLS | Reverse proxy, or Jetty application-port-ssl with jetty-https.xml | HTTPS only; remove jetty-http.xml from nexus-args when Nexus terminates TLS; Base URL set to https |
| Outbound TLS | Proxy remote URLs, SSL Certificates truststore | HTTPS remotes only, as Sonatype advises; add internal CAs through the truststore |
| Upstream scope | Routing rules on proxy repositories | ALLOW rules for the namespaces you need; test with Test Path; keep regular expressions simple |
| Scripting | nexus.scripts.allowCreation | Left at false |
| Rate limiting | nexus.auth.ratelimit.enabled | Left at true |
| Audit | Audit capability | Enabled and forwarded off the host |
| Backups | Scheduled backup procedure | Configuration and blob stores backed up and restore-tested |
Rollout plan
- Inventory: export users, roles, realms, anonymous settings, proxy remotes and every credential configured in CI that points at Nexus.
- Test instance: restore a backup to a test server and trial realm order, SAML, token settings and routing rules there rather than in production, the approach Sonatype recommends for testing scripts.
- Introduce tokens: issue service account tokens per pipeline and user tokens per person, and move CI to them while passwords still work.
- Enforce: turn on Require user tokens for repository authentication and token expiry, then disable anonymous access, after notifying teams.
- Tighten roles: replace broad roles with repository-scoped ones and remove stale users. Roll back by restoring the previous role assignment from your export if builds fail.
- Keep current: apply Sonatype's security updates promptly and follow Sonatype's security advisories.
Framework mapping
| Nexus control | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | ATT&CK technique addressed |
|---|---|---|---|
| Repository-scoped roles, content selectors | AC-6, CM-5 | PR.AA-05 | T1195.002 Compromise Software Supply Chain |
| Central realms, group mapping, account reviews | AC-2, IA-2, IA-4 | PR.AA-05 | T1078 Valid Accounts |
| Service account and user tokens with expiry | IA-5 | PR.AA-05 | T1552.001 Credentials In Files |
| Rate limiting | IA-5 | PR.AA-05 | T1110 Brute Force |
| Routing rules, HTTPS remotes | SR-3, SR-11, SC-8 | GV.SC-07 | T1195.002 Compromise Software Supply Chain |
| Audit log forwarded to SIEM | AU-2, AU-6, AU-9 | PR.PS-04, DE.CM-09 | T1078 Valid Accounts |
| Scripting off, anonymous access off, backups | CM-6, CM-7 | PR.PS-01, PR.DS-01 | T1195.002 Compromise Software Supply Chain |
Common misconfigurations
- Anonymous read left on after installation: anonymous read stays on until it is configured in the wizard, and the built-in anonymous role reads every repository. Turn it off or attach a narrow custom role.
- Directory passwords in build files: a developer's LDAP password in
settings.xmlor.npmrcunlocks far more than Nexus. Replace it with a user token or service account token. - One shared deploy account for every pipeline: a leak from any job can publish to every release repository, and the audit log cannot tell jobs apart. Issue one token per pipeline with its own role.
- Service account tokens set to Never by default: use expiring tokens and rotate them from the secrets manager; keep Never for documented exceptions.
- Proxy repositories with no routing rules: an unrestricted proxy can fetch any public name, including one that collides with an internal package. Add ALLOW rules for expected namespaces. See the Malicious Package and Dependency Confusion Guide.
- Local Authenticating Realm moved below SAML or removed: administrators can be locked out when the identity provider fails, and recovery is difficult. Keep it at the top.
Practitioner checklist
- Change and vault the initial
adminpassword and replace the default admin email. - Disable anonymous access, or assign a custom role limited to named public repositories.
- Activate only the realms you need, with the Local Authenticating Realm at the top; use
ldapsor SAML for people. - Create repository-scoped roles; limit
nx-admin,nx-allandnexus:users:updateto a small group. - Issue one expiring service account token per pipeline and purpose, stored in a secrets manager.
- Enable user tokens, require them for repository URLs and set token expiry.
- Serve Nexus over HTTPS only and use HTTPS for every proxy remote.
- Assign routing rules to proxy repositories for the namespaces you use.
- Keep scripting off, rate limiting on and the audit log forwarded to your SIEM.
- Back up configuration and blob stores, test restores, and apply Sonatype security updates promptly.
Standards and references
- Sonatype: Realms
- Sonatype: Service Account Tokens
- Sonatype: User Tokens
- Sonatype: Privileges
- Sonatype: Administration Best Practices
- Sonatype: Post Install Checklist
- Sonatype: Auditing
- Sonatype: Routing Rules
Related NHI Mgmt Group resources: Malicious Package and Dependency Confusion Guide · CI/CD Pipeline Identity Security Guide · Service Account Security Guide · Software Supply Chain Security Guide