k6 login
Authenticate with cloud services for k6.Synopsis
Description
Thek6 login command authenticates k6 with cloud services. Currently, it supports:
- Grafana Cloud k6 (via
k6 cloud login) - InfluxDB Cloud (via
k6 login influxdb)
Grafana Cloud k6 Login
Synopsis
Description
Authenticates with Grafana Cloud k6 using an interactive browser flow. This is the recommended method for authentication.Examples
Flags
Provide an API token directly instead of using browser authentication
Authentication Flow
- Run
k6 cloud login - Your browser opens to the Grafana Cloud authentication page
- Log in or sign up for Grafana Cloud
- Select or create a stack
- Your credentials are saved locally
- You can now run
k6 cloud runwithout additional authentication
Token Storage
Authentication tokens are stored in:- Linux/macOS:
~/.config/k6/cloud.json - Windows:
%APPDATA%\k6\cloud.json
Alternative Authentication Methods
Environment Variable
Set the token via environment variable:Script Configuration
Embed in your test script:Obtaining API Tokens
To manually obtain a Grafana Cloud k6 API token:- Go to Grafana Cloud
- Navigate to your k6 organization
- Go to Settings → API Tokens
- Create a new token with appropriate permissions
- Copy the token and use it with
k6 cloud login --token YOUR_TOKEN
Stack and Project Configuration
After logging in, k6 stores:- Stack ID: Your Grafana Cloud k6 instance
- Default Project ID: Default project for organizing tests
InfluxDB Cloud Login (Deprecated)
Synopsis
Troubleshooting
Authentication Failed
If authentication fails:- Clear stored credentials:
rm ~/.config/k6/cloud.json - Try logging in again:
k6 cloud login - Check your internet connection
- Verify you have access to Grafana Cloud
Token Not Working
If your token isn’t working:- Verify the token hasn’t expired
- Check the token has correct permissions
- Regenerate the token in Grafana Cloud
- Try logging in again:
k6 cloud login --token NEW_TOKEN
Browser Doesn’t Open
If the browser doesn’t open automatically:- Copy the URL from the terminal
- Open it manually in your browser
- Complete the authentication
- The CLI will detect the successful authentication
Security Best Practices
- Never share tokens - They provide full access to your k6 account
- Use environment variables - Don’t hardcode tokens in scripts
- Rotate tokens regularly - Create new tokens periodically
- Use project-specific tokens - Limit token scope when possible
- Store securely - Use secret management tools in CI/CD
Environment Variables
Grafana Cloud k6 authentication token
Grafana Cloud k6 API host
Stack ID for the Grafana Cloud instance
Default project ID for organizing tests
See Also
- k6 cloud - Run tests in Grafana Cloud
- Environment variables
- Grafana Cloud k6 Documentation