Token Authentication
Token authentication uses a shared secret to authenticate requests to Gitaly. This is the recommended authentication method for most deployments.Configuring Authentication Tokens
Generate a secure token
Generate a secure random token. You can use OpenSSL or any secure random generator:This will output a 64-character hexadecimal string like:
Configure Gitaly server
Add the authentication token to your Gitaly configuration file (
config.toml):Configure GitLab to use the token
Update your GitLab configuration to include the same token. In your GitLab configuration:For Omnibus installations, edit For source installations, edit
/etc/gitlab/gitlab.rb:config/gitlab.yml:Authentication Configuration Options
The shared secret token used to authenticate requests. This should be a long, random string.
Set to
true to temporarily allow unauthenticated requests while rolling out authentication. This is useful during deployment to avoid downtime.TLS Authentication
For additional security, especially when Gitaly is accessed over TCP, you should configure TLS encryption.Generating TLS Certificates
Generate a certificate signing request
Create a CSR with your server details:Fill in the prompted information, ensuring the Common Name (CN) matches your server’s hostname or IP.
Generate a self-signed certificate
For development or internal use, generate a self-signed certificate:
For production environments, obtain a certificate from a trusted Certificate Authority (CA).
Configuring TLS
Add TLS configuration to your Gitalyconfig.toml:
The address and port where Gitaly listens for TLS connections.
Path to the TLS certificate file.
Path to the TLS private key file.
Configuring GitLab for TLS
When using TLS, update your GitLab configuration to connect to Gitaly over TLS: For Omnibus installations, edit/etc/gitlab/gitlab.rb:
Security Best Practices
Use strong tokens
Use strong tokens
Always generate tokens with sufficient entropy. Use at least 32 bytes (64 hex characters) for production systems:
Rotate tokens regularly
Rotate tokens regularly
Implement a token rotation policy. Use the
transitioning flag to enable a gradual rollout:- Add new token with
transitioning = true - Update all clients with the new token
- Set
transitioning = falseonce all clients are updated - Remove the old token
Use TLS for remote connections
Use TLS for remote connections
Always use TLS when Gitaly is accessed over a network. Token authentication alone does not encrypt traffic.
Restrict network access
Restrict network access
Use firewall rules to restrict access to Gitaly ports. Only allow connections from trusted GitLab application servers.
Secure file permissions
Secure file permissions
Ensure configuration files containing tokens and TLS keys have restrictive permissions:
Monitor authentication failures
Monitor authentication failures
Enable logging and monitor for authentication failures which may indicate unauthorized access attempts:
Transitioning to Authenticated Mode
If you’re adding authentication to an existing Gitaly installation, use the transitioning mode to avoid downtime:Enable transitioning mode
Set Restart Gitaly. It will now accept both authenticated and unauthenticated requests.
transitioning = true in Gitaly’s configuration:Verify client connections
Monitor logs to ensure all clients are successfully authenticating with the token.
Troubleshooting
Authentication Failed Errors
If you see authentication errors:- Verify token matches: Ensure the token in Gitaly’s config matches the token in GitLab’s config
- Check for whitespace: Tokens should not have leading/trailing whitespace
- Verify file permissions: Ensure Gitaly can read its configuration file
- Check logs: Review Gitaly logs at the configured log directory
TLS Connection Errors
If TLS connections fail:- Verify certificate paths: Ensure certificate and key files exist and are readable
- Check certificate validity: Verify the certificate hasn’t expired
- Verify hostname: The certificate’s CN should match the hostname clients use to connect
- Check firewall: Ensure the TLS port (default 8888) is accessible
Testing Authentication
You can test authentication usinggrpcurl (if available):
Related Configuration
Configuration Reference
View all Gitaly configuration options
Storage Configuration
Configure Git repository storage