Overview
Each System-X service has an associatedAccount class that contains connection information. For external services (like AWS, Salesforce, Twitter), credentials should not be hardcoded. TNB’s AccountFactory automatically loads credentials from configured sources.
Self-hosted services (Kafka, MongoDB, PostgreSQL) use hardcoded credentials by default since they’re deployed by TNB. External services require credential configuration.
Credential loading methods
TNB supports three methods for loading credentials, with the following priority:Using YAML credentials file
The simplest method for local development is using a YAML credentials file.File format
Create a YAML file with the following structure:The credentials ID (like
aws, jira) must match the ID returned by the account’s credentialsId() method.Configuring the credentials file
Specify the path to your credentials file:- test.properties
- System property
- Environment variable
Field naming conventions
YAML field names must match the Java account class field names exactly:Using HashiCorp Vault
For production environments, use HashiCorp Vault to securely store credentials.Vault structure
Store credentials in Vault with the same YAML structure:Configuration
Configure Vault access with these properties:- Token authentication
- AppRole authentication
%s in the path pattern is replaced with the credentials ID (e.g., aws, jira).Vault path patterns
The path pattern determines where credentials are stored in Vault:| Pattern | Example resolution for aws |
|---|---|
/secret/services/%s/credentials | /secret/services/aws/credentials |
/kv/data/%s | /kv/data/aws |
/team/shared/%s/creds | /team/shared/aws/creds |
Using system property credentials
For CI/CD pipelines, pass credentials as a YAML string in system properties:This method uses the same YAML format as the credentials file, but passed as a string.
Overriding account IDs
Each account has a default credentials ID. Override it using a system property:tnb.<AccountClassName>.id
- credentials.yaml
- test.properties
Composite accounts
Composite accounts allow credential inheritance from parent account classes.How it works
When creating an account, TNB checks all parent classes for theWithId interface and merges credentials:
ChildAccount, TNB:
- Loads credentials from
parentID - Merges credentials from
childID - Result: both
parentKeyandchildKeyare populated
Partial credentials
At least one credentials ID must exist. You can provide all values under one ID:Loading credentials in code
UseAccountFactory to load credentials automatically:
If the account doesn’t implement
WithId, AccountFactory.create() returns an instance with default values and no credential loading.TNB CLI credential management
The TNB CLI tool has special credential handling:Credential request
When deploying a service that needs credentials, the CLI prompts you to enter them interactively if not found.
Security best practices
Never commit credentials
Add credentials files to
.gitignore. Use template files to document required structure.Use Vault for production
Always use HashiCorp Vault or similar secret management for production and shared environments.
Rotate credentials
Regularly rotate credentials, especially after team member changes or potential exposure.
Minimal permissions
Use service accounts with minimal required permissions instead of personal credentials.
Separate environments
Use different credentials for development, staging, and production environments.
Environment variables
In CI/CD, inject credentials via environment variables, never hardcode in pipeline definitions.
Troubleshooting
Could not load credentials error
Could not load credentials error
Ensure the credentials ID matches between your account’s
credentialsId() method and your YAML file or Vault path.Check that the credentials file path is correct and the file exists:Field names don't match
Field names don't match
Verify that YAML field names exactly match the Java account class field names (including underscores).Use the same case and naming convention:
Vault authentication fails
Vault authentication fails
Verify your Vault token is valid:Check the Vault path exists and you have read permissions:
Composite account issues
Composite account issues
Remember that at least one credentials ID (parent or child) must exist in your credentials source.Check that parent classes implementing
WithId have credentials defined if using inheritance.Example configurations
- Local development
- CI/CD with Vault
- Multi-environment
credentials.yaml
test.properties